在 Mule 中用 http:request 替换已弃用的 https:outbound-endpoint

Replacing the deprecated https:outbound-endpoint with http:request in Mule

我使用以下配置在 mule 3.2 中访问基于 SOAP 的服务,效果很好

<https:connector name="https" doc:name="HTTP\HTTPS"></https:connector>

<https:outbound-endpoint exchange-pattern="request-response" method="POST" 
            address="https://localhost:8080/CXF3Service/test" responseTimeout="15000" contentType="application/xml" 
            doc:name="HTTP Submit Request SOAP" connector-ref="https"> <message-properties-transformer 
            scope="outbound"> <add-message-property key="SOAPAction" value="https://myservice/myEndpoint" 
            /> </message-properties-transformer> </https:outbound-endpoint>

wsdl 中的 SOAP 绑定看起来像,

<wsdl:operation name="sayHello">
<soap:operation soapAction="https://myservice/myEndpoint" style="document"/>
<wsdl:input name="sayHello">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="sayHelloResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>

在迁移到 Mule 3.6 时,我按如下方式替换了代码。这样做是为了用 http:request

替换已弃用的 https:outbound-endpoint
<http:request-config name="http" protocol="HTTPS"
        host="localhost" port="8080"
        doc:name="HTTP Request Configuration"/>

<http:request config-ref="http" path="CXF3Service/test" method="POST"
            doc:name="HTTP" responseTimeout="15000" >
            <http:request-builder>
                <http:header headerName="SOAPAction" value="https://myservice/myEndpoint" ></http:header>
            </http:request-builder>         
            <http:success-status-code-validator
                values="0..599" />
        </http:request>

但是在使用新代码访问服务时,我收到 SOAP 错误作为响应。

<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <soap:Fault>
      <faultcode>soap:Client</faultcode>
      <faultstring>Server did not recognize the value of HTTP Header SOAPAction: https://myservice/myEndpoint, "".</faultstring>
      <detail/>
    </soap:Fault>
  </soap:Body>
</soap:Envelope>

这可能是什么原因?

仅供参考。我正在使用一个 cxf:proxy-client,以有效载荷作为信封,两者都保持不变。

<cxf:proxy-client payload="envelope" doc:name="Proxy client">
    <cxf:inInterceptors>
        <spring:bean class="org.apache.cxf.interceptor.LoggingInInterceptor">
            <spring:property name="prettyLogging" value="true" />
        </spring:bean>
    </cxf:inInterceptors>
    <cxf:outInterceptors>
        <spring:bean class="org.apache.cxf.interceptor.LoggingOutInterceptor">
            <spring:property name="prettyLogging" value="true" />
        </spring:bean>
    </cxf:outInterceptors>
    <cxf:outFaultInterceptors>
        <spring:bean class="org.apache.cxf.interceptor.LoggingOutInterceptor">
            <spring:property name="prettyLogging" value="true" />
        </spring:bean>
    </cxf:outFaultInterceptors>
</cxf:proxy-client>

小小的调整就产生了魔力!!

我在 http:request 之前设置了 SOAPAction,而不是在内部设置。

<cxf:proxy-client payload="envelope" doc:name="Proxy client">
<cxf:inInterceptors>
    <spring:bean class="org.apache.cxf.interceptor.LoggingInInterceptor">
        <spring:property name="prettyLogging" value="true" />
    </spring:bean>
</cxf:inInterceptors>
<cxf:outInterceptors>
    <spring:bean class="org.apache.cxf.interceptor.LoggingOutInterceptor">
        <spring:property name="prettyLogging" value="true" />
    </spring:bean>
</cxf:outInterceptors>
<cxf:outFaultInterceptors>
    <spring:bean class="org.apache.cxf.interceptor.LoggingOutInterceptor">
        <spring:property name="prettyLogging" value="true" />
    </spring:bean>
</cxf:outFaultInterceptors>
</cxf:proxy-client>
  <message-properties-transformer>
      <add-message-property key="SOAPAction" value="https://myservice/myEndpoint"/>
    </message-properties-transformer>
    <http:request config-ref="http" path="CXF3Service/test" method="POST"
        doc:name="HTTP" responseTimeout="15000" >        
        <http:success-status-code-validator
            values="0..599" />
    </http:request>