JAX-WS error on WSDL file: "Error resolving component 's:schema'"
Asked Answered
P

5

25

The Error

I am using wsimport in a Java project to generate sources for three SOAP web services. The first two work fine: I use the JAX-WS Maven plugin to grab the WSDL file and generate corresponding Java source files.

This fails for one web service; I get the following error:

[jaxws:wsimport]
Processing: /home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl
jaxws:wsimport args: [-s, /home/me/NetBeansProjects/Admin/AdminWeb/target/generated-sources/jaxws-wsimport, -d, /home/me/NetBeansProjects/Admin/AdminWeb/target/classes, -verbose, -catalog, /home/me/NetBeansProjects/Admin/AdminWeb/src/jax-ws-catalog.xml, -wsdllocation, http://erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx?WSDL, -target, 2.0, -extension, -Xnocompile, /home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl]
parsing WSDL...


src-resolve.4.2: Error resolving component 's:schema'. It was detected that 's:schema' is in namespace 'http://www.w3.org/2001/XMLSchema', but components from this namespace are not referenceable from schema document 'file:/home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl#types?schema1'. If this is the incorrect namespace, perhaps the prefix of 's:schema' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 'file:/home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl#types?schema1'.
  line 80 of file:/home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl#types?schema1

undefined element declaration 's:schema'
  line 80 of file:/home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl

undefined element declaration 's:schema'
  line 127 of file:/home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl

undefined element declaration 's:schema'
  line 142 of file:/home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl


The Culprit

The difference between this WSDL file and the ones that work is what's at the lines noted in the error message, lines 80, 127, and 142:

<s:element ref="s:schema" />

Note: the root element of the wsdl file defines the "s" namespace thus:

xmlns:s="http://www.w3.org/2001/XMLSchema" 


What I've Tried

I have done my research. It looks like other people have had similar problems, with solutions from "just don't use <s:element ref="s:schema" />", to "use an import tag", to some unknowable solution that was apparently on the old java.net forum (before it was taken down, an arson of the modern-day Alexandrian Library of Java knowledge).

  • I have tried putting the following import statement just inside the element that contains the problem tags: <s:import namespace="http://www.w3.org/2001/XMLSchema" schemaLocation="http://www.w3.org/2001/XMLSchema.xsd" />. wsimport gives me a new error:

    [jaxws:wsimport]
    Processing: /home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl
    jaxws:wsimport args: [-s, /home/me/NetBeansProjects/Admin/AdminWeb/target/generated-sources/jaxws-wsimport, -d, /home/me/NetBeansProjects/Admin/AdminWeb/target/classes, -verbose, -catalog, /home/me/NetBeansProjects/Admin/AdminWeb/src/jax-ws-catalog.xml, -wsdllocation, http://erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx?WSDL, -target, 2.0, -extension, -Xnocompile, /home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl]
    parsing WSDL...
    
    
    Element "{http://www.w3.org/2001/XMLSchema}annotation" shows up in more than one properties.
      line 248 of http://www.w3.org/2001/XMLSchema.xsd
    
    The following location is relevant to the above error
      line 242 of http://www.w3.org/2001/XMLSchema.xsd
    
    Property "Any" is already defined. Use &lt;jaxb:property> to resolve this conflict.
      line 108 of file:/home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl
    
    The following location is relevant to the above error
      line 109 of file:/home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl
    
    Property "Any" is already defined. Use &lt;jaxb:property> to resolve this conflict.
      line 184 of file:/home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl
    
    The following location is relevant to the above error
      line 185 of file:/home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl
    
    Property "Any" is already defined. Use &lt;jaxb:property> to resolve this conflict.
      line 199 of file:/home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl
    
    The following location is relevant to the above error
      line 200 of file:/home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl
    

    Lines 108 and 109 referenced in this error are: (lines 184-5, 199-200 are similar)

    <s:any minOccurs="0" maxOccurs="unbounded" namespace="http://www.w3.org/2001/XMLSchema" processContents="lax" />
    <s:any minOccurs="1" namespace="urn:schemas-microsoft-com:xml-diffgram-v1" processContents="lax" />
    
  • I have tried upgrading jaxws-maven-plugin from 1.10 to 2.2. Same problem.

  • Here's a possible solution -- I'm trying to figure out how to implement this using the JAX-WS Maven plugin. Any hints?


Conclusion

Any ideas? Any further information you need? I've omitted the pom.xml and Service.asmx.wsdl files for brevity, but could include them if there's more important information in them.

Thank you!


Addenda

Here's another person having the same problem, if this is helpful to any potential answerers. Here's yet another similar problem. I don't really understand this article, but it seems to imply that I have to parse the SOAP XML manually! Horror!

Phenosafranine answered 21/11, 2012 at 18:35 Comment(1)
This may be due to bug JAXP-14 ... any known workarounds?Phenosafranine
P
16

I solved this by adapting Vivek Pandey's method to Maven, while updating to the jaxws-maven-plugin 2.2. I'll reiterate it here for posterity:

Summary

Put this XJB customization file (see below) in your default binding files directory, and set wsimport to bind it and http://www.w3.org/2001/XMLSchema.xsd .

XJB Customization

The contents of the aforementioned XML file, xsd.xjb, that should go in your default binding files directory, is as follows (credit goes to Kohsuke):

<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
          xmlns:xsd="http://www.w3.org/2001/XMLSchema"
          xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
          version="2.0">

  <globalBindings>
    <xjc:simple />
  </globalBindings>

  <bindings scd="~xsd:complexType">
    <class name="ComplexTypeType"/>
  </bindings>

  <bindings scd="~xsd:simpleType">
    <class name="SimpleTypeType"/>
  </bindings>

  <bindings scd="~xsd:group">
    <class name="GroupType"/>
  </bindings>

  <bindings scd="~xsd:attributeGroup">
    <class name="AttributeGroupType"/>
  </bindings>

  <bindings scd="~xsd:element">
    <class name="ElementType"/>
  </bindings>

  <bindings scd="~xsd:attribute">
    <class name="attributeType"/>
  </bindings>
</bindings>

POM

Here's the relevant part of my POM file, with changes noted:

<plugin>
    <!-- CHANGE: updated groupId and version -->
    <groupId>org.jvnet.jax-ws-commons</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>2.2</version>
    <executions>
        <execution> 
            <goals>
                <goal>wsimport</goal>
            </goals>
            <configuration>
                <!-- CHANGE: added args tag to bind http://www.w3.org/2001/XMLSchema.xsd -->
                <args>
                    <arg>-b</arg><arg>http://www.w3.org/2001/XMLSchema.xsd</arg>
                </args>
                <wsdlFiles>
                    <wsdlFile>erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl</wsdlFile>
                </wsdlFiles>
                <wsdlLocation>http://erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl</wsdlLocation>
                <staleFile>${project.build.directory}/jaxws/stale/Service.asmx.stale</staleFile>
                <!-- CHANGE: added bindingFiles tag to bind XJB customization, located at the default binding files directory, MyProject/src/jaxws/xsd.xjb . -->
                <bindingFiles>
                    <bindingFile>xsd.xjb</bindingFile>
                </bindingFiles>
            </configuration>
            <id>wsimport-generate-egtestreportengine</id>
            <phase>generate-sources</phase>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>javax.xml</groupId>
            <artifactId>webservices-api</artifactId>
            <version>1.4</version>
        </dependency>
    </dependencies>
    <configuration>
        <sourceDestDir>${project.build.directory}/generated-sources/jaxws-wsimport</sourceDestDir>
        <xnocompile>true</xnocompile>
        <verbose>true</verbose>
        <extension>true</extension>
        <catalog>${basedir}/src/jax-ws-catalog.xml</catalog>
        <target>2.0</target>
    </configuration>
</plugin>
Phenosafranine answered 22/11, 2012 at 0:44 Comment(3)
Unless I'm mistaken, the bindingFiles section of the pom file and the -b command-line argument to wsimport do the same thing. Why not combine them? For reference, thewsimport command at the provided link is (effectively) wsimport -b http://www.w3.org/2001/XMLSchema.xsd -b xsd.xjb <TARGET-WSDL>Motoneuron
Also, thanks for posting your answer! It works great! Especially, thanks for saving the xjb from bitrot.Motoneuron
@Motoneuron You are very welcome! I am absolutely delighted that, three and a half years later, I was helpful to someone :DPhenosafranine
L
10

For Nick's solution to work you may have to add these two jvm arguments to your pom.xml So when encountering those errors:

org.xml.sax.SAXParseException; systemId: http://www.w3.org/2001/XMLSchema.xsd; lineNumber: 67; columnNumber: 11; External DTD: Failed to read external DTD 'XMLSchema.dtd', because 'http' access is not allowed due to restriction set by the accessExternalDTD property.

[WARNING] schema_reference: Failed to read schema document 'xml.xsd', because 'http' access is not allowed due to restriction set by the accessExternalSchema property. line 91 of http://www.w3.org/2001/XMLSchema.xsd

Just add those to your pom.xml

-Djavax.xml.accessExternalDTD=all
-Djavax.xml.accessExternalSchema=all

<vmArgs>
    <vmArg>-Djavax.xml.accessExternalDTD=all</vmArg>
    <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
</vmArgs>
Lizliza answered 12/8, 2015 at 13:17 Comment(2)
But depending on external resources is most of the time a bad idea for production systems. What if you need to re-build and cant get to the external resources?Paraphrast
It is sufficient just adding the <vmargs> block to the pom.xml.Purine
T
2

Had same issue fixed it with below command:

wsimport -b http://www.w3.org/2001/XMLSchema.xsd -b xsd.xjb service.wsdl

where xsd.xjb refers to :

<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
          xmlns:xsd="http://www.w3.org/2001/XMLSchema"
          xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
          version="2.0">

  <globalBindings>
    <xjc:simple />
  </globalBindings>

  <bindings scd="~xsd:complexType">
    <class name="ComplexTypeType"/>
  </bindings>

  <bindings scd="~xsd:simpleType">
    <class name="SimpleTypeType"/>
  </bindings>

  <bindings scd="~xsd:group">
    <class name="GroupType"/>
  </bindings>

  <bindings scd="~xsd:attributeGroup">
    <class name="AttributeGroupType"/>
  </bindings>

  <bindings scd="~xsd:element">
    <class name="ElementType"/>
  </bindings>

  <bindings scd="~xsd:attribute">
    <class name="attributeType"/>
  </bindings>
</bindings>
Territory answered 13/7, 2016 at 13:36 Comment(0)
G
1

If you don't actually care about this particular bit of the model data you might be able to use a JAXB bindings file to tell JAXB to map the offending bits to properties whose type is a DOM Element rather than actually trying to data bind them into normal JAXB classes. The unofficial JAXB guide has a section on this technique.

Gosse answered 21/11, 2012 at 23:56 Comment(1)
Thank you. The method that I just detailed in my answer might actually boil down to this; I don't know JAXB well enough to say.Phenosafranine
M
0

This seems to be working for me finally. I am using apache maven cfx plugin

    <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <additionalJvmArgs>
                                -Djavax.xml.accessExternalDTD=all
                            </additionalJvmArgs>
                            <sourceRoot>${basedir}/src/main/generated</sourceRoot> 
                            <wsdlOptions>
                                <wsdlOption>
                                    <extraargs>
                                        <extraarg>-autoNameResolution</extraarg>
                                        <extraarg>-impl</extraarg>
                                        <extraarg>-verbose</extraarg>
                                        <extraarg>-b</extraarg>
                                        <extraarg>http://www.w3.org/2001/XMLSchema.xsd</extraarg>

                                        <extraarg>-p</extraarg>
                                        <extraarg>com.nevado.travelstudio</extraarg>
                                    </extraargs>
                                    <!-- <bindingFiles> <bindingFile>${basedir}/src/main/resources/wsdl/mybindings.xjb</bindingFile> 
                                        </bindingFiles> -->
                                    <wsdl>${basedir}/src/main/resources/wsdl/B2.wsdl</wsdl>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

along with these changes I had to create jaxp.properties file in ..java/jdk/jre/lib folder with following property

  -Djavax.xml.accessExternalDTD=all
Moonlit answered 20/3, 2017 at 14:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.