Examples of ExceptionMapper


Examples of javax.ws.rs.ext.ExceptionMapper

     *
     * @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;

        wa.getResponseListener().onMappedException(
                Thread.currentThread().getId(),
                e,
                em
        );

        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

Examples of javax.ws.rs.ext.ExceptionMapper

    }
   
    @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

Examples of javax.ws.rs.ext.ExceptionMapper

    }
   
    @SuppressWarnings("unchecked")
    public static Response convertFaultToResponse(Throwable ex, Message inMessage) {
       
        ExceptionMapper mapper =
            ProviderFactory.getInstance(inMessage).createExceptionMapper(ex.getClass(), inMessage);
        if (mapper != null) {
            Response excResponse = mapper.toResponse(ex);
            if (excResponse != null) {
                return excResponse;
            }
        } else if (ex instanceof WebApplicationException) {
            WebApplicationException wex = (WebApplicationException)ex;
View Full Code Here

Examples of javax.ws.rs.ext.ExceptionMapper

        final Exception cause = exception.getCausedByException();

        if (cause != null) {

            final ExceptionMapper mapper = mappers.get().findMapping(cause);
            if (mapper != null && mapper != this) {

                return mapper.toResponse(cause);

            } else if (cause instanceof WebApplicationException) {

                return ((WebApplicationException)cause).getResponse();
            }
View Full Code Here

Examples of javax.ws.rs.ext.ExceptionMapper

      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

Examples of javax.ws.rs.ext.ExceptionMapper

    }
   
    @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

Examples of javax.ws.rs.ext.ExceptionMapper

         {
            if (e instanceof WebApplicationException)
            {

               Response errorResponse = ((WebApplicationException)e).getResponse();
               ExceptionMapper excmap = ProviderBinder.getInstance().getExceptionMapper(WebApplicationException.class);

               int errorStatus = errorResponse.getStatus();
               // should be some of 4xx status
               if (errorStatus < 500)
               {
                  // Warn about error in debug mode only.
                  if (LOG.isDebugEnabled() && e.getCause() != null)
                  {
                     LOG.warn("WebApplication exception occurs.", e.getCause());
                  }
               }
               else
               {
                  if (e.getCause() != null)
                  {
                     LOG.warn("WebApplication exception occurs.", e.getCause());
                  }
               }
               // -----
               if (errorResponse.getEntity() == null)
               {
                  if (excmap != null)
                  {
                     errorResponse = excmap.toResponse(e);
                  }
                  else
                  {
                     if (e.getMessage() != null)
                     {
                        errorResponse = createErrorResponse(errorStatus, e.getMessage());
                     }
                  }
               }
               else
               {
                  if (errorResponse.getMetadata().getFirst(ExtHttpHeaders.JAXRS_BODY_PROVIDED) == null)
                  {
                     String jaxrsHeader = getJaxrsHeader(errorStatus);
                     if (jaxrsHeader != null)
                     {
                        errorResponse.getMetadata().putSingle(ExtHttpHeaders.JAXRS_BODY_PROVIDED, jaxrsHeader);
                     }
                  }
               }
               response.setResponse(errorResponse);
            }
            else if (e instanceof InternalException)
            {
               Throwable cause = e.getCause();
               Class causeClazz = cause.getClass();
               ExceptionMapper excmap = ProviderBinder.getInstance().getExceptionMapper(causeClazz);
               while (causeClazz != null && excmap == null)
               {
                  excmap = ProviderBinder.getInstance().getExceptionMapper(causeClazz);
                  if (excmap == null)
                     causeClazz = causeClazz.getSuperclass();
               }
               if (excmap != null)
               {
                  if (LOG.isDebugEnabled())
                  {
                     // Hide error message if exception mapper exists.
                     LOG.warn("Internal error occurs.", cause);
                  }
                  response.setResponse(excmap.toResponse(e.getCause()));
               }
               else
               {
                  LOG.error("Internal error occurs.", cause);
                  throw new UnhandledException(e.getCause());
View Full Code Here

Examples of javax.ws.rs.ext.ExceptionMapper

        final Exception cause = exception.getCausedByException();

        if (cause != null) {

            final ExceptionMapper mapper = mappers.get().findMapping(cause);
            if (mapper != null && mapper != this) {

                return mapper.toResponse(cause);

            } else if (cause instanceof WebApplicationException) {

                return ((WebApplicationException)cause).getResponse();
            }
View Full Code Here

Examples of javax.ws.rs.ext.ExceptionMapper

    @Inject
    Provider<ExceptionMappers> mappers;

    @Override
    public Response toResponse(TransactionalException exception) {
        final ExceptionMapper mapper = mappers.get().findMapping(exception);

        if (mapper != null && !TransactionalExceptionMapper.class.isAssignableFrom(mapper.getClass())) {
            return mapper.toResponse(exception);
        } else {
            if (waeHolder != null) {
                final WebApplicationException wae = waeHolder.exception;
                if (wae != null) {
                    return wae.getResponse();
View Full Code Here

Examples of javax.ws.rs.ext.ExceptionMapper

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

      Class causeClass = exception.getClass();
      while (mapper == null)
      {
         if (causeClass == null) break;
         mapper = providerFactory.getExceptionMapper(causeClass);
         if (mapper == null) causeClass = causeClass.getSuperclass();
      }
      if (mapper != null)
      {
         writeFailure(response, mapper.toResponse(exception));
         return true;
      }
      return false;
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.