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:com.iflytek.edu.cloud.frame.spring.DefaultHandlerExceptionResolver.java

protected MainError handleBindException(BindException ex, HttpServletRequest request,
        HttpServletResponse response, Object handler) throws IOException {
    response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);

    List<ObjectError> errorList = ex.getBindingResult().getAllErrors();

    //Bean??Rop//w w w.j  ava 2s .c  om
    MainError mainError = null;
    if (errorList != null && errorList.size() > 0) {
        mainError = toMainErrorOfSpringValidateErrors(errorList,
                (Locale) request.getAttribute(Constants.SYS_PARAM_KEY_LOCALE));
    }

    return mainError;
}

From source file:edu.emory.cci.aiw.cvrg.eureka.servlet.filter.HaveUserRecordFilter.java

private void sendForbiddenError(HttpServletResponse servletResponse, HttpServletRequest servletRequest,
        boolean created) throws IOException {
    if (this.properties.isRegistrationEnabled()) {
        servletResponse.setStatus(HttpServletResponse.SC_FORBIDDEN);
        if (created) {
            servletResponse.sendRedirect(servletRequest.getContextPath() + "/logout?awaitingActivation=true");
        } else {/*from  w w  w . ja v a 2  s . c om*/
            servletResponse.sendRedirect(servletRequest.getContextPath() + "/logout?notRegistered=true");
        }
    } else {
        servletResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
    }
}

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

@Override
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public @ResponseBody Cliente getCliente(@PathVariable Long id, HttpServletResponse response) {
    Cliente respuesta = this.clienteDao.consultar(id);
    if (respuesta == null) {
        response.setStatus(HttpStatus.NOT_FOUND.value());
    }/* w  ww.  j  a v  a 2 s . c o m*/
    response.setHeader("Content-Type", "application/json;charset=UTF-8");
    return respuesta;
}

From source file:byps.http.HIncomingStreamAsync.java

@Override
public void close() throws IOException {
    if (log.isDebugEnabled())
        log.debug("close(targetId=" + targetId);

    boolean alreadyClosed = closed.getAndSet(true);
    if (log.isDebugEnabled())
        log.debug("alreadyClosed=" + alreadyClosed);
    if (!alreadyClosed) {

        if (log.isDebugEnabled())
            log.debug("complete AsyncContext of targetId=" + targetId + " with status="
                    + HttpServletResponse.SC_OK);

        // The stream data must be completely read.
        // Otherwise the data remains in the socket and 
        // disturbs the next request.
        while (is.read() != -1) {
            //if (log.isDebugEnabled()) log.debug("read before close, " + (char)c);
        }/*from   w  w w  . java  2 s . co m*/
        is.close();

        HttpServletResponse response = (HttpServletResponse) rctxt.getResponse();
        response.getOutputStream().close();
        response.setStatus(HttpServletResponse.SC_OK);
        rctxt.complete();

        super.close();
    }
    if (log.isDebugEnabled())
        log.debug(")close");
}

From source file:com.kdab.daytona.Logger.java

@Override
public void doPut(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (m_error) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        PrintWriter out = response.getWriter();
        out.println("Daytona not operational. See server log for details.");
        out.flush();/*from  w  w  w.j  a v a  2s.  c om*/
        out.close();
        return;
    }

    String format = request.getParameter("format");
    if (format == null)
        format = "xml";

    if (!m_queuesByFormat.containsKey(format)) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        PrintWriter out = response.getWriter();
        out.println(String.format("Unknown format \'%s\'.", format));
        out.flush();
        out.close();
        return;
    }

    byte[] ba = IOUtils.toByteArray(request.getInputStream());
    try {
        m_queuesByFormat.get(format).put(ba);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }

    PrintWriter out = response.getWriter();
    out.println("Message received.");
    out.flush();
    out.close();
}

From source file:fi.aluesarjat.prototype.ContextAccessServlet.java

@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;

    long ifModifiedSince = request.getDateHeader("If-Modified-Since");
    if (ifModifiedSince >= LAST_MODIFIED) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return;//from  w ww  .ja v a  2 s  .co m
    }

    String context = request.getRequestURL().toString();
    RDFConnection connection = repository.openConnection();
    try {
        SPARQLQuery query = connection.createQuery(QueryLanguage.SPARQL,
                "CONSTRUCT { ?s ?p ?o } WHERE { GRAPH ?context { ?s ?p ?o } }");
        query.setBinding("context", new UID(context));

        String contentType = null;
        String format = request.getParameter("format");
        if ("turtle".equals(format)) {
            contentType = Format.TURTLE.getMimetype();
        } else if ("ntriples".equals(format)) {
            contentType = Format.NTRIPLES.getMimetype();
        } else {
            contentType = getAcceptedType(request, Format.RDFXML);
        }
        response.setDateHeader("Last-Modified", System.currentTimeMillis());
        response.setContentType(contentType);
        query.streamTriples(response.getWriter(), contentType);
    } finally {
        connection.close();
    }
}

From source file:com.oneops.ecv.ws.StatusController.java

@ExceptionHandler(AuthenticationException.class)
@ResponseBody//w  w w  .  j a v a2  s . c  om
public void handleAuthFailure(AuthenticationException e, HttpServletResponse response) throws IOException {
    ECV_LOGGER.error(e);
    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    response.getWriter().write(e.getMessage());
}

From source file:com.oneops.ecv.ws.StatusController.java

@ExceptionHandler(ConfigException.class)
@ResponseBody//from   w  ww. ja  v  a  2s  .c o  m
public void handleConfigException(ConfigException e, HttpServletResponse response) throws IOException {
    ECV_LOGGER.error(e);
    response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    response.getWriter().write(e.getMessage());
}

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

/**
 * ?teamteam admin//w w  w.j  ava 2s  . c om
 * @param req
 * @param resp
 */
@RequestMapping(params = "func=getAllTeam")
public void getAllTeam(HttpServletRequest req, HttpServletResponse resp) {
    VWBContainer container = VWBContainerImpl.findContainer();
    if (!validateRequest(req, container)) {
        resp.setStatus(401);
        return;
    }
    List<Team> teams = teamService.getAllTeams();
    JSONArray teamArray = new JSONArray();
    for (Team team : teams) {
        if (Team.PESONAL_TEAM.equals(team.getType())) {
            continue;
        }
        teamArray.add(team.getName());
    }
    JsonUtil.writeJSONObject(resp, teamArray);
}

From source file:hr.diskobolos.controller.SportController.java

/**
 * REST service responsible for deletion of the sport data
 *
 * @param sport/* www  .j a va  2  s .c o m*/
 * @param request
 * @param response
 * @return
 * @throws JSONException
 */
@RequestMapping(value = "/delete", method = RequestMethod.POST)
@ResponseBody
@PreAuthorize("hasAnyRole('ROLE_USER','ROLE_ADMIN')")
public String deleteSportData(@RequestBody Sport sport, HttpServletRequest request,
        HttpServletResponse response) throws JSONException {
    try {
        sportService.delete(sport);
        response.setStatus(HttpServletResponse.SC_OK);
        return new JSONObject().put("result", 200).toString();
    } catch (Exception e) {
        return ErrorHandlerUtils.handleAjaxError(request, response);
    }
}