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


Java Status.fromStatusCode方法代碼示例

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


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

示例1: apply

import javax.ws.rs.core.Response.Status; //導入方法依賴的package包/類
@Override
public Response apply(@NonNull ContainerRequestContext context) {
  String statusCode = context.getUriInfo().getPathParameters().getFirst(
      ErrorModule.SERVLET_ERROR_STATUS_CODE_PARAMETER);

  if (statusCode == null) {
    throw new IllegalArgumentException(String.format("Path parameter '%s' is required.",
        ErrorModule.SERVLET_ERROR_STATUS_CODE_PARAMETER));
  }

  Status responseStatus = Status.fromStatusCode(Integer.parseInt(statusCode));

  if (responseStatus == null) {
    throw new IllegalArgumentException(String.format("Status code '%s' is unknown.", statusCode));
  }

  return Response.status(responseStatus).type(MediaType.TEXT_PLAIN_TYPE).entity(
      responseStatus.getReasonPhrase()).build();
}
 
開發者ID:dotwebstack,項目名稱:dotwebstack-framework,代碼行數:20,代碼來源:ServletErrorHandler.java

示例2: convertExceptionToJsonResponse

import javax.ws.rs.core.Response.Status; //導入方法依賴的package包/類
public static ErrorResponse convertExceptionToJsonResponse(int status, WebApplicationException webAppException)
{
	final ErrorResponse err = new ErrorResponse();
	err.setCode(status);
	String msg = webAppException.getMessage();
	// if we happen to be using an 'unofficial' HTTP code, just repeat the
	// exception message
	String statusCodeErr = Status.fromStatusCode(status) != null ? Status.fromStatusCode(status).getReasonPhrase()
		: msg;
	err.setError(statusCodeErr);
	if( webAppException.getCause() != null )
	{
		msg = webAppException.getCause().getMessage();
	}
	err.setErrorDescription(msg);
	return err;
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:18,代碼來源:RestEasyExceptionMapper.java

示例3: buildAuthenticationErrorResponse

import javax.ws.rs.core.Response.Status; //導入方法依賴的package包/類
/**
 * Build an authentication error response
 * @param schemes Optional allowed authentication schemes
 * @param errorCode Optional error code
 * @param errorDescription Optional error description
 * @param statusCode HTTP status code
 * @param realmName Optional realm name
 * @return Authentication error response
 */
public static Response buildAuthenticationErrorResponse(String[] schemes, String errorCode, String errorDescription,
		int statusCode, String realmName) {

	// status
	Status status = Status.UNAUTHORIZED;
	if (statusCode > 0) {
		Status errorStatus = Status.fromStatusCode(statusCode);
		if (errorStatus != null) {
			status = errorStatus;
		}
	}

	// response
	ResponseBuilder responseBuilder = Response.status(status);

	if (schemes != null && schemes.length > 0) {
		for (String scheme : schemes) {
			responseBuilder.header(HttpHeaders.WWW_AUTHENTICATE,
					buildAuthenticationErrorHeader(scheme, errorCode, errorDescription, realmName));
		}
	}

	// response
	return responseBuilder.header(HttpHeaders.CACHE_CONTROL, "no-store").header(HttpHeaders.PRAGMA, "no-cache")
			.build();
}
 
開發者ID:holon-platform,項目名稱:holon-jaxrs,代碼行數:36,代碼來源:ResponseUtils.java

示例4: setStatusInfo

import javax.ws.rs.core.Response.Status; //導入方法依賴的package包/類
public void setStatusInfo(final int statusCode) {
    final Status status = Status.fromStatusCode(statusCode);
    if (status != null) {
        setStatusInfo(status);
    } else {
        setStatusCode(statusCode);
        setFamily(Status.Family.OTHER);
        setReasonPhrase(null);
    }
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:11,代碼來源:MinijaxStatusInfo.java


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