Dheeraj Joshi
Dheeraj Joshi

Reputation: 3147

Convert SOAP messages to Java objects

I am trying to find out a suitable library which will convert the SOAP messages to Java object.

I have come across XStream and JaxB. These libraries require class representation while converting xml to object.

The SOAP messages which we receive are dynamic meaning they will change depending on the SOAP method called. So it is impossible to create a class structure for SOAP messages. As for every iteration we get different SOAP responses.

Is there any java api available to convert incoming SOAP xml to Java classes and then use those in JaxB or XStream to convert xml to java object?

And is it possible to use JaxB or XStream to convert xml to Java Collection like Map or Map of Map without Class representation of it?

Upvotes: 1

Views: 3253

Answers (1)

Juned Ahsan
Juned Ahsan

Reputation: 68715

EclipseLink's Moxy provides dynamic JAXB OXM functionality.

With EclipseLink Dynamic MOXy, you can bootstrap a JAXBContext from a variety of metadata sources and use existing JAXB APIs to marshal and unmarshal data…without having compiled Java class files on the classpath. This allows you to alter the metadata as needed, without having to update and recompile the previously-generated Java source code.

FileInputStream xmlInputStream = new FileInputStream("src/example/dynamic/customer.xml");
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
DynamicEntity customer = (DynamicEntity) unmarshaller.unmarshal(xmlInputStream);

Instead of using actual Java classes (such as Customer.class or Address.class), Dynamic MOXy uses a simple get(propertyName)/set(propertyName, propertyValue) API to manipulate data. EclipseLink generates (in memory) a DynamicType associated with each DynamicEntity.

System.out.println(customer.<String>get("name"));

Suggested Reading:

https://wiki.eclipse.org/EclipseLink/Examples/MOXy/Dynamic/XmlToDynamicEntity https://docs.oracle.com/middleware/1212/toplink/TLJAX/dynamic_jaxb.htm#TLJAX442

Upvotes: 1

Related Questions