如何在Spring RestTemplate中记录响应? [英] How do I log response in Spring RestTemplate?

查看:117
本文介绍了如何在Spring RestTemplate中记录响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用RestTemplate来调用Web服务。

I am using RestTemplate to make calls to a web service.

String userId = restTemplate.getForObject(createUserUrl, String.class);

如果这不能返回用户ID我只是返回null但我不知道为什么。如何将实际的XML响应输出到日志?

If this fails to return a user ID I just get returned null but I don't know why. How do I output the actual XML response to a log?

推荐答案

根据您使用的HTTP连接的方法,您可以查看实际HTTP连接类中的日志记录。

Depending on which method of making the HTTP connection you are using, you could look at turning up the logging within the actual HTTP connection classes.

例如,如果您使用公共HttpClient,则可以设置

For example, if you are using commons HttpClient, you can set

log4j.logger.httpclient.wire=DEBUG

commons-httpclient项目有关于他们的文档中的整个页面记录实践

The commons-httpclient project has an entire page in the documentation on their logging practices.

这篇关于如何在Spring RestTemplate中记录响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆