Package javax.ws.rs.ext

Examples of javax.ws.rs.ext.ExceptionMapper


    // ExceptionMapperContext
   
    public ExceptionMapper find(Class<? extends Throwable> c) {
        int distance = Integer.MAX_VALUE;
        ExceptionMapper selectedEm = null;
        for (ExceptionMapperType emt : emts) {
            int d = distance(c, emt.c);
            if (d < distance) {
                distance = d;
                selectedEm = emt.em;
View Full Code Here


     *
     * @param e the exception.
     * @return true if the exception was mapped, otherwise false.
     */
    public boolean mapException(Throwable e) {
        ExceptionMapper em = wa.getExceptionMapperContext().find(e.getClass());
        if (em == null) return false;

        if (request.isTracingEnabled()) {
            request.trace(String.format("matched exception mapper: %s -> %s",
                    ReflectionHelper.objectToString(e),
                    ReflectionHelper.objectToString(em)));
        }

        try {
            Response r = em.toResponse(e);
            if (r == null)
                r = Response.noContent().build();
            onException(e, r, true);
        } catch (MappableContainerException ex) {
            // If the exception mapper throws a MappableContainerException then
View Full Code Here

    }

    public Response toResponse(EJBException exception) {
        final Exception cause = exception.getCausedByException();
        if (cause != null) {
            final ExceptionMapper mapper = providers.getExceptionMapper(cause.getClass());
            if (mapper != null) {
                return mapper.toResponse(cause);
            } else if (cause instanceof WebApplicationException) {
                return ((WebApplicationException)cause).getResponse();
            }
        }
View Full Code Here

    }
   
    @SuppressWarnings("unchecked")
    public static Response convertFaultToResponse(Throwable ex, Message inMessage) {
       
        ExceptionMapper mapper =
            ProviderFactory.getInstance(inMessage).createExceptionMapper(ex.getClass(), inMessage);
        if (mapper != null) {
            try {
                return mapper.toResponse(ex);
            } catch (Exception mapperEx) {
                mapperEx.printStackTrace();
                return Response.serverError().build();
            }
        }
View Full Code Here

      if (exception.getCausedByException() == null)
      {
         return Response.serverError().build();
      }
      Class cause = exception.getCausedByException().getClass();
      ExceptionMapper mapper = providers.getExceptionMapper(cause);
      if (mapper == null)
      {
         return Response.serverError().build();
      }
      else
      {
         return mapper.toResponse(exception.getCausedByException());
      }
   }
View Full Code Here

      return null;
   }

   protected void addExceptionMapper(Class<? extends ExceptionMapper> providerClass)
   {
      ExceptionMapper provider = createProviderInstance(providerClass);
      addExceptionMapper(provider, providerClass);
   }
View Full Code Here

      if (exception.getCausedByException() == null)
      {
         return Response.serverError().build();
      }
      Class cause = exception.getCausedByException().getClass();
      ExceptionMapper mapper = providers.getExceptionMapper(cause);
      if (mapper == null)
      {
         return Response.serverError().build();
      }
      else
      {
         return mapper.toResponse(exception.getCausedByException());
      }
   }
View Full Code Here

    * @param exception
    * @return
    */
   public Response executeExactExceptionMapper(Throwable exception)
   {
      ExceptionMapper mapper = providerFactory.getExceptionMappers().get(exception.getClass());
      if (mapper == null) return null;
      mapperExecuted = true;
      return mapper.toResponse(exception);
   }
View Full Code Here

   }


   public Response executeExceptionMapperForClass(Throwable exception, Class clazz)
   {
      ExceptionMapper mapper = providerFactory.getExceptionMappers().get(clazz);
      if (mapper == null) return null;
      mapperExecuted = true;
      return mapper.toResponse(exception);
   }
View Full Code Here

    * @param exception
    * @return true if an ExceptionMapper was found and executed
    */
   public Response executeExceptionMapper(Throwable exception)
   {
      ExceptionMapper mapper = null;

      Class causeClass = exception.getClass();
      while (mapper == null) {
         if (causeClass == null) break;
         mapper = providerFactory.getExceptionMappers().get(causeClass);
         if (mapper == null) causeClass = causeClass.getSuperclass();
      }
      if (mapper != null) {
         mapperExecuted = true;
         Response jaxrsResponse = mapper.toResponse(exception);
         if (jaxrsResponse == null) {
            jaxrsResponse = Response.status(204).build();
         }
         return jaxrsResponse;
      }
View Full Code Here

TOP

Related Classes of javax.ws.rs.ext.ExceptionMapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.