Java Code Examples for javax.ws.rs.WebApplicationException#getMessage()

The following examples show how to use javax.ws.rs.WebApplicationException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebApplicationExceptionMapper.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public Response toResponse(WebApplicationException exception) {
    // get the message and ensure it is not blank
    String message = exception.getMessage();
    if (message == null) {
        message = StringUtils.EMPTY;
    }

    // format the message
    if (message.contains(EXCEPTION_SEPARATOR)) {
        message = StringUtils.substringAfter(message, EXCEPTION_SEPARATOR);
    }

    // get the response
    final Response response = exception.getResponse();

    // log the error
    logger.info(String.format("%s. Returning %s response.", exception, response.getStatus()));

    if (logger.isDebugEnabled()) {
        logger.debug(StringUtils.EMPTY, exception);
    }

    // generate the response
    return Response.status(response.getStatus()).entity(message).type("text/plain").build();
}
 
Example 2
Source File: ElasticTestActions.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Override
public Result getResult(WebTarget target) {
  WebTarget t = target;
  target.path(Joiner.on(",").join(indexes)).path("_mapping");
  if (indexes.size() > 0) {
    t = t.path(Joiner.on(",").join(indexes));
  }
  t = t.path("_mapping");
  if (types.size() > 0) {
    t = t.path(Joiner.on(",").join(types));
  }
  try {
    return new JsonResult(t.request().buildGet().invoke(byte[].class));
  } catch (WebApplicationException e) {
    return new FailureResult(e.getResponse().getStatus(), e.getMessage());
  }
}
 
Example 3
Source File: PulsarAdminException.java    From pulsar with Apache License 2.0 6 votes vote down vote up
private static String getReasonFromServer(WebApplicationException e) {
    try {
        return e.getResponse().readEntity(ErrorData.class).reason.toString();
    } catch (Exception ex) {
        try {
            return ObjectMapperFactory.getThreadLocal().readValue(
                    e.getResponse().getEntity().toString(), ErrorData.class).reason;
        } catch (Exception ex1) {
            try {
                return ObjectMapperFactory.getThreadLocal().readValue(e.getMessage(), ErrorData.class).reason;
            } catch (Exception ex2) {
                // could not parse output to ErrorData class
                return e.getMessage();
            }
        }
    }
}
 
Example 4
Source File: GenericExceptionMapper.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
@Override
public Response toResponse(WebApplicationException webApplicationException) {
    if (log.isDebugEnabled()) {
        log.debug("Internal erver error", webApplicationException);
    }
    // if no specific error message specified, spitting out a generaic error
    // message
    String errorMessage =
            (webApplicationException.getMessage() != null)
                    ? webApplicationException.getMessage()
                    : "Internal server error";
    return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
            .type(MediaType.APPLICATION_JSON)
            .entity(Utils.buildMessage(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
                    errorMessage)).build();
}
 
Example 5
Source File: WebApplicationExceptionMapper.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public Response toResponse(WebApplicationException exception) {
    // get the message and ensure it is not blank
    String message = exception.getMessage();
    if (message == null) {
        message = StringUtils.EMPTY;
    }

    // format the message
    if (message.contains(EXCEPTION_SEPARATOR)) {
        message = StringUtils.substringAfter(message, EXCEPTION_SEPARATOR);
    }

    // get the response
    final Response response = exception.getResponse();

    // log the error
    logger.warn("{}. Returning {} response.", exception, response.getStatus(), exception);

    // generate the response
    return Response.status(response.getStatus()).entity(message).type("text/plain").build();
}
 
Example 6
Source File: ElasticActions.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public Result getResult(WebTarget target) {
  try {
    return new JsonResult(target.path("_nodes").request().header(CONTENT_TYPE, APPLICATION_JSON).buildGet().invoke(byte[].class));
  } catch (WebApplicationException e) {
    return new FailureResult(e.getResponse().getStatus(), e.getMessage());
  }
}
 
Example 7
Source File: ElasticActions.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public Result getResult(WebTarget target) {
  try {
    return new JsonResult(target.path("_cluster/health").request().header(CONTENT_TYPE, APPLICATION_JSON).buildGet().invoke(byte[].class));
  } catch (WebApplicationException e) {
    return new FailureResult(e.getResponse().getStatus(), e.getMessage());
  }
}
 
Example 8
Source File: ElasticActions.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public Result getResult(WebTarget target) {
  try {
    return new JsonResult(target.path(Joiner.on(",").join(indexes)).path("_search_shards").request().header(CONTENT_TYPE, APPLICATION_JSON).buildGet().invoke(byte[].class));
  } catch (WebApplicationException e) {
    return new FailureResult(e.getResponse().getStatus(), e.getMessage());
  }
}
 
Example 9
Source File: ElasticActions.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public Result getResult(WebTarget target) {
  try {
    return new CountResult(parse(target.path(Joiner.on(",").join(indexes)).path(Joiner.on(",").join(types)).path("_count").request().header(CONTENT_TYPE, APPLICATION_JSON).buildGet().invoke(String.class)).get("count").getAsLong());
  } catch (WebApplicationException e) {
    return new FailureResult(e.getResponse().getStatus(), e.getMessage());
  }
}
 
Example 10
Source File: ElasticActions.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public Result getResult(WebTarget target) {
  try {
    return new JsonResult(target.path("_alias").path(alias).request().header("Accept", APPLICATION_JSON).header("content-type", APPLICATION_JSON).buildGet().invoke(byte[].class));
  } catch (WebApplicationException e) {
    return new FailureResult(e.getResponse().getStatus(), e.getMessage());
  }
}
 
Example 11
Source File: GenericExceptionMapper.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
public Response toResponse(WebApplicationException webApplicationException) {
    if (log.isDebugEnabled()) {
        log.debug("Internal server error", webApplicationException);
    }
    // if no specific error message specified, spitting out a generic error message
    String errorMessage = (webApplicationException.getMessage() != null) ?
            webApplicationException.getMessage() : "Internal server error";
    return Response.status(Response.Status.INTERNAL_SERVER_ERROR).type(MediaType.APPLICATION_JSON).
            entity(MockIaasApiUtils.buildMessage(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), errorMessage)).build();
}
 
Example 12
Source File: GenericExceptionMapper.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
public Response toResponse(WebApplicationException e) {
    if (log.isDebugEnabled()) {
        log.debug("Internal server error", e);
    }
    // if no specific error message specified, spitting out a generaic error message
    String errorMessage = (e.getMessage() != null) ? e.getMessage() : "Internal server error";
    return Response.status(Response.Status.INTERNAL_SERVER_ERROR).type(MediaType.APPLICATION_JSON).
            entity(new ResponseMessageBean(ResponseMessageBean.ERROR, errorMessage)).build();
}
 
Example 13
Source File: WebApplicationExceptionMapper.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected String buildErrorMessage(Response r, WebApplicationException ex) {
    StringBuilder sb = new StringBuilder();
    sb.append(ERROR_MESSAGE_START).append(r.getStatus());

    Throwable cause = ex.getCause();
    String message = cause == null ? ex.getMessage() : cause.getMessage();
    if (message == null && cause != null) {
        message = "exception cause class: " + cause.getClass().getName();
    }
    if (message != null) {
        sb.append(", message: ").append(message);
    }
    return sb.toString();
}
 
Example 14
Source File: GenericExceptionMapper.java    From product-private-paas with Apache License 2.0 5 votes vote down vote up
public Response toResponse(WebApplicationException webApplicationException) {
    if (log.isDebugEnabled()) {
        log.debug("Internal erver error", webApplicationException);
    }
    // if no specific error message specified, spitting out a generaic error message
    String errorMessage = (webApplicationException.getMessage() != null) ?
            webApplicationException.getMessage() :
            "Internal server error";
    return Response.status(Response.Status.INTERNAL_SERVER_ERROR).type(MediaType.APPLICATION_JSON).
            entity(Utils.buildMessage(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), errorMessage)).build();
}
 
Example 15
Source File: RemoteResourceException.java    From pnc with Apache License 2.0 4 votes vote down vote up
public RemoteResourceException(ErrorResponse response, WebApplicationException cause) {
    super(response == null ? cause.getMessage() : response.getErrorMessage(), cause);
    this.status = cause.getResponse().getStatus();
    this.response = response;
}
 
Example 16
Source File: ErrorInfo.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
public ErrorInfo(WebApplicationException exception) {
  this.message = exception.getMessage();
  this.status = exception.getResponse().getStatus();
}