1

我正在使用 apache cxf 和 codegen maven 插件(均发布 3.1.11)实现一个简单的客户端。

这是我的示例 wsdl:

    <?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="urn:webServiceTest" xmlns:s0="urn:webServiceTest" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <wsdl:types>
  <xsd:schema elementFormDefault="qualified" targetNamespace="urn:webServiceTest">
   <xsd:element name="OpenTk" type="s0:InputMapping1"/>
   <xsd:complexType name="InputMapping1">
    <xsd:sequence>
     <xsd:element minOccurs="0" name="ID_NOTIFICA" type="xsd:string"/>
     <xsd:element minOccurs="0" name="ID_MESSAGGIO" type="xsd:string"/>
     <xsd:element minOccurs="0" name="DATA_ID_NOTIFICA" type="xsd:dateTime"/>
     <xsd:element minOccurs="0" name="DATA_ID_MESSAGGIO" type="xsd:dateTime"/>
     <xsd:element minOccurs="0" name="ID_RISORSA" type="xsd:string"/>
    </xsd:sequence>
   </xsd:complexType>
   <xsd:element name="APERTURATKResponse" type="s0:OutputMapping1"/>
   <xsd:complexType name="OutputMapping1">
    <xsd:sequence>
     <xsd:element minOccurs="0" name="CODICE" type="xsd:string"/>
     <xsd:element minOccurs="0" name="DESCRIZIONE" type="xsd:string"/>
     <xsd:element minOccurs="0" name="NOTE" nillable="true" type="xsd:string"/>
    </xsd:sequence>
   </xsd:complexType>

   <xsd:element name="AuthenticationInfo" type="s0:AuthenticationInfo"/>
   <xsd:complexType name="AuthenticationInfo">
    <xsd:sequence>
     <xsd:element name="userName" type="xsd:string"/>
     <xsd:element name="password" type="xsd:string"/>
     <xsd:element minOccurs="0" name="authentication" type="xsd:string"/>
     <xsd:element minOccurs="0" name="locale" type="xsd:string"/>
     <xsd:element minOccurs="0" name="timeZone" type="xsd:string"/>
    </xsd:sequence>
   </xsd:complexType>
  </xsd:schema>
 </wsdl:types>
   <wsdl:message name="OpenTkSoapOut">
      <wsdl:part element="s0:APERTURATKResponse" name="parameters">
      </wsdl:part>
   </wsdl:message>
   <wsdl:message name="OpenTkSoapIn">
      <wsdl:part element="s0:OpenTk" name="parameters">
      </wsdl:part>
   </wsdl:message>
   <wsdl:message name="ARAuthenticate">
      <wsdl:part element="s0:AuthenticationInfo" name="parameters">
      </wsdl:part>
   </wsdl:message>
   <wsdl:portType name="New_Port_0PortType">
      <wsdl:operation name="OpenTk">
         <wsdl:input message="s0:OpenTkSoapIn">
       </wsdl:input>
         <wsdl:output message="s0:OpenTkSoapOut">
       </wsdl:output>
      </wsdl:operation>
   </wsdl:portType>
   <wsdl:binding name="New_Port_0SoapBinding" type="s0:New_Port_0PortType">
      <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
      <wsdl:operation name="OpenTk">
         <soap:operation soapAction="urn:webServiceTest/OpenTk" style="document"/>
         <wsdl:input>
            <soap:header message="s0:ARAuthenticate" part="parameters" use="literal">
            </soap:header>
            <soap:body use="literal"/>
         </wsdl:input>
         <wsdl:output>
            <soap:body use="literal"/>
         </wsdl:output>
      </wsdl:operation>
   </wsdl:binding>
   <wsdl:service name="WebServicesFWCFFService">
      <wsdl:port binding="s0:New_Port_0SoapBinding" name="New_Port_0Soap">
         <soap:address location="http://localhost:9090/testService"/>
      </wsdl:port>
   </wsdl:service>
</wsdl:definitions>

我需要更改客户端端点,所以我决定使用 cxf.frontend 功能。我创建了一个简单的客户端,并使用 api 来设置地址属性。这是代码:

QName SERVICE = new QName("urn:webServiceTest", "WebServicesFWCFFService");

URL url = this.getClass().getClassLoader().getResource("testWsdl.wsdl").toURI().toURL();
            NewPort0PortType portType = new WebServicesFWCFFService(url, SERVICE).getNewPort0Soap();
            Client client = ClientProxy.getClient(portType);
            client.getRequestContext().put(Message.ENDPOINT_ADDRESS,address);

然后在我的单元测试中,我尝试调用服务(由 codegen 插件创建的服务):

ClientTest client = new ClientTest();
        Holder<String> code= new Holder<>();
        Holder<String> description= new Holder<>();
        Holder<String> notes= new Holder<>();
        client.portType.openTk("12","",
                null,null,"1",code, description, notes);
        assertNotNull(notes.value);
        assertNotNull(code.value);

但我收到一个肥皂错误 org.apache.cxf.binding.soap.SoapFault:在调用 public void it.test.cxf.impl.New_Port_0SoapImpl.openTk 时参数数量错误。

我发现问题似乎出在 org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor 内部,特别是当这个拦截器使用 getHelperWrapper 方法创建 WrapperHelper 类时。然后使用这个包装器使用由 codegen 插件创建的 ObjectFactory (createWrapperObject(objs);) 创建对象。这会产生一个所有字段为空的新 InputMappin1 对象。

有人可以解释我这种行为以及如何避免这种行为吗?我是否需要实现某种自定义拦截器或者我缺少一些配置?

4

0 回答 0