当前位置: 首页>>代码示例>>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;未经允许,请勿转载。