本文整理汇总了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
}
示例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();
}
示例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();
}
示例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;
}
示例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() }
};
}
示例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();
}
示例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();
}
示例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());
}