List of usage examples for javax.servlet.http HttpServletResponse SC_ACCEPTED
int SC_ACCEPTED
To view the source code for javax.servlet.http HttpServletResponse SC_ACCEPTED.
Click Source Link
From source file:org.jbpm.designer.filter.DesignerBasicAuthSecurityFilter.java
@Override public void challengeClient(HttpServletRequest request, HttpServletResponse response) throws IOException { // allow OPTIONS preflight requests if (request.getMethod().equals("OPTIONS")) { response.setStatus(HttpServletResponse.SC_ACCEPTED); } else {//from w w w . ja v a 2s . co m super.challengeClient(request, response); } }
From source file:org.apache.axis2.transport.http.util.SOAPUtil.java
/** * Handle SOAP Messages//from w w w . j a v a 2 s.com * * @param msgContext * @param request * @param response * @throws AxisFault */ public boolean processPostRequest(MessageContext msgContext, HttpServletRequest request, HttpServletResponse response) throws AxisFault { try { response.setHeader("Content-Type", "text/html"); if (server(msgContext) != null) { response.setHeader("Server", server(msgContext)); } String soapAction = request.getHeader(HTTPConstants.HEADER_SOAP_ACTION); msgContext.setProperty(Constants.Configuration.CONTENT_TYPE, request.getContentType()); InvocationResponse ir = HTTPTransportUtils.processHTTPPostRequest(msgContext, request.getInputStream(), response.getOutputStream(), request.getContentType(), soapAction, request.getRequestURL().toString()); response.setContentType( "text/xml; charset=" + msgContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING)); if (!TransportUtils.isResponseWritten(msgContext)) { Integer statusCode = (Integer) msgContext.getProperty(Constants.RESPONSE_CODE); if (statusCode != null) { response.setStatus(statusCode.intValue()); } else { response.setStatus(HttpServletResponse.SC_ACCEPTED); } } boolean closeReader = true; Parameter parameter = msgContext.getConfigurationContext().getAxisConfiguration() .getParameter("axis2.close.reader"); if (parameter != null) { closeReader = JavaUtils.isTrueExplicitly(parameter.getValue()); } if (closeReader && !InvocationResponse.SUSPEND.equals(ir)) { try { ((StAXBuilder) msgContext.getEnvelope().getBuilder()).close(); } catch (Exception e) { log.debug(e); } } return true; } catch (AxisFault axisFault) { throw axisFault; } catch (IOException ioException) { throw AxisFault.makeFault(ioException); } }
From source file:org.appcelerator.transport.AjaxServiceTransportServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // make sure we have a session req.getSession();//www .j a v a 2s .c om // just return empty session resp.setHeader("Content-Length", "0"); resp.setContentType("text/plain;charset=UTF-8"); resp.setStatus(HttpServletResponse.SC_ACCEPTED); return; }
From source file:com.rmn.qa.servlet.BmpServlet.java
/** * Stops and cleans up the proxy.//w ww . ja va 2 s .c o m * * Content should contain the uuid in a json content * * expects a parameter passed in query string of "uuid" * * @return Responds with a 202 Accepted if the proxy is removed or does not exist. * @return Responds with a 400 Bad Request if the uuid is not specified or there is no reason to create the proxy * (see above). */ @Override protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String uuid = request.getParameter("uuid"); if (StringUtils.isBlank(uuid)) { log.error("uuid not present"); response.sendError(HttpServletResponse.SC_BAD_REQUEST, "uuid must be specified in json"); return; } log.info("Stopping proxy with uuid " + uuid); BmpProxyRegistry.getInstance().stopProxy(uuid); response.setStatus(HttpServletResponse.SC_ACCEPTED); }
From source file:org.apache.servicemix.http.security.HttpSecurityTest.java
protected void testAuthenticate(final String username, final String password) throws Exception { HttpClient client = new HttpClient(); client.getState().setCredentials(new AuthScope(AuthScope.ANY), new UsernamePasswordCredentials(username, password)); PostMethod method = new PostMethod("http://localhost:8192/Service/"); try {/* ww w .ja v a2 s . co m*/ method.setDoAuthentication(true); method.setRequestEntity(new StringRequestEntity("<hello>world</hello>")); int state = client.executeMethod(method); FileUtil.copyInputStream(method.getResponseBodyAsStream(), System.err); if (state != HttpServletResponse.SC_OK && state != HttpServletResponse.SC_ACCEPTED) { throw new IllegalStateException("Http status: " + state); } } finally { method.releaseConnection(); } }
From source file:org.eclipse.orion.internal.server.servlets.task.TaskJobHandler.java
/** * Schedules {@link TaskJob} and handles response. If job lasts more than {@link this#WAIT_TIME} * handler starts a task and returns 202 (Accepted) response with task details. If job finishes sooner the * response if immediately returned filled with {@link TaskJob#getResult()}, if result is OK, than only * {@link ServerStatus#getJsonData()} is returned, if result is OK and it is not an instance of {@link ServerStatus} * than {@link TaskJob#getFinalResult()} is returned as a response content. * //w w w .jav a 2 s . co m * @param request * @param response * @param job Job that should be handled as a task. * @param statusHandler status handler to handle error statuses. * @return <code>true</code> if job was handled properly. * @throws IOException * @throws ServletException * @throws URISyntaxException * @throws JSONException */ public static boolean handleTaskJob(HttpServletRequest request, HttpServletResponse response, TaskJob job, ServletResourceHandler<IStatus> statusHandler) throws IOException, ServletException, URISyntaxException, JSONException { job.schedule(); final Object jobIsDone = new Object(); final JobChangeAdapter jobListener = new JobChangeAdapter() { public void done(IJobChangeEvent event) { synchronized (jobIsDone) { jobIsDone.notify(); } } }; job.addJobChangeListener(jobListener); try { synchronized (jobIsDone) { if (job.getState() != Job.NONE) { jobIsDone.wait(WAIT_TIME); } } } catch (InterruptedException e) { } job.removeJobChangeListener(jobListener); if (job.getState() == Job.NONE || job.getRealResult() != null) { return writeResult(request, response, job, statusHandler); } else { TaskInfo task = job.startTask(); JSONObject result = task.toJSON(); URI taskLocation = createTaskLocation(ServletResourceHandler.getURI(request), task.getId(), task.isKeep()); result.put(ProtocolConstants.KEY_LOCATION, taskLocation); if (!task.isRunning()) { job.removeTask(); // Task is not used, we may remove it return writeResult(request, response, job, statusHandler); } response.setHeader(ProtocolConstants.HEADER_LOCATION, ServletResourceHandler.resovleOrionURI(request, taskLocation).toString()); OrionServlet.writeJSONResponse(request, response, result); response.setStatus(HttpServletResponse.SC_ACCEPTED); return true; } }
From source file:org.opendatakit.aggregate.task.gae.servlet.UploadSubmissionsTaskServlet.java
/** * Handler for HTTP Get request to create xform upload page * * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse) */// w w w .j a va 2s . co m @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { CallingContext cc = ContextFactory.getCallingContext(this, req); cc.setAsDaemon(true); // get parameter String fscUri = getParameter(req, ExternalServiceConsts.FSC_URI_PARAM); if (fscUri == null) { logger.error("Missing " + ExternalServiceConsts.FSC_URI_PARAM + " key"); errorMissingParam(resp); return; } logger.info("Beginning servlet processing"); FormServiceCursor fsc; try { fsc = FormServiceCursor.getFormServiceCursor(fscUri, cc); } catch (ODKEntityNotFoundException e) { // TODO: fix bug we should not be generating tasks for fsc that don't // exist // however not critical bug as execution path dies with this try/catch logger.error("BUG: we generated an task for a form service cursor that didn't exist" + e.toString()); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); return; } catch (ODKOverQuotaException e) { logger.error("Over quota." + e.toString()); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); return; } catch (ODKDatastoreException e) { e.printStackTrace(); logger.error("Datastore failure." + e.toString()); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); return; } // determine whether we are running on a backend or not... BackendService bes = BackendServiceFactory.getBackendService(); boolean isBackend = (bes.getCurrentBackend() != null); logger.info("Request is running on " + (isBackend ? "backend" : "frontend")); try { UploadSubmissionsWorkerImpl worker = new UploadSubmissionsWorkerImpl(fsc, isBackend, cc); worker.uploadAllSubmissions(); logger.info("ending successful servlet processing"); resp.setStatus(HttpServletResponse.SC_ACCEPTED); } catch (ODKEntityNotFoundException e) { e.printStackTrace(); logger.error(e.toString()); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); return; } catch (ODKExternalServiceException e) { logger.error(e.toString()); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); return; } catch (ODKFormNotFoundException e) { logger.error(e.toString()); odkIdNotFoundError(resp); return; } catch (Exception e) { e.printStackTrace(); logger.error(e.toString()); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); return; } }
From source file:com.imaginary.home.device.hue.HueMethod.java
public void delete(@Nonnull String resource) throws HueException { Logger std = Hue.getLogger(HueMethod.class); Logger wire = Hue.getWireLogger(HueMethod.class); if (std.isTraceEnabled()) { std.trace("enter - " + HueMethod.class.getName() + ".delete(" + resource + ")"); }//from ww w .java2s . c o m if (wire.isDebugEnabled()) { wire.debug(""); wire.debug(">>> [DELETE (" + (new Date()) + ")] -> " + hue.getAPIEndpoint() + resource); } try { HttpClient client = getClient(); HttpDelete method = new HttpDelete(hue.getAPIEndpoint() + resource); method.addHeader("Content-Type", "application/json"); if (wire.isDebugEnabled()) { wire.debug(method.getRequestLine().toString()); for (Header header : method.getAllHeaders()) { wire.debug(header.getName() + ": " + header.getValue()); } wire.debug(""); } HttpResponse response; StatusLine status; try { response = client.execute(method); status = response.getStatusLine(); } catch (IOException e) { std.error("DELETE: Failed to execute HTTP request due to a cloud I/O error: " + e.getMessage()); if (std.isTraceEnabled()) { e.printStackTrace(); } throw new HueException(e); } if (std.isDebugEnabled()) { std.debug("DELETE: HTTP Status " + status); } Header[] headers = response.getAllHeaders(); if (wire.isDebugEnabled()) { wire.debug(status.toString()); for (Header h : headers) { if (h.getValue() != null) { wire.debug(h.getName() + ": " + h.getValue().trim()); } else { wire.debug(h.getName() + ":"); } } wire.debug(""); } if (status.getStatusCode() != HttpServletResponse.SC_OK && status.getStatusCode() != HttpServletResponse.SC_NO_CONTENT && status.getStatusCode() != HttpServletResponse.SC_ACCEPTED) { std.error("DELETE: Expected OK or NO_CONTENT or ACCEPTED for DELETE request, got " + status.getStatusCode()); HttpEntity entity = response.getEntity(); if (entity == null) { throw new HueException(status.getStatusCode(), "An error was returned without explanation"); } String body; try { body = EntityUtils.toString(entity); } catch (IOException e) { throw new HueException(status.getStatusCode(), e.getMessage()); } if (wire.isDebugEnabled()) { wire.debug(body); } wire.debug(""); throw new HueException(status.getStatusCode(), body); } } finally { if (std.isTraceEnabled()) { std.trace("exit - " + HueMethod.class.getName() + ".delete()"); } if (wire.isDebugEnabled()) { wire.debug("<<< [DELETE (" + (new Date()) + ")] -> " + hue.getAPIEndpoint() + resource + " <--------------------------------------------------------------------------------------"); wire.debug(""); } } }
From source file:org.apache.servicemix.http.security.HttpSecurityTest.java
public void testWSSec() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); FileUtil.copyInputStream(getClass().getResourceAsStream("request.xml"), out); String request = out.toString(); HttpClient client = new HttpClient(); PostMethod method = new PostMethod("http://localhost:8192/WSSec/"); try {//from w ww .j a v a2 s.c o m method.setDoAuthentication(true); method.setRequestEntity(new StringRequestEntity(request)); int state = client.executeMethod(method); String str = method.getResponseBodyAsString(); log.info(str); if (state != HttpServletResponse.SC_OK && state != HttpServletResponse.SC_ACCEPTED) { throw new IllegalStateException("Http status: " + state); } } finally { method.releaseConnection(); } }
From source file:org.springsource.ide.eclipse.boot.maven.analyzer.server.AetherialController.java
/** * Helper method to send a 'Future' as a response to the client. * If the future is 'done' actual content (or error) is sent. Otherwise * a 'try later' result is sent instead. *//* w ww. j av a2 s . co m*/ private void sendResponse(HttpServletResponse resp, Future<byte[]> result) throws IOException, UnsupportedEncodingException { if (!result.isDone()) { //Return something quickly to let client know we are working on their request but // it may be a while. resp.setStatus(HttpServletResponse.SC_ACCEPTED); resp.setContentType("text/plain"); resp.setCharacterEncoding("utf8"); resp.getWriter().println("I'm working on it... ask me again later"); } else { //Done: could be a actual result or an error try { byte[] resultData = result.get(); //this will throw in case of an error in processing. resp.setStatus(HttpServletResponse.SC_OK); //resp.setContentType(contentType); //resp.setCharacterEncoding("utf8"); resp.getOutputStream().write(resultData); } catch (Exception e) { resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); resp.setContentType("text/plain"); resp.setCharacterEncoding("utf8"); e.printStackTrace(new PrintStream(resp.getOutputStream(), true, "utf8")); } } }