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.nekorp.workflow.backend.controller.imp.UploadControllerImp.java

/**{@inheritDoc}*/
@Override//  ww w  .  java  2  s. c  o  m
@RequestMapping(value = "/imagenes/{rawBlobKey}", method = RequestMethod.DELETE)
public void deleteImage(@PathVariable final String rawBlobKey, final HttpServletResponse response) {
    try {
        BlobKey blobKey = new BlobKey(rawBlobKey);
        blobstoreService.delete(blobKey);
        response.setStatus(HttpStatus.ACCEPTED.value());
    } catch (Exception e) {
        response.setStatus(HttpStatus.NOT_FOUND.value());
    }
}

From source file:bentolor.grocerylist.JsonResultRenderer.java

@Override
public void render(ActionRequest request, JsonResult jsonResult) throws Exception {
    HttpServletResponse response = request.getHttpServletResponse();
    response.setContentType(MimeTypes.MIME_APPLICATION_JSON);

    if (jsonResult.getStatus() > 0) {
        response.setStatus(jsonResult.getStatus());
    }//from  ww w .  jav a  2s.com

    PrintWriter writer = null;
    try {
        writer = response.getWriter();
        String result;
        try {
            result = objectMapper.writeValueAsString(jsonResult.getModel());
        } catch (JsonProcessingException e) {
            throw new IllegalArgumentException("Invalid JSON to render");
        }
        writer.println(result);
    } finally {
        StreamUtil.close(writer);
    }
}

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

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

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

    PrintWriter out = response.getWriter();

    List<String> targetObjects = Arrays.asList(target.split("/"));

    SortedMap<String, UAVTalkXMLObject> objects = new TreeMap<>();

    for (UAVTalkXMLObject xmlObj : mFcDevice.getObjectTree().getXmlObjects().values()) {
        if (targetObjects.size() == 0 || targetObjects.contains(xmlObj.getName())) {
            if (mShowSettings && xmlObj.isSettings() || mShowState && !xmlObj.isSettings()) {
                objects.put(xmlObj.getName(), xmlObj);
            }/*  w  w  w . j  a v  a  2  s . c o m*/
        }
    }

    String callback = request.getParameter("callback");

    if (callback != null) {
        response.setContentType("application/javascript");
        out.println(callback + "(");
    } else {
        response.setContentType("application/json");
    }

    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);

    out.println(mapper.writeValueAsString(objects));

    if (callback != null) {
        out.print(")");
    }

    baseRequest.setHandled(true);
}

From source file:com.envision.envservice.filter.CertificateFilter.java

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

    if (verifyCertificate()) {
        chain.doFilter(request, response);
    } else {/*from  ww w . ja va 2s.  c om*/
        response.setStatus(HttpStatus.SC_UNAUTHORIZED);
        response.setContentType(MediaType.APPLICATION_JSON);
        response.getWriter().print(FailResult.toJson(Code.NO_CERTIFICATE, ""));
    }
}

From source file:ca.uhn.fhir.rest.server.servlet.ServletRestfulResponse.java

@Override
public Writer getResponseWriter(int theStatusCode, String theStatusMessage, String theContentType,
        String theCharset, boolean theRespondGzip) throws UnsupportedEncodingException, IOException {
    addHeaders();//from  ww  w  . j a  va 2s.  c  o  m
    HttpServletResponse theHttpResponse = getRequestDetails().getServletResponse();
    theHttpResponse.setCharacterEncoding(theCharset);
    theHttpResponse.setStatus(theStatusCode);
    theHttpResponse.setContentType(theContentType);
    if (theRespondGzip) {
        theHttpResponse.addHeader(Constants.HEADER_CONTENT_ENCODING, Constants.ENCODING_GZIP);
        return new OutputStreamWriter(new GZIPOutputStream(theHttpResponse.getOutputStream()),
                Constants.CHARSET_NAME_UTF8);
    } else {
        return theHttpResponse.getWriter();
    }
}

From source file:jp.mathes.databaseWiki.dav.DavServlet.java

@Override
public void service(final javax.servlet.ServletRequest servletRequest,
        final javax.servlet.ServletResponse servletResponse) throws ServletException, IOException {
    HttpServletRequest req = (HttpServletRequest) servletRequest;
    HttpServletResponse resp = (HttpServletResponse) servletResponse;
    if (req.getHeader("Authorization") != null) {
        resp.setStatus(HttpServletResponse.SC_OK);
        resp.setContentType("application/xhtml+xml");
        try {//from w  w w .  ja  v a2s.c o m
            Request request = new ServletRequest(req);
            Response response = new ServletResponse(resp);
            this.httpManager.process(request, response);
        } finally {
            servletResponse.getOutputStream().flush();
            servletResponse.flushBuffer();
        }
    } else {
        resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        resp.setHeader("WWW-Authenticate", "Basic realm=\"databaseWiki\"");
    }
}

From source file:edu.cornell.library.scholars.webapp.controller.api.DistributeDataApiController.java

private void do400BadRequest(String message, HttpServletResponse resp) throws IOException {
    log.debug("400BadRequest: " + message);
    resp.setStatus(400);
    resp.getWriter().println(message);//from   w w w .j  a  v  a  2  s.co  m
}

From source file:de.elomagic.mag.ServletMock.java

@Override
protected void doHead(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (request.getRequestURI().endsWith("TestFile.pdf")) {
        response.setStatus(HttpServletResponse.SC_OK);
    } else {/* w  w  w  .  jav  a 2 s.c  o  m*/
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    }
}

From source file:org.eclipse.virgo.samples.rest.RestController.java

@RequestMapping(value = "/users/{userId}/{name}/{invention}", method = RequestMethod.PUT)
public void putUser(@PathVariable("userId") String userId, @PathVariable("name") String name,
        @PathVariable("invention") String invention, HttpServletResponse httpServletResponse) {
    this.model.put(userId, new Info(name, invention));
    httpServletResponse.setStatus(HttpServletResponse.SC_OK);
}

From source file:org.magnum.dataup.MyVideoController.java

@RequestMapping(value = "/video/{id}/data", method = RequestMethod.GET)
@Streaming//from www. j a v  a  2s  . c om
Response getData(@PathVariable("id") long id, HttpServletResponse response) {
    Video v = videos.get(id);
    if (v == null) {
        response.setStatus(404);
        return null;
    }
    try {
        VideoFileManager vfm = VideoFileManager.get();
        vfm.copyVideoData(v, response.getOutputStream());
    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
}