wsimport: multiple wsdl overwrite ObjectFactory
Asked Answered
T

2

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.

Terminate answered 3/4, 2013 at 9:10 Comment(0)
I
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).

Idiocrasy answered 18/11, 2016 at 11:32 Comment(0)
H
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

Haro answered 3/4, 2013 at 9:20 Comment(4)
Ok! I used this XML binding : <jxb:bindings version="2.1" xmlns:jxb="java.sun.com/xml/ns/jaxb" xmlns:xs="w3.org/2001/XMLSchema"> <jxb:bindings node="//xsd:schema[@targetNamespace='mydomain.com/myapp/A']"> <jxb:package name="com.mydomain.myapp.a"> </jxb:package> </jxb:bindings> </jxb:bindings> However, it gives me XPath error: null . I don't have xsd, do you have suggestions ?Terminate
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...)Haro
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."Terminate
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 <jxb:bindings :/> 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): illegalargumentexception.blogspot.com/2011/04/…Haro

© 2022 - 2024 — McMap. All rights reserved.