【问题标题】:How do I get the request URL for message headers如何获取消息标头的请求 URL
【发布时间】:2014-08-04 16:14:12
【问题描述】:

我有一个入站网关来处理 JSON 负载。由于我们使用与 SOAP 端点相同的后端服务,因此我需要一个映射到所有路径的入站网关。我可以看到默认的 HTTP 标头出现在消息中,但我特别需要请求 URL,以便我可以解析它并根据需要路由到适当的服务。

我的入站网关:

<int-http:inbound-gateway id="JSONGateway"
        path="*" request-channel="JSONRequestChannel" supported-methods="POST"
        reply-timeout="5000" 
        header-mapper="headerMapper"
        request-payload-type="java.lang.String" >
</int-http:inbound-gateway>

我尝试像添加 SOAP 一样添加标头丰富器,但 TransportContextListener 为空。

<int:header-enricher input-channelJSONequestChannel"
    output-channel="JSONRequestChannelWithHeaders">

    <int:header name="service"
        expression="T(org.springframework.ws.transport.context.TransportContextHolder).transportContext.connection.uri.toString().substring(T(org.springframework.ws.transport.context.TransportContextHolder).transportContext.connection.uri.toString().lastIndexOf('/')+1)" />
</int:header-enricher>

我需要一种方法来获取请求的 URL,以便我可以将服务解析到下游路由器的消息头中。

/json/ContactService = "ContactService"
/json/ContactService/insert = "ContactService"
/json/ContactService/get/234 = "ContactService"

我也尝试添加一个 header-mapper 类,但仍然遇到同样的问题。如何在代码中获取 HTTPServletRequest 的句柄?一旦我得到它,我就可以获得我需要的所有标题。

【问题讨论】:

    标签: spring-integration spring-ws


    【解决方案1】:

    嗯,你没有检查邮件标题。

    在将ServletServerHttpRequest 转换为Message 后,默认情况下会获取这些标头:

    Message<?> message = messageBuilder
                        .setHeader(org.springframework.integration.http.HttpHeaders.REQUEST_URL,
                                request.getURI().toString())
                        .setHeader(org.springframework.integration.http.HttpHeaders.REQUEST_METHOD,
                                request.getMethod().toString())
                        .setHeader(org.springframework.integration.http.HttpHeaders.USER_PRINCIPAL,
                                servletRequest.getUserPrincipal())
                        .build();
    

    所以,http_requestUrl 是让您继续并适当地解析它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-27
      • 2013-10-25
      • 1970-01-01
      • 2020-02-29
      • 1970-01-01
      • 2016-03-21
      • 1970-01-01
      相关资源
      最近更新 更多