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:de.afbb.bibo.servlet.server.servlet.MainServlet.java

@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response) {
    try {/* www  .  ja  v  a  2s  .c  o  m*/
        processRequest(request, response);
    } catch (final NumberFormatException | IOException e) {
        log.debug(e.getMessage());
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:de.afbb.bibo.servlet.server.servlet.MainServlet.java

@Override
protected void doPost(final HttpServletRequest request, final HttpServletResponse response) {
    try {//from ww w  .  j  ava2s  . co m
        processRequest(request, response);
    } catch (final NumberFormatException | IOException e) {
        log.debug(e.getMessage());
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:th.co.geniustree.osgi.prototype.authen.security.DefaultLogoutSuccessHandler.java

private void invalidSessionAndRedirect(HttpSession session, HttpServletResponse response, String redirectUrl)
        throws IOException {
    try {//from   w  w w.jav a  2s  .  co  m
        session.invalidate();
    } catch (Exception ex) {
        //swallow exception
        ex.printStackTrace();
    } finally {
        response.setStatus(HttpServletResponse.SC_OK);
        response.sendRedirect(redirectUrl);
    }
}

From source file:com.excella.deploy.agent.core.DynamicCommandServlet.java

/**
  * COMMENT DynamicCommandServlet.success()
  */*from   www.  ja va2  s  .  c o  m*/
  * @param execute
  * @param response 
  * @param request 
  */
protected void success(String execute, HttpServletRequest request, HttpServletResponse response) {
    try {
        log.debug("Attempting to respond with a success...");
        response.setContentType("text/html");
        response.setStatus(HttpServletResponse.SC_OK);
        PrintWriter writer = response.getWriter();
        writer.println("<h1>SUCCESS</h1>");
        writer.println("<p>");
        writer.println(execute);
        writer.println("</p>");
        ((Request) request).setHandled(true);
    } catch (Exception e) {
        log.error("Failed to respond with a success.", e);
    }
}

From source file:com.excella.deploy.agent.core.DynamicCommandServlet.java

/**
 * COMMENT DynamicCommandServlet.fail()//from   w ww . j  a  v  a2  s  . c  o m
 *
 * @param command
 * @param e
 * @param request
 * @param response
 */
protected void fail(Command command, Exception cause, HttpServletRequest request,
        HttpServletResponse response) {
    try {
        log.debug("Attempting to respond with a failure...");
        response.setContentType("text/html");
        response.setStatus(HttpServletResponse.SC_OK);
        response.getWriter().println("<h1>FAIL</h1>");
        response.getWriter().println("<p>");
        cause.printStackTrace(response.getWriter());
        response.getWriter().println("<p>");
        ((Request) request).setHandled(true);
    } catch (Exception e) {
        log.error("Failed to respond with a failure.", e);
    }
}

From source file:io.druid.server.AsyncManagementForwardingServlet.java

private void handleBadRequest(HttpServletResponse response, String errorMessage) throws IOException {
    if (!response.isCommitted()) {
        response.resetBuffer();//from   www  .j  a  va  2s  . c om
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        jsonMapper.writeValue(response.getOutputStream(), ImmutableMap.of("error", errorMessage));
    }
    response.flushBuffer();
}

From source file:net.duckling.ddl.web.controller.LynxTeamInfoController.java

/**
 * teamCode/*from  w  ww.  j a  va 2  s .  c o  m*/
 * @param 
 * */
@RequestMapping(params = "func=getMyTemCodes")
public void getMyTemCodes(HttpServletRequest req, HttpServletResponse resp) {
    VWBContainer container = VWBContainerImpl.findContainer();
    if (!validateRequest(req, container)) {
        resp.setStatus(401);
        return;
    }
    String uid = req.getParameter("uid");
    if (StringUtils.isEmpty(uid)) {
        resp.setStatus(400);
        return;
    }
    List<Team> myTeams = teamService.getAllUserTeams(uid);
    JSONArray teamArray = new JSONArray();
    for (Team team : myTeams) {
        if (Team.PESONAL_TEAM.equals(team.getType())) {
            continue;
        }
        teamArray.add(team.getName());
    }
    JsonUtil.writeJSONObject(resp, teamArray);

}

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

@Override
@RequestMapping(method = RequestMethod.POST)
public void crearCliente(@Valid @RequestBody Cliente cliente, HttpServletResponse response) {
    cliente.setId(null);/*from  w  w w  . j  a  va 2  s  . co  m*/
    preprocesaCliente(cliente);
    this.clienteDao.guardar(cliente);
    response.setStatus(HttpStatus.CREATED.value());
    response.setHeader("Location", "/clientes/" + cliente.getId());
}

From source file:edu.harvard.iq.dvn.core.web.servlet.ICPSRproxyServlet.java

private void createErrorResponse403(HttpServletResponse res) {
    res.setContentType("text/html");
    res.setStatus(res.SC_FORBIDDEN);
    try {/*from  w w w .j a  v  a 2  s.  com*/
        PrintWriter out = res.getWriter();
        out.println("<HTML>");
        out.println("<HEAD><TITLE>ICPSR File Download</TITLE></HEAD>");
        out.println("<BODY>");
        out.println("<BIG>You do not have permission to download this file.</BIG>");
        out.println("</BODY></HTML>");
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:edu.harvard.iq.dvn.core.web.servlet.ICPSRproxyServlet.java

private void createErrorResponse404(HttpServletResponse res) {
    res.setContentType("text/html");
    res.setStatus(res.SC_NOT_FOUND);
    try {/*from  ww w.  j ava2  s  .  c  om*/
        PrintWriter out = res.getWriter();
        out.println("<HTML>");
        out.println("<HEAD><TITLE>ICPSR File Download</TITLE></HEAD>");
        out.println("<BODY>");
        out.println("<BIG>No such object found for the File Id supplied.</BIG>");
        out.println("</BODY></HTML>");
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}