Hello Jersey users ,
I am using Jersey 1.1.1-ea with JDK 1.6. We are using
custom exception class along with exception mapper as shown below
public class SmartServicesRSException extends WebApplicationException {
public Response.Status httpStatus;
public String applicationErrCode;
public SmartServicesRSException(int httpStatusCode , String
applicationErrCode){
super(httpStatusCode);
this.applicationErrCode = applicationErrCode;
this.httpStatus =
Response.Status.fromStatusCode(httpStatusCode);
}
}
@Provider
public class SmartServicesExceptionMapper implements
ExceptionMapper<SmartServicesRSException>{
public Response toResponse(SmartServicesRSException exception) {
// TODO Auto-generated method stub
System.out.println("the application error code is
:"+exception.applicationErrCode);
return
Response.status(exception.httpStatus).entity(newGenericEntity<String>(ex
ception.applicationErrCode){}).type("application/text").build();
}
}
The TCP trace captured in the run time shows a status code of 0 , even
when I am passing a valid HTTP status code as shown below
@GET
@Path("400")
@Produces("application/text")
public String testBadRequest() throws SmartServicesRSException {
throw new
SmartServicesRSException(Response.Status.BAD_REQUEST,"input.error.code")
;
}
TCP Response trace
HTTP/1.1 400 Bad Request
Server: Apache-Coyote/1.1
X-Powered-By: Servlet 2.5; JBoss-5.0/JBossWeb-2.1
Content-Type: application/text
Transfer-Encoding: chunked
Date: Thu, 15 Apr 2010 05:58:52 GMT
Connection: close
10
input.error.code
0
Could you please let me know , if there is anything missing in my
approach. The status code is sent as 0 as per the last line of the
output.
Thanks,
Suchitha