File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes Customising wsimport classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Customising wsimport classes" Watch "Customising wsimport classes" New topic
Author

Customising wsimport classes

David Clarke
Greenhorn

Joined: Jan 02, 2008
Posts: 11
Kia ora - I have a couple of questions about accepted/common practices in web services.

I am using NetBeans to generate the client for a web service. I have approx. zero control over the WSDL and the resulting classes generated by wsimport are pretty dreadful. Is it possible to manually define a class for de-serialising the WS response? At the moment I'm stuck with a List of JAXBElement.class, one List entry for each of the response items.

Also, some of the xml data in the response payload is in a format that would be useful for performing XSL transforms to generate html web controls. Is this a really dumb idea or is this a reasonable practice. It seems a bit silly to convert my xml ws response to Java objects only to then subsequently generate html output from the Java and I find XSL to be much less verbose than the equivalent Java for generating html. If it is possible, how do I access the payload from my app?

Thanks
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by David Clarke:
Is it possible to manually define a class for de-serialising the WS response?


You should be able use JAXB Binding Customizations to coerce the code generation process towards classes that are more to your liking.

Outside of NetBeans Axis2 provides the option of using JiBX. Basically you have to provide all the classes and the JiBX mapping for the XML elements in the message - WSDL2Java will then generate the remaining glue code (Starting from WSDL).

Is this a really dumb idea or is this a reasonable practice.


It is reasonable - it just isn't the current default. The default behaviour of the code generation (in an attempt to please the majority of users) attempts to produce code that has the look-and-feel of Java with all its advantages and disadvantages - that doesn't necessarily mean that it is perfect or the best option, especially considering that circumstances always vary.

Again you might be able to use JAXB binding customization to prevent the marshalling to custom Java objects - in the extreme case you may have to doctor the WSDL that you are using and replace the elements in question with <xs:any /> (Mapping of <xs:any />) - "any" is always mapped to org.w3c.dom.Element.
David Clarke
Greenhorn

Joined: Jan 02, 2008
Posts: 11
Thanks for the reply - I think I'm beginning to get a handle on things. The WSDL for the web service is generated by an object database development environment called Jade. Everything in Jade derives from an Object and this is reflected in the WSDL by for example:

Object is itself defined in WSDL as

This really hoses the generated java type classes, with everything being a list of JAXBElement's. If I edit the WSDL and remove the <xsd:complexContent/> and <xsd:extension/> nodes, i.e. making the sequence a direct child of the parent of <xsd:complexContent/> then the java generated is exactly what I want.

So I guess to rephrase my original question, what is the best way to achieve this? Manually editing the wsdl isn't really a good long term option as far as I can see. I've had a look at javaType binding declarations but don't think that is necessarily the right approach either. Any suggestions?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Customising wsimport classes