简体   繁体   English

如何在Mule 3.7.0 CE上代理Web服务

[英]How to proxy a web service on mule 3.7.0 CE

I was using mule 3.4.0 CE to proxy a remote web service, but with the new 3.7.0 CE i cant find any example of this working over flow so i can use http shared connector, any clue? 我使用mule 3.4.0 CE代理远程Web服务,但是使用新的3.7.0 CE时,找不到该工作流的任何示例,因此我可以使用http共享连接器,有任何线索吗?

Example that does not work for C# based consumers: 对于基于C#的使用者不起作用的示例:

<flow name="Test">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/services/teste/teste" doc:name="HTTP"/>
    <logger message="AutenticacaoServicoFlowTesteHttp - #[message]" level="INFO" doc:name="Logger"/>
    <response>
        <logger message="ATestHttp - response - #[message]" level="INFO" doc:name="Logger"/>
    </response>
    <set-variable variableName="queryStringIncompleto" value="#[message.inboundProperties.'host']/logTicket?ipFrom=#[message.inboundProperties.'http.remote.address']&amp;requestSize=#[message.inboundProperties.'http.request.uri'.length()]&amp;url=#[message.inboundProperties.'host']#[message.inboundProperties.'http.request.uri'.replaceAll(&quot;&amp;&quot;, &quot;%26&quot;)]&amp;userName=#[message.inboundProperties.'authorization']&amp;modifiedRequestSize=#[message.inboundProperties.'http.request.uri'.length()]" doc:name="QueryString LogTicket"/>
    <choice doc:name="Choice">
        <when expression="#[message.inboundProperties.'http.request.uri' == '/services/Autentic?wsdl']">
            <set-variable variableName="queryString" value="#[flowVars.queryStringIncompleto]&amp;method=#[message.inboundProperties.'http.method']" doc:name="QueryString LogBilhetagem"/>
            <cxf:proxy-service  namespace="logTeste.gov" service="AutenticacaoServico" payload="envelope" wsdlLocation="${targetServerLog}/servicos/v2/Autentic.svc?singleWsdl" soapVersion="1.2" doc:name="CXF"/>
        </when>
        <otherwise>
            <set-variable variableName="queryString" value="#[flowVars.queryStringIncompleto]&amp;method=#[message.inboundProperties.'SOAPAction'.replaceAll(&quot;\&quot;&quot;, &quot;&quot;)]" doc:name="QueryString LogTicket"/>
            <message-properties-transformer doc:name="Message Properties">
                <add-message-property key="SOAPAction" value="#[message.inboundProperties.'SOAPAction']"/>
            </message-properties-transformer>
            <outbound-endpoint exchange-pattern="request-response" address="${targetServerLog}/servicos/v2/Autentc.svc" encoding="UTF-8" mimeType="text/xml" doc:name="Generic"/>
        </otherwise>
    </choice>
    <set-variable variableName="payloadLog" value="#[message.payloadAs(java.lang.String)]" doc:name="Guarda Payload Log"/>
    <outbound-endpoint exchange-pattern="request-response" address="https://teste:teste@#[flowVars.queryString]" doc:name="Log Bilhetagem"/>
    <set-payload value="#[flowVars.payloadLog]" doc:name="Set Payload"/>
    <response>
        <message-properties-transformer doc:name="Message Properties">
            <add-message-property key="Content-Type" value="text/xml"/>
        </message-properties-transformer>
    </response>
</flow>

On most C# applications that consume this WS will do a first connection OK and the seccond will do a timeout... 在使用此WS的大多数C#应用程序上,将执行第一个连接正常,而seccond将执行超时...

Ok, found the problem and solved, wasnt the implementation, what i do is redirect a WS to the correct place but i also log the message into another WS, that will hang the flow and will not be possible to do a cascade call to alot of methods. 好的,找到问题并解决了,没有实现,我要做的是将WS重定向到正确的位置,但是我还将消息记录到另一个WS中,这将导致流程挂起,并且无法对很多对象进行级联调用方法。 So i just took out the seccond outbound to log the message and i will use another approach to log the message. 因此,我只是取出seccond出站来记录该消息,而我将使用另一种方法来记录该消息。

Code: 码:

<flow name="Test">
<http:listener config-ref="HTTP_Listener_Configuration" path="/services/teste/teste" doc:name="HTTP"/>
<set-variable variableName="queryStringIncompleto" value="#[message.inboundProperties.'host']/logTicket?ipFrom=#[message.inboundProperties.'http.remote.address']&amp;requestSize=#[message.inboundProperties.'http.request.uri'.length()]&amp;url=#[message.inboundProperties.'host']#[message.inboundProperties.'http.request.uri'.replaceAll(&quot;&amp;&quot;, &quot;%26&quot;)]&amp;userName=#[message.inboundProperties.'authorization']&amp;modifiedRequestSize=#[message.inboundProperties.'http.request.uri'.length()]" doc:name="QueryString LogTicket"/>
<choice doc:name="Choice">
    <when expression="#[message.inboundProperties.'http.request.uri' == '/services/Autentic?wsdl']">
        <set-variable variableName="queryString" value="#[flowVars.queryStringIncompleto]&amp;method=#[message.inboundProperties.'http.method']" doc:name="QueryString LogBilhetagem"/>
        <cxf:proxy-service  namespace="logTeste.gov" service="AutenticacaoServico" payload="envelope" wsdlLocation="${targetServerLog}/servicos/v2/Autentic.svc?singleWsdl" soapVersion="1.2" doc:name="CXF"/>
    </when>
    <otherwise>
        <set-variable variableName="queryString" value="#[flowVars.queryStringIncompleto]&amp;method=#[message.inboundProperties.'SOAPAction'.replaceAll(&quot;\&quot;&quot;, &quot;&quot;)]" doc:name="QueryString LogTicket"/>
        <message-properties-transformer doc:name="Message Properties">
            <add-message-property key="SOAPAction" value="#[message.inboundProperties.'SOAPAction']"/>
        </message-properties-transformer>
        <outbound-endpoint exchange-pattern="request-response" address="${targetServerLog}/servicos/v2/Autentc.svc" encoding="UTF-8" mimeType="text/xml" doc:name="Generic"/>
    </otherwise>
</choice>
<response>
    <message-properties-transformer doc:name="Message Properties">
        <add-message-property key="Content-Type" value="text/xml"/>
    </message-properties-transformer>
</response>

The way you're trying to proxy the services would not be the Ideal way of doing it, also was not the ideal in 3.4, please see the following documentation pages: 您尝试代理服务的方式不是理想的方式,也不是3.4中的理想方式,请参见以下文档页面:

https://developer.mulesoft.com/docs/display/current/Proxying+Web+Services+with+CXF https://developer.mulesoft.com/docs/display/current/Web+Service+Proxy+Pattern https://developer.mulesoft.com/docs/display/current/Proxying+Web+Services+with+CXF https://developer.mulesoft.com/docs/display/current/Web+Service+Proxy+Pattern

These are two standard way of proxying webservices. 这是代理Web服务的两种标准方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM