users@jersey.java.net

Viewable in ExceptionMapper

From: Charles Brooking <public+jersey_at_charlie.brooking.id.au>
Date: Fri, 20 Feb 2009 12:07:09 +1000 (EST)

G'day,

I've been using the JSP Template Processor for views and have found it to
work well for normal resources, but am unsure if it can be used from an
ExceptionMapper. I'm hoping to serve "custom error pages" using JSP
templates.

If I try this, the view cannot be resolved:

  Response
  .fromResponse(exception.getResponse())
  .entity(new Viewable("/WEB-INF/jsp/404.jsp", this))
  .build();

And using the following crashes too (at JSPTemplateProcessor:112), because
uriInfo.getMatchedResources() is empty in the ExceptionMapper.

  @Context UriInfo uriInfo;
  @Context TemplateContext templateContext;
  ...
  for (TemplateProcessor t : templateContext.getTemplateProcessors()) {
    String resolvedPath = t.resolve("/WEB-INF/jsp/404.jsp");
    if (resolvedPath != null) {
      return
        Response
        .fromResponse(exception.getResponse())
        .entity(new ResolvedViewable(t, resolvedPath, this))
        .build();
    }
  }

Further to this, is there also a means for producing different content
types (eg HTML, XML, etc) from ExceptionMapper<T>#toResponse()? It cannot
be annotated with @Produces in the usual way.

Thanks
Charlie