use of javax.servlet.AsyncContext in project tomee by apache.
the class ConcurrencyServlet method service.
@Override
protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
final AsyncContext asyncCtx = req.startAsync();
execService.execute(new Runnable() {
@Override
public void run() {
try {
req.login("test", "secret");
resp.getWriter().println(user.getUser());
} catch (final Exception e) {
try {
e.printStackTrace(resp.getWriter());
} catch (final IOException e1) {
throw new IllegalStateException(e);
}
} finally {
asyncCtx.complete();
}
}
});
}
use of javax.servlet.AsyncContext in project AngularBeans by bessemHmidi.
the class SockJsServlet method service.
@Override
protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
res.setHeader("Access-Control-Allow-Origin", "true");
log.log(Level.FINE, "SockJsServlet#service for {0} {1}", new Object[] { req.getMethod(), req.getPathInfo() });
AsyncContext asyncContext = req.startAsync();
// no timeout
asyncContext.setTimeout(0);
SockJsServletRequest sockJsReq = new SockJsServletRequest(req);
SockJsServletResponse sockJsRes = new SockJsServletResponse(res, asyncContext);
try {
sockJsServer.dispatch(sockJsReq, sockJsRes);
} catch (SockJsException ex) {
throw new ServletException("Error during SockJS request:", ex);
}
if ("application/x-www-form-urlencoded".equals(req.getHeader("Content-Type"))) {
// Let the servlet parse data and just pretend like we did
sockJsReq.onAllDataRead();
} else if (req.isAsyncStarted()) {
req.getInputStream().setReadListener(sockJsReq);
}
}
use of javax.servlet.AsyncContext in project tomcat by apache.
the class Async1 method service.
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
final AsyncContext actx = req.startAsync();
actx.setTimeout(30 * 1000);
Runnable run = new Runnable() {
@Override
public void run() {
try {
String path = "/jsp/async/async1.jsp";
Thread.currentThread().setName("Async1-Thread");
log.info("Putting AsyncThread to sleep");
Thread.sleep(2 * 1000);
log.info("Dispatching to " + path);
actx.dispatch(path);
} catch (InterruptedException x) {
log.error("Async1", x);
} catch (IllegalStateException x) {
log.error("Async1", x);
}
}
};
Thread t = new Thread(run);
t.start();
}
use of javax.servlet.AsyncContext in project tomcat by apache.
the class Async2 method service.
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
final AsyncContext actx = req.startAsync();
actx.setTimeout(30 * 1000);
Runnable run = new Runnable() {
@Override
public void run() {
try {
Thread.currentThread().setName("Async2-Thread");
log.info("Putting AsyncThread to sleep");
Thread.sleep(2 * 1000);
log.info("Writing data.");
Date date = new Date(System.currentTimeMillis());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
actx.getResponse().getWriter().write("Output from background thread. Time: " + sdf.format(date) + "\n");
actx.complete();
} catch (InterruptedException x) {
log.error("Async2", x);
} catch (IllegalStateException x) {
log.error("Async2", x);
} catch (IOException x) {
log.error("Async2", x);
}
}
};
Thread t = new Thread(run);
t.start();
}
use of javax.servlet.AsyncContext in project tomcat by apache.
the class Async3 method service.
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
final AsyncContext actx = req.startAsync();
actx.setTimeout(30 * 1000);
actx.dispatch("/jsp/async/async3.jsp");
}
Aggregations