1

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.

Sebastian G.
  • 616
  • 1
  • 7
  • 25
  • Is there a definition of two elements with the same name in a choice? I fixed that with a binding that renamed one of the definitions so the names are unique. – daniu Dec 23 '17 at 12:25
  • yes it is, can you show me how you did it? I edit my question with the full log – Sebastian G. Dec 23 '17 at 12:27
  • Sorry I'm on mobile, no way to look it up properly. General idea is to add a binding for one of the elements (defined by an xpath) and assign it a different name that will be used in the Jaxb model. – daniu Dec 23 '17 at 12:51

2 Answers2

5

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.

lexicore
  • 42,748
  • 17
  • 132
  • 221
  • i copied the part you gave as an example but IntelliJ is telling me that "jaxb:factoryMethod" and "jaxb:extensionBindingPrefixes" are not allowed here. Why is that so? – Sebastian G. Dec 26 '17 at 10:44
  • 1
    This is an [example from a working project](https://github.com/highsource/ogc-schemas/blob/master/citygml/1.0/src/main/resources/citygml-v_1_0.xjb#L120-L126), so I'd ignore IntelliJ warnings in this case. Probably it uses some outdated XSD to validate XJB files. – lexicore Dec 27 '17 at 08:27
3

Faced the same issue and I had multiple schemas and it was bit difficult to identify which elements cause collision. I was able to resolve and generate ObjectFactory class after adding jaxb bindings to provide different names for the elements that were duplicate.

Example: I had "Id" as one of the common element in Product.xsd and CustomerOrder.xsd so had to provide the binding in in common.xjb file.

    <jaxb:bindings schemaLocation="../../Common/XSD/Product.xsd" node="//xs:element[@name='Id']">
        <jaxb:class name="ProductId" />
    </jaxb:bindings>

     <jaxb:bindings schemaLocation="../../Common/XSD/CustomerOrder.xsd" node="//xs:element[@name='Id']">
         <jaxb:class name="CustomerOrderId" />
     </jaxb:bindings>

And this is the execution I defined in pm.xml

                  <execution>
                        <id>Outbound</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <args>
                                <arg>-XautoNameResolution</arg>
                                <arg>-XtoString</arg>
                            </args>
                            <schemaLanguage>WSDL</schemaLanguage>
                            <generatePackage>some.package.name</generatePackage>
                            <generateDirectory>${project.build.directory}/generated-sources/xjc1</generateDirectory>
                            <schemaDirectory>${project.basedir}/src/main/resources/Outbound/WSDL</schemaDirectory>
                            <bindingDirectory>${project.basedir}/src/main/resources/Outbound/WSDL</bindingDirectory>
                            <strict>false</strict>
                            <bindingIncludes>
                                <include>*.xjb</include>
                            </bindingIncludes>
                            <schemaIncludes>
                                <include>*.wsdl</include>
                            </schemaIncludes>
                            <plugins>
                                <plugin>
                                    <groupId>org.jvnet.jaxb2_commons</groupId>
                                    <artifactId>jaxb2-basics</artifactId>
                                    <version>${jaxb2.basics.version}</version>
                                </plugin>
                            </plugins>
                        </configuration>
                    </execution>
Ashwath
  • 131
  • 1
  • 4