當前位置: 首頁>>代碼示例>>Java>>正文


Java StatusType.getStatusCode方法代碼示例

本文整理匯總了Java中javax.ws.rs.core.Response.StatusType.getStatusCode方法的典型用法代碼示例。如果您正苦於以下問題:Java StatusType.getStatusCode方法的具體用法?Java StatusType.getStatusCode怎麽用?Java StatusType.getStatusCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.ws.rs.core.Response.StatusType的用法示例。


在下文中一共展示了StatusType.getStatusCode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toResponse

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
@Override
public Response toResponse(@NonNull Exception exception) {
	ResponseBuilder builder;
	StatusType statusInfo;
	if (exception instanceof WebApplicationException) {
		Response response = ((WebApplicationException) exception).getResponse();
		builder = Response.fromResponse(response);
		statusInfo = response.getStatusInfo();
	} else {
		builder = Response.serverError();
		statusInfo = Status.INTERNAL_SERVER_ERROR;
	}

	SimpleExceptionJson simpleExceptionJson = new SimpleExceptionJson(statusInfo.getReasonPhrase(),
			statusInfo.getStatusCode(), exception.getMessage());
	builder.entity(simpleExceptionJson);
	builder.type("application/problem+json");

	if (statusInfo.getFamily() == Family.CLIENT_ERROR) {
		log.debug("Got client Exception", exception);
	} else {
		log.error("Sending error to client", exception);
	}

	return builder.build();
}
 
開發者ID:Mercateo,項目名稱:rest-jersey-utils,代碼行數:27,代碼來源:RFCExceptionMapper.java

示例2: status

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
static void status(final StatusType statusInfo, final Family expectedFamily,
                   final Status... expectedStatuses) {
    requireNonNull(statusInfo, "null statusInfo");
    final Family actualFamily = statusInfo.getFamily();
    final int statusCode = statusInfo.getStatusCode();
    final String reasonPhrase = statusInfo.getReasonPhrase();
    logger.debug("-> response.status: {} {}", statusCode, reasonPhrase);
    if (expectedFamily != null) {
        assertEquals(actualFamily, expectedFamily);
    }
    if (expectedStatuses != null && expectedStatuses.length > 0) {
        assertTrue(
                Stream.of(expectedStatuses).map(Status::getStatusCode)
                .filter(v -> v == statusCode)
                .findAny()
                .isPresent()
        );
    }
}
 
開發者ID:jinahya,項目名稱:kt-ucloud-storage-client,代碼行數:20,代碼來源:StorageClientWsRsITs.java

示例3: insertAppointment

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
public URI insertAppointment(AppointmentType resource) {
    Response response = client.target(connection)
            .path("/rest/api/appointments")
            .request()
            // overrides previous headers: Content-Type, Content-Language, Content-Encoding
            .post(xml(resource));

    response.close();

    if (response.getStatus() >= HTTP_BAD_REQUEST) {
        StatusType stat = response.getStatusInfo();
        throw new IllegalStateException(stat.getStatusCode() + "/" + stat.getFamily().name()
                + " " + stat.getReasonPhrase());
    }

    return response.getLocation();
}
 
開發者ID:Tibor17,項目名稱:javaee-samples,代碼行數:18,代碼來源:RESTfulClientLevel3Service.java

示例4: updateIssueWithoutCharset

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
public void updateIssueWithoutCharset(int issueId, ResourcesType resource) {
    Response response = client.target(connection)
            .path("/rest/api/2.0-alpha1/issues/{id}")
            .resolveTemplate("id", issueId)
            .request()
            // overrides previous headers: Content-Type, Content-Language, Content-Encoding
            .put(xml(resource));

    response.close();

    if (response.getStatus() >= HTTP_BAD_REQUEST) {
        StatusType stat = response.getStatusInfo();
        throw new IllegalStateException(stat.getStatusCode() + "/" + stat.getFamily().name()
                + " " + stat.getReasonPhrase());
    }
}
 
開發者ID:Tibor17,項目名稱:javaee-samples,代碼行數:17,代碼來源:RestClientService.java

示例5: updateIssue

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
public void updateIssue(int issueId, ResourcesType resource) {
    Response response = client.target(connection)
            .path("/rest/api/2.0-alpha1/issues/{id}")
            .resolveTemplate("id", issueId)
            .request()
                    // overrides previous headers: Content-Type, Content-Language, Content-Encoding
            .put(entity(resource, MediaType.valueOf(APPLICATION_XML + "; charset=UTF-8")));

    response.close();

    if (response.getStatus() >= HTTP_BAD_REQUEST) {
        StatusType stat = response.getStatusInfo();
        throw new IllegalStateException(stat.getStatusCode() + "/" + stat.getFamily().name()
                + " " + stat.getReasonPhrase());
    }
}
 
開發者ID:Tibor17,項目名稱:javaee-samples,代碼行數:17,代碼來源:RestClientService.java

示例6: updateIssueAsJson

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
public void updateIssueAsJson(int issueId, ResourcesType resource) {
    Response response = client.target(connection)
            .path("/rest/api/2.0-alpha1/issues/{id}")
            .resolveTemplate("id", issueId)
            .request()
            // overrides previous headers: Content-Type, Content-Language, Content-Encoding
            .put(entity(resource, MediaType.valueOf(APPLICATION_JSON)));

    response.close();

    if (response.getStatus() >= HTTP_BAD_REQUEST) {
        StatusType stat = response.getStatusInfo();
        throw new IllegalStateException(stat.getStatusCode() + "/" + stat.getFamily().name()
                + " " + stat.getReasonPhrase());
    }
}
 
開發者ID:Tibor17,項目名稱:javaee-samples,代碼行數:17,代碼來源:RestClientService.java

示例7: updateIssueIfLast

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
public boolean updateIssueIfLast(int issueId, ResourcesType resource, String md5) {
    MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>();
    headers.putSingle("If-Match", md5);

    Response response = client.target(connection)
            .path("/rest/api/2.0-alpha1/issues/{id}")
            .resolveTemplate("id", issueId)
            .request()
            .headers(headers)
            // overrides previous headers: Content-Type, Content-Language, Content-Encoding
            .put(entity(resource, MediaType.valueOf(APPLICATION_XML + "; charset=UTF-8")));

    response.close();

    if (response.getStatus() != HTTP_OK && response.getStatus() != HTTP_NOT_MODIFIED) {
        StatusType stat = response.getStatusInfo();
        throw new IllegalStateException(stat.getStatusCode() + "/" + stat.getFamily().name()
                + " " + stat.getReasonPhrase());
    }

    return response.getStatus() == HTTP_OK;
}
 
開發者ID:Tibor17,項目名稱:javaee-samples,代碼行數:23,代碼來源:RestClientService.java

示例8: addStatusType

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
public void addStatusType(StatusType status) {
  if (statusMap.containsKey(status.getStatusCode())) {
    throw new IllegalStateException("repeated status code: " + status.getStatusCode());
  }

  statusMap.put(status.getStatusCode(), status);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:8,代碼來源:HttpStatusManager.java

示例9: setStatusInfo

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
public void setStatusInfo(final StatusType statusInfo) {
    if (statusInfo != null) {
        statusCode = statusInfo.getStatusCode();
        family = statusInfo.getFamily();
        reasonPhrase = statusInfo.getReasonPhrase();
    } else {
        setStatusInfo(Status.OK);
    }
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:10,代碼來源:MinijaxStatusInfo.java

示例10: assertSuccesfulAuthentication

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
@Override
protected int assertSuccesfulAuthentication(final Response response) {
    final StatusType statusInfo = response.getStatusInfo();
    final Family family = statusInfo.getFamily();
    final int statusCode = statusInfo.getStatusCode();
    final String reasonPhrase = statusInfo.getReasonPhrase();
    assertEquals(family, SUCCESSFUL,
                 "status: " + statusCode + " " + reasonPhrase);
    return statusCode;
}
 
開發者ID:jinahya,項目名稱:kt-ucloud-storage-client,代碼行數:11,代碼來源:StorageClientWsRsIT.java

示例11: getSuccessfulResponse

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
/**
 * Get the return value for a successful response.
 * @param response
 * @param returnType
 * @param status
 * @return
 */
@SuppressWarnings("unchecked")
protected <T> T getSuccessfulResponse(Response response, Class<T> returnType, StatusType status) {
	if ( returnType == null || status.getStatusCode() == Status.NO_CONTENT.getStatusCode() ) {
		return null;
	} else if ( returnType.isAssignableFrom(response.getClass()) ) {
		return (T)response;
	} else {
		return response.readEntity(returnType);
	}
}
 
開發者ID:fod-dev,項目名稱:FoDBugTrackerUtility,代碼行數:18,代碼來源:RestConnection.java

示例12: writeResponse

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
@Override
public void writeResponse(StatusType statusType, Map<String, List<String>> headers,
		OutputStream entityOutputStream) throws IOException {
	String body = ((ByteArrayOutputStream) entityOutputStream).toString(StandardCharsets.UTF_8.name());
	response = new DefaultServiceResponse(body, headers, statusType.getStatusCode(),
			statusType.getReasonPhrase());
}
 
開發者ID:bbilger,項目名稱:jrestless,代碼行數:8,代碼來源:ServiceRequestHandler.java

示例13: GatewayResponse

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
public GatewayResponse(@Nullable String body, @Nonnull Map<String, String> headers,
		@Nonnull StatusType statusType, boolean base64Encoded) {
	requireNonNull(headers);
	requireNonNull(statusType);
	this.statusCode = statusType.getStatusCode();
	this.body = body;
	this.headers = Collections.unmodifiableMap(new HashMap<>(headers));
	this.base64Encoded = base64Encoded;
}
 
開發者ID:bbilger,項目名稱:jrestless,代碼行數:10,代碼來源:GatewayResponse.java

示例14: createApiException

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
/**
 * Create an {@link AuthleteApiException} instance.
 */
private AuthleteApiException createApiException(Throwable cause, Response response)
{
    // Error message.
    String message = cause.getMessage();

    if (response == null)
    {
        // Create an exception without HTTP response information.
        return new AuthleteApiException(message, cause);
    }

    // Status code and status message.
    int statusCode = 0;
    String statusMessage = null;

    // Get the status information.
    StatusType type = response.getStatusInfo();
    if (type != null)
    {
        statusCode    = type.getStatusCode();
        statusMessage = type.getReasonPhrase();
    }

    // Response body.
    String responseBody = null;

    // If the response has response body.
    if (hasEntity(response))
    {
        // Get the response body.
        responseBody = extractResponseBody(response);
    }

    // Response headers.
    Map<String, List<String>> headers = response.getStringHeaders();

    // Create an exception with HTTP response information.
    return new AuthleteApiException(message, cause, statusCode, statusMessage, responseBody, headers);
}
 
開發者ID:authlete,項目名稱:authlete-java-jaxrs,代碼行數:43,代碼來源:AuthleteApiImpl.java

示例15: checkAndHandleResponse

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
private void checkAndHandleResponse(String content, StatusType status) {
    if (status.getStatusCode() == Status.OK.getStatusCode()) {
        return;
    }

    final String errorMessage = extractErrorMessage(content, status);

    if (status.getStatusCode() == Status.BAD_REQUEST.getStatusCode()) {
        throw new ConnectionInitializationException(errorMessage);
    } else if (status.getStatusCode() == Status.UNAUTHORIZED.getStatusCode()) {
        throw new UnauthorizedException(errorMessage);
    } else {
        throw new ConnectionInitializationException(errorMessage);
    }
}
 
開發者ID:osiam,項目名稱:addon-administration,代碼行數:16,代碼來源:ExtensionsService.java


注:本文中的javax.ws.rs.core.Response.StatusType.getStatusCode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。