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.smigo.plants.PlantController.java

@RequestMapping(value = { "/rest/plant" }, method = RequestMethod.POST)
@ResponseBody/*from w w  w .  j a v a2  s.c  o m*/
public Integer addPlant(@Valid @RequestBody Plant plant, BindingResult result,
        @AuthenticationPrincipal AuthenticatedUser user, HttpServletResponse response) {
    if (result.hasErrors()) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return null;
    }
    return plantHandler.addPlant(user, plant);

}

From source file:edu.cornell.mannlib.vitro.webapp.controller.api.VitroApiServlet.java

protected void sendShortResponse(int statusCode, String message, HttpServletResponse resp) throws IOException {
    resp.setStatus(statusCode);
    PrintWriter writer = getWriter(resp);
    writer.println("<H1>" + statusCode + " " + message + "</H1>");
}

From source file:eu.morfeoproject.fast.catalogue.services.GenericServlet.java

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 *///  w ww .  j a  v a2 s  .  c  o m
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
}

From source file:eu.morfeoproject.fast.catalogue.services.GenericServlet.java

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 *//*  ww  w .  j a  v a  2 s.  com*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
}

From source file:eu.morfeoproject.fast.catalogue.services.GenericServlet.java

/**
 * @see HttpServlet#doPut(HttpServletRequest request, HttpServletResponse response)
 *//*from   w w w  . j a v  a  2s .c o m*/
@Override
protected void doPut(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
}

From source file:eu.morfeoproject.fast.catalogue.services.GenericServlet.java

/**
 * @see HttpServlet#doDelete(HttpServletRequest request, HttpServletResponse response)
 *///from  www.ja v  a 2  s .c o m
@Override
protected void doDelete(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController.java

@ExceptionHandler(ValidationException.class)
@ResponseBody/* ww  w  .j  a  v a  2 s .  co  m*/
public SimpleObject validationExceptionHandler(ValidationException validationException,
        HttpServletRequest request, HttpServletResponse response) {
    response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    return RestUtil.wrapValidationErrorResponse(validationException);
}

From source file:com.fengduo.bee.commons.exception.SystemExceptionResolver.java

/**
 * Response?/* w  w w .j a  va 2s.co m*/
 * 
 * @param response
 * @param errorCode
 * @param errorMsg
 */
private void setResponse(HttpServletResponse response, int errorCode, String errorMsg) {
    if (-1 != errorCode)
        response.setStatus(errorCode);
    if (errorMsg != null)
        printJSON(response, errorMsg);
}

From source file:com.konakart.actions.gateways.GlobalCollectBaseAction.java

/**
 * Common code for setting up the redirect response.
 * // w  w  w.  jav a2  s . c o m
 * @param response
 */
protected void setupResponseForTemporaryRedirect(HttpServletResponse response) {
    response.setStatus(302);
    response.setHeader("Expires", "Wed, 11 Jan 1984 05:00:00 GMT");
    response.setHeader("Cache-Control", "max-age=0, no-cache, no-store, must-revalidate");
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Connection", "close");
}

From source file:dtu.ds.warnme.ws.rest.json.AbstractRestWS.java

@ExceptionHandler({ BadRequestException.class, MissingServletRequestParameterException.class })
@ResponseBody//  www  .ja v  a 2 s .c  o  m
String handleBadRequestExceptions(Exception ex, HttpServletRequest request, HttpServletResponse response) {
    log.info(ex.getMessage(), ex);
    response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    String responseBody = getMessage(ex, request.getLocale());
    RestUtils.decorateResponseHeaderWithMD5(response, responseBody);
    RestUtils.decorateResponseHeaderForJsonContentType(response);
    return responseBody;
}