users@jersey.java.net

[Jersey] How do I register an ExceptionMapper?

From: <drach_at_itsit.org>
Date: Sat, 18 Jun 2011 20:28:28 +0000 (GMT)

I created a small ExceptionMapper that I thought would catch all
exceptions thrown from my resource class. But it doesn't catch any
exceptions. That makes me think it's not properly registered. How can
I tell if it's registered or not? What is the proper way to do it. I
can't seem to find what I'm looking for in the forums or the samples.

My ExceptionMapper starts off like this:

package com.foobar.atg.sniffernet.collector.provider;

import javax.ws.rs.core.*;
import javax.ws.rs.ext.*;

@Provider
public class JSONExceptionMapper implements ExceptionMapper<Exception>
{
    public Response toResponse(Exception e) {

-------
My web.xml has this in it:

   
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</s
ervlet-class>
     <init-param>
       <param-name>com.sun.jersey.config.property.packages</param-name>
       <param-value>com.foobar.atg.sniffernet.collector.resource;
                    com.foobar.atg.sniffernet.collector.provider
       </param-value>

------
The jetty server log shows this:

INFO: Scanning for root resource and provider classes in the packages:
  com.foobar.atg.sniffernet.collector.resource
  com.foobar.atg.sniffernet.collector.provider
Jun 18, 2011 12:01:23 PM com.sun.jersey.api.core.ScanningResourceConfig
logClasses
INFO: Root resource classes found:
  class com.foobar.atg.sniffernet.collector.resource.DataCollection
Jun 18, 2011 12:01:23 PM com.sun.jersey.api.core.ScanningResourceConfig
logClasses
INFO: Provider classes found:
  class
com.foobar.atg.sniffernet.collector.provider.JSONExceptionMapper
  class com.foobar.atg.sniffernet.collector.provider.S3ClientResolver