Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (3.9k points)

I have been using the Spring RestTemplate for a while and I consistently hit a wall when I'am trying to debug it's requests and responses. I'm basically looking to see the same things as I see when I use curl with the "verbose" option turned on. For example :

curl -v http://twitter.com/statuses/public_timeline.rss

Would display both the sent data and the received data (including the headers, cookies, etc.).

I have checked some related posts like : How do I log response in Spring RestTemplate? but I haven't managed to solve this issue.

One way to do this would be to actually change the RestTemplate source code and add some extra logging statements there, but I would find this approach really a last resort thing. There should be some way to tell Spring Web Client/RestTemplate to log everything in a much friendlier way.

My goal would be to be able to do this with code like :

restTemplate.put("http://someurl", objectToPut, urlPathValues);

and then to get the same type of debug information (as I get with curl) in the log file or in the console. I believe this would be extremely useful for anyone that uses the Spring RestTemplate and has problems. Using curl to debug your RestTemplate problems just doesn't work (in some cases).

1 Answer

0 votes
by (46k points)

Your best bet is to add logging.level.org.springframework.web.client.RestTemplate=DEBUG to the application.properties file.

Other solutions like setting log4j.logger.httpclient.wire will not always work because they assume you use log4j and Apache HttpClient, which is not always true.

Note, however, that this syntax will work only on latest versions of Spring Boot.

Related questions

0 votes
1 answer
0 votes
4 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Dec 19, 2020 in SQL by Appu (6.1k points)

Browse Categories

...