【问题标题】:Accessing request object along with response in http outbound gateway在 http 出站网关中访问请求对象和响应
【发布时间】:2014-07-29 07:09:06
【问题描述】:

我正在使用 http 出站网关使用以下类似配置发出 http 请求:

<int-http:outbound-gateway id="httpOutboundGateway" request-channel="requestChannel"
    url="http://www.google.com" http-method="GET" reply-channel="responseChannel"
    expected-response-type="java.lang.String" charset="UTF-8" reply-timeout="5000"
    message-converters="" >
</int-http:outbound-gateway>
  1. 处理响应时如何访问请求对象(请求消息推送到请求通道)?
  2. 有没有办法在替换 url 中的请求参数后查看它正在执行的最终 url/请求?

【问题讨论】:

    标签: java spring spring-integration


    【解决方案1】:
      1234563将它放在标题中,您可以从responseChannel 下游访问它。
    1. 要查看真实的URL,您应该为org.springframework.web.client.RestTemplate 打开DEBUG,这样做是:

      private void logResponseStatus(HttpMethod method, URI url, ClientHttpResponse response) {
          if (logger.isDebugEnabled()) {
              try {
                  logger.debug(method.name() + " request for \"" + url + "\" resulted in " +
                          response.getStatusCode() + " (" + response.getStatusText() + ")");
              }
              catch (IOException e) {
                  // ignore
              }
          }
      }
      

    【讨论】:

    • 您可以使用&lt;header-enricher/&gt; 将有效负载保存在标头中。
    猜你喜欢
    • 1970-01-01
    • 2018-07-16
    • 1970-01-01
    • 2011-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多