Java Code Examples for org.springframework.oxm.Marshaller#marshal()

The following examples show how to use org.springframework.oxm.Marshaller#marshal() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MarshallingMessageConverter.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * Marshal the given object to a {@link TextMessage}.
 * @param object the object to be marshalled
 * @param session current JMS session
 * @param marshaller the marshaller to use
 * @return the resulting message
 * @throws JMSException if thrown by JMS methods
 * @throws IOException in case of I/O errors
 * @throws XmlMappingException in case of OXM mapping errors
 * @see Session#createTextMessage
 * @see Marshaller#marshal(Object, Result)
 */
protected TextMessage marshalToTextMessage(Object object, Session session, Marshaller marshaller)
		throws JMSException, IOException, XmlMappingException {

	StringWriter writer = new StringWriter();
	Result result = new StreamResult(writer);
	marshaller.marshal(object, result);
	return session.createTextMessage(writer.toString());
}
 
Example 2
Source File: MarshallingMessageConverter.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * Marshal the given object to a {@link BytesMessage}.
 * @param object the object to be marshalled
 * @param session current JMS session
 * @param marshaller the marshaller to use
 * @return the resulting message
 * @throws JMSException if thrown by JMS methods
 * @throws IOException in case of I/O errors
 * @throws XmlMappingException in case of OXM mapping errors
 * @see Session#createBytesMessage
 * @see Marshaller#marshal(Object, Result)
 */
protected BytesMessage marshalToBytesMessage(Object object, Session session, Marshaller marshaller)
		throws JMSException, IOException, XmlMappingException {

	ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
	StreamResult streamResult = new StreamResult(bos);
	marshaller.marshal(object, streamResult);
	BytesMessage message = session.createBytesMessage();
	message.writeBytes(bos.toByteArray());
	return message;
}
 
Example 3
Source File: MarshallingMessageConverter.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * Marshal the given object to a {@link TextMessage}.
 * @param object the object to be marshalled
 * @param session current JMS session
 * @param marshaller the marshaller to use
 * @return the resulting message
 * @throws JMSException if thrown by JMS methods
 * @throws IOException in case of I/O errors
 * @throws XmlMappingException in case of OXM mapping errors
 * @see Session#createTextMessage
 * @see Marshaller#marshal(Object, Result)
 */
protected TextMessage marshalToTextMessage(Object object, Session session, Marshaller marshaller)
		throws JMSException, IOException, XmlMappingException {

	StringWriter writer = new StringWriter();
	Result result = new StreamResult(writer);
	marshaller.marshal(object, result);
	return session.createTextMessage(writer.toString());
}
 
Example 4
Source File: MarshallingMessageConverter.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * Marshal the given object to a {@link BytesMessage}.
 * @param object the object to be marshalled
 * @param session current JMS session
 * @param marshaller the marshaller to use
 * @return the resulting message
 * @throws JMSException if thrown by JMS methods
 * @throws IOException in case of I/O errors
 * @throws XmlMappingException in case of OXM mapping errors
 * @see Session#createBytesMessage
 * @see Marshaller#marshal(Object, Result)
 */
protected BytesMessage marshalToBytesMessage(Object object, Session session, Marshaller marshaller)
		throws JMSException, IOException, XmlMappingException {

	ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
	StreamResult streamResult = new StreamResult(bos);
	marshaller.marshal(object, streamResult);
	BytesMessage message = session.createBytesMessage();
	message.writeBytes(bos.toByteArray());
	return message;
}
 
Example 5
Source File: MarshallingMessageConverter.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * Marshal the given object to a {@link TextMessage}.
 * @param object the object to be marshalled
 * @param session current JMS session
 * @param marshaller the marshaller to use
 * @return the resulting message
 * @throws JMSException if thrown by JMS methods
 * @throws IOException in case of I/O errors
 * @throws XmlMappingException in case of OXM mapping errors
 * @see Session#createTextMessage
 * @see Marshaller#marshal(Object, Result)
 */
protected TextMessage marshalToTextMessage(Object object, Session session, Marshaller marshaller)
		throws JMSException, IOException, XmlMappingException {

	StringWriter writer = new StringWriter();
	Result result = new StreamResult(writer);
	marshaller.marshal(object, result);
	return session.createTextMessage(writer.toString());
}
 
Example 6
Source File: MarshallingMessageConverter.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * Marshal the given object to a {@link BytesMessage}.
 * @param object the object to be marshalled
 * @param session current JMS session
 * @param marshaller the marshaller to use
 * @return the resulting message
 * @throws JMSException if thrown by JMS methods
 * @throws IOException in case of I/O errors
 * @throws XmlMappingException in case of OXM mapping errors
 * @see Session#createBytesMessage
 * @see Marshaller#marshal(Object, Result)
 */
protected BytesMessage marshalToBytesMessage(Object object, Session session, Marshaller marshaller)
		throws JMSException, IOException, XmlMappingException {

	ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
	StreamResult streamResult = new StreamResult(bos);
	marshaller.marshal(object, streamResult);
	BytesMessage message = session.createBytesMessage();
	message.writeBytes(bos.toByteArray());
	return message;
}