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:org.eurekastreams.server.service.servlets.GetThemeCssServlet.java

/**
 * Pump out an HTTP error.//from   www . ja  va  2 s .  c om
 * 
 * @param statusCode
 *            the status code.
 * @param response
 *            the response.
 */
private void httpError(final int statusCode, final HttpServletResponse response) {
    try {
        response.setStatus(statusCode);
        response.setContentType("text/html");
        PrintWriter writer = response.getWriter();
        writer.append("<html><body><h1>Error Code: " + statusCode + "</h1><body></html>");
        writer.flush();
    } catch (IOException e) {
        log.error(e);
    }
}

From source file:org.opentestsystem.shared.permissions.rest.APIHandler.java

@SuppressWarnings("rawtypes")
@ExceptionHandler(HttpResponseException.class)
@ResponseBody// w  ww. ja v  a  2s.co  m
public ReturnStatus handleException(HttpResponseException e, HttpServletResponse response) {
    response.setStatus(e.getStatusCode());
    return new ReturnStatus(StatusEnum.FAILURE, e.getMessage());
}

From source file:com.zimbra.cs.dav.service.DavMethod.java

protected void sendResponse(DavContext ctxt) throws IOException {
    if (ctxt.isResponseSent())
        return;/* w ww.  j a  v  a 2s.c  o  m*/
    HttpServletResponse resp = ctxt.getResponse();
    resp.setStatus(ctxt.getStatus());
    String compliance = ctxt.getDavCompliance();
    if (compliance != null)
        setResponseHeader(resp, DavProtocol.HEADER_DAV, compliance);
    if (ctxt.hasResponseMessage()) {
        resp.setContentType(DavProtocol.DAV_CONTENT_TYPE);
        DavResponse respMsg = ctxt.getDavResponse();
        respMsg.writeTo(resp.getOutputStream());
    }
    ctxt.responseSent();
}

From source file:de.undercouch.gradle.tasks.download.ContentEncodingTest.java

@Override
protected Handler[] makeHandlers() throws IOException {
    ContextHandler contentEncodingHandler = new ContextHandler("/" + CONTENT_ENCODING) {
        @Override// w w  w  .  java 2 s .c  o m
        public void handle(String target, HttpServletRequest request, HttpServletResponse response,
                int dispatch) throws IOException, ServletException {
            response.setStatus(200);
            if (contentEncoding != null) {
                response.setHeader("Content-Encoding", contentEncoding);
            }
            PrintWriter rw = response.getWriter();
            rw.write("ce: " + String.valueOf(contentEncoding));
            rw.close();
        }
    };
    return new Handler[] { contentEncodingHandler };
}

From source file:ee.ria.xroad.proxy.testsuite.testcases.ServiceReturnsFault.java

@Override
public AbstractHandler getServiceHandler() {
    return new AbstractHandler() {
        @Override/*  w w w  . j a v a 2  s  .  c o m*/
        public void handle(String target, Request baseRequest, HttpServletRequest request,
                HttpServletResponse response) throws IOException {
            response.setContentType(MimeTypes.TEXT_XML);
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);

            try (FileInputStream in = new FileInputStream(QUERIES_DIR + "/fault.query")) {
                IOUtils.copy(in, response.getOutputStream());
            }

            baseRequest.setHandled(true);
        }
    };
}

From source file:core.NiprSyncController.java

@CrossOrigin
@RequestMapping(value = "/ping", method = RequestMethod.GET)
public void ping(HttpServletRequest request, HttpServletResponse response) {
    System.out.println("Licensing+ app is running.");
    response.setStatus(HttpServletResponse.SC_OK);
}

From source file:com.egreen.tesla.server.api.config.resolver.RequestResolver.java

private void sendErrorMessage(HttpServletResponse resp, String message) throws IOException {
    resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    resp.getWriter().print("<html><head><title>Oops an error happened!</title></head>");
    resp.getWriter().print("<body>" + message + "!</body>");
    resp.getWriter().println("</html>");
}

From source file:costumetrade.user.login.BasicAuthenticateInterceptor.java

private void handleFailure(HttpServletResponse response, ApiResponse apiResponse) throws IOException {

    response.setStatus(HttpServletResponse.SC_OK);
    response.setContentType(MediaType.APPLICATION_JSON_VALUE);
    response.setCharacterEncoding(StandardCharsets.UTF_8.name());

    PrintWriter out = response.getWriter();
    out.println(JSON.toJSONString(apiResponse));
    out.flush();//from   w  w w.  ja  va2 s  .c o  m
}

From source file:org.nekorp.workflow.backend.controller.imp.ReporteGlobalControllerImp.java

/**{@inheritDoc}*/
@Override//from w  w  w . j a  v  a  2s . com
@RequestMapping(value = "/{idServicio}", method = RequestMethod.GET)
@ResponseBody
public RenglonRG getRenglon(@PathVariable final Long idServicio, final HttpServletResponse response) {
    Servicio servicio = servicioDAO.consultar(idServicio);
    if (servicio == null) {
        response.setStatus(HttpStatus.NOT_FOUND.value());
        return null;
    }
    RenglonRG r = renglonFactoryRG.build(servicio);
    response.setHeader("Content-Type", "application/json;charset=UTF-8");
    return r;
}

From source file:fr.univrouen.poste.web.ExceptionController.java

@RequestMapping("/denied")
public ModelAndView deniedHandler(HttpServletRequest request, HttpServletResponse response) {
    String ip = request.getRemoteAddr();
    log.warn("Access Denied for " + ip);
    response.setStatus(HttpServletResponse.SC_FORBIDDEN);
    return new ModelAndView("accessDeniedException");
}