users@jersey.java.net

[Jersey] Re: could not be mapped to a response, re-throwing to the HTTP container

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Thu, 13 Oct 2011 15:52:46 +0200

Hi Lukas,

You may also define a bit more general ExceptionMapper<Throwable>,
which will then cover all throwables including your CustomErrorException.

You can still keep this concrete exception mapper bellow, if you need
to build a more specific response from that. Jersey will try to invoke
the "closest" available mapper for you.

Anyway, I still do not understand what was wrong related to Eclipse IDE.
Is it using a special container, where the exception->web page mapping
does not work?
Was that the issue?

Or you are suggesting a particular JAX-RS exception mapper
does not work with Jersey under certain circumstances?

Thanks,

~Jakub

On 12.10.2011 19:31, Lukas Lentner wrote:
>
> I did it using a ExceptionMapper:
>
> package com.perfectprintpattern.service.exception.handling;
>
> import javax.servlet.http.HttpServletRequest;
> import javax.ws.rs.core.Context;
> import javax.ws.rs.core.Response;
> import javax.ws.rs.ext.ExceptionMapper;
> import javax.ws.rs.ext.Provider;
>
> import
> com.perfectprintpattern.service.exception.customError.CustomErrorException;
>
> @Provider
> public class CustomExceptionMapper implements
> ExceptionMapper<CustomErrorException> {
>
> @Context
> protected HttpServletRequest request;
>
> public Response toResponse(CustomErrorException exception) {
>
> this.request.setAttribute("javax.servlet.jsp.jspException",
> exception);
>
> return Response.status(exception.getStatus()).build();
>
> }
>
> }
>
> works great!!!
>
> -----Ursprüngliche Nachricht-----
> *An:* users_at_jersey.java.net;
> *Von:* Lukas Lentner <kontakt_at_lukaslentner.de>
> *Gesendet:* Mi 12.10.2011 18:57
> *Betreff:* [Jersey] could not be mapped to a response, re-throwing
> to the HTTP container
>
> Hi,
>
> when I fire a MyException extending RuntimeException it properly
> gets mapped to the JSP I defined for MyException via error-page in
> the web.xml.
>
> This Exception gets handled properly! Why do I see the error in
> the subject in the eclipse IDE???
>
> It's not wrong that it is mapped that way?
>
> Lukas
>