Examples of HttpStatus


Examples of org.springframework.http.HttpStatus

   * @param response the response to check for a message body
   * @return {@code true} if the response has a body, {@code false} otherwise
   * @throws IOException in case of I/O errors
   */
  protected boolean hasMessageBody(ClientHttpResponse response) throws IOException {
    HttpStatus responseStatus = response.getStatusCode();
    if (responseStatus == HttpStatus.NO_CONTENT || responseStatus == HttpStatus.NOT_MODIFIED) {
      return false;
    }
    long contentLength = response.getHeaders().getContentLength();
    return contentLength != 0;
View Full Code Here

Examples of org.springframework.http.HttpStatus

   * is {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR}, a {@link HttpServerErrorException}
   * if it is {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR},
   * and a {@link RestClientException} in other cases.
   */
  public void handleError(ClientHttpResponse response) throws IOException {
    HttpStatus statusCode = response.getStatusCode();
    MediaType contentType = response.getHeaders().getContentType();
    Charset charset = contentType != null ? contentType.getCharSet() : null;
    byte[] body = getResponseBody(response);
    switch (statusCode.series()) {
      case CLIENT_ERROR:
        throw new HttpClientErrorException(statusCode, response.getStatusText(), body, charset);
      case SERVER_ERROR:
        throw new HttpServerErrorException(statusCode, response.getStatusText(), body, charset);
      default:
View Full Code Here

Examples of org.springframework.http.HttpStatus

        // Send status code 302 by default.
        response.sendRedirect(encodedRedirectURL);
      }
    }
    else {
      HttpStatus statusCode = getHttp11StatusCode(request, response, targetUrl);
      response.setStatus(statusCode.value());
      response.setHeader("Location", encodedRedirectURL);
    }
  }
View Full Code Here

Examples of org.springframework.http.HttpStatus

      HttpServletRequest request, HttpServletResponse response, String targetUrl) {

    if (this.statusCode != null) {
      return this.statusCode;
    }
    HttpStatus attributeStatusCode = (HttpStatus) request.getAttribute(View.RESPONSE_STATUS_ATTRIBUTE);
    if (attributeStatusCode != null) {
      return attributeStatusCode;
    }
    return HttpStatus.SEE_OTHER;
  }
View Full Code Here

Examples of org.springframework.http.HttpStatus

  public final ResponseEntity<Object> handleException(Exception ex, WebRequest request) {

    HttpHeaders headers = new HttpHeaders();

    if (ex instanceof NoSuchRequestHandlingMethodException) {
      HttpStatus status = HttpStatus.NOT_FOUND;
      return handleNoSuchRequestHandlingMethod((NoSuchRequestHandlingMethodException) ex, headers, status, request);
    }
    else if (ex instanceof HttpRequestMethodNotSupportedException) {
      HttpStatus status = HttpStatus.METHOD_NOT_ALLOWED;
      return handleHttpRequestMethodNotSupported((HttpRequestMethodNotSupportedException) ex, headers, status, request);
    }
    else if (ex instanceof HttpMediaTypeNotSupportedException) {
      HttpStatus status = HttpStatus.UNSUPPORTED_MEDIA_TYPE;
      return handleHttpMediaTypeNotSupported((HttpMediaTypeNotSupportedException) ex, headers, status, request);
    }
    else if (ex instanceof HttpMediaTypeNotAcceptableException) {
      HttpStatus status = HttpStatus.NOT_ACCEPTABLE;
      return handleHttpMediaTypeNotAcceptable((HttpMediaTypeNotAcceptableException) ex, headers, status, request);
    }
    else if (ex instanceof MissingServletRequestParameterException) {
      HttpStatus status = HttpStatus.BAD_REQUEST;
      return handleMissingServletRequestParameter((MissingServletRequestParameterException) ex, headers, status, request);
    }
    else if (ex instanceof ServletRequestBindingException) {
      HttpStatus status = HttpStatus.BAD_REQUEST;
      return handleServletRequestBindingException((ServletRequestBindingException) ex, headers, status, request);
    }
    else if (ex instanceof ConversionNotSupportedException) {
      HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR;
      return handleConversionNotSupported((ConversionNotSupportedException) ex, headers, status, request);
    }
    else if (ex instanceof TypeMismatchException) {
      HttpStatus status = HttpStatus.BAD_REQUEST;
      return handleTypeMismatch((TypeMismatchException) ex, headers, status, request);
    }
    else if (ex instanceof HttpMessageNotReadableException) {
      HttpStatus status = HttpStatus.BAD_REQUEST;
      return handleHttpMessageNotReadable((HttpMessageNotReadableException) ex, headers, status, request);
    }
    else if (ex instanceof HttpMessageNotWritableException) {
      HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR;
      return handleHttpMessageNotWritable((HttpMessageNotWritableException) ex, headers, status, request);
    }
    else if (ex instanceof MethodArgumentNotValidException) {
      HttpStatus status = HttpStatus.BAD_REQUEST;
      return handleMethodArgumentNotValid((MethodArgumentNotValidException) ex, headers, status, request);
    }
    else if (ex instanceof MissingServletRequestPartException) {
      HttpStatus status = HttpStatus.BAD_REQUEST;
      return handleMissingServletRequestPart((MissingServletRequestPartException) ex, headers, status, request);
    }
    else if (ex instanceof BindException) {
      HttpStatus status = HttpStatus.BAD_REQUEST;
      return handleBindException((BindException) ex, headers, status, request);
    }
    else {
      logger.warn("Unknown exception type: " + ex.getClass().getName());
      HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR;
      return handleExceptionInternal(ex, null, headers, status, request);
    }
  }
View Full Code Here

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

Examples of org.springframework.http.HttpStatus

    public ModelAndView getModelAndView(Method handlerMethod, Class handlerType, Object returnValue,
        ExtendedModelMap implicitModel, 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);
        }

        // to be picked up by the RedirectView
        webRequest.getRequest().setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, responseStatus);
View Full Code Here

Examples of org.springframework.http.HttpStatus

    public ModelAndView getModelAndView(Method handlerMethod, Class handlerType, Object returnValue,
        ExtendedModelMap implicitModel, 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);
        }

        // to be picked up by the RedirectView
        webRequest.getRequest().setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, responseStatus);
View Full Code Here

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

Examples of org.tmatesoft.svn.core.internal.io.dav.http.HTTPStatus

                }
                getDescription().append(cdata);
            }
        } else if (element == DAVElement.STATUS) {
            try {
                HTTPStatus status = HTTPStatus.createHTTPStatus(cdata.toString());
                if (parent != DAVElement.PROPSTAT) {
                    myResponseContainsError |= status.getCodeClass() != 2;
                } else {
                    myPropstatContainsError = status.getCodeClass() != 2;
                }
            } catch (ParseException e) {
                SVNErrorManager.error(SVNErrorMessage.create(SVNErrorCode.RA_DAV_REQUEST_FAILED,
                        "The response contains a non-conforming HTTP status line"), SVNLogType.NETWORK);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.