【问题标题】:JAX-WS error on WSDL file: "Error resolving component 's:schema'"WSDL 文件上的 JAX-WS 错误:“解析组件 's:schema' 时出错”
【发布时间】:2012-11-21 18:35:50
【问题描述】:

错误

我在一个 Java 项目中使用 wsimport 为三个 SOAP Web 服务生成源代码。前两个工作正常:我使用 JAX-WS Maven 插件来抓取 WSDL 文件并生成相应的 Java 源文件。

这对于一项 Web 服务失败;我收到以下错误:

[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


罪魁祸首

此 WSDL 文件与有效文件之间的区别在于错误消息中指出的第 80、127 和 142 行:

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

注意:wsdl 文件的根元素定义了“s”命名空间:

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


我的尝试

我已经完成了我的研究。看起来其他人也有类似的问题,从“只是不要使用&lt;s:element ref="s:schema" /&gt;”到“使用导入标签”,再到一些显然在旧的 java.net 论坛上的不可知的解决方案(之前它是取缔,对现代亚历山大 Java 知识图书馆的纵火)。

  • 我尝试将以下导入语句放在包含问题标签的元素中:&lt;s:import namespace="http://www.w3.org/2001/XMLSchema" schemaLocation="http://www.w3.org/2001/XMLSchema.xsd" /&gt;。 wsimport 给了我一个新错误:

    [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
    

    此错误中引用的第 108 行和第 109 行是:(第 184-5、199-200 行类似)

    <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" />
    
  • 我已尝试将 jaxws-maven-plugin 从 1.10 升级到 2.2。同样的问题。

  • Here's a possible solution -- 我试图弄清楚如何使用 JAX-WS Maven 插件来实现这一点。有什么提示吗?


结论

有什么想法吗?您需要任何进一步的信息吗?为简洁起见,我省略了 pom.xml 和 Service.asmx.wsdl 文件,但如果其中包含更重要的信息,可以包含它们。

谢谢!


附录

Here's another person having the same problem,如果这对任何潜在的回答者有帮助的话。 Here's yet another similar problem. 我不太了解this article,但这似乎暗示我必须手动解析 SOAP XML!恐怖!

【问题讨论】:

  • 这可能是由于bug JAXP-14 ...任何已知的解决方法?

标签: java jaxb wsdl jax-ws wsimport


【解决方案1】:

我通过将Vivek Pandey's method 适应 Maven 解决了这个问题,同时更新到 jaxws-maven-plugin 2.2。我会在这里重申它的后代:

总结

this XJB customization file(见下文)放在您的默认绑定文件目录中,并设置 wsimport 将其与http://www.w3.org/2001/XMLSchema.xsd 绑定。

XJB 定制

上述 XML 文件 xsd.xjb 的内容应该放在您的默认绑定文件目录中,如下所示(归功于 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

这是我的 POM 文件的相关部分,并注明了更改:

<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>

【讨论】:

  • 除非我弄错了,pom 文件的bindingFiles 部分和wsimport-b 命令行参数做同样的事情。为什么不把它们结合起来?作为参考,提供的链接上的wsimport 命令是(有效的)wsimport -b http://www.w3.org/2001/XMLSchema.xsd -b xsd.xjb &lt;TARGET-WSDL&gt;
  • 另外,感谢您发布您的答案!效果很好!特别感谢您从 bitrot 中保存 xjb。
  • @jpaugh 不客气!三年半后,我对某人有所帮助,我感到非常高兴:D
【解决方案2】:

要使 Nick 的解决方案起作用,您可能必须将这两个 jvm 参数添加到您的 pom.xml 所以当遇到这些错误时:

org.xml.sax.SAXParseException;系统ID:http://www.w3.org/2001/XMLSchema.xsd;行号:67;列号:11;外部 DTD:无法读取外部 DTD“XMLSchema.dtd”,因为 accessExternalDTD 属性设置的限制不允许“http”访问。

[警告] schema_reference:无法读取架构文档“xml.xsd”,因为 accessExternalSchema 属性设置的限制不允许“http”访问。 http://www.w3.org/2001/XMLSchema.xsd的第 91 行

只需将它们添加到您的 pom.xml

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

<vmArgs>
    <vmArg>-Djavax.xml.accessExternalDTD=all</vmArg>
    <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
</vmArgs>

【讨论】:

  • 但是依赖外部资源在大多数情况下对于生产系统来说是个坏主意。如果您需要重新构建并且无法获取外部资源怎么办?
  • 块添加到 pom.xml 就足够了。
【解决方案3】:

用下面的命令解决了同样的问题:

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

xsd.xjb 指的是:

<?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>

【讨论】:

    【解决方案4】:

    如果您实际上并不关心模型数据的这一特定位,您可以使用 JAXB 绑定文件告诉 JAXB 将有问题的位映射到类型为 DOM Element 的属性,而不是实际尝试将它们数据绑定到普通的 JAXB 类中。 unofficial JAXB guide 有一节介绍这种技术。

    【讨论】:

    • 谢谢。我刚才在回答中详述的方法实际上可能归结为这一点;我不太了解 JAXB。
    【解决方案5】:

    这似乎终于对我有用了。我正在使用 apache maven cfx 插件

        <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>
    

    连同这些更改,我必须在 ..java/jdk/jre/lib 文件夹中创建 jaxp.properties 文件 具有以下属性

      -Djavax.xml.accessExternalDTD=all
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-27
      • 1970-01-01
      • 1970-01-01
      • 2010-11-09
      • 1970-01-01
      • 2012-06-06
      • 1970-01-01
      相关资源
      最近更新 更多