Wsimport: multiple wsdl overwrite ObjectFactory

I have several (let them say, 2, A and B) webservices, and I need to create a client to use their togheter. In Netbeans, I use the "new web service client" wizard to submit two wsdl, looking at the Netbeans weekend, just call wsimport for each of them.

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

Both A and B generate the same package com.mydomain.myapp (I assume they are defined in the same namespace), so I get a set of stub classes A and B combined into the same package.

However, wsimport also creates an ObjectFactory for each web service, so if I create a stub B after A, I get only the ObjectFactory associated with the definitions of B (because the first, A, is overwritten). Conversely, ObjectFactory of A is preserved if I switch the order.

The problem is that I need both ObjectFactories to create JAXBElements wrapper shell instances for web service types A and B.

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

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

and so keep both ObjectFactories?

Simple refactoring does not help, because internally getClass () is called as soon as the package has been reorganized, it no longer works.

+6
source share
2 answers

Perhaps you can do this through JAXB binding files - look at this question / answer: java wsimport rename / different ObjectFactory.java

From this answer, take a look at the file binding file in oracle: http://docs.oracle.com/javaee/5/tutorial/doc/bnbbf.html

+1
source

This worked for me (using Spring java config)

 @Bean public Jaxb2Marshaller marshaller() { Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); marshaller.setPackagesToScan("com.example.api"); return marshaller; } 

Using setPackagesToScan instead of setContextPath did the job for me (I assume that it ignores what is in ObjectFactory and scans the entire package).

0
source

All Articles