javax.ws.rs.ext.ExceptionMapper类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(291)

本文整理了Java中javax.ws.rs.ext.ExceptionMapper类的一些代码示例,展示了ExceptionMapper类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ExceptionMapper类的具体详情如下:
包路径:javax.ws.rs.ext.ExceptionMapper
类名称:ExceptionMapper

ExceptionMapper介绍

[英]Contract for a provider that maps Java exceptions to javax.ws.rs.core.Response. An implementation of this interface must be annotated with Provider.
[中]将Java异常映射到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: com.carecon.fabric3/fabric3-binding-rs-jersey

public Response toResponse(E exception) {
    return getDelegate().toResponse(exception);
  }
}

代码示例来源:origin: org.fabric3/fabric3-binding-rs-jersey

public Response toResponse(E exception) {
    return getDelegate().toResponse(exception);
  }
}

代码示例来源:origin: org.glassfish.jersey.containers.glassfish/jersey-gf-cdi

@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.exception;
      if (wae != null) {
        return wae.getResponse();
      }
    }
    throw exception;
  }
}

代码示例来源:origin: org.jboss.resteasy/resteasy-jaxrs-20

/**
* If there exists an Exception mapper for exception, execute it, otherwise, do NOT recurse up class hierarchy
* of exception.
*
* @param exception
* @return
*/
@SuppressWarnings(value = "unchecked")
public Response executeExactExceptionMapper(Throwable exception)
{
 ExceptionMapper mapper = providerFactory.getExceptionMappers().get(exception.getClass());
 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: bazaarvoice/emodb

@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());
    }
  }
}

代码示例来源:origin: org.glassfish.jersey.ext.cdi/jersey-cdi1x-transaction

@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: 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: org.fcrepo/fcrepo-http-commons

@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();
  }
}

相关文章

ExceptionMapper类方法