CXF JaxWs Endpoint失败,并且给定的SOAPAction与操作不匹配'当动作包含重音时

时间:2014-06-19 11:42:36

标签: soap cxf action non-ascii-characters

我遇到了包含重音符号的SOAPAction问题。

从第三方WSDL,我使用CXF wsdl2java插件生成了Java Classes。使用生成的类,我开发了一个基于CXF的客户端和服务器。问题是服务器无法获得客户端的请求,并出现以下错误:

2014-06-19 11:45:08,423 [qtp1051344475-17] WARN - Interceptor for {http://simulator.be.connectors.cam/}RIBSOAPSoapImplService#{http://tempuri.org/}Opération_1 has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: The given SOAPAction http://tempuri.org/RIB_SOAP/Opération_1 does not match an operation.
    at org.apache.cxf.binding.soap.interceptor.SoapActionInInterceptor$SoapActionInAttemptTwoInterceptor.handleMessage(SoapActionInInterceptor.java:188)
    at org.apache.cxf.binding.soap.interceptor.SoapActionInInterceptor$SoapActionInAttemptTwoInterceptor.handleMessage(SoapActionInInterceptor.java:163)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
    at ...

客户端请求的日志显示SOAPAction的正确值,而服务器端的请求显示错误的值。

客户端的请求是:

2014-06-19 11:45:08,349 [main] INFO - Outbound Message
---------------------------
ID: 1
Address: http://localhost:17081/SIMULATOR/RIB/WS
Encoding: UTF-8
Http-Method: POST
Content-Type: text/xml
Headers: {Accept=[*/*], Connection=[Keep-Alive], SOAPAction=["http://tempuri.org/RIB_SOAP/Opération_1"]}
Payload: <?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <ns3:Opération_1 xmlns:ns2="http://Rib_InSchema" xmlns:ns3="http://tempuri.org/" xmlns:ns4="http://Rib_OutSchema">
      <ns2:Root>
        <RIB>1234567890</RIB>
      </ns2:Root>
    </ns3:Opération_1>
  </soap:Body>
</soap:Envelope>

--------------------------------------

服务器端的请求是:

2014-06-19 11:45:08,408 [qtp1051344475-17] INFO - Inbound Message
----------------------------
ID: 2
Address: http://localhost:17081/SIMULATOR/RIB/WS
Encoding: UTF-8
Http-Method: POST
Content-Type: text/xml; charset=UTF-8
Headers: {Accept=[*/*], Cache-Control=[no-cache], connection=[keep-alive], Content-Length=[339], content-type=[text/xml; charset=UTF-8], Host=[localhost:17081], Pragma=[no-cache], SOAPAction=["http://tempuri.org/RIB_SOAP/Opération_1"], User-Agent=[Apache CXF 2.7.10]}
Payload: <?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <ns3:Opération_1 xmlns:ns2="http://Rib_InSchema" xmlns:ns3="http://tempuri.org/" xmlns:ns4="http://Rib_OutSchema">
      <ns2:Root>
        <RIB>1234567890</RIB>
      </ns2:Root>
    </ns3:Opération_1>
  </soap:Body>
</soap:Envelope>

--------------------------------------

从日志中可以看出,UTF-8是所有级别使用的编码。但是,出于某种原因,在服务器端,SOAPAction已使用ISO-8859-1进行解码。

使用的WSDL是:

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/"
    xmlns:s1="http://Rib_InSchema" xmlns:s="http://www.w3.org/2001/XMLSchema"
    xmlns:s2="http://Rib_OutSchema"
    xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
    targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
    <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">BizTalk assembly
        "BTS, Version=1.0.0.0, Culture=neutral,
        PublicKeyToken=dab3109d17486051" published web service.
    </wsdl:documentation>
    <wsdl:types>
        <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
            <s:import namespace="http://Rib_InSchema" />
            <s:import namespace="http://Rib_OutSchema" />
            <s:element name="Opération_1">
                <s:complexType>
                    <s:sequence>
                        <s:element minOccurs="0" maxOccurs="1" ref="s1:Root" />
                    </s:sequence>
                </s:complexType>
            </s:element>
            <s:element name="Opération_1Response">
                <s:complexType>
                    <s:sequence>
                        <s:element minOccurs="0" maxOccurs="1" ref="s2:Root" />
                    </s:sequence>
                </s:complexType>
            </s:element>
        </s:schema>
        <s:schema elementFormDefault="qualified"
            targetNamespace="http://Rib_InSchema">
            <s:element name="Root">
                <s:complexType>
                    <s:sequence>
                        <s:element minOccurs="0" maxOccurs="1" form="unqualified"
                            name="RIB" type="s:string" />
                    </s:sequence>
                </s:complexType>
            </s:element>
        </s:schema>
        <s:schema elementFormDefault="qualified"
            targetNamespace="http://Rib_OutSchema">
            <s:element name="Root">
                <s:complexType>
                    <s:sequence>
                        <s:element minOccurs="0" maxOccurs="1" form="unqualified"
                            name="NumCompte" type="s:string" />
                        <s:element minOccurs="0" maxOccurs="1" form="unqualified"
                            name="Nom" type="s:string" />
                        <s:element minOccurs="0" maxOccurs="1" form="unqualified"
                            name="Prenom" type="s:string" />
                        <s:element minOccurs="0" maxOccurs="1" form="unqualified"
                            name="Agence" type="s:string" />
                        <s:element minOccurs="0" maxOccurs="1" form="unqualified"
                            name="AgenceAdresse" type="s:string" />
                        <s:element minOccurs="0" maxOccurs="1" form="unqualified"
                            name="RIB" type="s:string" />
                    </s:sequence>
                </s:complexType>
            </s:element>
        </s:schema>
    </wsdl:types>
    <wsdl:message name="Opération_1SoapIn">
        <wsdl:part name="parameters" element="tns:Opération_1" />
    </wsdl:message>
    <wsdl:message name="Opération_1SoapOut">
        <wsdl:part name="parameters" element="tns:Opération_1Response" />
    </wsdl:message>
    <wsdl:portType name="RIB_SOAPSoap">
        <wsdl:operation name="Opération_1">
            <wsdl:input message="tns:Opération_1SoapIn" />
            <wsdl:output message="tns:Opération_1SoapOut" />
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="RIB_SOAPSoap"
        type="tns:RIB_SOAPSoap">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="Opération_1">
            <soap:operation
                soapAction="http://tempuri.org/RIB_SOAP/Opération_1"
                style="document" />
            <wsdl:input>
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:binding name="RIB_SOAPSoap12"
        type="tns:RIB_SOAPSoap">
        <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="Opération_1">
            <soap12:operation
                soapAction="http://tempuri.org/RIB_SOAP/Opération_1"
                style="document" />
            <wsdl:input>
                <soap12:body use="literal" />
            </wsdl:input>
            <wsdl:output>
                <soap12:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="RIB_SOAP">
        <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">BizTalk assembly
            "BTS, Version=1.0.0.0, Culture=neutral,
            PublicKeyToken=dab3109d17486051" published web service.
        </wsdl:documentation>
        <wsdl:port name="RIB_SOAPSoap"
            binding="tns:RIB_SOAPSoap">
            <soap:address
                location="http://localhost/BTS_Proxy/RIB_SOAP.asmx" />
        </wsdl:port>
        <wsdl:port name="RIB_SOAPSoap12"
            binding="tns:RIB_SOAPSoap12">
            <soap12:address
                location="http://localhost/BTS_Proxy/RIB_SOAP.asmx" />
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

客户端的Spring conf:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
        http://cxf.apache.org/jaxws
            http://cxf.apache.org/schemas/jaxws.xsd
        http://cxf.apache.org/transports/http/configuration
            http://cxf.apache.org/schemas/configuration/http-conf.xsd
    "
>
    <!--.~~~~~~~~..~~~~~~~~..~~~~~~~~..~~~~~~~~..~~~~~~~~..~~~~~~~~..~~~~~~~~-->
    <!--.~~~~~~~~..~~~~~~~~..~~~~~~~~..~~~~~~~~..~~~~~~~~..~~~~~~~~..~~~~~~~~-->
    <http-conf:conduit name=".*">
        <http-conf:client ConnectionTimeout="30000" ReceiveTimeout="30000" />
    </http-conf:conduit>

    <jaxws:client 
        id="ribWebServiceClient"
        serviceClass="org.tempuri.RIBSOAPSoap"
        address="${ws.rib.url}"
    >
        <jaxws:features>
            <bean class="org.apache.cxf.feature.LoggingFeature" >
                <property name="prettyLogging" value="true" />
            </bean>
        </jaxws:features>
        <jaxws:properties>
            <entry key="exceptionMessageCauseEnabled" value="true" />
            <entry key="faultStackTraceEnabled" value="true" />
        </jaxws:properties>
    </jaxws:client>
    <!--.~~~~~~~~..~~~~~~~~..~~~~~~~~..~~~~~~~~..~~~~~~~~..~~~~~~~~..~~~~~~~~-->
</beans>

服务器的Spring conf:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
        http://cxf.apache.org/jaxws
            http://cxf.apache.org/schemas/jaxws.xsd
    "
>
    <!--.~~~~~~~~..~~~~~~~~..~~~~~~~~..~~~~~~~~..~~~~~~~~..~~~~~~~~..~~~~~~~~-->
    <!--.~~~~~~~~..~~~~~~~~..~~~~~~~~..~~~~~~~~..~~~~~~~~..~~~~~~~~..~~~~~~~~-->
    <import resource="classpath:META-INF/cxf/cxf.xml" />
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

    <!--.~~~~~~~~..~~~~~~~~..~~~~~~~~-->
    <jaxws:endpoint
        id="ribWebServiceEndPoint"
        implementor="#ribWebService"
        address="${ws.rib.url}"
    >
        <jaxws:features>
            <bean class="org.apache.cxf.feature.LoggingFeature" >
                <property name="prettyLogging" value="true" />
            </bean>
        </jaxws:features>
        <jaxws:properties>
            <entry key="exceptionMessageCauseEnabled" value="true" />
            <entry key="faultStackTraceEnabled" value="true" />
        </jaxws:properties>
    </jaxws:endpoint>
    <!--.~~~~~~~~..~~~~~~~~..~~~~~~~~..~~~~~~~~..~~~~~~~~..~~~~~~~~..~~~~~~~~-->
</beans>

1 个答案:

答案 0 :(得分:2)

根据HTTP规范,所有HTTP头应该是ISO-8859-1。如何将非ISO-8859-1字符编码到标题(http://tools.ietf.org/html/rfc2047)中有一个单独的规范,但我不确定JDK中的HTTPUrlConnection对象是否支持。我也不确定其他肥皂客户是否会支持它。

我强烈建议确保SOAPAction值与ISO-8859-1兼容。