How to implement Mule HTTP GET Method redirect?

2020-08-03 05:21发布

问题:

I'm trying to redirect HTTP GET requests to a seperate web server. I could not find any example code. I configured mule.xml as below. I think there must be a better way than this. Any ideas? thanks.

<flow name="sampleInsert" doc:name="sampleInsert">
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" responseTimeout="1"  doc:name="HTTP" path="indb/sampleInsert" >                 
    </http:inbound-endpoint>                
    <logger level="INFO" doc:name="Logger" message="In Time #[server.dateTime]"/>

    <logger level="INFO" doc:name="Logger" message="Out Time #[server.dateTime]"/>
   <http:outbound-endpoint address="http://www.mulesoft.org/" doc:name="HTTP" exchange-pattern="request-response" followRedirects="true" method="GET"/>


</flow>

回答1:

Thats a valid pattern but there is also an out of the box pattern for a http proxy:

http://www.mulesoft.org/documentation/display/current/HTTP+Proxy+Pattern

Or you instead you can let the client redirect by setting the http 'Location' header and 30x response code:

    <flow name="testResponseMove" processingStrategy="synchronous">
        <http:inbound-endpoint address="http://localhost:${port1}/resources/move" exchange-pattern="request-response"/>
        <http:response-builder status="302">
            <http:location value="http://localhost:9090/resources/moved"/>
        </http:response-builder>
        <echo-component/>
    </flow>