Announcement Announcement Module
Collapse
No announcement yet.
sample for messageconverter using e.g. jaxb, xstream Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • sample for messageconverter using e.g. jaxb, xstream

    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?

  • #2
    JaxbMessageConverter implementation

    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/
    • : JAXB 2 MessageConverter based on Spring WS Jaxb2Marshaller
    • : 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)).
    • : 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.
    • : Unit test
    • : Spring integrated test
    Spring Configuration Sample
    Code:
       <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>
    Maven2 pom.xml

    Add following dependencies :

    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>
    Hope this helps,

    Cyrille

    Comment

    Working...
    X