【问题标题】:Jaxws doesn't populate resultsJaxws 不填充结果
【发布时间】:2014-09-22 06:52:34
【问题描述】:

我有一个使用 Axis1 制作的有效 Web 服务,我正在将它迁移到 Jaxws

我正在使用我的工作 WSDL 文件中的 wsimport 和 maven 创建我的客户端类。

我遇到的问题是,我可以在记录器中看到带有数据的 SOAP 响应消息,但对象没有填充这些数据。

我的 wsdl 看起来是这样的(我只发布了 1 个服务以使其更短并删除了一些元素,因此如果缺少像 ResultadoProcesamiento 这样的内容,请忽略):

<wsdl:definitions targetNamespace="http://ws.test" xmlns:apachesoap="http://xml.apache.org/xml-soap" 
    xmlns:impl="http://ws.test" 
    xmlns:intf="http://ws.test" 
    xmlns:tns1="http://pojo.test" 
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
    xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<schema elementFormDefault="qualified" targetNamespace="http://ws.test" xmlns="http://www.w3.org/2001/XMLSchema" >
       <import namespace="http://pojo.test"/>
       <element name="validarCertificado">
        <complexType>
         <sequence>
          <element name="cert" type="xsd:string"/>
         </sequence>
        </complexType>
       </element>
       <element name="validarCertificadoResponse">
        <complexType>
         <sequence>
          <element name="validarCertificadoReturn" type="tns1:MensajeSalida"/>
         </sequence>
        </complexType>
       </element>
      </schema>
      <schema elementFormDefault="qualified" targetNamespace="http://pojo.test" xmlns="http://www.w3.org/2001/XMLSchema">
       <import namespace="http://ws.test"/>
       <complexType name="Respuesta">
        <sequence>
         <element name="excepcion" nillable="true" type="tns1:Excepcion"/>
         <element name="resultadoProcesamiento" nillable="true" type="tns1:ResultadoProcesamiento"/>
        </sequence>
       </complexType>
       <complexType name="MensajeSalida">
        <sequence>
         <element name="peticion" nillable="true" type="xsd:string"/>
         <element name="respuesta" nillable="true" type="tns1:Respuesta"/>
         <element name="versionMsg" nillable="true" type="xsd:string"/>
        </sequence>
       </complexType>
      </schema>
     </wsdl:types>

       <wsdl:message name="validarCertificadoRequest">
          <wsdl:part element="impl:validarCertificado" name="parameters"/>
       </wsdl:message>
       <wsdl:message name="validarCertificadoResponse">
          <wsdl:part element="impl:validarCertificadoResponse" name="parameters"/>
       </wsdl:message>

       <wsdl:portType name="WsTest">
          <wsdl:operation name="validarCertificado">
             <wsdl:input message="impl:validarCertificadoRequest" name="validarCertificadoRequest"/>
             <wsdl:output message="impl:validarCertificadoResponse" name="validarCertificadoResponse"/>
          </wsdl:operation>
       </wsdl:portType>

       <wsdl:binding name="WsTestSoapBinding" type="impl:WsTest">
          <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
          <wsdl:operation name="validarCertificado">
             <wsdlsoap:operation soapAction=""/>
             <wsdl:input name="validarCertificadoRequest">
                <wsdlsoap:body use="literal"/>
             </wsdl:input>
             <wsdl:output name="validarCertificadoResponse">
                <wsdlsoap:body use="literal"/>
             </wsdl:output>
          </wsdl:operation>
       </wsdl:binding>

       <wsdl:service name="WsTestService">

       </wsdl:service>

    </wsdl:definitions>

我不得不创建 2 个包,因为我有一些同名但来自不同架构的元素。

第一个包:

package-info.java

@XmlSchema(namespace = "http://ws.test", elementFormDefault = XmlNsForm.QUALIFIED)
package test.ws;

ValidarCertificadoResponse.java

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = { "validarCertificadoReturn" })
@XmlRootElement(name = "validarCertificadoResponse")
public class ValidarCertificadoResponse {

        @XmlElement(required = true)
        protected MensajeSalida validarCertificadoReturn;

第二包:

package-info.java

@XmlSchema(namespace = "http://pojo.test", elementFormDefault = XmlNsForm.QUALIFIED)
package pojo.ws;

MensajeSalida.java

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "MensajeSalida", propOrder = { "peticion", "respuesta", "versionMsg" })
public class MensajeSalida {

    @XmlElement(required = true, nillable = true)
    protected String peticion;
    @XmlElement(required = true, nillable = true)
    protected Respuesta respuesta;
    @XmlElement(required = true, nillable = true)
    protected String versionMsg;

还有我的响应 SOAP 消息(它只包含一些标签):

<soapenv:Body>
<validarCertificadoResponse xmlns="http://ws.test">
    <validarCertificadoReturn>
      <peticion>value1</peticion>
      <respuesta>
         datas
      <respuesta/>
      <resultadoProcesamiento>
         more datas
      </resultadoProcesamiento>

执行 jaxws-maven-plugin:2.3 生成的客户端后,我的 ValidarCertificadoResponse 具有以下属性:

ValidarCertificadoResponse.java
   validarCertificadoReturn
       peticion = null;
       respuesta = null;
       resultadoProcesamiento = null;

你觉得有什么不对吗?我猜 WSDL 中有错误,或者插件没有正确创建标头?

谢谢。

【问题讨论】:

    标签: java jax-ws jaxws-maven-plugin


    【解决方案1】:

    我找到了解决问题的方法。

    如果我们检查响应 SOAP 消息,我们可以看到只有一个模式 (http://ws.test),因此属于第二个模式的所有其他元素都无法转换,因为 jaxws 找不到匹配项。

    我无法修改 Web 服务,因为它不是我的,所以我将我的 wsdl 调整为只有 1 个架构。我想这不是最干净的解决方案,但它确实有效。

    下面是一个例子:

    之前

    <element name="validarCertificadoResponse">
        <complexType>
          <sequence>
            <element name="validarCertificadoReturn" type="tns1:MensajeSalida"/>
          </sequence>
        </complexType>
    </element>
    

    之后

    <xsd:element name="validarCertificadoResponse">
      <xsd:complexType>
        <xsd:sequence>
          <xsd:element name="validarCertificadoReturn">
            <!-- This is the content of tns1:MensajeSalida -->
            <xsd:complexType>
             <xsd:sequence>
               <xsd:element name="peticion" type="xsd:string"/>
               <!-- This is the content of tns1:Respuesta -->
               <xsd:element name="respuesta">
                <xsd:complexType>
                  <xsd:sequence>
                    <xsd:element name="excepcion" nillable="true">
                      <!-- This is the content of tns1:Excepcion -->
                      <xsd:complexType>
                        <xsd:sequence>
                          <xsd:element name="codigoError" nillable="true" type="xsd:string"/>
                        </xsd:sequence>
                      </xsd:complexType>
                    </xsd:element>
                    <xsd:element name="resultadoProcesamiento" nillable="true">
                      <!-- This is the content of tns1:ResultadoProcesamiento -->
                      <xsd:complexType>
                        <xsd:sequence>
                          <xsd:element name="resultado" nillable="true" type="xsd:string"/>
                        </xsd:sequence>
                      </xsd:complexType>
                    </xsd:element>
                  </xsd:sequence>
                </xsd:complexType>
              </xsd:element>
              <xsd:element name="versionMsg" type="xsd:string"/>
             </xsd:sequence>
            </xsd:complexType>
          </xsd:element>
        </xsd:sequence>
      </xsd:complexType>
    </xsd:element>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-26
      • 1970-01-01
      • 2023-03-23
      • 2014-09-09
      • 1970-01-01
      • 2023-04-11
      • 2017-05-19
      • 1970-01-01
      相关资源
      最近更新 更多