Package org.springframework.http

Examples of org.springframework.http.HttpStatus


  private ModelAndView getModelAndView(Method handlerMethod, Object returnValue, ServletWebRequest webRequest)
      throws Exception {

    ResponseStatus responseStatusAnn = AnnotationUtils.findAnnotation(handlerMethod, ResponseStatus.class);
    if (responseStatusAnn != null) {
      HttpStatus responseStatus = responseStatusAnn.value();
      String reason = responseStatusAnn.reason();
      if (!StringUtils.hasText(reason)) {
        webRequest.getResponse().setStatus(responseStatus.value());
      }
      else {
        webRequest.getResponse().sendError(responseStatus.value(), reason);
      }
    }

    if (returnValue != null && AnnotationUtils.findAnnotation(handlerMethod, ResponseBody.class) != null) {
      return handleResponseBody(returnValue, webRequest);
View Full Code Here


  private String getExceptionMessage(Throwable throwable, Integer statusCode) {
    if (throwable != null) {
      return Throwables.getRootCause(throwable).getMessage();
    }
    HttpStatus httpStatus = HttpStatus.valueOf(statusCode);
    return httpStatus.getReasonPhrase();
  }
View Full Code Here

    * Will process normal response with/without a task location header
    */
   private TaskRead processResponse(ResponseEntity<String> response,
         HttpMethod verb, PrettyOutput... prettyOutput) throws Exception {

      HttpStatus responseStatus = response.getStatusCode();
      if (responseStatus == HttpStatus.ACCEPTED) {//Accepted with task in the location header
         //get task uri from response to trace progress
         HttpHeaders headers = response.getHeaders();
         URI taskURI = headers.getLocation();
         String[] taskURIs = taskURI.toString().split("/");
View Full Code Here

      messageConverters.add(new MappingJacksonHttpMessageConverter());
      delegate = new HttpMessageConverterExtractor<BddErrorMessage>(BddErrorMessage.class, messageConverters);
   }

   public boolean hasError(ClientHttpResponse response) throws IOException {
      HttpStatus statusCode = response.getStatusCode();
      if (statusCode.series() == Series.CLIENT_ERROR || statusCode.series() == Series.SERVER_ERROR) {
         return true;
      } else {
         return false;
      }
   }
View Full Code Here

   public void handleError(ClientHttpResponse response) throws IOException {
      MediaType contentType = response.getHeaders().getContentType();
      if (contentType.equals(MediaType.APPLICATION_JSON)) {
         throw new CliRestException(delegate.extractData(response).getMessage());
      } else {
         HttpStatus statusCode = response.getStatusCode();
         String errorMsg = "";
         if (statusCode == HttpStatus.UNAUTHORIZED) {
            errorMsg = Constants.CONNECT_SESSION_TIME_OUT;
         } else if (statusCode == HttpStatus.INTERNAL_SERVER_ERROR) {
            errorMsg =
                  "vCenter Server connect command failed: "
                        + getVCConnectErrorMsg(response.getBody());
         } else {
            errorMsg = statusCode.getReasonPhrase();
         }

         throw new CliRestException(statusCode, errorMsg);
      }
   }
View Full Code Here

    ResponseEntity<String> response;
    try {
      restTemplate.setErrorHandler(new ResponseErrorHandler() {
        @Override
        public boolean hasError(ClientHttpResponse response) throws IOException {
          HttpStatus status = response.getStatusCode();
          return (status == HttpStatus.BAD_GATEWAY || status == HttpStatus.GATEWAY_TIMEOUT);
        }

        @Override
        public void handleError(ClientHttpResponse response) throws IOException {
View Full Code Here

    RestTemplate restTemplate = new RestTemplate();

    restTemplate.setErrorHandler(new ResponseErrorHandler() {
      @Override
      public boolean hasError(ClientHttpResponse response) throws IOException {
        HttpStatus status = response.getStatusCode();
        return (status == HttpStatus.BAD_GATEWAY || status == HttpStatus.GATEWAY_TIMEOUT || status == HttpStatus.INTERNAL_SERVER_ERROR);
      }

      @Override
      public void handleError(ClientHttpResponse response) throws IOException {
View Full Code Here

  /**
   * 处理异常,对于客户端自己的异常,抛出HystrixBadRequestException,不算入短路统计内。
   */
  protected Exception handleException(HttpStatusCodeException e) {
    HttpStatus status = e.getStatusCode();
    if (status.equals(HttpStatus.BAD_REQUEST)) {
      throw new HystrixBadRequestException(e.getResponseBodyAsString(), e);
    }
    throw e;
  }
View Full Code Here

   * 一类是Command内部抛出异常(返回500).
   * 一类是Hystrix已进入保护状态(返回503).
   */
  @ExceptionHandler(value = { HystrixRuntimeException.class })
  public final ResponseEntity<?> handleException(HystrixRuntimeException e, WebRequest request) {
    HttpStatus status = HttpStatus.SERVICE_UNAVAILABLE;
    String message = e.getMessage();

    FailureType type = e.getFailureType();

    // 对命令抛出的异常进行特殊处理
View Full Code Here

      finally {
        stopWatch.stop();
        int status = getStatus(response);
        Object bestMatchingPattern = request
            .getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
        HttpStatus httpStatus = HttpStatus.OK;
        try {
          httpStatus = HttpStatus.valueOf(status);
        }
        catch (Exception ex) {
          // not convertible
        }
        if (bestMatchingPattern != null) {
          suffix = fixSpecialCharacters(bestMatchingPattern.toString());
        }
        else if (httpStatus.is4xxClientError()) {
          suffix = UNKNOWN_PATH_SUFFIX;
        }
        String gaugeKey = getKey("response" + suffix);
        MetricFilterAutoConfiguration.this.gaugeService.submit(gaugeKey,
            stopWatch.getTotalTimeMillis());
View Full Code Here

TOP

Related Classes of org.springframework.http.HttpStatus

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.