My Quotes


When U were born , you cried and the world rejoiced
Live U'r life in such a way that when you go
THE WORLD SHOULD CRY






Saturday, March 8, 2014

Spring OXM in 2 minutes

Once you have XSD defined, here are the easy steps to generate the OXM (JAXB) classes using Spring.

You can also ensure that the XSD validations are done prior to absorbing the XML into your system.

Here are the steps to configure and code with Spring and OXM.

Firstly the pom.xml 


3.1.3.RELEASE


  
   org.springframework
   spring-oxm
   ${org.springframework.version}
  
  
   org.springframework
   spring-asm
   ${org.springframework.version}
  
  
   org.springframework
   spring-aspects
   ${org.springframework.version}
  
  
   org.springframework
   spring-aop
   ${org.springframework.version}
  

Secondly the Spring configuration

 
  
  
 

You can attach this messageConverter into any bean for example into a JMS Template as


Right click on the XSD (sample.xsd) in your eclipse and generate the JAXB classes into the package (com.oxm.test)

Last a simple method to convert the incoming XML into the OXM Objects

    private Projection convertXmlStringToMyAppPayload(final String xmlMessage) throws ApplicationException {
 try {
     return  (ClassFileFromsample.xsd) marshaller.unmarshal(new StreamSource(new StringReader(xmlMessage)));     
 } catch (Exception appex) {
     LOGGER.error("ApplicationException Found in convertXmlStringToMyAppPayload() of Service class ", appex);
 }
    }


No comments :