views:

88

answers:

1

I have a legacy Java webservice based on Axis2. This webservice classes consist of:

  • a service interface (generated from WSDL);
  • an implementation of the service (written in-house);
  • a bunch of autogenerated entity-like classes representing requests and responses.

I also have a requirement to extract and cache part of one of the responses to XML (ultimately going to the filesystem as a well-formed document). I've been hacking around with the getOMElement() method on the response classes for serialisation, but to no avail. The deserialise looks easier, as the generated classes all have a Factory static member that will take XML in and produce objects.

how can I serialise a subset of the strongly-typed object graph to XML in a way that the generated Axis2 Factory can subsequently deserialise?

ps: I'm stuck with Axis2. Yes, this is very easy with (say) xfire...

A: 

For completeness, here's the solution I eventually came up with...

object -> XML (this is not nice):

// in this case, response is the Axis2 generated class at the root
// of the webservice response
String xml = response.getOMElement(null, null).toString();

XML -> object (only slightly less unpleasant):

// xml is the string we created earlier
XMLStreamReader reader = XMLInputFactory
                                .newInstance()
                                .createXMLStreamReader(new StringReader(xml));

// WebserviceResponse is the class generated by Axis2        
return WebserviceResponse.Factory.parse(reader);

Neither of these methods are nice, but at least they're functional (and surrounded by serious unit testing...).

Dan Vinton