21

Trying to use wsimport to generate a client for a SOAP endpoint. The WSDL and all XSD files used are local copies.

This is the command being executed:

wsimport ./bwWsdl.xml -p com.generated -Xnocompile -d ../src -extension -keep -XadditionalHeaders -B-XautoNameResolution

Which gives this error:

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 16 of file:/schemas/newSchema.xsd

[ERROR] (Related to above error) This is the other declaration.   
  line 16 of file:/schemas/newSchema.xsd

Note the line number is the same for the reported collision.

Here's the schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
  version="2.004" id="OTA2003A2009A">

  <xs:complexType name="TPA_ExtensionsType">
    <xs:annotation>
      <xs:documentation xml:lang="en">Description here.
      </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:any processContents="skip" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>

  <xs:element name="TPA_Extensions" type="TPA_ExtensionsType">
    <xs:annotation>
      <xs:documentation xml:lang="en">More description here.</xs:documentation>
    </xs:annotation>
  </xs:element>
</xs:schema>  

I've tried removing the type definition, but it's referenced in a slew of other places.

Could anyone please offer any advice for how to get this to work?

Thanks

Edit:

Here's the lines where the WSDL imports these schemas:

<definitions name='ResLookupGet' targetNamespace='http://org.jboss.ws/resLookupGet' xmlns='http://schemas.xmlsoap.org/wsdl/' xmlns:http='http://schemas.xmlsoap.org/wsdl/http/' xmlns:mime='http://schemas.xmlsoap.org/wsdl/mime/' xmlns:ns='http://www.opentravel.org/OTA/2003/05/beta' xmlns:rq='http://www.opentravel.org/OTA/2003/05/betarq' xmlns:rs='http://www.opentravel.org/OTA/2003/05/betars' xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' xmlns:tns='http://org.jboss.ws/resLookupGet' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
 <types>
  <xsd:schema targetNamespace='http://org.jboss.ws/resLookupGet' xmlns:tns='http://org.jboss.ws/resLookupGet' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
   <xsd:import namespace='http://www.opentravel.org/OTA/2003/05/betarq' schemaLocation='./schemas/FooAffiliateHeaderRQ.xsd'/>
   <xsd:import namespace='http://www.opentravel.org/OTA/2003/05/betarq' schemaLocation='./schemas/FooResLookupGetRQ.xsd'/>
   <xsd:import namespace='http://www.opentravel.org/OTA/2003/05/betars' schemaLocation='./schemas/FooResLookupGetRS.xsd'/>
  </xsd:schema>
 </types>
<message name='ResLookupGetRQ'>
  <part element='rq:FooResLookupGetRQ' name='FooResLookupGetRQ'></part>
 </message>
 <message name='ResLookupGetRS'>
  <part element='rs:FooResLookupGetRS' name='FooResLookupGetRS'></part>
 </message>
Cuga
  • 17,668
  • 31
  • 111
  • 166
  • Any chance you can post a set of files which would give the same? This error message is typically caused by loading the same definition twice or more in a way that confuses the loader with regards to the base URI. – Petru Gardea Aug 09 '12 at 13:21
  • I don't think so-- there's 136 total schemas that are referencing it... – Cuga Aug 09 '12 at 13:24
  • I would try to visualize/trace the paths into the XSD file which is causing the issue. If this is based on the Open Travel Alliance... I assume you built the WSDL; can you indicate the highlevel structure i.e. do you do import of OTA xsds from your WSDL, do you define XSD content in WSDL, or do you import one external XSD which in turn references all others? – Petru Gardea Aug 09 '12 at 13:31
  • The WSDL was developed elsewhere, and it imports three XSDs which in turn reference others... eventually down to the one 20-line XSD containing just the types in the snippet above. I've tried renaming the types to be various things, but keep running into the same error... Thanks for the help btw – Cuga Aug 09 '12 at 13:56
  • Updated to include the top of the WSDL which imports the schemas. – Cuga Aug 09 '12 at 14:00
  • Can you please do the following: extract the xsd:schema under wsdl:types as a standalone file in the same folder where the WSDL resides (call that new.xsd). Run the xjc against new.xsd and see if you're getting errors or not. – Petru Gardea Aug 09 '12 at 14:51
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/15129/discussion-between-petru-gardea-and-cuga) – Petru Gardea Aug 09 '12 at 14:53

2 Answers2

33

Thanks to the help of @Petru Gardea I was able to eventually get past this by omitting the -p com.generated package specification to wsimport. So this is what I was eventually able to run to get past this problem:

wsimport ./bwWsdl.xml -Xnocompile -d ../src -extension -keep -XadditionalHeaders -B-XautoNameResolution

The reasoning for it is wsimport is trying to generate classes in the same package with the same name and/or methods, which it obviously cannot do.

So by omitting the forced package declaration, wsimport is able to put the classes in whatever packages it wants, which turns out to be 3 different packages per the <xsd:schema> definition in the WSDL.

Thanks again @Petru!

Cuga
  • 17,668
  • 31
  • 111
  • 166
  • 2
    On JDK 1.8, this has come to be useful as well: `wsimport wsdlName.xml -J-Djavax.xml.accessExternalDTD=all ...` As well as `wsimport wsdlName.xml -J-Djavax.xml.accessExternalSchema=all ...` – Cuga Jul 29 '16 at 15:26
  • If you running wsimport in your maven pom then you have to remove the tag – Jan Seevers Feb 06 '20 at 13:31
  • @Cuga Hi Cuga, thank you for this excellent post! I'm aware this is an old post but, I'm also in similar problem as you once were. I'm using this wsdl https://clienttesthorizon.horizonafs.com/AFSServices/AFSService.svc?wsdl but there is no way to generate java stubs. Is there any possible chance you can pitch in here? – Wrapper Jan 20 '21 at 20:06
  • Sounds like you need to specify Jaxb bindings. Take a look at this question: https://stackoverflow.com/questions/15079913/applying-external-jaxb-binding-file-to-schema-elements-imported-from-wsdl – Cuga Jan 21 '21 at 15:28
  • Also this guy: https://stackoverflow.com/questions/42928279/wsimport-two-declarations-cause-a-collision – Cuga Jan 21 '21 at 15:29
0

I had the same issue and I was calling webservice through pom.xml. I just removed packageName and defined a sourceDestDir. This will create stubs inside source packages. I am taking wsdlURL from a config. Here are the changes I did in pom.xml:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxws-maven-plugin</artifactId>
        <version>2.6</version>
        <executions>
            <execution>
                <id>wsimport-from-jdk</id>
                <goals>
                    <goal>wsimport</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <args>
                <arg>-B-XautoNameResolution</arg>
            </args>
            <wsdlUrls>
                <wsdlUrl>${service.wsdl.url}</wsdlUrl> 
            </wsdlUrls>
            <keep>true</keep> 
            <sourceDestDir>src/main/java</sourceDestDir>
        </configuration>
    </plugin>