本文整理汇总了Java中org.springframework.http.HttpStatus.value方法的典型用法代码示例。如果您正苦于以下问题:Java HttpStatus.value方法的具体用法?Java HttpStatus.value怎么用?Java HttpStatus.value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.http.HttpStatus
的用法示例。
在下文中一共展示了HttpStatus.value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processHttpServerError
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
@ExceptionHandler(HttpServerErrorException.class)
@ResponseBody
public ResponseEntity<ErrorVM> processHttpServerError(HttpServerErrorException ex) {
BodyBuilder builder;
ErrorVM fieldErrorVM;
HttpStatus responseStatus = ex.getStatusCode();
if (responseStatus != null) {
builder = ResponseEntity.status(responseStatus.value());
fieldErrorVM = new ErrorVM(ERROR_PREFIX + responseStatus.value(), translate(ERROR_PREFIX
+ responseStatus.value()));
} else {
builder = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR);
fieldErrorVM = new ErrorVM(ErrorConstants.ERR_INTERNAL_SERVER_ERROR,
translate(ErrorConstants.ERR_INTERNAL_SERVER_ERROR));
}
return builder.body(fieldErrorVM);
}
示例2: handleMessageException
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
/**
* Handles MessageException exception.
*
* @param exception the MessageException instance
* @param request the WebRequest caused exception
* @return the ResponseEntity object instance
*/
@ExceptionHandler(MessageException.class)
protected ResponseEntity<Object> handleMessageException(MessageException exception, WebRequest request) {
HttpStatus status;
switch (exception.getErrorType()) {
case NOT_FOUND:
status = HttpStatus.NOT_FOUND;
break;
case DATA_INVALID:
case PARAMETERS_INVALID:
status = HttpStatus.BAD_REQUEST;
break;
case ALREADY_EXISTS:
status = HttpStatus.CONFLICT;
break;
case AUTH_FAILED:
status = HttpStatus.UNAUTHORIZED;
break;
case OPERATION_TIMED_OUT:
case INTERNAL_ERROR:
default:
status = HttpStatus.INTERNAL_SERVER_ERROR;
break;
}
MessageError error = new MessageError(request.getHeader(CORRELATION_ID), exception.getTimestamp(),
status.value(), status.getReasonPhrase(),
exception.getMessage(), exception.getClass().getSimpleName());
return super.handleExceptionInternal(exception, error, new HttpHeaders(), status, request);
}
示例3: handleExceptionInternal
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected ResponseEntity<Object> handleExceptionInternal(Exception exception, Object body, HttpHeaders headers,
HttpStatus status, WebRequest request) {
MessageError error = new MessageError(request.getHeader(CORRELATION_ID), System.currentTimeMillis(),
status.value(), status.getReasonPhrase(),
exception.getMessage(), exception.getClass().getSimpleName());
return super.handleExceptionInternal(exception, error, headers, status, request);
}
示例4: errorPage
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
@RequestMapping(produces = "text/html")
public String errorPage(HttpServletRequest request, Model model) {
String message, error;
HttpStatus status = getStatus(request);
RequestAttributes requestAttributes = new ServletRequestAttributes(request);
Map<String, Object> attributeMap = this.errorAttributes.getErrorAttributes(requestAttributes, false);
if (attributeMap != null) {
message = (String) attributeMap.get("message");
error = (String) attributeMap.get("error");
model.addAttribute("header", error);
model.addAttribute("message", message);
}
if (status.is4xxClientError()){
if(status.value() == 404) {
model.addAttribute("header", "Sorry but we couldn't find this page");
model.addAttribute("message", "This page you are looking for does not exist.");
} else if (status.value() == 403) {
model.addAttribute("header", "Access denied");
model.addAttribute("message", "Full authentication is required to access this resource.");
}
} else if (status.value() == 500){
model.addAttribute("header", "Internal Server Error");
model.addAttribute("message",
"If the problem persists feel free to create an issue in Github.");
}
model.addAttribute("number", status.value());
return "errorPage";
}
示例5: HttpStatusCodeException
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
/**
* Construct a new instance of {@code HttpStatusCodeException} based on an
* {@link HttpStatus}, status text, and response body content.
* @param statusCode the status code
* @param statusText the status text
* @param responseHeaders the response headers, may be {@code null}
* @param responseBody the response body content, may be {@code null}
* @param responseCharset the response body charset, may be {@code null}
* @since 3.1.2
*/
protected HttpStatusCodeException(HttpStatus statusCode, String statusText,
HttpHeaders responseHeaders, byte[] responseBody, Charset responseCharset) {
super(statusCode.value() + " " + statusText);
this.statusCode = statusCode;
this.statusText = statusText;
this.responseHeaders = responseHeaders;
this.responseBody = responseBody != null ? responseBody : new byte[0];
this.responseCharset = responseCharset != null ? responseCharset.name() : DEFAULT_CHARSET;
}
示例6: handleResponseException
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
@ExceptionHandler(SearchResponseException.class)
@ResponseBody
ResponseEntity<?> handleResponseException(SearchResponseException ex) {
int statusCode = ex.getResponseException().getResponse().getStatusLine().getStatusCode();
HttpStatus status = HttpStatus.valueOf(statusCode);
return new ResponseEntity<>(new EndpointError(status.value(), ex.getErrorMessage()), status);
}
示例7: create
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
public static ResultMap create(String message, HttpStatus status) {
return new ResultMap(status.value(), message, status.getReasonPhrase());
}
示例8: ErrorMessage
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
public ErrorMessage(String error, HttpStatus status, String details) {
this(error, status.value(), details);
}
示例9: handleGenericException
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
private ExceptionDTO handleGenericException(Throwable e, HttpStatus status) {
return new ExceptionDTO(status.value(), status.getReasonPhrase(), e.getMessage());
}
示例10: handleAnotherException
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
@ExceptionHandler(AnotherException.class)
@ResponseBody
ResponseEntity<?> handleAnotherException(HttpServletRequest request, Throwable ex) {
HttpStatus status = getStatus(request);
return new ResponseEntity<>(new AnotherExceptionErrorMessage(status.value(), ex.getMessage()), status);
}
示例11: RestErrorResponse
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
protected RestErrorResponse(HttpStatus status, String detailMessage) {
statusCode = status.value();
reasonPhrase = status.getReasonPhrase();
this.detailMessage = detailMessage;
}
示例12: JsonResult
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
public JsonResult(HttpStatus code, String message, Object data) {
this.code = code.value();
this.message = message;
this.data = data;
}
示例13: createLog
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
private String createLog(HttpServletRequest request, HttpStatus status, String code, String message) {
return request.getMethod() + " " + request.getRequestURI() + " " + status.value() + " | " + code + " | " + message;
}
示例14: of
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
public static ErrorResponse of(HttpStatus httpStatus, String message) {
return new ErrorResponse(httpStatus.getReasonPhrase(), message, httpStatus.value());
}
示例15: ApiError
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
public ApiError(HttpStatus httpStatus, String message, String description) {
statusCode = httpStatus.value();
meaning = httpStatus.getReasonPhrase();
this.message = message;
this.description = description;
}