How to output the generated request and response from Groovy RestClient?
-
11-02-2021 - |
Question
i am currently using the RestClient and cannot seem to figure out how to output the request xml and response xml for debugging and informational purpose...
I tried the solution mentioned here: http://agileice.blogspot.com/2009/09/pretty-printing-xml-results-returned.html
But that fails to work, any other suggestions?
Solution
Since it depends on HTTPClient, you could try enabling header and wire logging for your script.
http://blog.techstacks.com/2009/12/configuring-wire-logging-in-groovy-httpbuilder.html
OTHER TIPS
The accepted answer (turn on wire logging using log4j) is basically correct, but I've had a fair bit of trouble turning on wire logging for HTTP builder in my Groovy script. For some reason, dropping a log4j.xml file in my $GROOVY_HOME/conf directory isn't working. Ultimately, I had to just add the appropriate logging options to the groovy command when I was running it.
groovy
-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
-Dorg.apache.commons.logging.simplelog.showdatetime=true
-Dorg.apache.commons.logging.simplelog.log.org.apache.http=DEBUG
myscript.groovy
If you're using spring-boot
you can set logging.level
in your application properties file and use an slf4j
back-end.
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>