wsimport - Two declarations cause a collision, same line given
Asked Answered
H

2

23

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>
Hallel answered 9/8, 2012 at 12:46 Comment(7)
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.Hacking
I don't think so-- there's 136 total schemas that are referencing it...Hallel
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?Hacking
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 btwHallel
Updated to include the top of the WSDL which imports the schemas.Hallel
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.Hacking
let us continue this discussion in chatHacking
H
34

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!

Hallel answered 9/8, 2012 at 16:18 Comment(5)
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 ...Hallel
If you running wsimport in your maven pom then you have to remove the tag <packageName>Binal
@Hallel 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 clienttesthorizon.horizonafs.com/AFSServices/… but there is no way to generate java stubs. Is there any possible chance you can pitch in here?Coom
Sounds like you need to specify Jaxb bindings. Take a look at this question: #15080413Hallel
Also this guy: #42928779Hallel
A
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>
Attestation answered 21/10, 2021 at 13:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.