禁用http侦听器的重定向mule

时间:2017-10-08 05:19:04

标签: http redirect http-headers mule mule-esb

只要代码中存在位置标头和http状态302,mule http侦听器就会在内部调用位置URL并获取http状态为200的响应,这看起来像是正常行为。

但是我希望看到一个302 http状态和一个在邮递员名称位置的标题。

可以通过任何方式完成吗?下面是我的代码

    <http:request-config name="HTTP_Request_Configuration2" host="localhost" port="8081" doc:name="HTTP Request Configuration"/>
<flow name="xpathforeachFlow">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/xpath" doc:name="HTTP"/>
    <logger message="inside another flow" level="INFO" doc:name="Logger"/>
    <set-payload value="this is a test flow" doc:name="Set Payload"/>
</flow>
<flow name="MainFlow">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/location302" doc:name="HTTP" >
    </http:listener>
    <logger message="inside 302" level="INFO" doc:name="Logger"/>
    <set-property propertyName="http.status" value="#['302']" doc:name="Property"/>
    <set-property propertyName="location" value="http://localhost:8081/xpath" doc:name="Property"/>
    <logger message="after property setting #[message]" level="INFO" doc:name="Logger"/>
</flow>

日志如下: -

    INFO  2017-10-08 10:41:35,800 [[demo].HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: inside 302
INFO  2017-10-08 10:41:35,807 [[demo].HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: after property setting 
org.mule.DefaultMuleMessage
{
  id=282de160-abe7-11e7-893f-dcc820524153
  payload=org.mule.transport.NullPayload
  correlationId=<not set>
  correlationGroup=-1
  correlationSeq=-1
  encoding=UTF-8
  exceptionPayload=<not set>

Message properties:
  INVOCATION scoped properties:
  INBOUND scoped properties:
    accept=*/*
    accept-encoding=gzip, deflate, br
    accept-language=en-US,en;q=0.8
    cache-control=no-cache
    connection=keep-alive
    cookie=cookie2:123
    host=localhost:8081
    http.listener.path=/location302
    http.method=GET
    http.query.params=ParameterMap{[]}
    http.query.string=
    http.relative.path=/location302
    http.remote.address=/127.0.0.1:36700
    http.request.path=/location302
    http.request.uri=/location302
    http.scheme=http
    http.uri.params=ParameterMap{[]}
    http.version=HTTP/1.1
    postman-token=d1cf089e-501f-aa9b-51b6-36a50b2b3806
    user-agent=Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
  OUTBOUND scoped properties:
    http.status=302
    location=http://localhost:8081/xpath
  SESSION scoped properties:
}
INFO  2017-10-08 10:41:35,819 [[demo].HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: inside another flow

我也无法在Chrome网络中看到任何302。如果有办法不仅可以在日志中捕获302,还可以在网络或邮递员中捕获302,请告诉我。

1 个答案:

答案 0 :(得分:0)

你不能在header属性中设置相同的位置,它最终会对自身进行递归调用。请参阅以下代码以设置状态和其他标头属性。

<http:request-config name="HTTP_Request_Configuration2" host="localhost" port="8081" doc:name="HTTP Request Configuration"/>
<flow name="xpathforeachFlow">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/xpath" allowedMethods="GET" doc:name="HTTP">
        <http:response-builder statusCode="302" reasonPhrase="found" >
            <http:header headerName="date" value="#[server.dateTime]"/>
        </http:response-builder>
    </http:listener>
    <logger message="inside another flow" level="INFO" doc:name="Logger" />
    <set-payload value="this is a test flow" doc:name="Set Payload" />
</flow>
<flow name="MainFlow">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/location302" doc:name="HTTP" allowedMethods="GET"/>
    <logger message="inside 302" level="INFO" doc:name="Logger" />
    <set-property propertyName="http.status" value="#['302']" doc:name="Property" />
    <set-property propertyName="location" value="http://localhost:8081/xpath" doc:name="Property"/>
    <logger message="after property setting #[message]" level="INFO" doc:name="Logger" />
</flow>