7

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.

alexroat
  • 1,687
  • 3
  • 23
  • 34

2 Answers2

3

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 work for me (I assume it ignores what's in ObjectFactory and scans the whole package).

Amin Abu-Taleb
  • 4,423
  • 6
  • 33
  • 50
2

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

Community
  • 1
  • 1
FOOM
  • 426
  • 5
  • 13
  • Ok! I used this XML binding : However, it gives me XPath error: null . I don't have xsd, do you have suggestions ? – alexroat Apr 03 '13 at 13:41
  • 2
    Just had a thought - have you tried "wsimport -p com.mydomain.myapp.a http:/mydomain/wsA.svc?wsdl" and then "wsimport -p com.mydomain.myapp.b http:/mydomain/wsB.svc?wsdl"? That will put all the generated code into the specified package (as per the "-p" switch), without needing a binding file. (Should've thought've it sooner...) – FOOM Apr 04 '13 at 14:17
  • Yes, I did. There are a lot of errors like "Two declarations cause a collision in the ObjectFactory" class. and "A class/interface with the same name "com.anthesi.prova.ExecuteTransmDocModelResponse" is already in use. Use a class customization to resolve this conflict." – alexroat Apr 05 '13 at 06:50
  • Ok, seems strange, and you might want to make sure you're using separate packages, etc; but moving on: I think the problem is that you don't have a wsdlLocation in your elements. Also, note that the targetNameSpace should be the one in the wsdl, not the package you want it to generate to. Here's a pretty good example (look under Java Bindings): http://illegalargumentexception.blogspot.com/2011/04/java-jax-ws-web-services-and-clients.html#ws_bindings – FOOM Apr 05 '13 at 08:55