【问题标题】:Getting the request URL of a SOAP request in handleResponse Method in ClientInterceptor在ClientInterceptor的handleResponse方法中获取SOAP请求的请求URL
【发布时间】:2019-06-24 07:22:18
【问题描述】:

我正在使用弹簧靴。我已经为 SOAP Web 服务编写了一个 ClientInterceptor,我想记录我发送请求的 URL,我想在 handleResponse 方法中进行。但是我找不到办法做到这一点。是否可以?任何帮助都会很棒。

public class SoapClientHttpRequestInterceptor implements ClientInterceptor {

@Override
    public boolean handleResponse(MessageContext messageContext) throws WebServiceClientException {
        // I would like to get the URL and log it here. 

    }

}

我创建 restTemplate 的方式

@Bean
@Qualifier("testRestTemplate")
public RestTemplate testRestTemplate() {

    SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
    requestFactory.setOutputStreaming(false);
    ClientHttpRequestFactory factory = new BufferingClientHttpRequestFactory(requestFactory);
    RestTemplate restTemplate = new RestTemplate(factory);
    restTemplate.setInterceptors(Collections.singletonList(restClientHttpRequestInterceptor));
    restTemplate.setErrorHandler(testErrorHandler);
    restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(Charset.forName("UTF-8")));
    return restTemplate;
}

【问题讨论】:

    标签: spring spring-boot soap resttemplate


    【解决方案1】:

    您可以在您的 handleResponse 方法中执行此操作:

    TransportContext context = TransportContextHolder.getTransportContext();
    context.getConnection().getUri().toString()
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-26
      • 1970-01-01
      • 1970-01-01
      • 2011-05-01
      • 1970-01-01
      • 2019-01-08
      相关资源
      最近更新 更多