當前位置: 首頁>>代碼示例>>Java>>正文


Java AsyncContext.complete方法代碼示例

本文整理匯總了Java中javax.servlet.AsyncContext.complete方法的典型用法代碼示例。如果您正苦於以下問題:Java AsyncContext.complete方法的具體用法?Java AsyncContext.complete怎麽用?Java AsyncContext.complete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.servlet.AsyncContext的用法示例。


在下文中一共展示了AsyncContext.complete方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doGet

import javax.servlet.AsyncContext; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    AsyncContext ac = req.startAsync();
    // Quick and dirty. Sufficient for this test but ignores lots of
    // edge cases.
    String target = null;
    if (dispatchPath != null) {
        target = req.getServletPath();
        int lastSlash = target.lastIndexOf('/');
        target = target.substring(0, lastSlash + 1);
        if (encodePath) {
            target = URLEncoder.DEFAULT.encode(target, "UTF-8");
        }
        target += dispatchPath;
    }
    try {
        ac.dispatch(target);
    } catch (UnsupportedOperationException uoe) {
        ac.complete();
        resp.setContentType("text/plain");
        resp.setCharacterEncoding("UTF-8");
        resp.getWriter().print(NULL);
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:27,代碼來源:TestApplicationContextGetRequestDispatcher.java

示例2: doGet

import javax.servlet.AsyncContext; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, final HttpServletResponse resp)
        throws ServletException, IOException {

    final AsyncContext actxt = req.startAsync();
    actxt.setTimeout(TIMEOUT);
    if (threaded) {
        actxt.start(new Runnable() {
            @Override
            public void run() {
                try {
                    resp.sendError(status, ERROR_MESSAGE);
                    actxt.complete();
                } catch (IOException e) {
                    // Ignore
                }
            }
        });
    } else {
        resp.sendError(status, ERROR_MESSAGE);
        actxt.complete();
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:24,代碼來源:TestAsyncContextImpl.java

示例3: writeStock

import javax.servlet.AsyncContext; //導入方法依賴的package包/類
public void writeStock(AsyncContext actx, Stock stock) {
    HttpServletResponse response = (HttpServletResponse)actx.getResponse();
    try {
        PrintWriter writer = response.getWriter();
        writer.write("STOCK#");//make client parsing easier
        writer.write(stock.getSymbol());
        writer.write("#");
        writer.write(stock.getValueAsString());
        writer.write("#");
        writer.write(stock.getLastChangeAsString());
        writer.write("#");
        writer.write(String.valueOf(stock.getCnt()));
        writer.write("\n");
        writer.flush();
        response.flushBuffer();
    }catch (IOException x) {
        try {actx.complete();}catch (Exception ignore){/* Ignore */}
    }
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:20,代碼來源:AsyncStockServlet.java

示例4: onProxyResponseFailure

import javax.servlet.AsyncContext; //導入方法依賴的package包/類
@Override
protected void onProxyResponseFailure(final HttpServletRequest clientRequest, final HttpServletResponse proxyResponse,
		final Response serverResponse, final Throwable failure) {
	_log.warn(failure.toString());

	if (proxyResponse.isCommitted()) {
		// Parent behavior
		super.onProxyResponseFailure(clientRequest, proxyResponse, serverResponse, failure);
	} else {
		proxyResponse.resetBuffer();
		if (failure instanceof TimeoutException) {
			proxyResponse.setStatus(HttpServletResponse.SC_GATEWAY_TIMEOUT);
		} else {

			// Unavailable business server as JSON response
			proxyResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
			proxyResponse.setContentType("application/json");
			try {
				proxyResponse.getOutputStream().write("{\"code\":\"business-down\"}".getBytes(StandardCharsets.UTF_8));
			} catch (final IOException ioe) {
				_log.warn("Broken proxy stream", ioe);
			}
		}
		proxyResponse.setHeader(HttpHeader.CONNECTION.asString(), HttpHeaderValue.CLOSE.asString());
		final AsyncContext asyncContext = clientRequest.getAsyncContext();
		asyncContext.complete();
	}
}
 
開發者ID:ligoj,項目名稱:bootstrap,代碼行數:29,代碼來源:BackendProxyServlet.java

示例5: doDispatch

import javax.servlet.AsyncContext; //導入方法依賴的package包/類
@Override
protected void doDispatch(final HttpServletRequest request, final HttpServletResponse response) throws Exception {

    final AsyncContext ac = request.startAsync(request, response);

    ac.setTimeout(TIME_OUT);

    // FIXME: convert to Lambda
    FutureTask task = new FutureTask(new Runnable() {

        @Override
        public void run() {
            try {
                logger.debug("Dispatching request " + request);
                AsyncDispatcherServlet.super.doDispatch(request, response);
                logger.debug("doDispatch returned from processing request " + request);
                ac.complete();
            } catch (Exception ex) {
                logger.error("Error in async request", ex);
            }
        }
    }, null);

    ac.addListener(new AsyncDispatcherServletListener(task));
    exececutor.execute(task);
}
 
開發者ID:PacktPublishing,項目名稱:Spring-Security-Third-Edition,代碼行數:27,代碼來源:AsyncDispatcherServlet.java

示例6: doGet

import javax.servlet.AsyncContext; //導入方法依賴的package包/類
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    final AsyncContext asyncContext = request.startAsync(request, response);
    response.setStatus(204);
    asyncContext.complete();
}
 
開發者ID:opentracing-contrib,項目名稱:java-web-servlet-filter,代碼行數:9,代碼來源:AbstractJettyTest.java

示例7: compelete

import javax.servlet.AsyncContext; //導入方法依賴的package包/類
public static void compelete(AsyncContext asyncContext) {
    try {
        asyncContext.complete();
    } catch (Exception e) {
        LOGGER.error("unexpect error", e);
    }
}
 
開發者ID:wxz1211,項目名稱:dooo,代碼行數:8,代碼來源:AsyncContextUtils.java

示例8: writeResult

import javax.servlet.AsyncContext; //導入方法依賴的package包/類
private void writeResult(AsyncContext ctx, String result) {
    try {
        ctx.getResponse().getWriter().append(result);
        ctx.complete();
    } catch (IOException e) {

    }
}
 
開發者ID:cschneider,項目名稱:reactive-components,代碼行數:9,代碼來源:TestServlet.java

示例9: doGet

import javax.servlet.AsyncContext; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    resp.setContentType("text/plain");
    resp.setCharacterEncoding("UTF-8");

    final OutputStream os = resp.getOutputStream();

    final AsyncContext asyncCtxt = req.startAsync();
    asyncCtxt.setTimeout(3000);

    t = new Thread(new Runnable() {

        @Override
        public void run() {
            for (int i = 0; i < 20; i++) {
                try {
                    // Some tests depend on this write failing (e.g.
                    // because the client has gone away). In some cases
                    // there may be a large (ish) buffer to fill before
                    // the write fails.
                    for (int j = 0 ; j < 8; j++) {
                        os.write(BYTES_8K);
                    }
                    os.flush();
                    Thread.sleep(1000);
                } catch (Exception e) {
                    log.info("Exception caught " + e);
                    try {
                        // Note if request times out before this
                        // exception is thrown and the complete call
                        // below is made, the complete call below will
                        // fail since the timeout will have completed
                        // the request.
                        asyncCtxt.complete();
                        break;
                    } finally {
                        completed = true;
                    }
                }
            }
        }
    });
    t.setName("testBug54928");
    t.start();
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:48,代碼來源:TestCoyoteAdapter.java


注:本文中的javax.servlet.AsyncContext.complete方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。