本文整理汇总了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);
}
}
示例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();
}
}
示例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 */}
}
}
示例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();
}
}
示例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);
}
示例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();
}
示例7: compelete
import javax.servlet.AsyncContext; //导入方法依赖的package包/类
public static void compelete(AsyncContext asyncContext) {
try {
asyncContext.complete();
} catch (Exception e) {
LOGGER.error("unexpect error", e);
}
}
示例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) {
}
}
示例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();
}