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.ms.app.web.commons.pagecache.PageCacheManager.java

protected void setStatus(final HttpServletResponse response, final PageInfo pageInfo) {
    response.setStatus(pageInfo.getStatusCode());
}

From source file:MyServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/html");
    PrintWriter out = res.getWriter();

    int siteIndex = Math.abs(random.nextInt()) % sites.size();
    String site = (String) sites.elementAt(siteIndex);

    res.setStatus(res.SC_MOVED_TEMPORARILY);
    res.setHeader("Location", site);
}

From source file:com.graphaware.module.resttest.RestTestApi.java

@RequestMapping(value = "/assertEmpty", method = RequestMethod.POST)
@ResponseBody/*from w  w  w. jav a2 s  . co m*/
public String assertEmpty(@RequestBody(required = false) RestTestRequest request, HttpServletResponse response)
        throws IOException {
    try {
        GraphUnit.assertEmpty(database, resolveInclusionPolicies(request));
        response.setStatus(HttpServletResponse.SC_OK);
        return null;
    } catch (AssertionError error) {
        response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
        return error.getMessage();
    }
}

From source file:eu.trentorise.smartcampus.permissionprovider.controller.BasicProfileController.java

@RequestMapping(method = RequestMethod.GET, value = "/accountprofile/me")
public @ResponseBody AccountProfile findAccountProfile(HttpServletResponse response) throws IOException {
    try {//www.  jav a2  s. co m
        Long user = getUserId();
        if (user == null) {
            response.setStatus(HttpServletResponse.SC_FORBIDDEN);
            return null;
        }
        return profileManager.getAccountProfileById(user.toString());
    } catch (Exception e) {
        e.printStackTrace();
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return null;
    }
}

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

@Override
@RequestMapping(method = RequestMethod.POST)
public void crearEvento(@PathVariable final Long idServicio, @Valid @RequestBody final Evento dato,
        final HttpServletResponse response) {
    dato.setId(null);/*from  www. j  a  va  2s .com*/
    if (!idServicioValido(idServicio)) {
        response.setStatus(HttpStatus.NOT_FOUND.value());
        return;
    }
    this.eventoDAO.guardar(idServicio, dato);
    response.setStatus(HttpStatus.CREATED.value());
    response.setHeader("Location", "/servicios/" + idServicio + "/bitacora/eventos/" + dato.getId());

}

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

@Override
@RequestMapping(method = RequestMethod.POST)
public void crearRegistro(@PathVariable final Long idServicio, @Valid @RequestBody final RegistroCosto dato,
        final HttpServletResponse response) {
    dato.setId(null);//from  w w  w .j  av  a  2  s. c o  m
    if (!idServicioValido(idServicio)) {
        response.setStatus(HttpStatus.NOT_FOUND.value());
        return;
    }
    this.registroCostoDAO.guardar(idServicio, dato);
    response.setStatus(HttpStatus.CREATED.value());
    response.setHeader("Location", "/servicios/" + idServicio + "/costo/registros/" + dato.getId());
}

From source file:bluevia.ReceiveSMS.java

public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {

    //Dump Http Info
    Util.dumpHttpInfo(req);/*w w  w  . j  av a2  s . c  o  m*/
    resp.setStatus(HttpServletResponse.SC_NO_CONTENT);

    /*String contentType = req.getContentType();
    String oauth_consumer_key="";
               
    String htmlAuthHeader=req.getHeader("Authorization");
    if (htmlAuthHeader!=null){
               
       StringTokenizer htmlHeader = new StringTokenizer(htmlAuthHeader," ");
       String szAux = htmlHeader.nextToken();
       if (szAux.compareTo("OAuth")==0){
    szAux = htmlHeader.nextToken(",");
    szAux=szAux.trim();
    while(szAux!=null){
       StringTokenizer headerParam = new StringTokenizer(szAux,"='");
       String param = headerParam.nextToken();
       if (param.compareTo("oauth_consumer_key")==0){
          szAux=headerParam.nextToken();
          szAux = szAux.replace('"', ' ');
          oauth_consumer_key=szAux.trim();      
          break;
       }else{
          szAux = htmlHeader.nextToken(",");
          szAux = szAux.replace('"', ' ');
          szAux=szAux.trim();
       }
    }
       }
               
       if (oauth_consumer_key.compareTo(Util.BlueViaOAuth.consumer_key)==0){
    if (contentType.compareTo("application/json")==0){
       try{
          StringBuffer doc = new StringBuffer();
          BufferedReader br = new BufferedReader(new InputStreamReader(req.getInputStream()));
          String line = br.readLine();
          while (line != null) {
             doc.append(line);
             line = br.readLine();
          }
                  
          JSONObject receivedSMSAsync = new JSONObject(doc.toString());
          JSONObject smsInfo = receivedSMSAsync.getJSONObject("receivedSMSAsync").getJSONObject("message");
                  
          String szMessage = smsInfo.getString("message");
             String szOrigin = smsInfo.getJSONObject("originAddress").getString("phoneNumber");
             Date now= new Date();
                     
             StringTokenizer msgParser = new StringTokenizer(szMessage);
                  
          // Removing app id
          msgParser.nextToken();
                  
          String userAlias = msgParser.nextToken();
                  
          String msg = "";
          while (msgParser.hasMoreTokens())
             msg += " "+ msgParser.nextToken();                                                
                  
          String userEmail = (String)Util.getUserWithAlias(userAlias).getProperty("mail");
          if (userEmail!=null){
             Util.addUserMessage(userEmail, szOrigin, msg, Long.toString(now.getTime()));
                     
             SendSMS.setTwitterStatus(userEmail,msg);
            
             SendSMS.setFacebookWallPost(userEmail,msg);
                     
             resp.setStatus(HttpServletResponse.SC_NO_CONTENT);   
          }else
             resp.sendError(HttpServletResponse.SC_BAD_REQUEST,"Error processing receivedSMSAsync: invalid user/alias");
                  
       } catch (Exception e) {
          log.severe(e.getMessage());
          resp.sendError(HttpServletResponse.SC_BAD_REQUEST,"Error processing receivedSMSAsync: invalid json data structure\n"+e.getMessage());
       }                  
    }else
       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED,"This version of the server only accepts applicaciont/json");
       }else
    resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
    }else
       resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);*/
}

From source file:net.proest.librepilot.web.handler.ObjectHandler.java

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

    response.setCharacterEncoding("utf-8");
    response.setStatus(HttpServletResponse.SC_OK);

    if (request.getMethod().equals("POST")) {
        handlePost(target, baseRequest, request, response);
    } else if (request.getMethod().equals("GET")) {
        handleGet(target, baseRequest, request, response);
    }/*  ww  w  .ja  v a 2s  . c o m*/
    baseRequest.setHandled(true);
}

From source file:com.qwazr.webapps.exception.WebappException.java

private void sendQuietlyHTML(HttpServletResponse response) throws IOException {
    PrintWriter printWriter = response.getWriter();
    String message = StringEscapeUtils.escapeHtml4(error.message);
    response.setStatus(error.status);
    response.setContentType("text/html");
    printWriter.print("<html><head><title>");
    printWriter.print(error.title.title);
    printWriter.println("</title></head>");
    printWriter.print("<body><h3>");
    printWriter.print(error.title.title);
    printWriter.println("</h3>");
    printWriter.print("<pre>");
    printWriter.print(message);//w ww .j av a2 s  . co  m
    printWriter.println("</pre></body></html>");
}

From source file:es.logongas.encuestas.presentacion.controller.BorrarDatosController.java

@RequestMapping(value = { "/Encuesta" }, method = RequestMethod.DELETE)
public void delete(HttpServletRequest httpRequest, HttpServletResponse httpServletResponse) {
    try {/* www . j  ava2s.c  om*/
        EncuestaDAO encuestaDAO = (EncuestaDAO) daoFactory.getDAO(Encuesta.class);

        encuestaDAO.deleteAllData();

        noCache(httpServletResponse);
        httpServletResponse.setStatus(HttpServletResponse.SC_NO_CONTENT);
    } catch (Exception ex) {
        httpServletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        httpServletResponse.setContentType("text/plain");
        try {
            ex.printStackTrace(httpServletResponse.getWriter());
        } catch (Exception ex2) {
            log.error("Fall al imprimir la traza", ex2);
        }
    }
}