org.glassfish.jersey.server.ParamException Java Examples

The following examples show how to use org.glassfish.jersey.server.ParamException. 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: GenericExceptionMapper.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
private String getParamExceptionErrorMessage(ParamException pe) {
  Throwable cause = pe.getCause();
  if (cause instanceof ExtractorException && cause.getCause() != null) {
    // ExtractorException does not have any extra info
    cause = cause.getCause();
  }

  final String causeMessage =
      (cause != null)
      ? " " + cause.getMessage()
      : "";

  return pe.getDefaultStringValue() != null
      ? String.format("%s: %s %s (default: %s).%s",
          pe.getMessage(), // generic status message
          pe.getParameterType().getSimpleName(),
          pe.getParameterName(), // which param is wrong
          pe.getDefaultStringValue(), // if it has a default
          causeMessage)
      : String.format("%s: %s %s.%s",
          pe.getMessage(), // generic status message
          pe.getParameterType().getSimpleName(),
          pe.getParameterName(), // which param is wrong
          causeMessage);// the underlying problem
}
 
Example #2
Source File: QueryParamExceptionMapper.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
@Override
public Response toResponse(ParamException.QueryParamException exception) {
    logger.info(String.format("%s. Returning %s response.", exception, Response.Status.BAD_REQUEST));

    if (logger.isDebugEnabled()) {
        logger.debug(StringUtils.EMPTY, exception);
    }

    final String message = "Invalid value for " + exception.getParameterName();
    return Response.status(Response.Status.BAD_REQUEST).entity(message).type("text/plain").build();
}
 
Example #3
Source File: Jersey2WebApplicationExceptionHandlerListener.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Override
public ApiExceptionHandlerListenerResult shouldHandleException(Throwable ex) {

    ApiExceptionHandlerListenerResult result;
    SortedApiErrorSet handledErrors = null;
    List<Pair<String, String>> extraDetailsForLogging = new ArrayList<>();

    if (ex instanceof ParamException.UriParamException) {
        utils.addBaseExceptionMessageToExtraDetailsForLogging(ex, extraDetailsForLogging);
        // Returning a 404 is intentional here.
        //      The Jersey contract for URIParamException states it should map to a 404.
        handledErrors = singletonSortedSetOf(projectApiErrors.getNotFoundApiError());
    }
    else if (ex instanceof ParamException) {
        utils.addBaseExceptionMessageToExtraDetailsForLogging(ex, extraDetailsForLogging);
        handledErrors = singletonSortedSetOf(projectApiErrors.getMalformedRequestApiError());
    }

    // Return an indication that we will handle this exception if handledErrors got set
    if (handledErrors != null) {
        result = ApiExceptionHandlerListenerResult.handleResponse(handledErrors, extraDetailsForLogging);
    }
    else {
        result = ApiExceptionHandlerListenerResult.ignoreResponse();
    }

    return result;
}
 
Example #4
Source File: Jersey2WebApplicationExceptionHandlerListenerTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@DataProvider
public static Object[][] dataProviderForShouldHandleException() {
    return new Object[][] {
        { mock(ParamException.UriParamException.class), testProjectApiErrors.getNotFoundApiError() },
        { mock(ParamException.class), testProjectApiErrors.getMalformedRequestApiError() }
    };
}