Example usage for javax.servlet.http HttpServletResponse SC_ACCEPTED

List of usage examples for javax.servlet.http HttpServletResponse SC_ACCEPTED

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse SC_ACCEPTED.

Prototype

int SC_ACCEPTED

To view the source code for javax.servlet.http HttpServletResponse SC_ACCEPTED.

Click Source Link

Document

Status code (202) indicating that a request was accepted for processing, but was not completed.

Usage

From source file:org.jbpm.designer.filter.DesignerBasicAuthSecurityFilter.java

@Override
public void doFilter(ServletRequest _request, ServletResponse _response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) _request;
    HttpServletResponse response = (HttpServletResponse) _response;
    HttpSession session = request.getSession(false);
    User user = this.authenticationService.getUser();

    // For HTTP OPTIONS verb/method reply with ACCEPTED status code -- per CORS handshake
    if (request.getMethod().equals("OPTIONS")) {
        response.setStatus(HttpServletResponse.SC_ACCEPTED);
        return;/*from   w  w  w  . jav a 2  s. com*/
    }

    try {
        if (user == null) {
            if (this.authenticate(request)) {
                chain.doFilter(request, response);
                if (response.isCommitted()) {
                    this.authenticationService.logout();
                }
            } else {
                this.challengeClient(request, response);
            }
        } else {
            chain.doFilter(request, response);
        }
    } finally {
        if (session == null) {
            session = request.getSession(false);
            if (session != null) {
                session.invalidate();
            }
        }
    }
}

From source file:net.java.dev.weblets.impl.servlets.WebletResponseImpl.java

public void setStatus(int statusCode) {
    switch (statusCode) {
    case WebletResponse.SC_ACCEPTED:
        setResponseStatus(HttpServletResponse.SC_ACCEPTED);
        break;//from  w  w w.  j av a  2 s .  com
    case WebletResponse.SC_NOT_FOUND:
        setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
        break;
    case WebletResponse.SC_NOT_MODIFIED:
        setResponseStatus(HttpServletResponse.SC_NOT_MODIFIED);
        break;
    default:
        throw new IllegalArgumentException();
    }
}

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 {/*from   www . ja  v a2 s  .  c om*/
        httpServletResponse.setStatus(HttpServletResponse.SC_NO_CONTENT);
    }
}

From source file:com.cognifide.cq.cache.plugins.statistics.action.ShowKeysAction.java

private void readKeysFrom(String cacheName) throws IOException {
    String markup = generateMarkupForKeys(cacheHolder.getKeysFor(cacheName));
    response.getWriter().write(markup);/*from   w w w  .  ja v a2 s.  com*/
    response.setStatus(HttpServletResponse.SC_ACCEPTED);
    response.setContentType(StatisticsAction.TEXT_HTML);
    response.setCharacterEncoding(StatisticsAction.UTF_8);
}

From source file:org.opendatakit.aggregate.task.gae.servlet.WatchdogServlet.java

/**
 * Handler for HTTP Get request to run watchdog task
 *
 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse)
 *//* w w  w .j  a  v a 2  s.  c  o  m*/
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    CallingContext cc = ContextFactory.getCallingContext(this, req);
    cc.setAsDaemon(true);

    logger.info("Beginning servlet processing");
    WatchdogWorkerImpl worker = new WatchdogWorkerImpl();
    try {
        worker.checkTasks(cc);
        logger.info("ending successful servlet processing");
        resp.setStatus(HttpServletResponse.SC_ACCEPTED);
    } catch (ODKExternalServiceException e) {
        e.printStackTrace();
        logger.error(e.toString());
        resp.sendError(HttpServletResponse.SC_BAD_GATEWAY, e.toString());
        return;
    } catch (ODKFormNotFoundException e) {
        e.printStackTrace();
        logger.error(e.toString());
        odkIdNotFoundError(resp);
        return;
    } catch (ODKDatastoreException e) {
        e.printStackTrace();
        logger.error(e.toString());
        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());
        return;
    } catch (ODKIncompleteSubmissionData e) {
        e.printStackTrace();
        logger.error(e.toString());
        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());
        return;
    }
}

From source file:org.clothocad.phagebook.controllers.AutoCompleteController.java

@RequestMapping(value = "/autoComplete", method = RequestMethod.GET)
protected void autoComplete(@RequestParam Map<String, String> params, HttpServletResponse response)
        throws ServletException, IOException {

    //I WILL RETURN THE MAP AS A JSON OBJECT.. it is client side's issue to parse all data for what they need!
    //they could check over there if the schema matches what they are querying for and so i can do this generically!
    //user should be logged in so I will log in as that user.
    String query = params.get("query") != null ? params.get("query") : "";
    boolean isValid = false;
    System.out.println("Query is: " + query);
    if (!query.equals("")) {
        isValid = true;//  w ww .j a  v a 2 s  .  c  o  m
    }

    if (isValid) {
        ClothoConnection conn = new ClothoConnection(Args.clothoLocation);
        Clotho clothoObject = new Clotho(conn);
        //TODO: we need to have an authentication token at some point
        String username = this.backendPhagebookUser;
        String password = this.backendPhagebookPassword;
        Map loginMap = new HashMap();
        loginMap.put("username", username);
        loginMap.put("credentials", password);

        clothoObject.login(loginMap);

        JSONArray replies = (JSONArray) clothoObject.autocomplete(query);
        conn.closeConnection();
        response.setStatus(HttpServletResponse.SC_ACCEPTED);
        response.setContentType("application/json");
        PrintWriter out = response.getWriter();
        out.print(replies);
        out.flush();
        out.close();

        clothoObject.logout();

    }
    response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    response.setContentType("application/json");
    JSONObject reply = new JSONObject();
    reply.put("message", "Auto Complete requires a query parameter");
    PrintWriter out = response.getWriter();
    out.print(reply);
    out.flush();
    out.close();

}

From source file:org.apache.asterix.api.http.servlet.ShutdownAPIServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    response.setContentType("application/json");
    response.setCharacterEncoding("utf-8");

    PrintWriter out = response.getWriter();
    OutputFormat format = OutputFormat.JSON;
    String accept = request.getHeader("Accept");
    if ((accept == null) || (accept.contains("application/x-adm"))) {
        format = OutputFormat.ADM;/*from w  w w .  jav a 2  s  . c  o  m*/
    } else if (accept.contains("application/json")) {
        format = OutputFormat.JSON;
    }
    StringWriter sw = new StringWriter();
    IOUtils.copy(request.getInputStream(), sw, StandardCharsets.UTF_8.name());

    ServletContext context = getServletContext();
    IHyracksClientConnection hcc;
    try {
        synchronized (context) {
            hcc = (IHyracksClientConnection) context.getAttribute(HYRACKS_CONNECTION_ATTR);
            response.setStatus(HttpServletResponse.SC_ACCEPTED);
            hcc.stopCluster();
        }
    } catch (Exception e) {
        GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, e.getMessage(), e);
        ResultUtils.apiErrorHandler(out, e);
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:org.iplantc.phyloviewer.viewer.server.ParseTreeService.java

/**
 * Accepts a tree for parsing and storage, and returns a URL to view the tree.  
 * May return before the tree has finished importing.
 * /*from w  w w  . j  a v a  2  s  . c o  m*/
 * @param request has the following parameters:
 * <pre>
 * newickData or nexml: a string representing the tree data
 * name (optional): the label that is given to the newick tree. 
 *    Nexml documents already have an attribute for tree label, so they don't use this parameter.
 * </pre>
 * 
 * @param response contains the URL to view the tree
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) {
    Logger.getLogger("org.iplantc.phyloviewer").log(Level.FINE, "Received tree post request");

    PrintWriter writer = getWriter(response);

    Map<String, String[]> parameters = null;
    try {
        Logger.getLogger("org.iplantc.phyloviewer").log(Level.FINE, "Reading request parameters");
        parameters = getParameters(request);
    } catch (FileUploadException e) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        writer.println(e.getMessage());
        writer.flush();
        writer.close();
        return;
    }

    try {
        String id = parseTree.saveTree(parameters);

        if (id != null) {
            Logger.getLogger("org.iplantc.phyloviewer").log(Level.FINE, "Returning response");
            response.setStatus(HttpServletResponse.SC_ACCEPTED);

            String viewURL = getViewURL(id, request);
            response.setHeader("Location", viewURL);
            writer.println(viewURL);
        } else {
            Logger.getLogger("org.iplantc.phyloviewer").log(Level.FINE, "No trees found. Returning response");
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            writer.println("Bad request: No tree data found.");
        }
    } catch (ParserException e) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        writer.println(e.getMessage());
        e.printStackTrace(writer);
    } catch (SAXException e) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        writer.println(e.getMessage());
        e.printStackTrace(writer);
    } catch (Exception e) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        writer.println(e.getMessage());
        e.printStackTrace(writer);
    }

    writer.flush();
    writer.close();
}

From source file:eu.city4ageproject.delivery.HTTPService.java

/**{@inheritDoc} */
@Override//w  ww . j  ava 2 s  .c o  m
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    if (req.getContentType() != null && req.getContentType().toLowerCase().contains("application/json")
    //            && req.getCharacterEncoding() != null
    //            && req.getCharacterEncoding().toLowerCase().contains("utf")
    //            && req.getCharacterEncoding().toLowerCase().contains("8")
    ) {
        ServletInputStream is = req.getInputStream();
        String request = IOUtils.toString(is, "UTF-8");
        try {
            DeliveryRequest drequest = gsonBuilder.create().fromJson(request, DeliveryRequest.class);
            if (drequest.getPilotID() != null && !drequest.getPilotID().isEmpty()
                    && drequest.getUserID() != null && !drequest.getUserID().isEmpty()
                    && drequest.getIntervention() != null) {
                //connect to uAAL
                if (delivery.sendIntervention(drequest))
                    resp.setStatus(HttpServletResponse.SC_ACCEPTED);
                else
                    resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                return;
            }

            //TODO get parameters into the Actual delivery
        } catch (JsonSyntaxException e) {
            e.printStackTrace();

        }
        resp.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE);
        PrintStream ps = new PrintStream(resp.getOutputStream());
        ps.print("Request not acceptable.\n cotnent is not compliant to schema.");
    } else {
        resp.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE);
        resp.setContentType("text/html");
        resp.setCharacterEncoding("UTF-8");
        PrintStream ps = new PrintStream(resp.getOutputStream());
        ps.print("Request not acceptable.<br> " + "Content-Type: application/json <br>"
        //               +" Content-Encoding: UTF-8"
        );
    }
}

From source file:org.piraso.web.base.PirasoResponseWrapperTest.java

@Test
public void testSetStatus() throws Exception {
    wrapper.setStatus(HttpServletResponse.SC_ACCEPTED);
    assertEquals(HttpServletResponse.SC_ACCEPTED, entry.getStatus());

    wrapper.setStatus(HttpServletResponse.SC_FOUND, "found");
    assertEquals(HttpServletResponse.SC_FOUND, entry.getStatus());
    assertEquals("found", entry.getStatusReason());
}