From c0759a44f178aadf1f356e9a676f878930e61827 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 2 Sep 2010 01:40:52 +0000 Subject: [PATCH] 324260 jetty-6 continuations support complete calls git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2236 7e9141cc-0065-0410-87d8-b60c137991c4 --- VERSION.txt | 1 + .../continuation/ContinuationFilter.java | 1 - .../continuation/Jetty6Continuation.java | 4 +- test-continuation-jetty6/pom.xml | 7 + .../jetty/continuation/TestProxyServer.java | 37 +++++ .../continuation/test/ContinuationBase.java | 137 ++++++++++-------- 6 files changed, 119 insertions(+), 68 deletions(-) create mode 100644 test-continuation-jetty6/src/test/java/org/eclipse/jetty/continuation/TestProxyServer.java diff --git a/VERSION.txt b/VERSION.txt index 3064712b710..0f389b43290 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -20,6 +20,7 @@ jetty-7.2-SNAPSHOT + 323464 IPv6 localhost with no Host header + 324110 Merge async dispatch parameters + 324158 Durable download or Orbit jars + + 324260 Jetty-6 continuations handle complete calls + JETTY-912 added per exchange timeout api + JETTY-1245 Do not use direct buffers with NIO SSL + JETTY-1249 Apply max idle time to all connectors diff --git a/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/ContinuationFilter.java b/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/ContinuationFilter.java index 7ef25ad5515..d565f1b690a 100644 --- a/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/ContinuationFilter.java +++ b/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/ContinuationFilter.java @@ -73,7 +73,6 @@ public class ContinuationFilter implements Filter { if (_filtered) { - Continuation c = (Continuation) request.getAttribute(Continuation.ATTRIBUTE); FilteredContinuation fc; if (_faux && (c==null || !(c instanceof FauxContinuation))) diff --git a/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/Jetty6Continuation.java b/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/Jetty6Continuation.java index 2daab6c93a0..32c7c30ebb1 100644 --- a/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/Jetty6Continuation.java +++ b/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/Jetty6Continuation.java @@ -220,11 +220,9 @@ public class Jetty6Continuation implements ContinuationFilter.FilteredContinuati for (ContinuationListener l: _listeners) l.onTimeout(this); } - - return !_completed; } - return true; + return !_completed; } /* ------------------------------------------------------------ */ diff --git a/test-continuation-jetty6/pom.xml b/test-continuation-jetty6/pom.xml index 46af6eeeb90..98bf1edca86 100644 --- a/test-continuation-jetty6/pom.xml +++ b/test-continuation-jetty6/pom.xml @@ -52,5 +52,12 @@ + + org.eclipse.jetty + jetty-servlets + ${project.version} + jar + test + diff --git a/test-continuation-jetty6/src/test/java/org/eclipse/jetty/continuation/TestProxyServer.java b/test-continuation-jetty6/src/test/java/org/eclipse/jetty/continuation/TestProxyServer.java new file mode 100644 index 00000000000..e2b72fb2ba7 --- /dev/null +++ b/test-continuation-jetty6/src/test/java/org/eclipse/jetty/continuation/TestProxyServer.java @@ -0,0 +1,37 @@ +package org.eclipse.jetty.continuation; + +import org.eclipse.jetty.servlets.ProxyServlet; +import org.mortbay.jetty.Connector; +import org.mortbay.jetty.Server; +import org.mortbay.jetty.nio.SelectChannelConnector; +import org.mortbay.jetty.servlet.Context; +import org.mortbay.jetty.servlet.FilterHolder; +import org.mortbay.jetty.servlet.ServletHandler; +import org.mortbay.jetty.servlet.ServletHolder; + +public class TestProxyServer +{ + public static void main(String[] args) throws Exception + { + Server server = new Server(); + SelectChannelConnector selectChannelConnector = new SelectChannelConnector(); + server.setConnectors(new Connector[]{ selectChannelConnector }); + selectChannelConnector.setPort(8080); + + Context servletContext = new Context(Context.NO_SECURITY|Context.NO_SESSIONS); + server.setHandler(servletContext); + ServletHandler servletHandler=servletContext.getServletHandler(); + + + ServletHolder proxy=new ServletHolder(ProxyServlet.Transparent.class); + servletHandler.addServletWithMapping(proxy,"/ws/*"); + proxy.setInitParameter("ProxyTo","http://www.webtide.com"); + proxy.setInitParameter("Prefix","/ws"); + + FilterHolder filter=servletHandler.addFilterWithMapping(ContinuationFilter.class,"/*",0); + filter.setInitParameter("debug","true"); + + server.start(); + server.join(); + } +} diff --git a/test-continuation/src/main/java/org/eclipse/jetty/continuation/test/ContinuationBase.java b/test-continuation/src/main/java/org/eclipse/jetty/continuation/test/ContinuationBase.java index 0d715bd6079..8508433ad53 100644 --- a/test-continuation/src/main/java/org/eclipse/jetty/continuation/test/ContinuationBase.java +++ b/test-continuation/src/main/java/org/eclipse/jetty/continuation/test/ContinuationBase.java @@ -80,18 +80,22 @@ public abstract class ContinuationBase extends TestCase protected void doSuspendWaitComplete() throws Exception { - String response=process("suspend=200&complete=10",null); + String response=process("suspend=200&complete=50",null); assertContains("COMPLETED",response); + assertContains("history: initial",response); assertNotContains("history: onTimeout",response); assertContains("history: onComplete",response); + assertNotContains("history: !initial",response); } protected void doSuspendComplete() throws Exception { String response=process("suspend=200&complete=0",null); assertContains("COMPLETED",response); + assertContains("history: initial",response); assertNotContains("history: onTimeout",response); assertContains("history: onComplete",response); + assertNotContains("history: !initial",response); } protected void doSuspendWaitResumeSuspendWaitResume() throws Exception @@ -289,6 +293,7 @@ public abstract class ContinuationBase extends TestCase if (continuation.isInitial()) { + ((HttpServletResponse)response).addHeader("history","initial"); if (read_before>0) { byte[] buf=new byte[read_before]; @@ -384,85 +389,89 @@ public abstract class ContinuationBase extends TestCase response.getOutputStream().println("NORMAL\n"); } } - else if (suspend2_for>=0 && request.getAttribute("2nd")==null) + else { - request.setAttribute("2nd","cycle"); - - if (suspend2_for>0) - continuation.setTimeout(suspend2_for); - // continuation.addContinuationListener(__listener); - ((HttpServletResponse)response).addHeader("history","suspend"); - continuation.suspend(response); - - if (complete2_after>0) + ((HttpServletResponse)response).addHeader("history","!initial"); + if (suspend2_for>=0 && request.getAttribute("2nd")==null) { - TimerTask complete = new TimerTask() + request.setAttribute("2nd","cycle"); + + if (suspend2_for>0) + continuation.setTimeout(suspend2_for); + // continuation.addContinuationListener(__listener); + ((HttpServletResponse)response).addHeader("history","suspend"); + continuation.suspend(response); + + if (complete2_after>0) { - @Override - public void run() + TimerTask complete = new TimerTask() { - try + @Override + public void run() { - response.setStatus(200); - response.getOutputStream().println("COMPLETED\n"); - continuation.complete(); - } - catch(Exception e) - { - e.printStackTrace(); + try + { + response.setStatus(200); + response.getOutputStream().println("COMPLETED\n"); + continuation.complete(); + } + catch(Exception e) + { + e.printStackTrace(); + } } + }; + synchronized (_timer) + { + _timer.schedule(complete,complete2_after); } - }; - synchronized (_timer) - { - _timer.schedule(complete,complete2_after); } + else if (complete2_after==0) + { + response.setStatus(200); + response.getOutputStream().println("COMPLETED\n"); + continuation.complete(); + } + else if (resume2_after>0) + { + TimerTask resume = new TimerTask() + { + @Override + public void run() + { + ((HttpServletResponse)response).addHeader("history","resume"); + continuation.resume(); + } + }; + synchronized (_timer) + { + _timer.schedule(resume,resume2_after); + } + } + else if (resume2_after==0) + { + ((HttpServletResponse)response).addHeader("history","resume"); + continuation.resume(); + } + if (undispatch) + continuation.undispatch(); + return; } - else if (complete2_after==0) + else if (continuation.isExpired()) { response.setStatus(200); - response.getOutputStream().println("COMPLETED\n"); - continuation.complete(); + response.getOutputStream().println("TIMEOUT\n"); } - else if (resume2_after>0) + else if (continuation.isResumed()) { - TimerTask resume = new TimerTask() - { - @Override - public void run() - { - ((HttpServletResponse)response).addHeader("history","resume"); - continuation.resume(); - } - }; - synchronized (_timer) - { - _timer.schedule(resume,resume2_after); - } + response.setStatus(200); + response.getOutputStream().println("RESUMED\n"); } - else if (resume2_after==0) + else { - ((HttpServletResponse)response).addHeader("history","resume"); - continuation.resume(); + response.setStatus(200); + response.getOutputStream().println("unknown???\n"); } - if (undispatch) - continuation.undispatch(); - return; - } - else if (continuation.isExpired()) - { - response.setStatus(200); - response.getOutputStream().println("TIMEOUT\n"); - } - else if (continuation.isResumed()) - { - response.setStatus(200); - response.getOutputStream().println("RESUMED\n"); - } - else - { - response.setStatus(200); - response.getOutputStream().println("unknown???\n"); } } }