本文整理匯總了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();
}
示例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;
}
示例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();
}
示例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);
}
}