diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java index 9ba195d55a6..f943fb47ab9 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java @@ -28,6 +28,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentMap; +import javax.servlet.AsyncContext; import javax.servlet.DispatcherType; import javax.servlet.Filter; import javax.servlet.FilterChain; @@ -51,7 +52,6 @@ import org.eclipse.jetty.io.RuntimeIOException; import org.eclipse.jetty.security.IdentityService; import org.eclipse.jetty.security.SecurityHandler; import org.eclipse.jetty.server.AbstractHttpConnection; -import org.eclipse.jetty.server.AsyncContext; import org.eclipse.jetty.server.Dispatcher; import org.eclipse.jetty.server.AbstractHttpConnection; import org.eclipse.jetty.server.Request; diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextTest.java index b4d4e40de34..36786df26bd 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextTest.java @@ -4,6 +4,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.StringReader; +import javax.servlet.AsyncContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -11,8 +12,6 @@ import javax.servlet.http.HttpServletResponse; import junit.framework.Assert; -import org.eclipse.jetty.continuation.ContinuationSupport; -import org.eclipse.jetty.server.AsyncContext; import org.eclipse.jetty.server.AsyncContinuation; import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Handler; @@ -170,27 +169,17 @@ public class AsyncContextTest protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - AsyncContinuation continuation = (AsyncContinuation) ContinuationSupport.getContinuation(request); - if (request.getParameter("dispatch") != null) - { - continuation.suspend(); - continuation.dispatch("/servletPath2"); - //AsyncContext asyncContext = request.startAsync(request,response); + { + AsyncContext asyncContext = request.startAsync(request,response); + asyncContext.dispatch("/servletPath2"); } else { response.getOutputStream().print("doGet:getServletPath:" + request.getServletPath() + "\n"); - - continuation.suspend(); - - //AsyncContext asyncContext = request.startAsync(request,response); - - response.getOutputStream().print("doGet:async:getServletPath:" + ((HttpServletRequest)continuation.getRequest()).getServletPath() + "\n"); - - Runnable runable = new AsyncRunnable(continuation); - new Thread(runable).start(); - //asyncContext.start(new AsyncRunnable(asyncContext)); + AsyncContext asyncContext = request.startAsync(request,response); + response.getOutputStream().print("doGet:async:getServletPath:" + ((HttpServletRequest)asyncContext.getRequest()).getServletPath() + "\n"); + asyncContext.start(new AsyncRunnable(asyncContext)); } return; @@ -203,17 +192,10 @@ public class AsyncContextTest protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - AsyncContinuation continuation = (AsyncContinuation) ContinuationSupport.getContinuation(request); - response.getOutputStream().print("doGet:getServletPath:" + request.getServletPath() + "\n"); - - continuation.suspend(); - //AsyncContext asyncContext = request.startAsync(request, response); - - response.getOutputStream().print("doGet:async:getServletPath:" + ((HttpServletRequest)continuation.getRequest()).getServletPath() + "\n"); - Runnable runable = new AsyncRunnable(continuation); - new Thread(runable).start(); - //asyncContext.start(new AsyncRunnable(asyncContext)); + AsyncContext asyncContext = request.startAsync(request, response); + response.getOutputStream().print("doGet:async:getServletPath:" + ((HttpServletRequest)asyncContext.getRequest()).getServletPath() + "\n"); + asyncContext.start(new AsyncRunnable(asyncContext)); return; } @@ -221,32 +203,33 @@ public class AsyncContextTest private class AsyncRunnable implements Runnable { - private AsyncContinuation _continuation; + private AsyncContext _context; - public AsyncRunnable(AsyncContinuation continuation) + public AsyncRunnable(AsyncContext context) { - _continuation = continuation; + _context = context; } + @Override public void run() { - HttpServletRequest req = (HttpServletRequest)_continuation.getRequest(); + HttpServletRequest req = (HttpServletRequest)_context.getRequest(); try { - _continuation.getResponse().getOutputStream().print("async:run:" + req.getServletPath() + "\n"); - _continuation.getResponse().getOutputStream().print("async:run:attr:servletPath:" + req.getAttribute(AsyncContext.ASYNC_SERVLET_PATH) + "\n"); - _continuation.getResponse().getOutputStream().print("async:run:attr:pathInfo:" + req.getAttribute(AsyncContext.ASYNC_PATH_INFO) + "\n"); - _continuation.getResponse().getOutputStream().print("async:run:attr:queryString:" + req.getAttribute(AsyncContext.ASYNC_QUERY_STRING) + "\n"); - _continuation.getResponse().getOutputStream().print("async:run:attr:contextPath:" + req.getAttribute(AsyncContext.ASYNC_CONTEXT_PATH) + "\n"); - _continuation.getResponse().getOutputStream().print("async:run:attr:requestURI:" + req.getAttribute(AsyncContext.ASYNC_REQUEST_URI) + "\n"); + _context.getResponse().getOutputStream().print("async:run:" + req.getServletPath() + "\n"); + _context.getResponse().getOutputStream().print("async:run:attr:servletPath:" + req.getAttribute(AsyncContext.ASYNC_SERVLET_PATH) + "\n"); + _context.getResponse().getOutputStream().print("async:run:attr:pathInfo:" + req.getAttribute(AsyncContext.ASYNC_PATH_INFO) + "\n"); + _context.getResponse().getOutputStream().print("async:run:attr:queryString:" + req.getAttribute(AsyncContext.ASYNC_QUERY_STRING) + "\n"); + _context.getResponse().getOutputStream().print("async:run:attr:contextPath:" + req.getAttribute(AsyncContext.ASYNC_CONTEXT_PATH) + "\n"); + _context.getResponse().getOutputStream().print("async:run:attr:requestURI:" + req.getAttribute(AsyncContext.ASYNC_REQUEST_URI) + "\n"); } catch (IOException e) { e.printStackTrace(); } - _continuation.complete(); + _context.complete(); } }