Thanks for the replay.
This is what I have but my app does not return the output specified in
the ExceptionMapper. Instead it throws "HTTP Status 500" html error. Any
Idea why this happen? Am I suppose to do anything else except that I have
done so far? Like web.xml configuration?
@Provider
public class NuwanExceptionMapper implements
ExceptionMapper<RuntimeException> {
@Override
public Response toResponse(RuntimeException e) {
String msg = e.getMessage();
StringBuilder response = new StringBuilder("<response>");
response.append("<status>failed</status>");
response.append("<message>" + msg + "</message>");
response.append("</response>");
return
Response.serverError().entity(response.toString()).type("application/xml").build();
}
}
*Interface*
*
*
@GET
@Path("testWs")
@Produces({MediaType.APPLICATION_XML})
public NichProWSResponse testWs(@MatrixParam("status") String status,
@MatrixParam("message") String message) throws RuntimeException;
*Implementation*
public NichProWSResponse testWs(String status, String message) throws
RuntimeException {
NichProWSResponse response = new NichProWSResponse();
if (status.equals("404")) {
throw new RuntimeException();
}
else if (status.equals("202")) {
throw new RuntimeException();
}
else {
response.setStatus(status);
response.setMessage(message);
}
return response;
}
Thanks,
Nuwan
On Thu, Jan 31, 2013 at 10:10 AM, Michael Musgrove <mmusg...@redhat.com>wrote:
> Have you tried the docs http://docs.jboss.org/resteasy/docs. Search for
> ExceptionMapper.
>
> Mike
>
> Hi,
>
> I have a session bean exposed as a RESTeasy web service. I am
> using @Produces({"application/xml"}) to produce the response. Regardless of
> the outcome, I bundled success, failure, or application exception message
> into the xml and send back to the client. I know this is not the best way
> to handle exception handling. Can some one explain me or provide me a
> reference how to handle exceptions using ExceptionMapper interface?
>
> Would be great if I can have a reference to an example code.
>
> Thanks,
> Nuwan
>
>
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:http://p.sf.net/sfu/appdyn_d2d_jan
>
>
>
> _______________________________________________
> Resteasy-users mailing
> listResteasy-users@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/resteasy-users
>
>
>
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan
_______________________________________________
Resteasy-users mailing list
Resteasy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/resteasy-users