org.springframework.http.HttpStatus.valueOf()

Here are the examples of the java api org.springframework.http.HttpStatus.valueOf() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

101 Examples 7

19 View Source File : ErrorPagesController.java
License : MIT License
Project Creator : zhangyd-c

/**
 * 获取错误编码
 *
 * @param request
 * @return
 */
private HttpStatus getStatus(HttpServletRequest request) {
    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    if (statusCode == null) {
        return HttpStatus.INTERNAL_SERVER_ERROR;
    }
    try {
        return HttpStatus.valueOf(statusCode);
    } catch (Exception ex) {
        log.error("获取当前HttpStatus发生异常", ex);
        return HttpStatus.INTERNAL_SERVER_ERROR;
    }
}

19 View Source File : DefaultErrorWebExceptionHandler.java
License : Apache License 2.0
Project Creator : yuanmabiji

/**
 * Get the HTTP error status information from the error map.
 * @param errorAttributes the current error information
 * @return the error HTTP status
 */
protected HttpStatus getHttpStatus(Map<String, Object> errorAttributes) {
    int statusCode = (int) errorAttributes.get("status");
    return HttpStatus.valueOf(statusCode);
}

19 View Source File : DefaultErrorAttributes.java
License : Apache License 2.0
Project Creator : yuanmabiji

private void addStatus(Map<String, Object> errorAttributes, RequestAttributes requestAttributes) {
    Integer status = getAttribute(requestAttributes, "javax.servlet.error.status_code");
    if (status == null) {
        errorAttributes.put("status", 999);
        errorAttributes.put("error", "None");
        return;
    }
    errorAttributes.put("status", status);
    try {
        errorAttributes.put("error", HttpStatus.valueOf(status).getReasonPhrase());
    } catch (Exception ex) {
        // Unable to obtain a reason
        errorAttributes.put("error", "Http Status " + status);
    }
}

19 View Source File : ErrorExceptionHandler.java
License : MIT License
Project Creator : wligang

/**
 * 获取错误编码
 *
 * @param request
 * @return
 */
private HttpStatus getStatus(HttpServletRequest request) {
    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    if (statusCode == null) {
        return HttpStatus.INTERNAL_SERVER_ERROR;
    }
    try {
        return HttpStatus.valueOf(statusCode);
    } catch (Exception ex) {
        return HttpStatus.INTERNAL_SERVER_ERROR;
    }
}

19 View Source File : JettyXhrTransport.java
License : MIT License
Project Creator : Vip-Augus

protected ResponseEnreplacedy<String> executeRequest(URI url, HttpMethod method, HttpHeaders headers, @Nullable String body) {
    Request httpRequest = this.httpClient.newRequest(url).method(method);
    addHttpHeaders(httpRequest, headers);
    if (body != null) {
        httpRequest.content(new StringContentProvider(body));
    }
    ContentResponse response;
    try {
        response = httpRequest.send();
    } catch (Exception ex) {
        throw new SockJsTransportFailureException("Failed to execute request to " + url, ex);
    }
    HttpStatus status = HttpStatus.valueOf(response.getStatus());
    HttpHeaders responseHeaders = toHttpHeaders(response.getHeaders());
    return (response.getContent() != null ? new ResponseEnreplacedy<>(response.getContentreplacedtring(), responseHeaders, status) : new ResponseEnreplacedy<>(responseHeaders, status));
}

19 View Source File : WebClientResponseException.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Return the HTTP status code value.
 * @throws IllegalArgumentException in case of an unknown HTTP status code
 */
public HttpStatus getStatusCode() {
    return HttpStatus.valueOf(this.statusCode);
}

19 View Source File : StatusResultMatchers.java
License : MIT License
Project Creator : Vip-Augus

/**
 * replacedert the response status code is {@code HttpStatus.REQUEST_HEADER_FIELDS_TOO_LARGE} (431).
 */
public ResultMatcher isRequestHeaderFieldsTooLarge() {
    return matcher(HttpStatus.valueOf(431));
}

19 View Source File : StatusResultMatchers.java
License : MIT License
Project Creator : Vip-Augus

/**
 * replacedert the response status code is {@code HttpStatus.PERMANENT_REDIRECT} (308).
 */
public ResultMatcher isPermanentRedirect() {
    return matcher(HttpStatus.valueOf(308));
}

19 View Source File : StatusResultMatchers.java
License : MIT License
Project Creator : Vip-Augus

/**
 * replacedert the response status code is {@code HttpStatus.TOO_MANY_REQUESTS} (429).
 */
public ResultMatcher isTooManyRequests() {
    return matcher(HttpStatus.valueOf(429));
}

19 View Source File : StatusResultMatchers.java
License : MIT License
Project Creator : Vip-Augus

/**
 * replacedert the response status code is {@code HttpStatus.BANDWIDTH_LIMIT_EXCEEDED} (509).
 */
public ResultMatcher isBandwidthLimitExceeded() {
    return matcher(HttpStatus.valueOf(509));
}

19 View Source File : StatusResultMatchers.java
License : MIT License
Project Creator : Vip-Augus

/**
 * replacedert the response status code is {@code HttpStatus.PRECONDITION_REQUIRED} (428).
 */
public ResultMatcher isPreconditionRequired() {
    return matcher(HttpStatus.valueOf(428));
}

19 View Source File : StatusResultMatchers.java
License : MIT License
Project Creator : Vip-Augus

/**
 * replacedert the response status code is {@code HttpStatus.NETWORK_AUTHENTICATION_REQUIRED} (511).
 */
public ResultMatcher isNetworkAuthenticationRequired() {
    return matcher(HttpStatus.valueOf(511));
}

19 View Source File : StatusResultMatchers.java
License : MIT License
Project Creator : Vip-Augus

/**
 * replacedert the response status code is {@code HttpStatus.I_AM_A_TEAPOT} (418).
 */
public ResultMatcher isIAmATeapot() {
    return matcher(HttpStatus.valueOf(418));
}

19 View Source File : StatusResultMatchers.java
License : MIT License
Project Creator : Vip-Augus

/**
 * replacedert the response status code is {@code HttpStatus.CHECKPOINT} (103).
 */
public ResultMatcher isCheckpoint() {
    return matcher(HttpStatus.valueOf(103));
}

19 View Source File : StatusResultMatchers.java
License : MIT License
Project Creator : Vip-Augus

private HttpStatus.Series getHttpStatusSeries(MvcResult result) {
    int statusValue = result.getResponse().getStatus();
    HttpStatus status = HttpStatus.valueOf(statusValue);
    return status.series();
}

19 View Source File : StatusResultMatchers.java
License : MIT License
Project Creator : Vip-Augus

/**
 * replacedert the response status code is {@code HttpStatus.UNAVAILABLE_FOR_LEGAL_REASONS} (451).
 * @since 4.3
 */
public ResultMatcher isUnavailableForLegalReasons() {
    return matcher(HttpStatus.valueOf(451));
}

19 View Source File : GenericResponseService.java
License : Apache License 2.0
Project Creator : springdoc

/**
 * Sets description.
 *
 * @param httpCode the http code
 * @param apiResponse the api response
 */
public static void setDescription(String httpCode, ApiResponse apiResponse) {
    try {
        HttpStatus httpStatus = HttpStatus.valueOf(Integer.parseInt(httpCode));
        apiResponse.setDescription(httpStatus.getReasonPhrase());
    } catch (IllegalArgumentException e) {
        apiResponse.setDescription(DEFAULT_DESCRIPTION);
    }
}

19 View Source File : GrayClientHttpRequestIntercptor.java
License : Apache License 2.0
Project Creator : SpringCloud

protected ClientHttpResponse mockResultConvert(Object message) {
    HttpResponseMessage httpResponseMessage = HttpResponseMessage.toHttpResponseMessage(message);
    HttpStatus httpStatus = HttpStatus.valueOf(httpResponseMessage.getStatusCode());
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.putAll(httpResponseMessage.getHeaders().toMap());
    byte[] bodyBytes = httpResponseMessage.getBodyBytes();
    if (Objects.isNull(bodyBytes)) {
        bodyBytes = new byte[0];
    }
    InputStream bodyStream = new ByteArrayInputStream(bodyBytes);
    return new SimpleClientHttpResponse(httpStatus, httpHeaders, bodyStream);
}

19 View Source File : AWSLambdaUtils.java
License : Apache License 2.0
Project Creator : spring-cloud

@SuppressWarnings({ "rawtypes", "unchecked" })
public static byte[] generateOutput(Message requestMessage, Message<byte[]> responseMessage, ObjectMapper objectMapper) {
    if (!objectMapper.isEnabled(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES)) {
        configureObjectMapper(objectMapper);
    }
    byte[] responseBytes = responseMessage == null ? "\"OK\"".getBytes() : responseMessage.getPayload();
    if (requestMessage.getHeaders().containsKey("httpMethod") || isPayloadAnApiGatewayRequest(requestMessage.getPayload())) {
        // API Gateway
        Map<String, Object> response = new HashMap<String, Object>();
        response.put("isBase64Encoded", false);
        AtomicReference<MessageHeaders> headers = new AtomicReference<>();
        int statusCode = HttpStatus.OK.value();
        if (responseMessage != null) {
            headers.set(responseMessage.getHeaders());
            statusCode = headers.get().containsKey("statusCode") ? (int) headers.get().get("statusCode") : HttpStatus.OK.value();
        }
        response.put("statusCode", statusCode);
        if (isRequestKinesis(requestMessage)) {
            HttpStatus httpStatus = HttpStatus.valueOf(statusCode);
            response.put("statusDescription", httpStatus.toString());
        }
        String body = responseMessage == null ? "\"OK\"" : new String(responseMessage.getPayload(), StandardCharsets.UTF_8).replaceAll("\\\"", "\"");
        response.put("body", body);
        if (responseMessage != null) {
            Map<String, String> responseHeaders = new HashMap<>();
            headers.get().keySet().forEach(key -> responseHeaders.put(key, headers.get().get(key).toString()));
            response.put("headers", responseHeaders);
        }
        try {
            responseBytes = objectMapper.writeValueAsBytes(response);
        } catch (Exception e) {
            throw new IllegalStateException("Failed to serialize AWS Lambda output", e);
        }
    }
    return responseBytes;
}

19 View Source File : MockClientHttpResponse.java
License : Apache License 2.0
Project Creator : SourceHot

@Override
public HttpStatus getStatusCode() {
    return HttpStatus.valueOf(this.status);
}

19 View Source File : StatusResultMatchers.java
License : Apache License 2.0
Project Creator : SourceHot

/**
 * replacedert the response status code is {@code HttpStatus.TOO_EARLY} (425).
 * @since 5.2
 */
public ResultMatcher isTooEarly() {
    return matcher(HttpStatus.valueOf(425));
}

19 View Source File : AppErrorController.java
License : Apache License 2.0
Project Creator : rn-yx

/**
 * 获取状态码
 *
 * @param request request
 * @return HttpStatus
 */
private HttpStatus getStatus(HttpServletRequest request) {
    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    if (statusCode == null) {
        return HttpStatus.INTERNAL_SERVER_ERROR;
    } else {
        try {
            return HttpStatus.valueOf(statusCode);
        } catch (Exception e) {
            return HttpStatus.INTERNAL_SERVER_ERROR;
        }
    }
}

19 View Source File : ApiError.java
License : MIT License
Project Creator : ParveenBhadooOfficial

public HttpStatus getStatus() {
    return HttpStatus.valueOf(statusCode);
}

19 View Source File : ErrorControllerAdvice.java
License : Apache License 2.0
Project Creator : oneops

/**
 * Returns the http status from request.
 */
private HttpStatus getStatus(HttpServletRequest req) {
    Integer statusCode = (Integer) req.getAttribute("javax.servlet.error.status_code");
    if (statusCode == null) {
        return INTERNAL_SERVER_ERROR;
    }
    return HttpStatus.valueOf(statusCode);
}

19 View Source File : WechatResponseEntity.java
License : Apache License 2.0
Project Creator : NotFound403

/**
 * Is 1 xx informational boolean.
 *
 * @return the boolean
 */
public boolean is1xxInformational() {
    if (log.isDebugEnabled()) {
        log.debug("wechat httpStatus {}", this.httpStatus);
    }
    return HttpStatus.valueOf(this.httpStatus).is1xxInformational();
}

19 View Source File : WechatResponseEntity.java
License : Apache License 2.0
Project Creator : NotFound403

/**
 * Is 3xx redirection boolean.
 *
 * @return the boolean
 */
public boolean is3xxRedirection() {
    if (log.isDebugEnabled()) {
        log.debug("wechat httpStatus {}", this.httpStatus);
    }
    return HttpStatus.valueOf(this.httpStatus).is3xxRedirection();
}

19 View Source File : WechatResponseEntity.java
License : Apache License 2.0
Project Creator : NotFound403

/**
 * Is 2xx successful boolean.
 *
 * @return the boolean
 */
public boolean is2xxSuccessful() {
    if (log.isDebugEnabled()) {
        log.debug("wechat httpStatus {}", this.httpStatus);
    }
    return HttpStatus.valueOf(this.httpStatus).is2xxSuccessful();
}

19 View Source File : WechatResponseEntity.java
License : Apache License 2.0
Project Creator : NotFound403

/**
 * Is 4xx client error boolean.
 *
 * @return the boolean
 */
public boolean is4xxClientError() {
    if (log.isDebugEnabled()) {
        log.debug("wechat httpStatus {}", this.httpStatus);
    }
    return HttpStatus.valueOf(this.httpStatus).is4xxClientError();
}

19 View Source File : WechatResponseEntity.java
License : Apache License 2.0
Project Creator : NotFound403

/**
 * Is 5xx server error boolean.
 *
 * @return the boolean
 */
public boolean is5xxServerError() {
    if (log.isDebugEnabled()) {
        log.debug("wechat httpStatus {}", this.httpStatus);
    }
    return HttpStatus.valueOf(this.httpStatus).is5xxServerError();
}

19 View Source File : AuditLoggingFilter.java
License : Apache License 2.0
Project Creator : Nike-Inc

private boolean isResponseSuccessful(int statusCode) {
    HttpStatus status = HttpStatus.valueOf(statusCode);
    return status.is2xxSuccessful();
}

19 View Source File : LoggingWebInterceptor.java
License : Apache License 2.0
Project Creator : minbox-projects

/**
 * Check whether to filter the request of the specified {@link HttpStatus}
 *
 * @param httpStatusCode {@link HttpServletResponse#getStatus()}
 * @return
 */
private boolean checkIgnoreHttpStatus(int httpStatusCode) {
    HttpStatus httpStatus = HttpStatus.valueOf(httpStatusCode);
    List<HttpStatus> ignoreHttpStatus = factoryBean.getIgnoreHttpStatus();
    return ignoreHttpStatus.contains(httpStatus);
}

19 View Source File : WxErrorController.java
License : MIT License
Project Creator : liuweijw

private HttpStatus getStatus(HttpServletRequest request) {
    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    if (statusCode != null) {
        return HttpStatus.valueOf(statusCode);
    }
    return HttpStatus.INTERNAL_SERVER_ERROR;
}

19 View Source File : JettyXhrTransport.java
License : Apache License 2.0
Project Creator : langtianya

protected ResponseEnreplacedy<String> executeRequest(URI url, HttpMethod method, HttpHeaders headers, String body) {
    Request httpRequest = this.httpClient.newRequest(url).method(method);
    addHttpHeaders(httpRequest, headers);
    if (body != null) {
        httpRequest.content(new StringContentProvider(body));
    }
    ContentResponse response;
    try {
        response = httpRequest.send();
    } catch (Exception ex) {
        throw new SockJsTransportFailureException("Failed to execute request to " + url, ex);
    }
    HttpStatus status = HttpStatus.valueOf(response.getStatus());
    HttpHeaders responseHeaders = toHttpHeaders(response.getHeaders());
    return (response.getContent() != null ? new ResponseEnreplacedy<String>(response.getContentreplacedtring(), responseHeaders, status) : new ResponseEnreplacedy<String>(responseHeaders, status));
}

19 View Source File : AppExceptionHandlerController.java
License : BSD 2-Clause "Simplified" License
Project Creator : kangta123

private ResponseEnreplacedy<Object> createResponseEnreplacedy(String code, int httpStatus, String requestUri, String message) {
    Error error = new Error(code, requestUri, message);
    String json = JsonUtils.object2Json(error);
    return ResponseEnreplacedy.status(HttpStatus.valueOf(httpStatus)).body(json);
}

19 View Source File : ScheduledJesOrganisationListImporter.java
License : MIT License
Project Creator : InnovateUKGitHub

private static HttpStatus extractHttpCodeFromExceptionIfPossible(IOException e) {
    Matcher httpStatusCodeMatcher = Pattern.compile("^Server returned HTTP response code: (\\d+)").matcher(e.getMessage());
    if (httpStatusCodeMatcher.find()) {
        int httpNumericStatusCode = Integer.parseInt(httpStatusCodeMatcher.group(1));
        return HttpStatus.valueOf(httpNumericStatusCode);
    }
    return BAD_REQUEST;
}

19 View Source File : DefaultErrorWebExceptionHandler.java
License : Apache License 2.0
Project Creator : hello-shf

/**
 * Get the HTTP error status information from the error map.
 *
 * @param errorAttributes the current error information
 * @return the error HTTP status
 */
protected HttpStatus getHttpStatus(Map<String, Object> errorAttributes) {
    int statusCode = (int) errorAttributes.get("status");
    return HttpStatus.valueOf(statusCode);
}

19 View Source File : ErrorPagesController.java
License : MIT License
Project Creator : fujiangwei

/**
 * 获取错误编码
 *
 * @param request
 * @return
 */
private HttpStatus getStatus(HttpServletRequest request) {
    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    if (statusCode == null) {
        return HttpStatus.INTERNAL_SERVER_ERROR;
    }
    try {
        return HttpStatus.valueOf(statusCode);
    } catch (Exception ex) {
        LOG.error("获取当前HttpStatus发生异常", ex);
        return HttpStatus.INTERNAL_SERVER_ERROR;
    }
}

19 View Source File : ExceptionAdvice.java
License : MIT License
Project Creator : dolyw

/**
 * 获取状态码
 * @param request
 * @return
 */
private HttpStatus getStatus(HttpServletRequest request) {
    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    if (statusCode == null) {
        return HttpStatus.INTERNAL_SERVER_ERROR;
    }
    return HttpStatus.valueOf(statusCode);
}

19 View Source File : PageErrorController.java
License : GNU General Public License v2.0
Project Creator : CipherChina

private HttpStatus getStatus(HttpServletRequest request) {
    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    if (statusCode != null) {
        try {
            return HttpStatus.valueOf(statusCode);
        } catch (Exception ex) {
            logger.error("Enter PageErrorController.getStatus but failed, statusCode=[{}] ..==", statusCode);
            logger.error(ex.getMessage(), ex);
        }
    }
    return HttpStatus.INTERNAL_SERVER_ERROR;
}

19 View Source File : CustomErrorController.java
License : MIT License
Project Creator : Bitcoin-com

public HttpStatus getStatus(HttpServletRequest request) {
    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    if (statusCode == null) {
        return HttpStatus.INTERNAL_SERVER_ERROR;
    } else {
        try {
            return HttpStatus.valueOf(statusCode);
        } catch (Exception var4) {
            return HttpStatus.INTERNAL_SERVER_ERROR;
        }
    }
}

19 View Source File : LocationHeaderRewritingFilter.java
License : Apache License 2.0
Project Creator : apache

@Override
public boolean shouldFilter() {
    RequestContext ctx = RequestContext.getCurrentContext();
    int statusCode = ctx.getResponseStatusCode();
    return HttpStatus.valueOf(statusCode).is3xxRedirection();
}

19 View Source File : MetricStoreImpl.java
License : Apache License 2.0
Project Creator : apache

private ResponseEnreplacedy<?> getResponseEnreplacedyFromResponse(Response response) throws IOException {
    String body = EnreplacedyUtils.toString(response.getEnreplacedy());
    HttpStatus status = HttpStatus.valueOf(response.getStatusLine().getStatusCode());
    return new ResponseEnreplacedy<>(body, responseHeaders, status);
}

19 View Source File : FeignExceptionHandler.java
License : Apache License 2.0
Project Creator : adorsys

public static TppMessage getFailureMessage(FeignException e, MessageErrorCode errorCode) {
    logger.error(e.getMessage(), e);
    if (e.getCause() instanceof ConnectException) {
        throw new ResourceAccessException(e.getMessage());
    }
    switch(HttpStatus.valueOf(e.status())) {
        case INTERNAL_SERVER_ERROR:
            return new TppMessage(MessageErrorCode.INTERNAL_SERVER_ERROR);
        case UNAUTHORIZED:
            return new TppMessage(MessageErrorCode.PSU_CREDENTIALS_INVALID);
        default:
            return new TppMessage(errorCode);
    }
}

18 View Source File : BaseGlobalExceptionHandler.java
License : MIT License
Project Creator : zidoshare

protected ResponseEnreplacedy<Object> handleCommonBusinessException(CommonBusinessException e, WebRequest request, HttpServletResponse response) {
    logger.warn("business error:" + e.getMessage());
    response.setStatus(e.getHttpStatus());
    HttpStatus status = HttpStatus.valueOf(e.getHttpStatus());
    HttpHeaders headers = new HttpHeaders();
    return handleExceptionInternal(e, factory.error(e.getCode(), e.getMsg(), null), headers, status, request);
}

18 View Source File : ErrorPageController.java
License : Apache License 2.0
Project Creator : ZHENFENG13

private HttpStatus getStatus(HttpServletRequest request) {
    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    if (statusCode != null) {
        try {
            return HttpStatus.valueOf(statusCode);
        } catch (Exception ex) {
        }
    }
    return HttpStatus.INTERNAL_SERVER_ERROR;
}

18 View Source File : AbstractErrorController.java
License : Apache License 2.0
Project Creator : yuanmabiji

protected HttpStatus getStatus(HttpServletRequest request) {
    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    if (statusCode == null) {
        return HttpStatus.INTERNAL_SERVER_ERROR;
    }
    try {
        return HttpStatus.valueOf(statusCode);
    } catch (Exception ex) {
        return HttpStatus.INTERNAL_SERVER_ERROR;
    }
}

18 View Source File : WebMvcTags.java
License : Apache License 2.0
Project Creator : yuanmabiji

private static HttpStatus extractStatus(HttpServletResponse response) {
    try {
        return HttpStatus.valueOf(response.getStatus());
    } catch (IllegalArgumentException ex) {
        return null;
    }
}

18 View Source File : ExceptionController.java
License : MIT License
Project Creator : yidao620c

private HttpStatus getStatus(HttpServletRequest request) {
    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    if (statusCode == null) {
        return HttpStatus.INTERNAL_SERVER_ERROR;
    }
    return HttpStatus.valueOf(statusCode);
}

18 View Source File : ReactorClientHttpResponse.java
License : MIT License
Project Creator : Vip-Augus

@Override
public HttpStatus getStatusCode() {
    return HttpStatus.valueOf(getRawStatusCode());
}

18 View Source File : AbstractClientHttpResponse.java
License : MIT License
Project Creator : Vip-Augus

@Override
public HttpStatus getStatusCode() throws IOException {
    return HttpStatus.valueOf(getRawStatusCode());
}

See More Examples