users@glassfish.java.net

Re: how to send user defined error message in the status line of the http response using java restful web services?

From: Jason Lee <jason.d.lee_at_oracle.com>
Date: Wed, 06 Apr 2011 17:42:27 -0500

What I've done in the past is have my Resource method return a
Response. I can then use the Response builder to build the appropriate
response. If the call is a success, I set the status to 200, add the
payload and return. If the call fails, I set the status to, say, 500,
and the Exception's message as the payload.

try {
     return Response.ok(myEjb.someCall()).build();
} catch (Exception ex) {
     return Response.status(500).entity(ex.getMessage()).build();
     // or
     // throw new WebApplicationException(ex,
Response.Status.INTERNAL_SERVER_ERROR);
}

That's pretty bare, but hopefully enough to get you going.

On 4/6/11 5:29 PM, forums_at_java.net wrote:
> Usine Netbeans I have developed a restul web application and deployed in
> glassfish 3. These restful web services inturn call EJBs and send the
> result
> to the client. I have several custom user defined exceptions and
> interested
> in sending the client the error code along with the custom defined error
> message. At the client I always get error code 500 and description
> "Internal
> Server Error". I would really appreciate if somebody can tell me the
> way to
> pass custom error messages to the client.
>
>
> --
>
> [Message sent by forum member 'rkonkimalla']
>
> View Post: http://forums.java.net/node/789369
>
>


-- 
Jason Lee
Senior Member of Technical Staff
GlassFish REST API / Administration Console
Oracle Corporation
Phone +1 405-216-3193
Blog http://blogs.steeplesoft.com