@Override
public Object fromMessage(Message message) throws MessageConversionException {
MessageProperties messageProperties = message.getMessageProperties();
if(messageProperties == null)
throw new MessageConversionException("Cannot decode a message with no properties!");
byte[] body = message.getBody();
if(body == null)
return null;
String messageEncoding = messageProperties.getContentEncoding();
if(messageEncoding == null)
messageEncoding = getEncoding();
String contentType = messageProperties.getContentType();
if(! MessageProperties.CONTENT_TYPE_JSON.equalsIgnoreCase(contentType))
throw new MessageConversionException("Cannot understand a message of type "+contentType);
try {
ByteArrayInputStream inStream = new ByteArrayInputStream(body);
StaxReader reader = new StaxReader(new QNameMap(), this.inputFactory.createXMLStreamReader(inStream, messageEncoding));
return this.objectMapper.unmarshal(reader);
} catch (XMLStreamException ex) {
String typeId = (String) messageProperties.getHeaders().get(DefaultClassMapper.DEFAULT_CLASSID_FIELD_NAME);
LOG.error("XMLStreamException trying to unmarshal message of type {}", typeId, ex);
throw new MessageConversionException("Could not unmarshal message of type "+typeId, ex);
} catch (XStreamException ex) {
//For some reason messages appear to be getting eaten at this stage... very nasty when you try to troubleshoot.
String typeId = (String) messageProperties.getHeaders().get(DefaultClassMapper.DEFAULT_CLASSID_FIELD_NAME);
LOG.error("XStreamException trying to unmarshal message of type {}", typeId, ex);
throw new MessageConversionException("Could not unmarshal message of type "+typeId, ex);
}
}