【问题标题】:Clickatell SOAP wsdl to JAXB java classesClickatell SOAP wsdl 到 JAXB java 类
【发布时间】:2011-01-24 23:47:59
【问题描述】:

我正在尝试从 Clickatell wsdl 生成 JAXB 类: 你可以在这里找到相当大的 wsdl 定义: http://api.clickatell.com/soap/webservice.php?WSDL

当试图从这个 Wsdl 生成 java 类时,我得到了以下错误: [错误] 未定义的简单或复杂类型 'SOAP-ENC:Array' [错误] 未定义属性 'SOAP-ENC:arrayType'

我希望有人可以帮助我。 干杯, 蒂姆

【问题讨论】:

    标签: java web-services


    【解决方案1】:

    您的架构是指在架构 xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 中定义的 SOAP-ENC:Array 类型,但该架构不包含在 wsdl 中。

    我遇到了类似的问题,不得不使用目录来告诉 jaxb/xjc 在哪里可以找到架构。

    转到http://schemas.xmlsoap.org/soap/encoding/ 并保存为soapenc.xsd

    然后创建一个包含以下内容的纯文本文件

    PUBLIC "http://schemas.xmlsoap.org/soap/encoding/" "soapenc.xsd"
    

    然后将该文件作为目录文件传递给 xjc


    更新:如果你在 maven 上,这就是它的组合方式。

    将架构、soapenc.xsd 和 catalog.cat(纯文本文件)放在 src/main/resources 中

    然后告诉jaxb插件把目录传给xjc

    <plugin>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin</artifactId>
        <executions>
          <execution>
            <id>wsdl-generate</id>
            <configuration>
              <schemaIncludes>
                <include>*.wsdl</include>
              </schemaIncludes>
              <catalog>${project.basedir}/src/main/resources/catalog.cat</catalog>
            </configuration>
            <goals>
              <goal>generate</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    

    【讨论】:

    • 注意:如果您使用的是动态客户端,只需将编码文件传递给客户端:Client client = factory.createClient(wsdlURL.toExternalForm(), SERVICE_NAME, Collections.singletonList("http://schemas.xmlsoap.org/soap/encoding/"));
    • 如果我添加了 soapenc.xsd,arrayType 错误消失了,但它与其他类型冲突,例如:'positiveInteger' 已经定义。有什么想法吗?
    • maven 解决方案对我不起作用。目录文件中的“soapenc.xsd”似乎被忽略了。
    【解决方案2】:

    查看 WS-I BasicProfile-1.1 规范,网址为 http://www.ws-i.org/Profiles/BasicProfile-1.1.html#soapenc_Array

    上面写着:

    R2110 在说明中,声明不得扩展或限制 soapenc:Array 类型。

    R2111 在说明中,声明不得在类型声明中使用 wsdl:arrayType 属性。

    R2112 在说明中,不应使用约定 ArrayOfXXX 命名元素。

    R2113 信封不得包含 soapenc:arrayType 属性。

    哟!

    【讨论】:

    • 这有什么帮助?
    【解决方案3】:

    我认为最好的方法是使用旧的好轴 1.4。它旨在与 rpc 服务一起使用,并且通常可以完成其工作。主要问题是这个库非常非常旧(jar 是在 2006 年上传到中心的)并且不再维护。

    如果您决定试一试,只需将以下依赖项添加到您的 pom 中:

    <dependency>
        <groupId>axis</groupId>
        <artifactId>axis</artifactId>
        <version>1.4</version>
    </dependency>
    

    添加以下插件:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>axistools-maven-plugin</artifactId>
        <version>1.4</version>
        <executions>
            <execution>
                <goals>
                    <goal>wsdl2java</goal>
                </goals>
            </execution>
        </executions>
        <dependencies>
            <dependency>
                <groupId>javax.activation</groupId>
                <artifactId>javax.activation-api</artifactId>
                <version>1.2.0</version>
            </dependency>
            <dependency>
                <groupId>javax.mail</groupId>
                <artifactId>mail</artifactId>
                <version>1.4.7</version>
            </dependency>
        </dependencies>
        <configuration>
            <sourceDirectory>${project.basedir}/src/main/resources</sourceDirectory>
            <wsdlFiles>
                <wsdlFile>my_service.wsdl</wsdlFile>
            </wsdlFiles>
        </configuration>
    </plugin>
    

    将您的 wsdl 文件放入 src/main/resources/my_service.wsdl 并通过 mvn clean package 构建应用程序。

    插件详情可查看here

    【讨论】:

      【解决方案4】:

      JAXB 不支持 RPC/编码。使用 JAX-RPC 来解决这个问题。

      【讨论】:

      • 这与 JAXB 无关,是 JAX-WS 问题
      【解决方案5】:

      我使用的是axis1.5的wsdl2java实用程序,我们在数组上遇到了类似的错误。

      Exception in thread "main" org.apache.axis2.wsdl.codegen.CodeGenerationException: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
                  at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.generate(CodeGenerationEngine.java:271)
                  at org.apache.axis2.wsdl.WSDL2Code.main(WSDL2Code.java:35)
                  at org.apache.axis2.wsdl.WSDL2Java.main(WSDL2Java.java:24)
          Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
                  at org.apache.axis2.wsdl.codegen.extension.SimpleDBExtension.engage(SimpleDBExtension.java:53)
                  at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.generate(CodeGenerationEngine.java:224)
                  ... 2 more
          Caused by: java.lang.reflect.InvocationTargetException
                  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                  at java.lang.reflect.Method.invoke(Method.java:597)
                  at org.apache.axis2.wsdl.codegen.extension.SimpleDBExtension.engage(SimpleDBExtension.java:50)
                  ... 3 more
          Caused by: org.apache.axis2.schema.SchemaCompilationException: can not find type {http://schemas.xmlsoap.org/soap/encoding/}Array from the parent schema ....
                  at org.apache.axis2.schema.SchemaCompiler.copyMetaInfoHierarchy(SchemaCompiler.java:1296)
                  at org.apache.axis2.schema.SchemaCompiler.processComplexContent(SchemaCompiler.java:1258)
                  at org.apache.axis2.schema.SchemaCompiler.processContentModel(SchemaCompiler.java:1153)
                  at org.apache.axis2.schema.SchemaCompiler.processComplexType(SchemaCompiler.java:1097)
                  at org.apache.axis2.schema.SchemaCompiler.processNamedComplexSchemaType(SchemaCompiler.java:1017)
      

      正如上面关于 soapenc.xsd 的答案之一所述,我尝试通过使用网站“http://schemas.xmlsoap.org/soap/encoding/”中的内容创建 soapenc.xsd 来更新我的 wsdl 文件。 如下所示,这对我来说真的很有效。

      <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1= .. xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns=.. xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace=..>
      <types>
          <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" targetNamespace=.. xmlns:ns1=.. xmlns:ns2=.. xmlns:tns=.. xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/>
      </types>
      <import location="soapenc.xsd" namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
      <message name="Input">
          <part name=../>
      </message>
      <message name="Output">
          <part name=../>
      </message>
      <portType name=".."> .. </portType>
      <binding name="..." type="tns:"..">
          <operation name="...">          ..          </operation>
          <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
      </binding>
      <service name="...">
          <port binding="tns:..." name="...">         <soap:address location="..."/>      </port>
      </service>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-09-23
        • 1970-01-01
        • 2012-11-05
        相关资源
        最近更新 更多