Example usage for javax.servlet.http HttpServletResponse setStatus

List of usage examples for javax.servlet.http HttpServletResponse setStatus

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse setStatus.

Prototype

public void setStatus(int sc);

Source Link

Document

Sets the status code for this response.

Usage

From source file:dtu.ds.warnme.ws.rest.json.HelloWorldRestService.java

@ExceptionHandler(Exception.class)
public @ResponseBody String handleException(Exception ex, HttpServletRequest request,
        HttpServletResponse response) throws IOException {
    response.setHeader("Content-Type", "application/json");
    response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    return ex.getMessage();
}

From source file:ee.pri.rl.blog.web.servlet.FileDownloadServlet.java

private void sendNotModified(String calculatedTag, HttpServletResponse resp) {
    resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
    resp.setHeader("ETag", calculatedTag);
}

From source file:com.hp.autonomy.frontend.find.hod.web.SsoController.java

@RequestMapping(value = SSO_PAGE, method = RequestMethod.GET, params = HOD_SSO_ERROR_PARAM)
public ModelAndView ssoError(final HttpServletRequest request, final HttpServletResponse response)
        throws HodErrorException {
    response.setStatus(HttpStatus.UNAUTHORIZED.value());
    return hodErrorController.authenticationErrorPage(request, response);
}

From source file:com.hp.autonomy.frontend.find.hod.view.HodViewController.java

@ExceptionHandler
public ModelAndView hodAuthenticationFailedException(final HodAuthenticationFailedException e,
        final HttpServletRequest request, final HttpServletResponse response) {
    response.reset();//from w w  w  .  j  a v a2  s .  co m
    response.setStatus(HttpServletResponse.SC_FORBIDDEN);

    log.error("HodAuthenticationFailedException thrown while viewing document", e);

    return controllerUtils.buildErrorModelAndView(new ErrorModelAndViewInfo.Builder().setRequest(request)
            .setMainMessageCode(HOD_ERROR_MESSAGE_CODE_MAIN)
            .setSubMessageCode(HOD_ERROR_MESSAGE_CODE_TOKEN_EXPIRED)
            .setStatusCode(HttpServletResponse.SC_FORBIDDEN).setAuthError(true).build());
}

From source file:dtu.ds.warnme.ws.rest.json.AbstractRestWS.java

@ExceptionHandler(Exception.class)
@ResponseBody/*from  ww w . j a va  2  s.c  o m*/
String handleOtherExceptions(Exception ex, HttpServletRequest request, HttpServletResponse response) {
    log.error("Internal server error!", ex);
    response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    String responseBody = getMessage(ex, "exceptions.internalServerError", request.getLocale());
    RestUtils.decorateResponseHeaderWithMD5(response, responseBody);
    RestUtils.decorateResponseHeaderForJsonContentType(response);
    return responseBody;
}

From source file:cn.org.once.cstack.config.UserAjaxAuthenticationSuccessHandler.java

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {

    logger.info("SC_OK");
    response.setStatus(HttpServletResponse.SC_OK);
}

From source file:com.lennonjesus.auth.security.handler.AjaxLogoutSuccessHandler.java

@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {
    logger.debug("Logout Successful");
    response.setStatus(HttpServletResponse.SC_OK);
}

From source file:com.threewks.thundr.proxy.ProxyImpl.java

protected void sendResponse(Response proxiedResponse, HttpServletResponse outboundResponse) throws IOException {
    outboundResponse.setStatus(proxiedResponse.status());

    Map<String, String> headers = proxiedResponse.headers();
    for (String name : headers.keySet()) {
        outboundResponse.addHeader(name, headers.get(name));
    }/*ww w .  ja  v  a2 s.  c  o m*/

    byte[] body = proxiedResponse.body();
    if (body != null) {
        OutputStream os = null;
        try {
            os = outboundResponse.getOutputStream();
            os.write(body);
        } finally {
            if (os != null) {
                os.flush();
                os.close();
            }
        }
    }
}

From source file:com.oneops.cms.ws.rest.AbstractRestController.java

protected void sendError(HttpServletResponse response, int code, CmsError ex) throws IOException {
    ErrorResponse error = new ErrorResponse(code, ex);
    response.setStatus(error.getCode());
    response.getWriter().write(gson.toJson(error));
    logger.error(ex);//  w  ww  .  ja  v a 2s  .  c om
}