| Method from org.springframework.oxm.support.MarshallingMessageConverter Detail: |
public void afterPropertiesSet() throws Exception {
Assert.notNull(marshaller, "Property 'marshaller' is required");
Assert.notNull(unmarshaller, "Property 'unmarshaller' is required");
}
|
public Object fromMessage(Message message) throws JMSException, MessageConversionException {
try {
if (message instanceof TextMessage) {
TextMessage textMessage = (TextMessage) message;
return unmarshalFromTextMessage(textMessage, unmarshaller);
}
else if (message instanceof BytesMessage) {
BytesMessage bytesMessage = (BytesMessage) message;
return unmarshalFromBytesMessage(bytesMessage, unmarshaller);
}
else {
return unmarshalFromMessage(message, unmarshaller);
}
}
catch (UnmarshallingFailureException ex) {
throw new MessageConversionException("Could not unmarshal message [" + message + "]", ex);
}
catch (IOException ex) {
throw new MessageConversionException("Could not unmarshal message [" + message + "]", ex);
}
}
Unmarshals the given Message into an object. |
protected BytesMessage marshalToBytesMessage(Object object,
Session session,
Marshaller marshaller) throws JMSException, IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
StreamResult streamResult = new StreamResult(bos);
marshaller.marshal(object, streamResult);
BytesMessage message = session.createBytesMessage();
message.writeBytes(bos.toByteArray());
return message;
}
|
protected Message marshalToMessage(Object object,
Session session,
Marshaller marshaller) throws JMSException, IOException {
throw new MessageConversionException(
"Unknown 'marshalTo' value [" + marshalTo + "]. Cannot convert object to Message");
}
|
protected TextMessage marshalToTextMessage(Object object,
Session session,
Marshaller marshaller) throws JMSException, IOException {
StringResult result = new StringResult();
marshaller.marshal(object, result);
return session.createTextMessage(result.toString());
}
|
public void setMarshalTo(int marshalTo) {
this.marshalTo = marshalTo;
}
|
public void setMarshaller(Marshaller marshaller) {
this.marshaller = marshaller;
}
Sets the Marshaller to be used by this message converter. |
public void setUnmarshaller(Unmarshaller unmarshaller) {
this.unmarshaller = unmarshaller;
}
|
public Message toMessage(Object object,
Session session) throws JMSException, MessageConversionException {
try {
switch (marshalTo) {
case MARSHAL_TO_TEXT_MESSAGE:
return marshalToTextMessage(object, session, marshaller);
case MARSHAL_TO_BYTES_MESSAGE:
return marshalToBytesMessage(object, session, marshaller);
default:
return marshalToMessage(object, session, marshaller);
}
}
catch (MarshallingFailureException ex) {
throw new MessageConversionException("Could not marshal [" + object + "]", ex);
}
catch (IOException ex) {
throw new MessageConversionException("Could not marshal [" + object + "]", ex);
}
}
|
protected Object unmarshalFromBytesMessage(BytesMessage message,
Unmarshaller unmarshaller) throws JMSException, IOException {
byte[] bytes = new byte[(int) message.getBodyLength()];
message.readBytes(bytes);
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
StreamSource source = new StreamSource(bis);
return unmarshaller.unmarshal(source);
}
|
protected Object unmarshalFromMessage(Message message,
Unmarshaller unmarshaller) throws JMSException, IOException {
throw new MessageConversionException(
"MarshallingMessageConverter only supports TextMessages and BytesMessages");
}
|
protected Object unmarshalFromTextMessage(TextMessage message,
Unmarshaller unmarshaller) throws JMSException, IOException {
StringSource source = new StringSource(message.getText());
return unmarshaller.unmarshal(source);
}
|