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.xml3.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 configurationYou 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 :