Reputation: 13076
I used Eclipse to generate a java client code stub given a third party wsdl. The client works great, I'm able to access the webservice an do what I need to do.
Now, I'd like to write some unit tests that can run without needing to be connected to the webservice. Is it possible to use some mechanism within axis2 stack to deserialize a xml file into one of the java objects in the java client stub code?
For example, one of the classes in the client stub code is "Contact". Say I have an xml file that mimics the xml that would usually is found in soap request. How can I deserialize that into a java Contact object?
I've used XMLBeans before, but hoping there's an easier way since it seems that the java client is already doing this deserialization under the hood somewhere? Maybe axis2 has a method to do take a chunk of xml and return a java object?
UPDATE:
I tried this:
String packageName = Contact.class.getPackage().getName();
JAXBContext jc = JAXBContext.newInstance( packageName );
I get this:
java.lang.AssertionError: javax.xml.bind.JAXBException: "com.sforce.soap._2006._04.metadata" doesnt contain ObjectFactory.class or jaxb.index
Then, I tried this:
Contact c = new Contact();
JAXBContext jc = JAXBContext.newInstance( c.getClass() );
But then I get exception that one of the classes that the Contact Class uses does not have a no-arq default constructor
I was hoping this would be a quick and easy thing to do, but until I have time to fully grok axis2 and how it uses jaxb, I'm just gonna parse the xml manually.
Upvotes: 0
Views: 3060
Reputation: 2305
This is called "unmarshalling" in Axis. Have a look at org.apache.axis2.jaxws.message.databinding.JAXBUtils.getJAXBUnmarshaller(JAXBContext context). Once you have an unmarshaller, you can deserialize the XML back into objects.
Upvotes: 1