本文整理汇总了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);
}
}