Java Code Examples for org.springframework.http.HttpStatus#value()

The following examples show how to use org.springframework.http.HttpStatus#value() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomBasicErrorController.java    From nimrod with MIT License 6 votes vote down vote up
/**
     * html
     *
     * @param request  HttpServletRequest
     * @param response HttpServletResponse
     * @return ModelAndView
     */
    @RequestMapping(produces = MediaType.TEXT_HTML_VALUE)
    public ModelAndView errorHtml(HttpServletRequest request, HttpServletResponse response) {
        HttpStatus httpStatus = getStatus(request);
        int code = httpStatus.value();
//        Map<String, Object> errorAttributes = getErrorAttributes(request, true);
        Map<String, Object> errorAttributes = getErrorAttributes(request, ErrorAttributeOptions.defaults());
        LOGGER.info("status={},exception={}", code, errorAttributes);
        code = RestControllerAdviceHandler.codeSwitch(code);
        httpStatus = HttpStatus.valueOf(code);
//        Map<String, Object> model = Collections.unmodifiableMap(getErrorAttributes(
//                request, true));
        Map<String, Object> model = Collections.unmodifiableMap(getErrorAttributes(request, ErrorAttributeOptions.defaults()));
        ModelAndView modelAndView = resolveErrorView(request, response, httpStatus, model);
        return (modelAndView == null ? new ModelAndView(code + "", model, httpStatus) : modelAndView);
    }
 
Example 2
Source File: GriffinExceptionResponse.java    From griffin with Apache License 2.0 5 votes vote down vote up
GriffinExceptionResponse(HttpStatus status, GriffinExceptionMessage message,
                         String path) {
    this.status = status.value();
    this.error = status.getReasonPhrase();
    this.code = Integer.toString(message.getCode());
    this.message = message.getMessage();
    this.path = path;
}
 
Example 3
Source File: RestExceptionHandler.java    From metron with Apache License 2.0 5 votes vote down vote up
@ExceptionHandler(RestException.class)
@ResponseBody
ResponseEntity<?> handleControllerException(HttpServletRequest request, Throwable ex) {
  HttpStatus status = getStatus(request);
  LOG.error("Encountered error: " + ex.getMessage(), ex);
  return new ResponseEntity<>(new RestError(status.value(), ex.getMessage(), ExceptionUtils.getRootCauseMessage(ex)), status);
}
 
Example 4
Source File: SpringWebfluxServerRequestTagAdapter.java    From wingtips with Apache License 2.0 5 votes vote down vote up
@Override
public @Nullable Integer getResponseHttpStatus(@Nullable ServerHttpResponse response) {
    if (response == null) {
        return null;
    }

    HttpStatus httpStatus = response.getStatusCode();
    if (httpStatus == null) {
        return null;
    }

    return httpStatus.value();
}
 
Example 5
Source File: RestExceptionHandler.java    From osiam with MIT License 5 votes vote down vote up
private ErrorResponse produceErrorResponse(String message, HttpStatus status,
                                           ErrorMessageTransformer transformer) {
    if (transformer != null) {
        message = transformer.transform(message);
    }
    return new ErrorResponse(status.value(), message);
}
 
Example 6
Source File: ErrorInfo.java    From cloudstreetmarket.com with GNU General Public License v3.0 5 votes vote down vote up
public ErrorInfo(Throwable throwable, String message, String i18nKey, HttpStatus status) {
	this.error = ExceptionUtil.getRootMessage(throwable);
	this.message = message;
	this.date = dateFormat.format(new Date());
	this.status = status.value();
	this.i18nKey = i18nKey;
}
 
Example 7
Source File: HttpStatusCodeException.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private static String getMessage(HttpStatus statusCode, String statusText) {
	if (!StringUtils.hasLength(statusText)) {
		statusText = statusCode.getReasonPhrase();
	}
	return statusCode.value() + " " + statusText;
}
 
Example 8
Source File: V1ExceptionHandler.java    From kaif with Apache License 2.0 4 votes vote down vote up
@Override
protected V1ErrorResponse createErrorResponse(HttpStatus status, String reason) {
  return new V1ErrorResponse(status.value(), reason);
}
 
Example 9
Source File: DefaultServerResponseBuilder.java    From java-technology-stack with MIT License 4 votes vote down vote up
public DefaultServerResponseBuilder(HttpStatus status) {
	Assert.notNull(status, "HttpStatus must not be null");
	this.statusCode = status.value();
}
 
Example 10
Source File: ErrorRequestException.java    From yshopmall with Apache License 2.0 4 votes vote down vote up
public ErrorRequestException(HttpStatus status, String msg){
    super(msg);
    this.status = status.value();
}
 
Example 11
Source File: RichResponseEntity.java    From apollo with Apache License 2.0 4 votes vote down vote up
public static <T> RichResponseEntity<T> error(HttpStatus httpCode, Object message){
  RichResponseEntity<T> richResponseEntity = new RichResponseEntity<>();
  richResponseEntity.message = message;
  richResponseEntity.code = httpCode.value();
  return richResponseEntity;
}
 
Example 12
Source File: XAPIErrorInfo.java    From OpenLRW with Educational Community License v2.0 4 votes vote down vote up
private void getDataFromHttpStatus(final HttpStatus status) {
    this.status = status.value();
    this.reason = status.getReasonPhrase();
}
 
Example 13
Source File: EndpointAdvice.java    From jkes with Apache License 2.0 4 votes vote down vote up
@ExceptionHandler(value = { SearchException.class, RuntimeException.class })
@ResponseBody
ResponseEntity<?> handleException(HttpServletRequest request, Throwable ex) {
    HttpStatus status = getStatus(request);
    return new ResponseEntity<>(new EndpointError(status.value(), ex.getMessage()), status);
}
 
Example 14
Source File: SkException.java    From sk-admin with Apache License 2.0 4 votes vote down vote up
public SkException(HttpStatus status, String msg){
    super(msg);
    this.status = status.value();
}
 
Example 15
Source File: DefaultServerResponseBuilder.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public DefaultServerResponseBuilder(HttpStatus status) {
	Assert.notNull(status, "HttpStatus must not be null");
	this.statusCode = status.value();
}
 
Example 16
Source File: BadRequestException.java    From eladmin with Apache License 2.0 4 votes vote down vote up
public BadRequestException(HttpStatus status,String msg){
    super(msg);
    this.status = status.value();
}
 
Example 17
Source File: HttpResponse.java    From stevia with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public HttpResponse(HttpStatus statusCode, String body, HttpHeaders headers) {
	this.status = statusCode.value();
	this.body = body;
	this.headers = headers;
}
 
Example 18
Source File: BadRequestException.java    From supplierShop with MIT License 4 votes vote down vote up
public BadRequestException(HttpStatus status,String msg){
    super(msg);
    this.status = status.value();
}
 
Example 19
Source File: GlobalExceptionHandler.java    From karate with MIT License 3 votes vote down vote up
/**
 * Adding these properties will make the following code active:
 * spring.mvc.throw-exception-if-no-handler-found=true
 * spring.resources.add-mappings=false
 *
 * @param ex
 * @param headers
 * @param status
 * @param webRequest
 * @return
 */
@Override
protected ResponseEntity<Object> handleNoHandlerFoundException(NoHandlerFoundException ex, HttpHeaders headers, HttpStatus status, WebRequest webRequest) {
    String uriPath = webRequest.getDescription(false).substring(4);
    String message = "The URL you have reached is not in service at this time";
    String method = ((ServletWebRequest) webRequest).getRequest().getMethod();
    ErrorResponse errorResponse = new ErrorResponse(status.value(), uriPath, method, message);
    return new ResponseEntity<>(errorResponse, status);
}
 
Example 20
Source File: HttpStatusCodeException.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Construct instance with an {@link HttpStatus}, status text, content, and
 * a response charset.
 * @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, statusCode.value(), statusText,
			responseHeaders, responseBody, responseCharset);
	this.statusCode = statusCode;
}