本文整理了Java中javax.ws.rs.ext.ExceptionMapper.toResponse()
方法的一些代码示例,展示了ExceptionMapper.toResponse()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ExceptionMapper.toResponse()
方法的具体详情如下:
包路径:javax.ws.rs.ext.ExceptionMapper
类名称:ExceptionMapper
方法名:toResponse
[英]Map an exception to a javax.ws.rs.core.Response. Returning null results in a javax.ws.rs.core.Response.Status#NO_CONTENTresponse. Throwing a runtime exception results in a javax.ws.rs.core.Response.Status#INTERNAL_SERVER_ERROR response
[中]将异常映射到javax。ws。rs.core。回答返回null将导致javax。ws。rs.core。回答状态#无内容响应。引发运行时异常会导致javax。ws。rs.core。回答状态#内部_服务器_错误响应
代码示例来源:origin: jersey/jersey
@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.getException();
if (wae != null) {
return wae.getResponse();
}
}
throw exception;
}
}
代码示例来源:origin: jersey/jersey
private Response causeToResponse(EJBException exception) {
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();
}
}
return null;
}
}
代码示例来源:origin: jersey/jersey
processingContext.triggerEvent(RequestEvent.Type.EXCEPTION_MAPPER_FOUND);
try {
final Response mappedResponse = mapper.toResponse(throwable);
代码示例来源:origin: jersey/jersey
processingContext.triggerEvent(RequestEvent.Type.EXCEPTION_MAPPER_FOUND);
try {
final Response mappedResponse = mapper.toResponse(throwable);
代码示例来源:origin: com.sun.jersey/jersey-server
Response r = em.toResponse(e);
if (r == null)
r = Response.noContent().build();
代码示例来源:origin: resteasy/Resteasy
@SuppressWarnings(value = "unchecked")
protected Response executeExceptionMapperForClass(Throwable exception, Class clazz, RESTEasyTracingLogger logger)
{
if (logger == null)
logger = RESTEasyTracingLogger.empty();
ExceptionMapper mapper = providerFactory.getExceptionMappers().get(clazz);
if (mapper == null) return null;
mapperExecuted = true;
long timestamp = logger.timestamp("EXCEPTION_MAPPING");
Response resp = mapper.toResponse(exception);
logger.logDuration("EXCEPTION_MAPPING", timestamp, mapper, exception, exception.getLocalizedMessage(), resp);
return resp;
}
代码示例来源:origin: resteasy/Resteasy
/**
* If there exists an Exception mapper for exception, execute it, otherwise, do NOT recurse up class hierarchy
* of exception.
*
* @param exception exception
* @param logger logger
* @return response response object
*/
@SuppressWarnings(value = "unchecked")
protected Response executeExactExceptionMapper(Throwable exception, RESTEasyTracingLogger logger) {
if (logger == null)
logger = RESTEasyTracingLogger.empty();
ExceptionMapper mapper = providerFactory.getExceptionMappers().get(exception.getClass());
if (mapper == null) return null;
mapperExecuted = true;
long timestamp = logger.timestamp("EXCEPTION_MAPPING");
Response resp = mapper.toResponse(exception);
logger.logDuration("EXCEPTION_MAPPING", timestamp, mapper, exception, exception.getLocalizedMessage(), resp);
return resp;
}
代码示例来源:origin: resteasy/Resteasy
Response jaxrsResponse = mapper.toResponse(exception);
logger.logDuration("EXCEPTION_MAPPING", timestamp, mapper, exception, exception.getLocalizedMessage(), jaxrsResponse);
代码示例来源:origin: org.glassfish.jersey.core/jersey-server
processingContext.triggerEvent(RequestEvent.Type.EXCEPTION_MAPPER_FOUND);
try {
final Response mappedResponse = mapper.toResponse(throwable);
代码示例来源:origin: org.jboss.resteasy/resteasy-jaxrs-20
@SuppressWarnings(value = "unchecked")
public Response executeExceptionMapperForClass(Throwable exception, Class clazz)
{
ExceptionMapper mapper = providerFactory.getExceptionMappers().get(clazz);
if (mapper == null) return null;
mapperExecuted = true;
return mapper.toResponse(exception);
}
代码示例来源:origin: bazaarvoice/emodb
@SuppressWarnings("ThrowableNotThrown")
@Override
public Response toResponse(PartitionForwardingException exception) {
// To prevent herding advise the caller to retry after 1 to 5 seconds, chosen randomly.
return _providers.getExceptionMapper(ServiceUnavailableException.class)
.toResponse(new ServiceUnavailableException("Service unavailable, try again later", new Random().nextInt(5) + 1));
}
}
代码示例来源:origin: org.apache.wink/wink-server
private Response executeProvider(Throwable exception, ExceptionMapper<Throwable> provider) {
try {
return provider.toResponse(exception);
} catch (Throwable e) {
logger.error(Messages.getMessage("exceptionOccurredDuringExceptionMapper", provider.getClass().getName()), e); //$NON-NLS-1$
return RUNTIME_DELEGATE.createResponseBuilder().status(500).build();
}
}
代码示例来源:origin: icode/ameba
protected Response notFound() {
Throwable e = new NotFoundException();
return Response.fromResponse(mappers.get().findMapping(e).toResponse(e))
.type(MediaType.TEXT_HTML_TYPE).build();
}
代码示例来源:origin: bazaarvoice/emodb
@Override
public Response toResponse(AuthenticationException exception) {
// AuthenticationException is only used internally to propagate authorization errors. Convert the
// exception to the equivalent public-facing exception from the API.
UnauthorizedException apiException = new UnauthorizedException();
return _providers.getExceptionMapper(UnauthorizedException.class).toResponse(apiException);
}
}
代码示例来源:origin: bazaarvoice/emodb
@Override
public Response toResponse(AuthorizationException exception) {
// AuthorizationException is only used internally to propagate authorization errors. Convert the
// exception to the equivalent public-facing exception from the API.
UnauthorizedException apiException = new UnauthorizedException();
return _providers.getExceptionMapper(UnauthorizedException.class).toResponse(apiException);
}
}
代码示例来源:origin: icode/ameba
/**
* {@inheritDoc}
*/
@Override
public Response toResponse(QuerySyntaxException exception) {
return providers.getExceptionMapper(Throwable.class)
.toResponse(new UnprocessableEntityException(exception.getMessage(), exception));
}
}
代码示例来源:origin: palantir/conjure-java-runtime
@Test
public void testThrottle_withDuration() throws Exception {
QosException exception = QosException.throttle(Duration.ofMinutes(2));
Response response = mapper.toResponse(exception);
assertThat(response.getStatus()).isEqualTo(429);
assertThat(response.getHeaders()).containsEntry("Retry-After", ImmutableList.of("120"));
}
代码示例来源:origin: palantir/conjure-java-runtime
@Test
public void testRetryOther() throws Exception {
QosException exception = QosException.retryOther(new URL("http://foo"));
Response response = mapper.toResponse(exception);
assertThat(response.getStatus()).isEqualTo(308);
assertThat(response.getHeaders()).containsEntry("Location", ImmutableList.of("http://foo"));
}
代码示例来源:origin: palantir/conjure-java-runtime
@Test
public void testThrottle_withoutDuration() throws Exception {
QosException exception = QosException.throttle();
Response response = mapper.toResponse(exception);
assertThat(response.getStatus()).isEqualTo(429);
assertThat(response.getHeaders()).isEmpty();
}
代码示例来源:origin: palantir/conjure-java-runtime
@Test
public void testUnavailable() throws Exception {
QosException exception = QosException.unavailable();
Response response = mapper.toResponse(exception);
assertThat(response.getStatus()).isEqualTo(503);
assertThat(response.getHeaders()).isEmpty();
}
}
内容来源于网络,如有侵权,请联系作者删除!