0

Hello all in my doe I have a try catch and I am catching the exception from a webservice

However If I run my web service in Firefox Poster add-on I get a response as well as a stastus exception

This obviously is not ALL the code but basically the exception is happening at getInputStream()

How can I get the response from the exception?

try{
//Get Response
stream = connection.getInputStream();

} catch (Exception e) {
        throw new CustomException("Exception - " + e.getMessage());

1 Answer 1

2
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
int code = connection.getResponseCode();
String msg = connection.getResponseMessage();

These methods will still throw IOException if you can't reach the server. But if the server responds, even with an error, these methods give you access to the response.

Sign up to request clarification or add additional context in comments.

5 Comments

I get Unprocessable Entity Exception
That sounds like an error message from the server. In other words, this part of your code is working, but you aren't sending the right data to the web service.
I get that...the problem is..If I send the same data through a poster add-on through firefox I get an xml response with an actual error messae I can use in the form of a response object...java is throwing an exception before I can even read a response.....I cant seem to tap into to that
Have you read the data from connection.getErrorStream()? That will return the body of an error result.
Hey thanks!!.That did it...got the error number and error messgae!!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.