Example usage for org.springframework.http HttpStatus valueOf

List of usage examples for org.springframework.http HttpStatus valueOf

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus valueOf.

Prototype

public static HttpStatus valueOf(int statusCode) 

Source Link

Document

Return the enum constant of this type with the specified numeric value.

Usage

From source file:com.tsguild.videogamewebapp.controller.ErrorController.java

public String customError(HttpServletRequest request, HttpServletRequest response, Model model) {
    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    HttpStatus httpStatus = HttpStatus.valueOf((statusCode));

    Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception");
    String exceptionMessage = httpStatus.getReasonPhrase();

    String requestUri = (String) request.getAttribute("javax.servlet.error.request.uri");
    if (requestUri == null) {
        requestUri = "Unknown";
    }//from  ww w .j  a va  2 s  .  com

    String message = MessageFormat.format("{0} returned for {1}: {2}", statusCode, requestUri,
            exceptionMessage);

    model.addAttribute("errorMessage", message);
    return "customError";
}

From source file:com.swcguild.capstoneproject.controller.ErrorController.java

@RequestMapping(value = "/error")
public String customError(HttpServletRequest request, HttpServletResponse response, Model model) {
    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    HttpStatus httpStatus = HttpStatus.valueOf(statusCode);
    Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception");
    String exceptionMessage = null;
    exceptionMessage = httpStatus.getReasonPhrase();
    String requestUri = (String) request.getAttribute("javax.serlet.error.request_uri");
    if (requestUri == null) {
        requestUri = "Unknown";
    }//from ww w. ja  v  a2s  . c  o  m
    String message = MessageFormat.format("{0} returned for {1}: {2}", statusCode, requestUri,
            exceptionMessage);
    model.addAttribute("errorMessage", message);
    return "customError";
}

From source file:org.trustedanalytics.cloud.cc.api.customizations.FeignResponseException.java

public FeignResponseException(int statusCode, String message) {
    super(message);
    this.statusCode = HttpStatus.valueOf(statusCode);
}

From source file:com.swcguild.addressbookarch.controller.ErrorController.java

@RequestMapping(value = "/error")
// #2 - note the use of the Spring Model object rather than a Map
public String customError(HttpServletRequest request, HttpServletResponse response, Model model) {
    // #3 - retrieve some useful information from the request
    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    HttpStatus httpStatus = HttpStatus.valueOf(statusCode);
    Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception");
    String exceptionMessage = null;
    exceptionMessage = httpStatus.getReasonPhrase();
    String requestUri = (String) request.getAttribute("javax.servlet.error.request_uri");
    if (requestUri == null) {
        requestUri = "Unknown";
    }/* ww  w  .  j a v a2s.  co  m*/
    // #4 - format the message for the View
    String message = MessageFormat.format("{0} returned for {1}: {2}", statusCode, requestUri,
            exceptionMessage);
    // #5 - put the message in the model object
    model.addAttribute("errorMessage", message);
    return "customError";
}

From source file:com.swcguild.addressbookmvc.controller.ErrorController.java

@RequestMapping(value = "/error")
// #2 - note the use of the Spring Model object rather than a Map
public String customError(HttpServletRequest request, HttpServletResponse response, Model model) {
    // #3 - retrieve some useful information from the request
    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    HttpStatus httpStatus = HttpStatus.valueOf(statusCode);
    Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception");
    String exceptionMessage = null;
    exceptionMessage = httpStatus.getReasonPhrase();

    String requestUri = (String) request.getAttribute("javax.servlet.error.request_uri");
    if (requestUri == null) {
        requestUri = "Unknown";
    }/*www.  ja v a 2  s.  c o m*/
    // #4 - format the message for the View
    String message = MessageFormat.format("{0} returned for {1}: {2}", statusCode, requestUri,
            exceptionMessage);
    // #5 - put the message in the model object
    model.addAttribute("errorMessage", message);
    return "customError";
}

From source file:com.thesoftwareguild.capstoneblog.controller.ErrorController.java

@RequestMapping(value = "/error")
// #2 - note the use of the Spring Model object rather than a Map
public String customError(HttpServletRequest request, HttpServletResponse response, Model model) {
    // #3 - retrieve some useful information from the request
    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    HttpStatus httpStatus = HttpStatus.valueOf(statusCode);
    Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception");
    String exceptionMessage = null;
    exceptionMessage = httpStatus.getReasonPhrase();

    String requestUri = (String) request.getAttribute("javax.servlet.error.request_uri");
    if (requestUri == null) {
        requestUri = "Unknown";
    }/*w  ww  . j  a  v  a2 s.co  m*/
    // #4 - format the message for the view
    String message = MessageFormat.format("{0} returned for {1}: {2}", statusCode, requestUri,
            exceptionMessage);
    // #5 - put the message in the model object
    model.addAttribute("errorMessage", message);
    return "customError";
}

From source file:com.swcguild.addressbookwebapp.controller.ErrorController.java

@RequestMapping("error")
// #2 - note the use of the Spring Model object rather than a Map
public String customError(HttpServletRequest request, HttpServletResponse response, Model model) {
    // #3 - retrieve some useful information from the request
    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    HttpStatus httpStatus = HttpStatus.valueOf(statusCode);
    Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception");
    String exceptionMessage = null;
    exceptionMessage = httpStatus.getReasonPhrase();

    String requestUri = (String) request.getAttribute("javax.servlet.error.request_uri");
    if (requestUri == null) {
        requestUri = "Unknown";
    }//  ww  w .j  a  v  a2 s .c om

    // #4 - format the message for the View
    String message = MessageFormat.format("{0} returned for {1}: {2}", statusCode, requestUri,
            exceptionMessage);

    // #5 - put the message in the model object
    model.addAttribute("errorMessage", message);
    return "customError";
}

From source file:com.mycompany.capstone.controllers.ErrorController.java

@RequestMapping(value = "/error")
// #2 - note the use of the Spring Model object rather than a Map
public String customError(HttpServletRequest request, HttpServletResponse response, Model model) {
    // #3 - retrieve some useful information from the request
    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    HttpStatus httpStatus = HttpStatus.valueOf(statusCode);
    Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception");
    String exceptionMessage = null;
    exceptionMessage = httpStatus.getReasonPhrase();

    String requestUri = (String) request.getAttribute("javax.servlet.error.request_uri");
    if (requestUri == null) {
        requestUri = "Unknown";
    }/*  w  ww  .  j a  va 2  s  .co m*/
    // #4 - format the message for the view
    //        String message = MessageFormat.format("{0} returned for {1}: {2}",
    //                statusCode, requestUri, exceptionMessage);

    String message = "Page Content is not Available/ You are not Authorized to access";
    // #5 - put the message in the model object
    model.addAttribute("errorMessage", message);
    return "customError";
}

From source file:org.craftercms.engine.exception.HttpStatusCodeException.java

public HttpStatusCodeException(int statusCode) {
    this(HttpStatus.valueOf(statusCode));
}

From source file:io.pivotal.ecosystem.service.connector.HelloErrorDecoder.java

@Override
public Exception decode(String methodKey, Response response) {
    String content = "Error accessing hello-service.";
    try {/*  w  w  w  .j  a  v  a 2 s. c  om*/
        content = Util.toString(response.body().asReader());
    } catch (IOException e) {
        //no content? ignore.
    }
    return new HelloException(content, HttpStatus.valueOf(response.status()));
}