Repository: cxf Updated Branches: refs/heads/master 3d701b59b -> 11ecb9925
[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/11ecb992 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/11ecb992 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/11ecb992 Branch: refs/heads/master Commit: 11ecb9925c899a6696e7ccf03b80d8511374ddc8 Parents: 3d701b5 Author: Sergey Beryozkin <[email protected]> Authored: Fri Mar 28 12:57:40 2014 +0000 Committer: Sergey Beryozkin <[email protected]> Committed: Fri Mar 28 12:57:40 2014 +0000 ---------------------------------------------------------------------- .../http/Servlet3ContinuationProvider.java | 26 ++++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/11ecb992/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 5c1e8d2..2522913 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 @@ -76,6 +76,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() { @@ -91,10 +92,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) { @@ -105,6 +107,7 @@ public class Servlet3ContinuationProvider implements ContinuationProvider { isPending = true; } isNew = false; + isResumed = false; context.setTimeout(timeout); inMessage.getExchange().getInMessage().getInterceptorChain().suspend(); @@ -112,7 +115,9 @@ public class Servlet3ContinuationProvider implements ContinuationProvider { return true; } public void redispatch() { - context.dispatch(); + if (!isComplete) { + context.dispatch(); + } } public void resume() { isResumed = true; @@ -121,7 +126,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; if (callback != null) { final Exception ex = inMessage.getExchange().get(Exception.class); @@ -156,8 +170,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(); } @@ -170,9 +182,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(); } private Throwable isCausedByIO(final Exception ex) {
