Ejemplo n.º 1
0
 public boolean executeExceptionMapperForClass(
     HttpRequest request, HttpResponse response, Throwable exception, Class clazz) {
   ExceptionMapper mapper = providerFactory.getExceptionMapper(clazz);
   if (mapper == null) return false;
   writeFailure(request, response, mapper.toResponse(exception));
   return true;
 }
Ejemplo n.º 2
0
  /**
   * Execute an ExceptionMapper if one exists for the given exception. Recurse to base class if not
   * found
   *
   * @param response
   * @param exception
   * @return true if an ExceptionMapper was found and executed
   */
  public boolean executeExceptionMapper(
      HttpRequest request, HttpResponse response, Throwable exception) {
    ExceptionMapper mapper = null;

    Class causeClass = exception.getClass();
    while (mapper == null) {
      if (causeClass == null) break;
      mapper = providerFactory.getExceptionMapper(causeClass);
      if (mapper == null) causeClass = causeClass.getSuperclass();
    }
    if (mapper != null) {
      Response jaxrsResponse = mapper.toResponse(exception);
      if (jaxrsResponse == null) {
        jaxrsResponse = Response.status(204).build();
      }
      writeFailure(request, response, jaxrsResponse);
      return true;
    }
    return false;
  }