I am using RestTemplate to make calls to a web service.
String userId = restTemplate.getForObject(createUserUrl, String.class);
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?
Configure your logging as follows:
Then use a curl command to see the output, eg
By default, restTemplate uses HttpURlConnection (via SimpleClientHttpRequest), so you might need to switch to jakarta httpclient to see the log statement. Otherwise the above log configuration will out show you the response
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.
For example, if you are using commons HttpClient, you can set
The commons-httpclient project has an entire page in the documentation on their logging practices.
You can use spring-rest-template-logger to log
RestTemplate
HTTP traffic.Add a dependency to your Maven project:
Then customize your
RestTemplate
as follows:Now all RestTemplate HTTP traffic will be logged to
org.hobsoft.spring.resttemplatelogger.LoggingCustomizer
at debug level.DISCLAIMER: I wrote this library.