List of usage examples for org.springframework.amqp.support.converter DefaultClassMapper DEFAULT_CLASSID_FIELD_NAME
String DEFAULT_CLASSID_FIELD_NAME
To view the source code for org.springframework.amqp.support.converter DefaultClassMapper DEFAULT_CLASSID_FIELD_NAME.
Click Source Link
From source file:amqp.spring.converter.XStreamConverter.java
@Override protected Message createMessage(Object object, MessageProperties messageProperties) { try {/*from w w w .jav a 2s.c o m*/ byte[] body = null; if (object != null) { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); StaxWriter writer = new StaxWriter(new QNameMap(), this.outputFactory.createXMLStreamWriter(outStream)); this.objectMapper.marshal(object, writer); body = outStream.toByteArray(); } messageProperties.setContentType(MessageProperties.CONTENT_TYPE_JSON); messageProperties.setContentEncoding(this.encoding); messageProperties.setContentLength(body != null ? body.length : 0); classMapper.fromClass(object.getClass(), messageProperties); return new Message(body, messageProperties); } catch (XMLStreamException ex) { String typeId = (String) messageProperties.getHeaders() .get(DefaultClassMapper.DEFAULT_CLASSID_FIELD_NAME); LOG.error("XMLStreamException trying to marshal message of type {}", typeId, ex); throw new MessageConversionException("Could not marshal 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 marshal message of type {}", typeId, ex); throw new MessageConversionException("Could not marshal message of type " + typeId, ex); } }
From source file:amqp.spring.converter.XStreamConverter.java
@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 {//from w w w . j av a2 s.co m 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); } }