Example usage for org.springframework.http HttpStatus getReasonPhrase

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

Introduction

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

Prototype

public String getReasonPhrase() 

Source Link

Document

Return the reason phrase of this status code.

Usage

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";
    }/*  w  w  w .j  a  va2 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";
    }//www  .ja v a  2 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.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";
    }/*from www.  j  av a 2  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.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";
    }//from  w  w  w  . j av a 2 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";
    }//  ww w  .ja  va 2 s  .  c  o  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:com.somerledsolutions.pa11y.client.Application.java

private void runTask(CommandLine cl) {

    if (optionsValidator.validateRunOptions(cl)) {
        HttpStatus httpStatus = client.runTask(cl.getOptionValue(OptionsBuilder.TID_OPT),
                cl.getOptionValue(OptionsBuilder.URL_OPT));
        System.out.println(httpStatus.getReasonPhrase());
    }//from ww  w  .  j av a 2 s.c  om
}

From source file:it.reply.orchestrator.exception.GlobalControllerExceptionHandler.java

/**
 * Convert the exception into {@link Error} object.
 * //w  w  w  .  j a  va 2 s . c om
 * @param ex
 *          the exception to be handled
 * @param headers
 *          {@code HttpHeaders} instance
 * @param status
 *          {@code HttpStatus} instance
 * @return the error response
 */
private ResponseEntity<Object> handleResponse(Exception ex, HttpHeaders headers, HttpStatus status) {
    Error error = new Error().withCode(status.value()).withTitle(status.getReasonPhrase())
            .withMessage(ex.getMessage());

    return new ResponseEntity<Object>(error, headers, status);

}

From source file:com.evolveum.midpoint.web.page.error.PageError.java

public PageError(Integer code, Exception ex) {
    this.code = code;

    if (ex == null) {
        // Log this on debug level, this is normal during application initialization
        LOGGER.debug("Creating error page for code {}, no exception", code);
    } else {/*from  www .  ja  v  a 2s. c o m*/
        LOGGER.warn("Creating error page for code {}, exception {}: {}", ex.getClass().getName(),
                ex.getMessage(), ex);
    }

    Label codeLabel = new Label(ID_CODE, code);
    add(codeLabel);

    String errorLabel = "Unexpected error";
    if (code != null) {
        HttpStatus httpStatus = HttpStatus.valueOf(code);
        if (httpStatus != null) {
            errorLabel = httpStatus.getReasonPhrase();
        }
    }
    Label labelLabel = new Label(ID_LABEL, errorLabel);
    add(labelLabel);

    if (ex != null) {
        exClass = ex.getClass().getName();
        exMessage = ex.getMessage();
    }

    final IModel<String> message = new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            if (exClass == null) {
                return null;
            }

            SimpleDateFormat df = new SimpleDateFormat();
            return df.format(new Date()) + "\t" + exClass + ": " + exMessage;
        }
    };

    Label label = new Label(ID_MESSAGE, message);
    label.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return StringUtils.isNotEmpty(message.getObject());
        }
    });
    add(label);

    AjaxButton back = new AjaxButton(ID_BACK, createStringResource("PageError.button.back")) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            if (WebMiscUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_DASHBOARD_URL,
                    AuthorizationConstants.AUTZ_UI_HOME_ALL_URL)) {
                setResponsePage(PageDashboard.class);
            } else {
                setResponsePage(PageSelfDashboard.class);
            }
        }
    };
    add(back);
}

From source file:com.github.lynxdb.server.api.http.handlers.EpError.java

@RequestMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity error(HttpServletRequest request, HttpServletResponse response) {

    HttpStatus status = HttpStatus.valueOf((int) request.getAttribute("javax.servlet.error.status_code"));

    ObjectMapper mapper = new ObjectMapper();
    ObjectNode error = mapper.createObjectNode();
    error.put("code", status.value());
    error.put("message", status.getReasonPhrase());
    error.put("details", getErrorAttributes(request, true).get("message").toString());
    if (getErrorAttributes(request, true).get("exception") != null) {
        error.put("trace", getErrorAttributes(request, true).get("exception").toString() + "\n"
                + getErrorAttributes(request, true).get("trace").toString());
    }//from  w  ww  . j a v  a2s. c  o m

    return ResponseEntity.status(status).body(error.toString());
}

From source file:se.skltp.cooperation.web.rest.exception.DefaultExceptionHandler.java

private void buildErrorMessage(HttpServletRequest request, Exception e, HttpStatus status,
        ProblemDetail error) {//from   w w w  .  ja v  a 2  s.  c  om
    try {
        error.setType(new URI("http://httpstatus.es/" + status.value()));
    } catch (URISyntaxException e1) {
        log.error("Unable to set error type", e);
    }
    error.setTitle(status.getReasonPhrase());
    error.setStatus(status.value());
    error.setDetail(e.getMessage());
    String url = request.getRequestURL().toString();
    if (request.getQueryString() != null) {
        url = url + "?" + request.getQueryString();
    }
    error.setInstance(url);
}