followRedirects=false 时,Mule-ESB HTTP 重定向不起作用

Mule-ESB HTTP redirect does not work when followRedirects=false

我有一个不适用于 mule 的简单流程。在我的设置中,我在一个端口上侦听 HTTP 流量并在另一个端口上转发流量,我认为这是最典型的 ESB 用例。 proxy/gateway 流程有效,除非目标应用程序发出重定向。有谁知道解决这个问题的任何技巧?请注意,我无法使用 mule 中的 "HTTP-Proxy pattern",因为我打算将此流程扩展到更复杂的用例。

骡子流

<http:listener-config name=“HTTP_IN" host=“localhost" port="12344" doc:name=“IN_EP" />
<http:request-config name=“HTTP_OUT" host=“localhost" port="8380" doc:name=“OUT_EP"/>
<flow name="test2Flow2">
    <http:listener config-ref=“HTTP_IN" path="*" doc:name="IN"/>
    <logger level="INFO" doc:name="Request Logger"/>
    <http:request config-ref=“HTTP_OUT" path="#[message.inboundProperties.'http.request.path']" method="#[message.inboundProperties.'http.method']" doc:name="OUT" followRedirects="false" />
    <response>
        <logger level="INFO" doc:name="Response Logger"/>
    </response>
</flow>

情况 1:followRedirects=true(默认)

在这种情况下,mule 从目标端点获取 HTTP 302,并在内部导航到重定向页面并将该页面提供给客户端。如果我将 Mule 用作某些 Web 服务的网关,这非常好。但是,对于来自浏览器的 HTTP 流量,如果我们允许这种情况发生,所有相对 URL 都会从呈现的页面中断。

情况二:followRedirects=false

在这种情况下,mule 从目标端点获取 HTTP 302,并在记录响应后丢弃响应。 Mule 只是在浏览器上发送 HTTP 200 和空 HTML 页面。有关案例 2,请参阅下面的日志。我想将 HTTP 302 响应发送给最终用户。

已记录请求(案例 2)

INFO  2015-10-01 13:01:48,333 [[test2].APP_A_IN.worker.01] org.mule.api.processor.LoggerMessageProcessor: 
org.mule.DefaultMuleMessage
{
Message properties:
  INVOCATION scoped properties:
  INBOUND scoped properties:
    accept=text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    accept-encoding=gzip, deflate, sdch
    accept-language=en-US,en;q=0.8
    cache-control=max-age=0
    connection=keep-alive
    dnt=1
    host=localhost:12344
    http.listener.path=/*
    http.method=GET
    http.query.params=ParameterMap{[]}
    http.query.string=
    http.relative.path=/app_a
    http.remote.address=/127.0.0.1:53372
    http.request.path=/app_a
    http.request.uri=/app_a
    http.scheme=http
    http.uri.params=ParameterMap{[]}
    http.version=HTTP/1.1
    upgrade-insecure-requests=1
    user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36
    x-firephp-version=0.0.6
  OUTBOUND scoped properties:
  SESSION scoped properties:
}

已记录响应(案例 2)

INFO  2015-10-01 13:01:48,420 [[test2].APP_A_IN.worker.01] org.mule.api.processor.LoggerMessageProcessor: 
org.mule.DefaultMuleMessage
{

Message properties:
  INVOCATION scoped properties:
  INBOUND scoped properties:
    date=Thu, 01 Oct 2015 17:01:48 GMT
    http.reason=Moved Temporarily
    http.status=302
    location=http://localhost:8380/app_a/
    server=Apache-Coyote/1.1
    transfer-encoding=chunked
  OUTBOUND scoped properties:
  SESSION scoped properties:
}

我认为问题在于您没有将属性从请求者复制到侦听器的响应。我建议在请求者之后立即使用 copy-properties 元素。否则入站属性将丢失:此时您需要它们作为出站。 不过,某些属性(例如 http.status 可能需要使用 response-builder 显式映射到 headers。 HTH