0

Is it possible to call the jersey exception mapper directly?

We've got a Dropwizard REST app, and we need to add a non-REST interface.
We've got a large number of exception mappers that are called implicitly when a service throws an exception.
We'd like to call the same exception mappers in our non-REST code because they map to an application error code and message as well as the final http response code.

We found org.glassfish.jersey.internal.ExceptionMapperFactory, but it's in an "internal" package.

Is there an interface we can call to map the exception?

Ron Romero
  • 9,211
  • 8
  • 43
  • 64
  • 1
    There is the following interface: https://eclipse-ee4j.github.io/jersey.github.io/apidocs/latest/jersey/org/glassfish/jersey/spi/ExceptionMappers.html Once upon a time it was part of the JAX-RS specification. I'm not sure about the current status due to Oracle donation to Eclipse foundation. It is possible to do the following in a Jersey Resource class: `@Inject private ExceptionMappers exMapper;` The DI engine puts the appropriate class there. I don't know if this will solve your problem but it should give you some clues. – zloster Oct 15 '19 at 08:24
  • 1
    Also see here: https://github.com/eclipse-ee4j/jersey/blob/eafb9bdcb82dfa3fd76dd957d307b99d4a22c87f/tests/e2e-core-common/src/test/java/org/glassfish/jersey/tests/e2e/common/internal/ExceptionMapperFactoryTest.java#L81-L90 if you don't want to use `@Inject` annotation. – zloster Oct 15 '19 at 08:24

0 Answers0