Repository: cxf Updated Branches: refs/heads/2.7.x-fixes d418e090c -> ac8a4ab64
[CXF-5659] Updating Servlet3Continuation to prevent redispatch() called after reset() unless startAsyncAgain has been called and blocking possible ISE caused by the calls to complete() Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/ac8a4ab6 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/ac8a4ab6 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/ac8a4ab6 Branch: refs/heads/2.7.x-fixes Commit: ac8a4ab6450467f452d400c9fee3a2de8733740c Parents: d418e09 Author: Sergey Beryozkin <[email protected]> Authored: Fri Mar 28 12:57:40 2014 +0000 Committer: Sergey Beryozkin <[email protected]> Committed: Fri Mar 28 13:00:30 2014 +0000 ---------------------------------------------------------------------- .../http/Servlet3ContinuationProvider.java | 26 ++++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/ac8a4ab6/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java ---------------------------------------------------------------------- diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java index f0fe7de..e74a3ce 100644 --- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java +++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java @@ -77,6 +77,7 @@ public class Servlet3ContinuationProvider implements ContinuationProvider { volatile boolean isNew = true; volatile boolean isResumed; volatile boolean isPending; + volatile boolean isComplete; volatile Object obj; private ContinuationCallback callback; public Servlet3Continuation() { @@ -92,10 +93,11 @@ public class Servlet3ContinuationProvider implements ContinuationProvider { AsyncContext old = context; try { context = req.startAsync(); + context.addListener(this); + isComplete = false; } catch (IllegalStateException ex) { context = old; } - context.addListener(this); } public boolean suspend(long timeout) { @@ -106,6 +108,7 @@ public class Servlet3ContinuationProvider implements ContinuationProvider { isPending = true; } isNew = false; + isResumed = false; context.setTimeout(timeout); if (PhaseInterceptorChain.getCurrentMessage() == null) { @@ -119,7 +122,9 @@ public class Servlet3ContinuationProvider implements ContinuationProvider { return true; } public void redispatch() { - context.dispatch(); + if (!isComplete) { + context.dispatch(); + } } public void resume() { isResumed = true; @@ -128,7 +133,16 @@ public class Servlet3ContinuationProvider implements ContinuationProvider { } public void reset() { - context.complete(); + isComplete = true; + try { + context.complete(); + } catch (IllegalStateException ex) { + // ignore + } + isPending = false; + isResumed = false; + isNew = false; + obj = null; } @@ -155,8 +169,6 @@ public class Servlet3ContinuationProvider implements ContinuationProvider { public void onComplete(AsyncEvent event) throws IOException { inMessage.getExchange().getInMessage() .remove(AbstractHTTPDestination.CXF_CONTINUATION_MESSAGE); - isPending = false; - //REVISIT: isResumed = false; if (callback != null) { callback.onComplete(); } @@ -169,9 +181,7 @@ public class Servlet3ContinuationProvider implements ContinuationProvider { public void onStartAsync(AsyncEvent event) throws IOException { } public void onTimeout(AsyncEvent event) throws IOException { - isPending = false; - //REVISIT: isResumed = true; - redispatch(); + resume(); } }
