Class DirectTemplateExceptionMapper

  • All Implemented Interfaces:
    jakarta.ws.rs.ext.ExceptionMapper<jakarta.ws.rs.NotFoundException>, org.glassfish.jersey.spi.ExtendedExceptionMapper<jakarta.ws.rs.NotFoundException>

    @Provider
    public class DirectTemplateExceptionMapper
    extends java.lang.Object
    implements org.glassfish.jersey.spi.ExtendedExceptionMapper<jakarta.ws.rs.NotFoundException>
    NotFoundException thrown by jersey when matching rest path not found. Exception mapper detects it and if it is template call tries to render template directly instead.

    Handler is applied to all rest, but as its an extended mapper, it will not influence normal rest calls.

    NOTE: application may declare different exception mapper for NotFoundException and so it may override this mapper. It is highly unlikely, but still could happen.

    Another drawback is template rendering errors will be unreachable for default dropwizard exception mapper (IllegalStateExceptionMapper which logs all rest exceptions. But this is compensated by direct exception error logging.

    Since:
    06.12.2019
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected static boolean canHandle​(org.glassfish.jersey.server.monitoring.RequestEvent event)
      Exception event first will be catched by listener and it must not handle it initially.
      boolean isMappable​(jakarta.ws.rs.NotFoundException exception)  
      jakarta.ws.rs.core.Response toResponse​(jakarta.ws.rs.NotFoundException exception)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DirectTemplateExceptionMapper

        public DirectTemplateExceptionMapper()
    • Method Detail

      • isMappable

        public boolean isMappable​(jakarta.ws.rs.NotFoundException exception)
        Specified by:
        isMappable in interface org.glassfish.jersey.spi.ExtendedExceptionMapper<jakarta.ws.rs.NotFoundException>
      • toResponse

        public jakarta.ws.rs.core.Response toResponse​(jakarta.ws.rs.NotFoundException exception)
        Specified by:
        toResponse in interface jakarta.ws.rs.ext.ExceptionMapper<jakarta.ws.rs.NotFoundException>
      • canHandle

        protected static boolean canHandle​(org.glassfish.jersey.server.monitoring.RequestEvent event)
        Exception event first will be catched by listener and it must not handle it initially. Then this exception mapper (which should be chosen as the closest match) will render direct template. If template rendering fails then exception will be redirected directly to error mapper. If it was already error rendering then 404 or 500 will be returned directly.

        As a side effect, template rendering errors will be impossible to intercept with custom exception mappers.

        Parameters:
        event - exception event
        Returns:
        true if exception mapper will handle exception (render direct template), false otherwise