Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-377

Regression: Exception Mapper cannot be registered as singleton

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 2.0-beta-3
    • 2.0-beta-2
    • None
    • None

      I'm using JBossAS 6.0.0.M2 and replaced the RESTEasy JARs according to 2.0-beta-2. The following error didn't occur when using JBossAS 5.1 and RESTEasy 1.2 within a WAR.

      I have an application class:
      public class JaxrsApplication extends Application {
      private Set<Class<?>> classes = new HashSet<Class<?>>();
      private Set<Object> singletons = new HashSet<Object>();

      public JaxrsApplication()

      { singletons.add(new KundenverwaltungResource()); // resource class: works fine singletons.add(new KundeValidationExceptionMapper()); // WILL BE A PROBLEM ... }

      @Override
      public Set<Class<?>> getClasses()

      { return classes; }

      @Override
      public Set<Object> getSingletons()

      { return singletons; }

      }

      The exception mapper:
      @Provider
      public class KundeValidationExceptionMapper implements ExceptionMapper<KundeValidationException> {
      private static final Logger LOGGER = LoggerFactory.getLogger(KundeValidationExceptionMapper.class);
      private static final boolean DEBUG = LOGGER.isDebugEnabled();

      public Response toResponse(KundeValidationException e) {
      if (DEBUG) LOGGER.debug("BEGINN toResponse: " + e.getViolations());

      final Collection<ConstraintViolation<Kunde>> violations = e.getViolations();
      final StringBuilder sb = new StringBuilder();
      for (ConstraintViolation<Kunde> v: violations)

      { sb.append(v.getMessage()); sb.append(" "); }

      final String responseStr = sb.toString();
      final Response response = Response.status(NOT_FOUND)
      .type(TEXT_PLAIN)
      .entity(responseStr)
      .build();

      if (DEBUG) LOGGER.debug("ENDE toResponse: " + responseStr);
      return response;
      }
      }

      In the JBoss console I only see the resources being registered as singletons, but not the exception mappers:
      16:32:15,868 INFO [org.jboss.web.tomcat.service.deployers.TomcatDeployment] deploy, ctxPath=/hskaREST
      16:32:17,065 INFO [org.jboss.resteasy.spi.ResteasyDeployment] Deploying javax.ws.rs.core.Application: class de.hska.util.JaxrsApplication
      16:32:17,070 INFO [org.jboss.resteasy.spi.ResteasyDeployment] Adding singleton resource de.hska.kundenverwaltung.rest.KundenverwaltungResource from Application javax.ws.rs.core.Application

            patriot1burke@gmail.com Bill Burke (Inactive)
            juergen.zimmermann Juergen Zimmermann
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: