org.glassfish.jersey.server.internal.process.MappableException Java Examples

The following examples show how to use org.glassfish.jersey.server.internal.process.MappableException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AuthorizationFilter.java    From shiro-jersey with Apache License 2.0 5 votes vote down vote up
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
    try {
        for (Map.Entry<AuthorizingAnnotationHandler, Annotation> authzCheck : authzChecks.entrySet()) {
            AuthorizingAnnotationHandler handler = authzCheck.getKey();
            Annotation authzSpec = authzCheck.getValue();
            handler.assertAuthorized(authzSpec);
        }
    } catch (AuthorizationException e) {
        throw new MappableException(e); // TODO Try without wrapping
    }
}
 
Example #2
Source File: DefaultExceptionMapper.java    From ameba with MIT License 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public Response toResponse(Throwable exception) {
    int status = parseHttpStatus(exception);

    ErrorMessage message = new ErrorMessage();

    if (exception instanceof MappableException
            && exception.getCause() != null) {
        exception = exception.getCause();
    }

    message.setCode(Hashing.murmur3_32().hashUnencodedChars(exception.getClass().getName()).toString());
    message.setStatus(status);
    message.setThrowable(exception);
    message.setMessage(parseMessage(exception, status));
    message.setDescription(parseDescription(exception, status));
    message.setErrors(parseErrors(exception, status));

    MediaType type = ExceptionMapperUtils.getResponseType(status);
    if (status == 500) {
        String uri = "";
        if (Requests.getRequest() != null) {
            uri = " > " + Requests.getUriInfo().getRequestUri();
        }
        logger.error(message.getMessage() + uri, exception);
    } else if (status == 404) {
        Requests.setProperty(BEFORE_EXCEPTION_KEY, exception);
    }

    return Response.status(status)
            .type(type)
            .entity(message).build();
}
 
Example #3
Source File: AuthorizationFilter.java    From shiro-jersey with Apache License 2.0 5 votes vote down vote up
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
    try {
        for (Map.Entry<AuthorizingAnnotationHandler, Annotation> authzCheck : authzChecks.entrySet()) {
            AuthorizingAnnotationHandler handler = authzCheck.getKey();
            Annotation authzSpec = authzCheck.getValue();
            handler.assertAuthorized(authzSpec);
        }
    } catch (AuthorizationException e) {
        throw new MappableException(e); // TODO Try without wrapping
    }
}
 
Example #4
Source File: SpanCustomizingApplicationEventListener.java    From brave with Apache License 2.0 5 votes vote down vote up
@Nullable static Throwable unwrapError(RequestEvent event) {
  Throwable error = event.getException();
  // For example, if thrown in an async controller
  if (error instanceof MappableException && error.getCause() != null) {
    error = error.getCause();
  }
  // Don't create error messages for normal HTTP status codes.
  if (error instanceof WebApplicationException) return error.getCause();
  return error;
}
 
Example #5
Source File: TracingApplicationEventListener.java    From brave with Apache License 2.0 5 votes vote down vote up
@Override public int statusCode() {
  ContainerResponse response = event.getContainerResponse();
  if (response != null) return response.getStatus();

  Throwable error = event.getException();
  // For example, if thrown in an async controller
  if (error instanceof MappableException && error.getCause() != null) {
    error = error.getCause();
  }
  if (error instanceof WebApplicationException) {
    return ((WebApplicationException) error).getResponse().getStatus();
  }
  return 0;
}
 
Example #6
Source File: RequestEventWrapperTest.java    From brave with Apache License 2.0 4 votes vote down vote up
@Test public void statusCode_mappableException() {
  when(event.getException()).thenReturn(new MappableException(new ClientErrorException(400)));

  assertThat(new RequestEventWrapper(event).statusCode()).isEqualTo(400);
}