2017-10-08 70 views
0

只要代碼中存在位置標頭和http狀態302,mule http偵聽器將在內部調用位置URL並獲取http狀態200的響應,這看起來像是正常行爲。爲http偵聽器禁用重定向mule

但我想看到的是一個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不僅在日誌中,而且在網絡或郵遞員也是如此。

回答

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>