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.cfitzarl.cfjwed.controller.HealthController.java

/**
 * This attempts to hit the database and redis with simple calls, and will return a 502 if that isn't possible.
 *
 * @param response the servlet response/*from w  w w. ja v a2 s . c o m*/
 */
@RequestMapping(value = "", method = RequestMethod.GET)
public void checkHealth(HttpServletResponse response) {
    try {
        configurationService.findByKey(ConfigKey.EMAIL);
        redisService.get("health");
    } catch (Exception e) {
        LOGGER.error("CRITICAL: Service outage detected", e);
        response.setStatus(502);
    }
}

From source file:com.pkrete.locationservice.admin.controller.rest.v1.RestExceptionHandler.java

@ExceptionHandler(Exception.class)
@ResponseBody//from w  ww.j  av a2  s .c om
protected Map handleException(Exception ex, WebRequest request, HttpServletResponse response) {
    // Set response status
    response.setStatus(500);
    // Create Map containing all the fields   
    Map errors = new HashMap<String, String>();
    // Write exception stack trace to String
    StringWriter errorsStr = new StringWriter();
    ex.printStackTrace(new PrintWriter(errorsStr));
    // Log error
    logger.error(errorsStr.toString());
    // Get message
    String message = messageSource.getMessage("rest.error.general", null, null);
    // Add error message
    errors.put("error", message);
    // Return error
    return errors;
}

From source file:org.gvsig.framework.web.controllers.OGCInfoController.java

/**
 * Catch ServerGeoException and set error message into response
 *
 * @param ex the {@ServerGeoException}/*from w ww  .  j a  v  a 2 s. c o  m*/
 * @param response the {@code HttpServletResponse}.
 * @return the message error.
 */
@ExceptionHandler(ServerGeoException.class)
@ResponseBody
public String handleServerGeoException(ServerGeoException ex, HttpServletResponse response) {
    response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    return messageSource.getMessage(SERVER_ERROR_CODE, null, LocaleContextHolder.getLocale());
}

From source file:ch.systemsx.cisd.openbis.generic.client.web.server.UploadServiceServlet.java

private final void sendResponse(final HttpServletResponse response, final String textOrNull) {
    response.setContentType("text/html");
    response.setStatus(HttpServletResponse.SC_OK);
    if (textOrNull != null) {
        try {/*from w  w  w  . j a va2 s. c  o m*/
            response.getWriter().write(textOrNull);
        } catch (final IOException ex) {
            throw new IOExceptionUnchecked(ex);
        }
    }
}

From source file:net.jadler.stubbing.server.jetty.JadlerHandler.java

@Override
public void handle(final String target, final Request baseRequest, final HttpServletRequest request,
        final HttpServletResponse response) throws IOException, ServletException {

    final net.jadler.Request req = RequestUtils.convert(request);
    final StubResponse stubResponse = this.requestManager.provideStubResponseFor(req);

    response.setStatus(stubResponse.getStatus());
    this.insertResponseHeaders(stubResponse.getHeaders(), response);

    baseRequest.setHandled(true);/*from www  . ja  va2s.  c o m*/

    this.processDelay(stubResponse.getDelay());
    this.insertResponseBody(stubResponse.getBody(), response);
}

From source file:org.codehaus.groovy.grails.plugins.springsecurity.GrailsNtlmProcessingFilterEntryPoint.java

/**
 * {@inheritDoc}//from  w  w  w . j  a v  a  2 s  .c o m
 * @see org.springframework.security.ui.ntlm.NtlmProcessingFilterEntryPoint#commence(
 *    javax.servlet.ServletRequest, javax.servlet.ServletResponse,
 *    org.springframework.security.AuthenticationException)
 */
@Override
public void commence(final ServletRequest req, final ServletResponse res,
        final AuthenticationException authException) throws IOException, ServletException {

    // start authentication, if necessary and forceIdentification in NtlmProcessingFilter is false
    if (!(authException instanceof NtlmBaseException || authException instanceof BadCredentialsException)) {

        HttpServletRequest request = (HttpServletRequest) req;
        request.getSession().setAttribute(STATE_ATTR, BEGIN);

        HttpServletResponse response = (HttpServletResponse) res;

        response.setHeader("WWW-Authenticate", new NtlmBeginHandshakeException().getMessage());
        response.setHeader("Connection", "Keep-Alive");
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        response.setContentLength(0);
        response.flushBuffer();
    } else {
        super.commence(req, res, authException);
    }
}

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

@RequestMapping(value = VideoSvcApi.VIDEO_SVC_PATH + "/{id}/unlike", method = RequestMethod.POST)
public @ResponseBody void unlikeVideo(@PathVariable("id") long id, Principal p, HttpServletResponse response)
        throws IOException {
    if (!videos.exists(id)) {
        response.setStatus(404);
    } else {//from w w  w.  ja  v a2s .  co  m
        Video v = videos.findOne(id);
        Set<String> likesUserNames = v.getLikesUsernames();
        if (likesUserNames.contains(p.getName())) {
            likesUserNames.remove(p.getName());
            v.setLikes(likesUserNames.size());
            videos.save(v);
            response.setStatus(200);
        } else {
            response.setStatus(400);
        }
    }
}