javasoapjaxbwsdljaxb2-maven-plugin

JAXB2 Maven Plugin xjc parse error: org.xml.sax.SAXParseException: Unexpected <xs:element> appears


I want to use JAXB2 maven plugin to generate Java Objects from WSDL file to consume a soap service as a client.

When I use this plugin as "jaxb2:generate" and configuration below:

...
        <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.14.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <schemaLanguage>WSDL</schemaLanguage>
                    <generatePackage>tr.com.foo.dummy.model</generatePackage>
                    <generateDirectory>${project.basedir}/src/main/java</generateDirectory>
                    <schemaDirectory>${project.basedir}/src/main/resources/wsdl</schemaDirectory>
                    <bindingDirectory>${project.basedir}/src/main/resources</bindingDirectory>
                    <bindingIncludes>
                        <bindingInclude>*.xjb</bindingInclude>
                    </bindingIncludes>
                    <schemaIncludes>
                        <include>*.wsdl</include>
                    </schemaIncludes>
                </configuration>
            </plugin>

...

I get an error saying:

[INFO] --- maven-jaxb2-plugin:0.14.0:generate (default-cli) @ hmbs ---
[INFO] Latest timestamp of the source resources is [2020-03-13 18:10:23.000], earliest timestamp of the target resources is [2020-03-06 18:06:36.000].
[INFO] Sources are not up-to-date, XJC will be executed.
[ERROR] Error while parsing schema(s).Location [ file:/home/yigithan/playground/foo/bar/src/main/resources/wsdl/foo.wsdl{23,87}].
org.xml.sax.SAXParseException: Unexpected <xs:element> appears at line 23 column 87 
...

And my WSDL file is like:

<?xml version="1.0" encoding="utf-8" ?>
<wsdl:definitions xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
                  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
                  xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/"
                  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s1="http://tempuri.org/AbstractTypes"
                  xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
                  xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://tempuri.org/"
                  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
    <wsdl:types>
        <xs:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/" version="1.0">
            <xs:element name="Insert">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" maxOccurs="1" name="custom" type="tns:Custom"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:complexType name="Custom">
                <xs:sequence>
                    <xs:element minOccurs="1" maxOccurs="1" name="foo" type="xs:int"/>
                    <xs:element minOccurs="1" maxOccurs="1" name="bar" type="xs:int"/>
                    <xs:element minOccurs="1" maxOccurs="1" name="baz" type="xs:long"/> 
                    <xs:element minOccurs="1" maxOccurs="1" name="qux" type="xs:dateTime"/>
                </xs:sequence>
            </xs:complexType>
...

And the error location is in the line that contains "qux" element and {23, 87} point is the type="xs:dateTime" of "qux". As you can see there is no element that is unexpected. Or am I missing some point?


Solution

  • Okay, I have solved the problem. It was a really long road to solution. Two problems occured. The first one, which is the reason that i asked this question at the first place is, the WSDL file was sent to me as a DOCX file and reformat of file is needed even if i copy-pasted content of the file inside of a WSDL file. By reformat I am not telling about xml structure. It was like a joke but removing blank lines and reintend the file worked.

    The next problem occurs as "unexpected sequence" in a place like:

    <s:schema targetNamespace="http://tempuri.org/AbstractTypes">
                <s:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
                <s:complexType name="StringArray">
                    <s:complexContent>
                        <s:restriction base="soapenc:Array">
                            <s:sequence>
                                <s:element maxOccurs="unbounded" minOccurs="0" name="String" type="s:string"/>
                            </s:sequence>
                        </s:restriction>
                    </s:complexContent>
                </s:complexType>
            </s:schema>
    
    

    And the reason for it is JAXB2 can not handle encoded types according to my research. So, if an unrelated error occurs, first try to refactor xml file in case of misconstruction of xml and then make sure plugin is compatible with the types you are using.

    The maven-jaxrpc-plugin is working well in this situation.

    NOTE: R2110 In a DESCRIPTION, declarations MUST NOT extend or restrict the soapenc:Array type.