Package org.springframework.http

Examples of org.springframework.http.HttpStatus


      response = httpRequest.send();
    }
    catch (Exception ex) {
      throw new SockJsTransportFailureException("Failed to execute request to " + url, null, ex);
    }
    HttpStatus status = HttpStatus.valueOf(response.getStatus());
    HttpHeaders responseHeaders = toHttpHeaders(response.getHeaders());
    return (response.getContent() != null ?
      new ResponseEntity<String>(response.getContentAsString(), responseHeaders, status) :
      new ResponseEntity<String>(responseHeaders, status));
  }
View Full Code Here



    @Override
    public void onBegin(Response response) {
      if (response.getStatus() != 200) {
        HttpStatus status = HttpStatus.valueOf(response.getStatus());
        response.abort(new HttpServerErrorException(status, "Unexpected XHR receive status"));
      }
    }
View Full Code Here

  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 if (ex instanceof NoHandlerFoundException) {
      HttpStatus status = HttpStatus.NOT_FOUND;
      return handleNoHandlerFoundException((NoHandlerFoundException) 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

    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

    // Create view controller bean definition
    RootBeanDefinition controller = new RootBeanDefinition(ParameterizableViewController.class);
    controller.setSource(source);

    HttpStatus statusCode = null;
    if (element.hasAttribute("status-code")) {
      int statusValue = Integer.valueOf(element.getAttribute("status-code"));
      statusCode = HttpStatus.valueOf(statusValue);
    }
View Full Code Here

        // 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

      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

  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

  public void varArgsTemplateVariables() throws Exception {
    given(requestFactory.createRequest(new URI("http://example.com/hotels/42/bookings/21"), HttpMethod.GET))
        .willReturn(request);
    given(request.execute()).willReturn(response);
    given(errorHandler.hasError(response)).willReturn(false);
    HttpStatus status = HttpStatus.OK;
    given(response.getStatusCode()).willReturn(status);
    given(response.getStatusText()).willReturn(status.getReasonPhrase());

    template.execute("http://example.com/hotels/{hotel}/bookings/{booking}", HttpMethod.GET, null, null, "42",
        "21");

    verify(response).close();
View Full Code Here

  public void varArgsNullTemplateVariable() throws Exception {
    given(requestFactory.createRequest(new URI("http://example.com/-foo"), HttpMethod.GET))
        .willReturn(request);
    given(request.execute()).willReturn(response);
    given(errorHandler.hasError(response)).willReturn(false);
    HttpStatus status = HttpStatus.OK;
    given(response.getStatusCode()).willReturn(status);
    given(response.getStatusText()).willReturn(status.getReasonPhrase());

    template.execute("http://example.com/{first}-{last}", HttpMethod.GET, null, null, null, "foo");

    verify(response).close();
  }
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.