CXF:org.apache.cxf.interceptor.Fault:调用时参数的数量错误

时间:2017-10-10 17:37:55

标签: java apache web-services cxf cxf-codegen-plugin

我使用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时的参数数量错误it.test.cxf.impl.New_Port_0SoapImpl.openTk。

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

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

0 个答案:

没有答案