But there're times, when you want to see what exactly does the server returned for our request for diagnostics purpose. For example, a monitoring server may not just want to know what error code the server has returned, but also want details about what exactly happened at the server side. I've written simple groovy script which uses the commons-http client and core modules from Apache to do this task for me.
You should keep following files in the class path to run this program successfully.
import org.apache.commons.httpclient.HttpClient
import org.apache.commons.httpclient.methods.GetMethod
client = new HttpClient()
method = new GetMethod("http://10.11.12.48:8004/monitor")
def statusCode = client.executeMethod(method)
println "Status code is : ${statusCode}"
//Read the response body.
byte[] responseBody = method.getResponseBody();
// Deal with the response.
// Use caution: ensure correct character encoding and is not binary data
println(new String(responseBody));
- commons-httpclient.jar
- commons-codec.jar
- commons-logging.jar
And ofcourse, you can change the URL to which ever value you want to test out other error codes.
No comments:
Post a Comment