use of javax.servlet.AsyncContext in project undertow by undertow-io.
the class AsyncInputStreamServlet method doPost.
@Override
protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
final AsyncContext context = req.startAsync();
final ServletOutputStream outputStream = resp.getOutputStream();
ServletInputStream inputStream = req.getInputStream();
final MyListener listener = new MyListener(outputStream, inputStream, context);
inputStream.setReadListener(listener);
outputStream.setWriteListener(listener);
}
use of javax.servlet.AsyncContext in project undertow by undertow-io.
the class AnotherAsyncServlet method doGet.
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
final AsyncContext ctx = req.startAsync();
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(100);
resp.setContentType("text/plain");
resp.getWriter().write(AnotherAsyncServlet.class.getSimpleName());
ctx.complete();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
t.start();
}
use of javax.servlet.AsyncContext in project undertow by undertow-io.
the class AnotherAsyncServlet method doGet.
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
final AsyncContext ctx = req.startAsync();
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(100);
resp.setContentType("text/plain");
resp.getWriter().write(AnotherAsyncServlet.class.getSimpleName());
ctx.complete();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
t.start();
}
use of javax.servlet.AsyncContext in project undertow by undertow-io.
the class OnCompleteServlet method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
final AsyncContext ctx = req.startAsync();
ctx.addListener(new AsyncListener() {
@Override
public void onComplete(AsyncEvent event) throws IOException {
QUEUE.add("onComplete");
}
@Override
public void onTimeout(AsyncEvent event) throws IOException {
QUEUE.add("onTimeout");
}
@Override
public void onError(AsyncEvent event) throws IOException {
QUEUE.add("onError");
}
@Override
public void onStartAsync(AsyncEvent event) throws IOException {
QUEUE.add("onStartAsync");
}
});
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
ctx.dispatch("/message");
}
});
thread.start();
}
use of javax.servlet.AsyncContext in project undertow by undertow-io.
the class AsyncServlet method doGet.
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
AsyncContext ctx = req.startAsync();
// make the request timeout
ctx.setTimeout(100L);
ctx.addListener(new SimpleAsyncListener());
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(2000L);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
t.start();
}
Aggregations