Java Code Examples for javax.ws.rs.core.Response#Status

The following examples show how to use javax.ws.rs.core.Response#Status . These examples are extracted from open source projects. 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
@Override
public Response toResponse(GetMandateException exception) {
    Response.Status status;

    MandateError paymentError;

    if (exception.getErrorStatus() == NOT_FOUND.getStatusCode()) {
        paymentError = MandateError.aMandateError(GET_MANDATE_NOT_FOUND_ERROR);
        status = NOT_FOUND;
    } else {
        paymentError = MandateError.aMandateError(GET_MANDATE_CONNECTOR_ERROR);
        status = INTERNAL_SERVER_ERROR;
        LOGGER.error("Connector invalid response was {}.\n Returning http status {} with error body {}", exception.getMessage(), status, paymentError);
    }

    return Response
            .status(status)
            .entity(paymentError)
            .build();
}
 
Example 2
@NotNull
public static Response buildStreamingResponse(@NotNull final JsonFactory factory, @NotNull final Response.Status status, @NotNull final StreamingJsonResponse jsonResponse) {
    return Response.status(status).entity(new StreamingOutput() {
        @Override
        public void write(final OutputStream output) throws IOException, WebApplicationException {
            try (JsonGenerator json = factory.createGenerator(output)) {
                json.setPrettyPrinter(new DefaultPrettyPrinter());
                json.writeStartObject();

                jsonResponse.write(json);

                json.writeEndObject();
            }
        }
    }).type("application/json").build();
}
 
Example 3
Source Project: gitlab4j-api   File: AbstractApi.java    License: MIT License 6 votes vote down vote up
/**
 * Validates response the response from the server against the expected HTTP status and
 * the returned secret token, if either is not correct will throw a GitLabApiException.
 *
 * @param response response
 * @param expected expected response status
 * @return original response if the response status is expected
 * @throws GitLabApiException if HTTP status is not as expected, or the secret token doesn't match
 */
protected Response validate(Response response, Response.Status expected) throws GitLabApiException {

    int responseCode = response.getStatus();
    int expectedResponseCode = expected.getStatusCode();

    if (responseCode != expectedResponseCode) {

        // If the expected code is 200-204 and the response code is 200-204 it is OK.  We do this because
        // GitLab is constantly changing the expected code in the 200 to 204 range
        if (expectedResponseCode > 204 || responseCode > 204 || expectedResponseCode < 200 || responseCode < 200)
            throw new GitLabApiException(response);
    }

    if (!getApiClient().validateSecretToken(response)) {
        throw new GitLabApiException(new NotAuthorizedException("Invalid secret token in response."));
    }

    return (response);
}
 
Example 4
/**
 * Get governance connector.
 *
 * @param categoryId  Governance connector category id.
 * @param connectorId Governance connector id.
 * @return Governance connectors for the give id.
 */
public ConnectorRes getGovernanceConnector(String categoryId, String connectorId) {

    try {
        IdentityGovernanceService identityGovernanceService = GovernanceDataHolder.getIdentityGovernanceService();
        String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
        String connectorName = new String(Base64.getUrlDecoder().decode(connectorId), StandardCharsets.UTF_8);
        ConnectorConfig connectorConfig =
                identityGovernanceService.getConnectorWithConfigs(tenantDomain, connectorName);
        if (connectorConfig == null) {
            throw handleNotFoundError(connectorId, GovernanceConstants.ErrorMessage.ERROR_CODE_CONNECTOR_NOT_FOUND);
        }
        String categoryIdFound = Base64.getUrlEncoder()
                .withoutPadding()
                .encodeToString(connectorConfig.getCategory().getBytes(StandardCharsets.UTF_8));
        if (!categoryId.equals(categoryIdFound)) {
            throw handleNotFoundError(connectorId, GovernanceConstants.ErrorMessage.ERROR_CODE_CONNECTOR_NOT_FOUND);
        }

        return buildConnectorResDTO(connectorConfig);

    } catch (IdentityGovernanceException e) {
        GovernanceConstants.ErrorMessage errorEnum =
                GovernanceConstants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_CONNECTOR;
        Response.Status status = Response.Status.INTERNAL_SERVER_ERROR;
        throw handleException(e, errorEnum, status);
    }
}
 
Example 5
/**
 * Constructor
 *
 * @param status Status code to return
 * @param message Error message to return
 * @param cause Throwable which caused the exception
 */
public NotificationException(
    final Response.Status status, final String message, final Throwable cause) {
  super(cause, status);
  this.code = status.getStatusCode();
  this.status = status;
  this.message = message;
}
 
Example 6
Source Project: keycloak   File: ErrorPageException.java    License: Apache License 2.0 5 votes vote down vote up
public ErrorPageException(KeycloakSession session, AuthenticationSessionModel authSession, Response.Status status, String errorMessage, Object... parameters) {
    this.session = session;
    this.status = status;
    this.errorMessage = errorMessage;
    this.parameters = parameters;
    this.authSession = authSession;
}
 
Example 7
@Test
public void testToResponseStatus500() {
    int code = 500;
    Response.Status status = Response.Status.fromStatusCode(code);
    String message = "Some error message";
    KubernetesClientException kubernetesClientException = new KubernetesClientException(message, new NullPointerException("something's gone bad!"));

    Response response = new DefaultExceptionMapper().toResponse(kubernetesClientException);
    assertEquals(code, response.getStatus());
    assertEquals(status.getReasonPhrase(), response.getStatusInfo().getReasonPhrase());
    assertTrue(response.getEntity() instanceof Status);
    Status responseEntity = (Status) response.getEntity();
    assertEquals("Internal Server Error", responseEntity.getReason());
    assertEquals(message, responseEntity.getMessage());
}
 
Example 8
private APIError handleNotFoundError(String resourceId,
                                     GovernanceConstants.ErrorMessage errorMessage) {

    Response.Status status = Response.Status.NOT_FOUND;
    ErrorResponse errorResponse =
            getErrorBuilder(errorMessage, resourceId).build(LOG, errorMessage.getDescription());

    return new APIError(status, errorResponse);
}
 
Example 9
@Override
public Response toResponse(BuildConflictException e) {
    Response.Status status = Response.Status.CONFLICT;
    logger.debug("A BuildConflict error occurred when processing REST call", e);
    return Response.status(status).entity(new ErrorResponseRest(e)).build();
}
 
Example 10
public ApiException(String errorKey, String message, Response.Status status) {
	super(message);
	this.addError(errorKey, status);
}
 
Example 11
Source Project: onos   File: EntityNotFoundMapper.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Response.Status responseStatus() {
    return Response.Status.NOT_FOUND;
}
 
Example 12
Source Project: tomee   File: ErrorResponse.java    License: Apache License 2.0 4 votes vote down vote up
public Response.Status getStatus() {
    return status;
}
 
Example 13
Source Project: FHIR   File: FHIRRestOperationResponse.java    License: Apache License 2.0 4 votes vote down vote up
public void setStatus(Response.Status status) {
    this.status = status;
}
 
Example 14
public KubernetesHostDoesNotExistException(Response.Status httpStatusCode, String message, Throwable cause) {
    super(message, cause);
    this.message = message;
    this.httpStatusCode = httpStatusCode;
}
 
Example 15
public KubernetesMasterDoesNotExistException(Response.Status httpStatusCode, String message) {
    super(message);
    this.message = message;
    this.httpStatusCode = httpStatusCode;
}
 
Example 16
private static Response newResponse(Response.Status status, Object entity) {
  return Response.status(status)
      .entity(entity)
      .type(APPLICATION_JSON_TYPE)
      .build();
}
 
Example 17
Source Project: carbon-apimgt   File: AuthDTO.java    License: Apache License 2.0 4 votes vote down vote up
public Response.Status getResponseStatus() {
    return responseStatus;
}
 
Example 18
Source Project: agrest   File: CayenneFillResponseStage.java    License: Apache License 2.0 4 votes vote down vote up
public CayenneFillResponseStage(Response.Status status) {
    this.status = status;
}
 
Example 19
public KubernetesClusterDoesNotExistException(Response.Status httpStatusCode, String message, Throwable cause) {
    super(message, cause);
    this.message = message;
    this.httpStatusCode = httpStatusCode;
}
 
Example 20
Source Project: gitlab4j-api   File: ProjectApi.java    License: MIT License 2 votes vote down vote up
/**
 * Star a project.
 *
 * <pre><code>GitLab Endpoint: POST /projects/:id/star</code></pre>
 *
 * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
 * @return a Project instance with the new project info
 * @throws GitLabApiException if any exception occurs
 */
public Project starProject(Object projectIdOrPath) throws GitLabApiException {
    Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.CREATED);
    Response response = post(expectedStatus, (Form) null, "projects", getProjectIdOrPath(projectIdOrPath), "star");
    return (response.readEntity(Project.class));
}