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.alzatezabala.fp.presentacion.controller.EntidadBancariaController.java

@RequestMapping(value = { "/EntidadBancaria/{id}" }, method = RequestMethod.DELETE)
public void delete(HttpServletRequest httpRequest, HttpServletResponse httpServletResponse,
        @PathVariable("id") int idEntidad) throws IOException {
    if (entidadBancariaDAO.delete(idEntidad)) {
        httpServletResponse.setStatus(HttpServletResponse.SC_ACCEPTED);
    } else {// w w w . java  2s  .  c o m
        httpServletResponse.setStatus(HttpServletResponse.SC_NO_CONTENT);
    }
}

From source file:hmock.http.impl.DefaultServiceSpec.java

@Override
public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {

    ResponseDetail detail = _responseSpec.generateResponse(request);

    response.setStatus(detail.status());
    injectHeaders(response, detail.headers());

    InputStream body = null;/*from ww  w  .  j  a  v  a 2  s.c o  m*/
    try {
        body = detail.body();
        IOUtils.copy(body, response.getOutputStream());
    } finally {
        if (body != null) {
            body.close();
        }
    }

}

From source file:com.counter.counter.api.AuthenticationEntryPoint.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authEx)
        throws IOException, ServletException {
    response.addHeader("WWW-Authenticate", "Basic realm=" + getRealmName());
    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    PrintWriter writer = response.getWriter();
    writer.println("HTTP Status 401 - " + authEx.getMessage());
}

From source file:com.novartis.pcs.ontology.rest.servlet.SubtermsServlet.java

@Override
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
    resp.setContentLength(0);/*from w ww.  j a v  a  2 s  .  co  m*/
}

From source file:com.google.android.gcm.demo.server.SendMessageServlet.java

/**
 * Indicates to App Engine that this task should be retried.
 */
private void retryTask(HttpServletResponse resp) {
    resp.setStatus(500);
}

From source file:com.google.android.gcm.demo.server.SendMessageServlet.java

/**
 * Indicates to App Engine that this task is done.
 */
private void taskDone(HttpServletResponse resp) {
    resp.setStatus(200);
}

From source file:net.solarnetwork.central.dras.web.ControllerSupport.java

/**
 * SecurityException handler.//from   ww  w .  j  a v a2 s . c  om
 * 
 * <p>Logs a WARN log and returns HTTP 403 (Forbidden).</p>
 * 
 * @param e the security exception
 * @param res the servlet response
 */
@ExceptionHandler(SecurityException.class)
public void handleSecurityException(SecurityException e, HttpServletResponse res) {
    if (log.isWarnEnabled()) {
        log.warn("Security exception: " + e.getMessage());
    }
    res.setStatus(HttpServletResponse.SC_FORBIDDEN);
}

From source file:com.k42b3.quantum.handler.MessageHandler.java

public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    if (request.getMethod().equals("GET")) {
        response.setStatus(HttpServletResponse.SC_OK);
        response.setContentType("application/json;charset=utf-8");
        baseRequest.setHandled(true);//w  w w .  j av  a2 s  . c o  m

        try {
            String modifiedSince = request.getHeader("If-Modified-Since");
            Date date = null;

            if (modifiedSince != null && !modifiedSince.isEmpty()) {
                date = DateUtils.parseDate(modifiedSince);
            }

            response.getWriter()
                    .print(container.getGson().toJson(container.getMessageRepository().getAll(date)));
        } catch (SQLException e) {
            this.handleException(response, e);
        }
    } else if (request.getMethod().equals("POST")) {
        Message message = container.getGson().fromJson(readRequestBody(request), Message.class);

        container.getEventPublisher().publish(null, message);

        response.setContentType("application/json;charset=utf-8");
        response.setStatus(HttpServletResponse.SC_CREATED);
        response.getWriter().print(container.getGson().toJson(message));
    }
}

From source file:org.magnum.mobilecloud.video.VideoController.java

@RequestMapping(value = VideoSvcApi.VIDEO_SVC_PATH + "/{id}", method = RequestMethod.GET)
public @ResponseBody Video getVideoById(@PathVariable long id, HttpServletResponse response) {
    Video v = _videoRepository.findOne(id);
    if (v == null)
        response.setStatus(HttpStatus.SC_NOT_FOUND);
    return v;/*from  w w w .j  a  v  a 2  s  . c  o m*/
}

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

@Override
protected Handler[] makeHandlers() throws IOException {
    ContextHandler contentLengthHandler = new ContextHandler("/" + CONTENT_LENGTH) {
        @Override/*from  ww  w  .j a  v a  2 s .  co  m*/
        public void handle(String target, HttpServletRequest request, HttpServletResponse response,
                int dispatch) throws IOException, ServletException {
            response.setStatus(200);
            if (contentLength != null) {
                response.setHeader("Content-Length", contentLength);
            }
            PrintWriter rw = response.getWriter();
            rw.write("cl: " + String.valueOf(contentLength));
            rw.close();
        }
    };
    return new Handler[] { contentLengthHandler };
}