当前位置: 首页>>代码示例>>Java>>正文


Java ParamException类代码示例

本文整理汇总了Java中org.glassfish.jersey.server.ParamException的典型用法代码示例。如果您正苦于以下问题:Java ParamException类的具体用法?Java ParamException怎么用?Java ParamException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ParamException类属于org.glassfish.jersey.server包,在下文中一共展示了ParamException类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getParamExceptionErrorMessage

import org.glassfish.jersey.server.ParamException; //导入依赖的package包/类
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
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:26,代码来源:GenericExceptionMapper.java

示例2: toResponse

import org.glassfish.jersey.server.ParamException; //导入依赖的package包/类
@Override
public Response toResponse(MultiException exc) {
	LOGGER.debug("mapping " + exc.getClass(), exc);
	List<Throwable> errors = exc.getErrors();
	if (errors.size() > 0) {
		Throwable cause = errors.get(0);
		if (cause instanceof QueryParamException
				|| cause instanceof FormParamException) {
			ParamException paramException = (ParamException) cause;
			return Response
					.status(400)
					.type(MediaType.TEXT_PLAIN)
					.entity("illegal value for parameter '"
							+ paramException.getParameterName() + "'")
					.build();
		}

	}
	return Response.serverError().build();
}
 
开发者ID:Apereo-Learning-Analytics-Initiative,项目名称:Larissa,代码行数:21,代码来源:MultiExceptionMapper.java

示例3: toResponse

import org.glassfish.jersey.server.ParamException; //导入依赖的package包/类
@Override
public Response toResponse(ParamException notFoundException) {
    return Response
            .status(Response.Status.BAD_REQUEST)
            .type(getMediaType(headers, MediaType.APPLICATION_JSON_TYPE))
            .entity(new ErrorCodeDto(ErrorCodeDto.VMIDC_VALIDATION_EXCEPTION_ERROR_CODE, Arrays.asList("Not found")))
            .build();
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:9,代码来源:PathParamExceptionMapper.java

示例4: shouldHandleException

import org.glassfish.jersey.server.ParamException; //导入依赖的package包/类
@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;
}
 
开发者ID:Nike-Inc,项目名称:backstopper,代码行数:29,代码来源:Jersey2WebApplicationExceptionHandlerListener.java

示例5: dataProviderForShouldHandleException

import org.glassfish.jersey.server.ParamException; //导入依赖的package包/类
@DataProvider
public static Object[][] dataProviderForShouldHandleException() {
    return new Object[][] {
        { mock(ParamException.UriParamException.class), testProjectApiErrors.getNotFoundApiError() },
        { mock(ParamException.class), testProjectApiErrors.getMalformedRequestApiError() }
    };
}
 
开发者ID:Nike-Inc,项目名称:backstopper,代码行数:8,代码来源:Jersey2WebApplicationExceptionHandlerListenerTest.java

示例6: toResponse

import org.glassfish.jersey.server.ParamException; //导入依赖的package包/类
@Override
public Response toResponse(final Throwable exception) {
    if (exception instanceof ParamException.PathParamException) {
        return Response.status(Response.Status.NOT_FOUND)
                .header(HttpHeaders.CONTENT_TYPE, ExtraMediaType.TEXT_HTML)
                .entity(viewFactory.exceptionNotFoundView())
                .build();
    }

    if (exception instanceof FieldConversionException) {
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
                .header(HttpHeaders.CONTENT_TYPE, ExtraMediaType.TEXT_HTML)
                .entity(viewFactory.exceptionFieldConversionView(exception.getMessage()))
                .build();
    }

    if (exception instanceof InconsistencyException) {
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
                .header(HttpHeaders.CONTENT_TYPE, ExtraMediaType.TEXT_HTML)
                .entity(viewFactory.exceptionInconsistencyView(exception.getMessage()))
                .build();
    }

    LOGGER.error("Uncaught exception: {}", exception);

    return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
            .header(HttpHeaders.CONTENT_TYPE, ExtraMediaType.TEXT_HTML)
            .entity(viewFactory.exceptionServerErrorView())
            .build();
}
 
开发者ID:openregister,项目名称:openregister-java,代码行数:31,代码来源:ThrowableExceptionMapper.java

示例7: toResponse

import org.glassfish.jersey.server.ParamException; //导入依赖的package包/类
@Override
public Response toResponse(final ParamException e) {

    LOGGER.error("ParamException intercepted by ParamExceptionMapper: {}\n", e.getMessage());
    debugException(this, e, LOGGER);

    final StringBuilder msg = new StringBuilder("Error parsing parameter: ");
    msg.append(e.getParameterName());
    msg.append(", of type: ");
    msg.append(e.getParameterType().getSimpleName());

    return fromResponse(e.getResponse()).entity(msg.toString()).type(TEXT_PLAIN_WITH_CHARSET).build();
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:14,代码来源:ParamExceptionMapper.java

示例8: testToResponse

import org.glassfish.jersey.server.ParamException; //导入依赖的package包/类
@Test
public void testToResponse() {
    final ParamException input = new ParamException.HeaderParamException(new RuntimeException("canned-exception"),
                                                                         "test-header",
                                                                         null);
    final Response actual = testObj.toResponse(input);
    assertEquals(input.getResponse().getStatus(), actual.getStatus());
    assertNotNull(actual.getEntity());
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:10,代码来源:ParamExceptionMapperTest.java


注:本文中的org.glassfish.jersey.server.ParamException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。