• Post Reply Bookmark Topic Watch Topic
  • New Topic

Jersey Web Service - uses ExceptionMapper but client cant retrieve error message  RSS feed

 
Ally Cavs
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have web service that has to carry out some validation before saving a object to a DB. If the validation is successful I will save object and return the object with the assigned primary key to the client. if validation fails I have the following Exception Mapper code which works



This actually works. If I put in URL of websevice into a browser I get xml back:


but my client gives the following stack trace




Please help im looking at this for a few days now. the line which throws the stack trace is : ErrorResponse errRes = response.getEntity(ErrorResponse.class) --

 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Premature end of file.]
at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.readFrom(AbstractRootElementProvider.java:108)


I suspect there was no response body to read because the server sent an error you were not expecting - I would print the exact response status before that check for == 200


Bill
 
Ally Cavs
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Bill

I tried this piece of code. Hope it is what you mean :

and got



But the internet browser does return what I would expect when validation fails so i dont understand how my client fails to read what the internet browser is able to read?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried this piece of code. Hope it is what you mean :


I meant what I said - print the result of response.getStatus() - the response code.

That error message says that the URL you addressed does not have a valid handler for the HTTP method. How are you setting the request method in your client - ie GET, POST, DELETE, HEAD, etc.?

Just plugging a URL in a browser creates a GET request.

Bill
 
Ally Cavs
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The status code is 405. After reading up on 405 i changed my post call to a get call and i now get the error code i set in the exception mapper but I still cant parse the error respone out :-) I get the stack trace above.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming you mean this:
[org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Premature end of file.]
at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.readFrom(AbstractRootElementProvider.java:108)
at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:549)


Either:
1. the response body has already been read somewhere else in your code - you can only get the body one time, that positions the input stream at end-of-file
-or-
2. there was no response body

I am betting on one.

Bill
 
Ally Cavs
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would the below read the response body? if so how can I retrieve status with out reading the body. Im sorry but Im new to Restful web services...


 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect that line would read the body since it specifies a media type but I am not familiar with the actual method.

The response status code is NOT part of the body, it is part of the headers. You really should get familiar with tools such as SOAPui, TCPMON or browser functions such as the Firefox LiveHttp Headers function that let you see the actual content of requests and responses, bot headers and body.

But
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!