wsimport: multiple wsdl overwrite ObjectFactory

alexroat picture alexroat · Apr 3, 2013 · Viewed 9.9k times · Source

I have multiple (let's say 2, A and B) webservices and I need to generate a client to use them togheter. In Netbeans I use the wizard "new Web Service Client" passing the two wsdl, looking at the output Netbeans simply call wsimport for each of them.

wsimport http:/mydomain/wsA.svc?wsdl
wsimport http:/mydomain/wsB.svc?wsdl

Both A and B, generate a the same package com.mydomain.myapp (I guess they are defined in the same namespace), so I get the stub class set of A and B merged in the same package.

However, wsimport also creates an ObjectFactory for each webservice so if I generate the stub of B after A I obtain only the ObjectFactory related to B definitions (because the first, A, is overwritten). Conversely, ObjectFactory of A survives if I switch the order.

The problem is that I need both ObjectFactories in order to create the JAXBElements wrapping clas instances for the types of both webservices A and B.

Is there a way to map the namespace for A in a java package and the B in another one in order to obtain

com.mydomain.myapp.a
com.mydomain.myapp.b

and so keep both ObjectFactories ?

Simple refactoring is not helping because internally a getClass() is called so, once a package has been refactored it does not work anymore.

Answer

FOOM picture FOOM · Apr 3, 2013

You can probably do this via JAXB binding files - have a look at this question/answer: java wsimport rename/different ObjectFactory.java

From that answer, have a look at the binding file stuff at oracle: http://docs.oracle.com/javaee/5/tutorial/doc/bnbbf.html