From a33c8cdf1a5fa5a15bf2a7533be6756c6224be11 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 26 Aug 2009 03:01:35 +0000 Subject: [PATCH] 287632 FilterContinuations for blocking jetty6 git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@763 7e9141cc-0065-0410-87d8-b60c137991c4 --- VERSION.txt | 1 + .../continuation/ContinuationFilter.java | 68 +++++++++---------- .../continuation/ContinuationSupport.java | 24 ++++++- .../jetty/continuation/FauxContinuation.java | 14 +++- .../continuation/Jetty6Continuation.java | 10 ++- .../continuation/Jetty6ContinuationTest.java | 37 ++++++++-- 6 files changed, 103 insertions(+), 51 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 975d11161d1..f3120cc7bd1 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -6,6 +6,7 @@ jetty-7.0.0-SNAPSHOT + JETTY-1086 Added UncheckedPrintWriter to avoid ignored EOFs + JETTY-1087 Chunked SSL non blocking input + 287496 Use start.ini always and added --exec + + 287632 FilterContinuations for blocking jetty6 jetty-7.0.0.RC4 18 August 2009 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 7d9f6eff81c..1587b24fdfa 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 @@ -20,7 +20,7 @@ import javax.servlet.ServletResponse; * that is neither Jetty (>=6.1) nor a Servlet3.0 container. * The following init parameters may be used to configure the filter (these are mostly for testing):
*
debug
Boolean controlling debug output
- *
partial
Boolean to force support for partial continuation implementations (eg jetty 6)
+ *
jetty6
Boolean to force support for jetty 6 continuations)
*
faux
Boolean to force support for faux continuations
*
*/ @@ -28,7 +28,8 @@ public class ContinuationFilter implements Filter { static boolean __debug; // shared debug status private boolean _faux; - private boolean _partial; + private boolean _jetty6; + private boolean _filtered; ServletContext _context; private boolean _debug; @@ -42,41 +43,52 @@ public class ContinuationFilter implements Filter if (_debug) __debug=true; - param=filterConfig.getInitParameter("partial"); + param=filterConfig.getInitParameter("jetty6"); + if (param==null) + param=filterConfig.getInitParameter("partial"); if (param!=null) - _partial=Boolean.parseBoolean(param); + _jetty6=Boolean.parseBoolean(param); else - _partial=ContinuationSupport.__jetty6 && !jetty_7_or_greater; + _jetty6=ContinuationSupport.__jetty6 && !jetty_7_or_greater; param=filterConfig.getInitParameter("faux"); if (param!=null) _faux=Boolean.parseBoolean(param); else - _faux=!(jetty_7_or_greater || _partial || _context.getMajorVersion()>=3); + _faux=!(jetty_7_or_greater || _jetty6 || _context.getMajorVersion()>=3); + _filtered=_faux||_jetty6; if (_debug) _context.log("ContinuationFilter "+ " jetty="+jetty_7_or_greater+ - " partial="+_partial+ - " jetty6="+ContinuationSupport.__jetty6+ + " jetty6="+_jetty6+ " faux="+_faux+ + " filtered="+_filtered+ " servlet3="+ContinuationSupport.__servlet3); } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { - if (_faux) + if (_filtered) { - final FauxContinuation fc = new FauxContinuation(request); - request.setAttribute(Continuation.ATTRIBUTE,fc); + + Continuation c = (Continuation) request.getAttribute(Continuation.ATTRIBUTE); + FilteredContinuation fc; + if (_faux && (c==null || !(c instanceof FauxContinuation))) + { + fc = new FauxContinuation(request); + request.setAttribute(Continuation.ATTRIBUTE,fc); + } + else + fc=(FilteredContinuation)c; + boolean complete=false; - while (!complete) { try { - fc.setServletResponse(response); - chain.doFilter(request,response); + if (fc==null || ((FilteredContinuation)fc).enter(response)) + chain.doFilter(request,response); } catch (ContinuationThrowable e) { @@ -84,26 +96,12 @@ public class ContinuationFilter implements Filter } finally { - complete=fc.handleSuspension(); + if (fc==null) + fc = (FilteredContinuation) request.getAttribute(Continuation.ATTRIBUTE); + + complete=fc==null || ((FilteredContinuation)fc).exit(); } } - fc.onComplete(); - } - else if (_partial) - { - Continuation c = (Continuation) request.getAttribute(Continuation.ATTRIBUTE); - try - { - if (c==null || !(c instanceof PartialContinuation) || ((PartialContinuation)c).enter()) - chain.doFilter(request,response); - } - finally - { - if (c==null) - c = (Continuation) request.getAttribute(Continuation.ATTRIBUTE); - if (c!=null && c instanceof PartialContinuation) - ((PartialContinuation)c).exit(); - } } else { @@ -141,9 +139,9 @@ public class ContinuationFilter implements Filter { } - public interface PartialContinuation extends Continuation + public interface FilteredContinuation extends Continuation { - boolean enter(); - void exit(); + boolean enter(ServletResponse response); + boolean exit(); } } diff --git a/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/ContinuationSupport.java b/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/ContinuationSupport.java index 39fe772e259..a25434555f3 100644 --- a/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/ContinuationSupport.java +++ b/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/ContinuationSupport.java @@ -19,6 +19,8 @@ import javax.servlet.ServletRequestWrapper; import javax.servlet.ServletResponse; import javax.servlet.ServletResponseWrapper; +import org.mortbay.util.ajax.WaitingContinuation; + /* ------------------------------------------------------------ */ /** ContinuationSupport. * @@ -30,6 +32,7 @@ public class ContinuationSupport { static final boolean __jetty6; static final boolean __servlet3; + static final Class __waitingContinuation; static final Constructor __newServlet3Continuation; static final Constructor __newJetty6Continuation; static @@ -53,8 +56,7 @@ public class ContinuationSupport __servlet3=servlet3Support; __newServlet3Continuation=s3cc; } - - + boolean jetty6Support=false; Constructorj6cc=null; try @@ -75,6 +77,19 @@ public class ContinuationSupport __jetty6=jetty6Support; __newJetty6Continuation=j6cc; } + + Class waiting=null; + try + { + waiting=ContinuationSupport.class.getClassLoader().loadClass("org.mortbay.util.ajax.WaitingContinuation"); + } + catch (Exception e) + { + } + finally + { + __waitingContinuation=waiting; + } } /* ------------------------------------------------------------ */ @@ -116,7 +131,10 @@ public class ContinuationSupport Object c=request.getAttribute("org.mortbay.jetty.ajax.Continuation"); try { - continuation= __newJetty6Continuation.newInstance(request,c); + if (c==null || __waitingContinuation==null || __waitingContinuation.isInstance(c)) + continuation=new FauxContinuation(request); + else + continuation= __newJetty6Continuation.newInstance(request,c); request.setAttribute(Continuation.ATTRIBUTE,continuation); return continuation; } diff --git a/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/FauxContinuation.java b/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/FauxContinuation.java index 7debc3d02c8..20dfc650897 100644 --- a/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/FauxContinuation.java +++ b/jetty-continuation/src/main/java/org/eclipse/jetty/continuation/FauxContinuation.java @@ -20,6 +20,8 @@ import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.ServletResponseWrapper; +import org.eclipse.jetty.continuation.ContinuationFilter.FilteredContinuation; + /* ------------------------------------------------------------ */ /** @@ -27,7 +29,7 @@ import javax.servlet.ServletResponseWrapper; * This implementation of Continuation is used by the {@link ContinuationFilter} * when there are is no native or asynchronous continuation type available. */ -class FauxContinuation implements Continuation +class FauxContinuation implements FilteredContinuation { // common exception used for all continuations. // Turn on debug in ContinuationFilter to see real stack trace. @@ -255,9 +257,10 @@ class FauxContinuation implements Continuation /** * @see org.eclipse.jetty.continuation.Continuation#getServletResponse() */ - void setServletResponse(ServletResponse response) + public boolean enter(ServletResponse response) { _response=response; + return true; } /* ------------------------------------------------------------ */ @@ -305,7 +308,7 @@ class FauxContinuation implements Continuation /** * @return true if handling is complete */ - public boolean handleSuspension() + public boolean exit() { synchronized (this) { @@ -313,6 +316,7 @@ class FauxContinuation implements Continuation { case __HANDLING: _state=__COMPLETE; + onComplete(); return true; case __SUSPENDING: @@ -320,7 +324,10 @@ class FauxContinuation implements Continuation _state=__SUSPENDED; fauxSuspend(); // could block and change state. if (_state==__SUSPENDED || _state==__COMPLETING) + { + onComplete(); return true; + } _initial=false; _state=__HANDLING; @@ -334,6 +341,7 @@ class FauxContinuation implements Continuation case __COMPLETING: _initial=false; _state=__COMPLETE; + onComplete(); return true; case __SUSPENDED: 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 80626e97c15..c7c74aca2b9 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 @@ -14,7 +14,7 @@ import javax.servlet.ServletResponseWrapper; * when it detects that the application is deployed in a jetty-6 server. * This continuation requires the {@link ContinuationFilter} to be deployed. */ -public class Jetty6Continuation implements ContinuationFilter.PartialContinuation +public class Jetty6Continuation implements ContinuationFilter.FilteredContinuation { // Exception reused for all continuations // Turn on debug in ContinuationFilter to see real stack trace. @@ -195,8 +195,9 @@ public class Jetty6Continuation implements ContinuationFilter.PartialContinuatio } /* ------------------------------------------------------------ */ - public boolean enter() + public boolean enter(ServletResponse response) { + _response=response; _expired=!_j6Continuation.isResumed(); if (_initial) @@ -218,7 +219,8 @@ public class Jetty6Continuation implements ContinuationFilter.PartialContinuatio return true; } - public void exit() + /* ------------------------------------------------------------ */ + public boolean exit() { _initial=false; @@ -236,5 +238,7 @@ public class Jetty6Continuation implements ContinuationFilter.PartialContinuatio for (ContinuationListener l: _listeners) l.onComplete(this); } + + return true; } } diff --git a/test-continuation-jetty6/src/test/java/org/eclipse/jetty/continuation/Jetty6ContinuationTest.java b/test-continuation-jetty6/src/test/java/org/eclipse/jetty/continuation/Jetty6ContinuationTest.java index fb8a65bc2d1..3f3e076aa20 100644 --- a/test-continuation-jetty6/src/test/java/org/eclipse/jetty/continuation/Jetty6ContinuationTest.java +++ b/test-continuation-jetty6/src/test/java/org/eclipse/jetty/continuation/Jetty6ContinuationTest.java @@ -19,6 +19,7 @@ import java.io.InputStream; import org.eclipse.jetty.continuation.test.ContinuationBase; import org.mortbay.jetty.Connector; import org.mortbay.jetty.Server; +import org.mortbay.jetty.bio.SocketConnector; import org.mortbay.jetty.nio.SelectChannelConnector; import org.mortbay.jetty.servlet.Context; import org.mortbay.jetty.servlet.FilterHolder; @@ -31,13 +32,15 @@ public class Jetty6ContinuationTest extends ContinuationBase { protected Server _server = new Server(); protected ServletHandler _servletHandler; - protected SelectChannelConnector _connector; + protected SelectChannelConnector _selectChannelConnector; + protected SocketConnector _socketConnector; FilterHolder _filter; protected void setUp() throws Exception { - _connector = new SelectChannelConnector(); - _server.setConnectors(new Connector[]{ _connector }); + _selectChannelConnector = new SelectChannelConnector(); + _socketConnector = new SocketConnector(); + _server.setConnectors(new Connector[]{ _selectChannelConnector,_socketConnector }); Context servletContext = new Context(Context.NO_SECURITY|Context.NO_SESSIONS); _server.setHandler(servletContext); _servletHandler=servletContext.getServletHandler(); @@ -51,23 +54,43 @@ public class Jetty6ContinuationTest extends ContinuationBase _server.stop(); } - public void testJetty6() throws Exception + public void testJetty6Nio() throws Exception { _filter.setInitParameter("debug","true"); //_filter.setInitParameter("faux","false"); _server.start(); - _port=_connector.getLocalPort(); + _port=_selectChannelConnector.getLocalPort(); doit("Jetty6Continuation"); } - public void testFaux() throws Exception + public void testFauxNio() throws Exception { _filter.setInitParameter("debug","true"); _filter.setInitParameter("faux","true"); _server.start(); - _port=_connector.getLocalPort(); + _port=_selectChannelConnector.getLocalPort(); + doit("FauxContinuation"); + } + + public void testJetty6Bio() throws Exception + { + _filter.setInitParameter("debug","true"); + //_filter.setInitParameter("faux","false"); + _server.start(); + + _port=_socketConnector.getLocalPort(); + doit("FauxContinuation"); + } + + public void testFauxBio() throws Exception + { + _filter.setInitParameter("debug","true"); + _filter.setInitParameter("faux","true"); + _server.start(); + + _port=_socketConnector.getLocalPort(); doit("FauxContinuation"); }