javax.ws.rs.core.Response#Status()源码实例Demo

下面列出了javax.ws.rs.core.Response#Status() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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();
}
 
源代码2 项目: cassandra-mesos-deprecated   文件: JaxRsUtils.java
@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();
}
 
源代码3 项目: gitlab4j-api   文件: AbstractApi.java
/**
 * 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);
}
 
/**
 * 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);
    }
}
 
源代码5 项目: notification   文件: NotificationException.java
/**
 * 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;
}
 
源代码6 项目: keycloak   文件: ErrorPageException.java
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;
}
 
源代码7 项目: enmasse   文件: DefaultExceptionMapperTest.java
@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());
}
 
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);
}
 
源代码9 项目: pnc   文件: BuildConflictExceptionMapper.java
@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();
}
 
源代码10 项目: entando-core   文件: ApiException.java
public ApiException(String errorKey, String message, Response.Status status) {
	super(message);
	this.addError(errorKey, status);
}
 
源代码11 项目: onos   文件: EntityNotFoundMapper.java
@Override
protected Response.Status responseStatus() {
    return Response.Status.NOT_FOUND;
}
 
源代码12 项目: tomee   文件: ErrorResponse.java
public Response.Status getStatus() {
    return status;
}
 
源代码13 项目: FHIR   文件: FHIRRestOperationResponse.java
public void setStatus(Response.Status status) {
    this.status = status;
}
 
public KubernetesHostDoesNotExistException(Response.Status httpStatusCode, String message, Throwable cause) {
    super(message, cause);
    this.message = message;
    this.httpStatusCode = httpStatusCode;
}
 
public KubernetesMasterDoesNotExistException(Response.Status httpStatusCode, String message) {
    super(message);
    this.message = message;
    this.httpStatusCode = httpStatusCode;
}
 
源代码16 项目: dremio-oss   文件: GenericExceptionMapper.java
private static Response newResponse(Response.Status status, Object entity) {
  return Response.status(status)
      .entity(entity)
      .type(APPLICATION_JSON_TYPE)
      .build();
}
 
源代码17 项目: carbon-apimgt   文件: AuthDTO.java
public Response.Status getResponseStatus() {
    return responseStatus;
}
 
源代码18 项目: agrest   文件: CayenneFillResponseStage.java
public CayenneFillResponseStage(Response.Status status) {
    this.status = status;
}
 
public KubernetesClusterDoesNotExistException(Response.Status httpStatusCode, String message, Throwable cause) {
    super(message, cause);
    this.message = message;
    this.httpStatusCode = httpStatusCode;
}
 
源代码20 项目: gitlab4j-api   文件: ProjectApi.java
/**
 * 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));
}