users@glassfish.java.net

Re: how to send user defined error message in the status ...

From: <forums_at_java.net>
Date: Wed, 13 Apr 2011 15:28:55 -0500 (CDT)

Thanks for the code and the links. Theoretically, from the code and links I
should accomplish the task. Unfortunately, I could not get the custom status
message as the "geterrorreason" at the client's place. This is what I have
done:

@Provider
public class NotFoundExceptionMapper implements
ExceptionMapper<UserNotFoundException> {
    public Response toResponse(UserNotFoundException exception) {
        return Response.status(new Response.StatusType() {
            @Override
            public int getStatusCode() {
            return 522;  //remember this status code has no
relavance interms of actuall hppt status code.. This is custom one expected
to be caught by client when it invokes getStatus(). (This is happening)
            }
            @Override
            public Response.Status.Family getFamily() {
            return Response.Status.Family.SERVER_ERROR;
            }
            @Override
            public String getReasonPhrase() {
            return "User already
exists";               //custom message expected to be caught
by client when it invokes geterrormessage() ... (This is not happening)
            }
        }).build();   
    }
}

In the Restful service implmentation I have done the following:

    @GET
    @Produces("text/xml")
    public Advertisements getAdvertisements(.....) throws Exception {

      try {

            call bean methods

      }catch(UserNotFoundException ex) {

             //this exception is caught after a bean throws this
exception

             throw new UserNotFoundException("User already
exists"); 

      }catch(Exception ex) {

      }

   }

I have developed app using javaee6 and deployed in glassfish, hopefully this
is not causing the problem. I would really appreciate if you can add anything
I am missing.

 


--
[Message sent by forum member 'rkonkimalla']
View Post: http://forums.java.net/node/789369