Jersey not showing response in case it was an error
I have the following problem...
I'm testing a service that return HTTP responses on GET requests.
My problem is that I would like to view the response even if it was an HTTP 500 / 404 or whatever response.
I would like to view that. But I can't because it throws an exception and that's it.
Is there a way to view a jersey response even if it was an error response?
My code is like this:
开发者_如何学PythonwebResource = client.resource(url);
response = webResource.queryParams(alertParams)
.header("x-token", token).get(String.class);
So when get receives an error response from the service I wont be able to view that although the response is something like this:
{ "errCode" : "ERR002", "errMsg" : "", "techErrMsg" : "LoginFailureGeneric" }
Which is a 400 Bad Request.
Thanks very much for all the help!!
This is where you need to spend some time with the docs... WebRequest#get(Class) will throw an exception when you get an HTTP error status if you are trying to parse the response as anything other than ClientResponse.
So all you need to do is change the .get(String.class)
-> .get(ClientResponse.class)
and you can pull the entity itself (and the status, and everything else) off of the ClientResponse object sans exceptions.
精彩评论