Spring RestTemplate - how to enable full debugging/logging of requests/responses?
I finally found a way to do this in the right way.
Most of the solution comes from
How do I configure Spring and SLF4J so that I can get logging?
It seems there are two things that need to be done :
- Add the following line in log4j.properties :
log4j.logger.httpclient.wire=DEBUG
- Make sure spring doesn't ignore your logging config
The second issue happens mostly to spring environments where slf4j is used (as it was my case).
As such, when slf4j is used make sure that the following two things happen :
There is no commons-logging library in your classpath : this can be done by adding the exclusion descriptors in your pom :
<exclusions><exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>The log4j.properties file is stored somewhere in the classpath where spring can find/see it. If you have problems with this, a last resort solution would be to put the log4j.properties file in the default package (not a good practice but just to see that things work as you expect)
How do I log response in Spring RestTemplate?
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
log4j.logger.httpclient.wire=DEBUG
The commons-httpclient project has an entire page in the documentation on their logging practices.
Related Topics
Call an Executable and Pass Parameters
Controlling Maven Final Name of Jar Artifact
Bounding Generics with 'Super' Keyword
How to Use Annotations to Define Different Types of Relationships in Hibernate 4 and Spring
Java Reverse an Int Value Without Using Array
How Come Invoking a (Static) Method on a Null Reference Doesn't Throw Nullpointerexception
Importing Two Classes with Same Name. How to Handle
How to Change Text Color in the Jtextarea
What Is the Best Approach for Using an Enum as a Singleton in Java
Java Date Format Conversion - Getting Wrong Month
Seeking Useful Eclipse Java Code Templates
How Is the Java Memory Pool Divided
How to Get the Intersection Between Two Arrays as a New Array