在ClientInterceptor的handleResponse方法中获取SOAP请求的请求URL

时间:2019-06-24 07:22:18

标签: spring spring-boot soap resttemplate

我正在使用弹簧靴。我已经为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;
}

1 个答案:

答案 0 :(得分:0)

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

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

我希望这对您有帮助