Hello,
I wanted to have some sample code for custom MessageConverter for marshalling/unmarshalling to/from XML using jaxb or xstream. Does anyone have a sample that you can share?
Hello,
I wanted to have some sample code for custom MessageConverter for marshalling/unmarshalling to/from XML using jaxb or xstream. Does anyone have a sample that you can share?
Here is an implementation of JaxbMessageConverter that rely on Spring WS Jaxb2Marshaller.
We decided to rely on Jaxb2Marshaller to to leverage all the customization available in this marshaller, in particular all the schema based validation mechanism.
Code
Code is available on Xebia's demo subversion repository : http://xebia-france.googlecode.com/s...essaging-demo/Spring Configuration Sample
- JaxbMessageConverter.java.txt : JAXB 2 MessageConverter based on Spring WS Jaxb2Marshaller
- JaxbMessageConverterTibjmsImpl.java.txt : subclass of JaxbMessageConverter that keeps in sync generated XML encoding (set via Marshaller.JAXB_ENCODING property) and Tibco EMS' TibjmsMessage._encoding field (set via Tibjms.setMessageEncoding(Message, String)).
- JaxbMessageConverterWebsphereMqImpl.java.txt : subclass of JaxbMessageConverter that keeps in sync generated XML encoding (set via Marshaller.JAXB_ENCODING property) and Websphere MQ Message's encoding (set via JMSC.CHARSET_PROPERTY JMS property). Relies on IbmcharsetUtils to map IBM Coded Character Set Id (ccsid) with Java Charset.
- JaxbMessageConverterTest.java.txt : Unit test
- JaxbMessageConverterSpringTest.java.txt : Spring integrated test
Maven2 pom.xmlCode:<bean id="jaxbMessageConverter" class="fr.xebia.springframework.jms.support.converter.JaxbMessageConverter"> <property name="classesToBeBound"> <list> <value>fr.xebia.sample.messaging.Employee</value> <value>fr.xebia.sample.messaging.Gender</value> </list> </property> </bean>
Add following dependencies :
Hope this helps,Code:<project ...> <dependencies> ... <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jms</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework.ws</groupId> <artifactId>spring-oxm-tiger</artifactId> <version>1.0.3</version> </dependency> ... </dependencies> </project>
Cyrille