mule 3.5遵循出站端点上的重定向

时间:2016-02-13 19:16:32

标签: http mule

我有简单的流程如下。当我们点击一​​个流时,它会访问另一个流并获取http.status 302和Location,这意味着它必须重定向到Location头中的位置。但它正在抛出异常。

<flow name="httpconnectorFlowRedirection">
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="9876" path="redirect" connector-ref="NoSessionEncodingConnector" doc:name="HTTP"/>
    <http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="9876" method="POST"  doc:name="HTTP" path="temp" connector-ref="NoSessionEncodingConnector" contentType="text/plain"
   followRedirects="true" />
    <logger message="#[payload]" level="INFO" doc:name="Logger"/>
</flow>

<flow name="temp_flow">
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="9876" path="temp" connector-ref="NoSessionEncodingConnector" doc:name="HTTP" />
    <logger message="in temp flow" level="INFO" doc:name="Logger"/>
    <set-property propertyName="http.status" value="307" doc:name="Property" />
    <set-property propertyName="Location" value="http://localhost:9876/samplehttp" doc:name="Property" />
</flow>

我得到的错误如下

org.mule.exception.DefaultMessagingExceptionStrategy: 
      ********************************************************************************
Message               : Failed to route event via endpoint:        DefaultOutboundEndpoint{endpointUri=http://localhost:9876/temp,     connector=HttpConnector
{
name=NoSessionEncodingConnector
lifecycle=start
this=14c5f0c
numberOfConcurrentTransactedReceivers=4
createMultipleTransactedReceivers=true
connected=true
supportedProtocols=[http]
serviceOverrides=
  session.handler=org.mule.session.NullSessionHandler
}
  ,  name='endpoint.http.localhost.9876.temp', mep=REQUEST_RESPONSE,         properties={exceptionOnMessageError=true, http.method=POST,       followRedirects=true, Content-Type=text/plain},      transactionConfig=Transaction{factory=null, action=INDIFFERENT, timeout=0},    deleteUnacceptedMessages=false, initialState=started, responseTimeout=10000,    endpointEncoding=UTF-8, disableTransportTransformer=false}. Message payload is      of type: PostMethod
Type                  : org.mule.api.transport.DispatchException
Code                  : MULE_ERROR--2
JavaDoc               :      http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transport/Dispat    chException.html
Payload               : org.apache.commons.httpclient.methods.PostMethod@14efe2e
  ********************************************************************************

仅当在出站端点上将重定向设置为true时才会出现此错误

我正在使用mule 3.5。

1 个答案:

答案 0 :(得分:0)

我得到了答案。我需要使用GET reqeust成功重定向。 但是如果我使用http监听器(因为mule 3.6),我甚至可以重定向到POST请求。请考虑以下示例。

<http:listener-config name="GlobalHTTPConnector" host="localhost" port="9876"  doc:name="HTTP Listener Configuration" basePath="mulelearning"/>
    <flow name="redirection-flow">
        <http:listener config-ref="GlobalHTTPConnector" path="/requestredir" doc:name="HTTP"/>
        <!--
            When followRedirects is set to true, when http.status from called service is redirection(eg:301), it redirects to new location.
            In this case /redFlow1 sends a redirection code 301 and location header. Hence it redirects to /redFlow2 (see the flows below) and gives us the response 'payload from red-flow2'
         -->
        <http:request config-ref="HTTP_Request_Configuration" path="/redFlow1" method="POST" followRedirects="true" doc:name="HTTP" />
    </flow>

    <flow name="red-ser1">
        <http:listener config-ref="GlobalHTTPConnector" path="/redFlow1" doc:name="HTTP"/>
        <logger level="INFO" doc:name="Logger" message="I am in red-flow1"/>
        <set-payload value="payload from red-flow1" />
        <set-property propertyName="http.status" value="301" doc:name="Property" />
        <set-property propertyName="Location" value="http://localhost:9876/mulelearning/redFlow2" doc:name="Property" />
    </flow>
    <flow name="red-ser2">
        <http:listener config-ref="GlobalHTTPConnector" path="/redFlow2" doc:name="HTTP"/>
        <set-payload value="payload from red-flow2" />
        <logger level="INFO" doc:name="Logger" message="I am in red-flow2"/>
    </flow>