Search code examples
javaaffiliatemaven-jaxb2-plugin

Jaxb: Two declarations in a wsdl cause a collision in the objectFactory class


I want to work with the Affilinet API. One WSDL File of it is here:

Affilinet AccountService.wsdl

I use this Maven Plugin to generate the source:

Jaxb Maven Plugin

My Pom.xml Plugin configuration:

<plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.13.1</version>
                <executions>
                    <execution>
                        <id>schema1-generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <schemaLanguage>WSDL</schemaLanguage>
                            <generatePackage>webservices.framework.affilinet.logon</generatePackage>
                            <schemas>
                                <schema>
                                    <url>https://api.affili.net/V2.0/Logon.svc?wsdl</url>
                                </schema>
                            </schemas>
                        </configuration>
                    </execution>
                    <execution>
                    <id>schema2-generate</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <schemaLanguage>WSDL</schemaLanguage>
                        <generatePackage>webservices.framework.affilinet.inbox</generatePackage>
                        <schemas>
                            <schema>
                                <url>https://api.affili.net/V2.0/PublisherInbox.svc?wsdl</url>
                            </schema>
                        </schemas>
                    </configuration>
                </execution>
                    <execution>
                        <id>schema3-generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <schemaLanguage>WSDL</schemaLanguage>
                            <generatePackage>webservices.framework.affilinet.inbox</generatePackage>
                            <schemas>
                                <schema>
                                    <url>https://api.affili.net/V2.0/AccountService.svc?wsdl</url>
                                </schema>
                            </schemas>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

So, when compiling this, i get an error :

com.sun.istack.SAXParseException2; systemId: https://api.affili.net/V2.0/AccountService.svc?wsdl; lineNumber: 1; columnNumber: 2127; Two declarations cause a collision in the objectFactory class.

But how do i fix this with a wsdl file from a url?

schemaLocation does not accept the wsdl file....

Edit: Full log:

[ERROR] Error while generating code.Location [ https://api.affili.net/V2.0/AccountService.svc?wsdl{1,6200}].

com.sun.istack.SAXParseException2; systemId: https://api.affili.net/V2.0/AccountService.svc?wsdl; lineNumber: 1; columnNumber: 6200; This is the other declaration.


Solution

  • This typically happens if you have two conflicting definitions. It is a little bit difficult to tell what is exactly wrong with your WSDL since it is poorly formatted. But normally this will be something like two elements which get the same method name after conversion to Java.

    You can normally address this with a binding customization. Here's an example:

    <jaxb:bindings version="1.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" 
        xmlns:xs="http://www.w3.org/2001/XMLSchema" 
        xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" 
        jaxb:extensionBindingPrefixes="xjc">
    
        <jaxb:bindings 
            schemaLocation="http://schemas.opengis.net/citygml/texturedsurface/1.0/texturedSurface.xsd" 
            node="/xs:schema">
            <jaxb:bindings node="xs:element[@name='_Appearance']">
                <jaxb:factoryMethod name="AAppearance"/>
            </jaxb:bindings>
        </jaxb:bindings>
    
    </jaxb:bindings>
    

    So what you have to do is to find out what exactly causes the problem, write and apply the binding. The first thing I'd do would be download the WSDL, format it to be human-readable and compile it locally. This should give a clear pointer on which parts cause the problem.