本文整理汇总了Java中javax.ws.rs.ext.ExceptionMapper.toResponse方法的典型用法代码示例。如果您正苦于以下问题:Java ExceptionMapper.toResponse方法的具体用法?Java ExceptionMapper.toResponse怎么用?Java ExceptionMapper.toResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.ext.ExceptionMapper
的用法示例。
在下文中一共展示了ExceptionMapper.toResponse方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toResponse
import javax.ws.rs.ext.ExceptionMapper; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private Response toResponse(final MinijaxRequestContext context, final Exception ex) {
final MinijaxResourceMethod rm = context.getResourceMethod();
final List<MediaType> mediaTypes;
if (rm != null) {
mediaTypes = rm.getProduces();
} else {
mediaTypes = context.getAcceptableMediaTypes();
}
for (final MediaType mediaType : mediaTypes) {
final ExceptionMapper mapper = providers.getExceptionMapper(ex.getClass(), mediaType);
if (mapper != null) {
return mapper.toResponse(ex);
}
}
return ExceptionUtils.toWebAppException(ex).getResponse();
}
示例2: toResponse
import javax.ws.rs.ext.ExceptionMapper; //导入方法依赖的package包/类
@Override
public Response toResponse(Exception ex) {
if (Options.RETURN_EXCEPTION_BODY) {
if (ex instanceof PersistenceException) {
Throwable cause = ex.getCause();
if (cause != null) { // The type of this exception is determined at runtime
cause = cause.getCause();
if (cause instanceof SQLIntegrityConstraintViolationException) {
return new RestErrorBuilder(cause).createResponse();
}
}
}
}
ExceptionMapper exceptionMapper = providers.getExceptionMapper(ex.getClass());
if (exceptionMapper == null || exceptionMapper == this) {
return Response.serverError().build();
}
else {
return exceptionMapper.toResponse(ex);
}
}
示例3: toResponse
import javax.ws.rs.ext.ExceptionMapper; //导入方法依赖的package包/类
public Response toResponse(EJBException exception)
{
if (exception.getCausedByException() == null)
{
return Response.serverError().build();
}
Class cause = exception.getCausedByException().getClass();
ExceptionMapper mapper = providers.getExceptionMapper(cause);
if (mapper == null)
{
return Response.serverError().build();
}
else
{
return mapper.toResponse(exception.getCausedByException());
}
}
示例4: toResponse
import javax.ws.rs.ext.ExceptionMapper; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Response toResponse(EJBException exception) {
if (exception.getCausedByException() == null) {
LOGGER.error(exception.getMessage(), exception);
return Responses.errorResponse(Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(), "Internal Server Error", exception, LOGGER.isInfoEnabled());
} else {
Class cause = exception.getCausedByException().getClass();
ExceptionMapper mapper = providers.getExceptionMapper(cause);
if (mapper == null) {
LOGGER.error(exception.getMessage(), exception);
return Responses.errorResponse(Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(), "Internal Server Error", exception, LOGGER.isInfoEnabled());
} else {
return mapper.toResponse(exception.getCausedByException());
}
}
}
示例5: toResponse
import javax.ws.rs.ext.ExceptionMapper; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Response toResponse(UncheckedExecutionException e) {
ExceptionMapper mapper = _providers.getExceptionMapper(e.getCause().getClass());
if (mapper == null) {
return null;
} else if (mapper instanceof LoggingExceptionMapper) {
return mapper.toResponse(e);
} else {
return mapper.toResponse(e.getCause());
}
}
示例6: toResponse
import javax.ws.rs.ext.ExceptionMapper; //导入方法依赖的package包/类
@Override
public Response toResponse(final EJBException ejbException) {
final Exception cause = ejbException.getCausedByException();
if (cause != null) {
final Class causeClass = cause.getClass();
final ExceptionMapper exceptionMapper = providers.getExceptionMapper(causeClass);
if (exceptionMapper == null) {
return defaultResponse(cause);
}
return exceptionMapper.toResponse(cause);
} else if (EJBAccessException.class.isInstance(ejbException)) {
return Response.status(Response.Status.FORBIDDEN).build();
}
return defaultResponse(ejbException);
}
示例7: toResponse
import javax.ws.rs.ext.ExceptionMapper; //导入方法依赖的package包/类
@Override
public Response toResponse(final RepositoryRuntimeException e) {
final Throwable cause = e.getCause();
@SuppressWarnings("unchecked")
final ExceptionMapper<Throwable> exceptionMapper =
(ExceptionMapper<Throwable>) providers.getExceptionMapper(cause.getClass());
if (exceptionMapper != null) {
return exceptionMapper.toResponse(cause);
}
LOGGER.error("Caught a repository exception: {}", e.getMessage());
debugException(this, cause, LOGGER);
return serverError().entity(getStackTraceAsString(e)).type(TEXT_PLAIN_WITH_CHARSET).build();
}
示例8: toResponse
import javax.ws.rs.ext.ExceptionMapper; //导入方法依赖的package包/类
@Override
public Response toResponse(DBIException throwable) {
Throwable cause = Databases.findExceptionRootCause(throwable);
ExceptionMapper actualMapper = providers.getExceptionMapper(cause.getClass());
return actualMapper.toResponse(cause);
}