0

每当代码中存在位置标头和 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,还可以在网络或邮递员中捕获。

4

1 回答 1

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>
于 2017-10-11T14:30:14.873 回答