[CXF-5626] Restore former MessageContext into WebServiceContext instead of clearing it
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/9fa052b1 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/9fa052b1 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/9fa052b1 Branch: refs/heads/2.7.x-fixes Commit: 9fa052b13c2b11e4c0aa5c7d0907d33bf22bb8ec Parents: bb4fb70 Author: Alessio Soldano <[email protected]> Authored: Fri Mar 21 15:48:39 2014 +0100 Committer: Alessio Soldano <[email protected]> Committed: Fri Mar 21 15:58:41 2014 +0100 ---------------------------------------------------------------------- .../apache/cxf/jaxws/JAXWSMethodInvoker.java | 11 ++++++++--- .../jaxws/context/WebServiceContextImpl.java | 10 +++++++++- .../cxf/jaxws/handler/HandlerChainInvoker.java | 20 ++++++++++++++++---- 3 files changed, 33 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/9fa052b1/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java index 695aec1..4a7cddf 100644 --- a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java +++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import javax.xml.ws.Provider; +import javax.xml.ws.handler.MessageContext; import javax.xml.ws.handler.MessageContext.Scope; import org.apache.cxf.helpers.CastUtils; @@ -59,7 +60,7 @@ public class JAXWSMethodInvoker extends AbstractJAXWSMethodInvoker { Map<String, Object> handlerScopedStuff = removeHandlerProperties(ctx); - WebServiceContextImpl.setMessageContext(ctx); + final MessageContext oldCtx = WebServiceContextImpl.setMessageContext(ctx); List<Object> res = null; try { if ((params == null || params.isEmpty()) && m.getDeclaringClass().equals(Provider.class)) { @@ -87,8 +88,12 @@ public class JAXWSMethodInvoker extends AbstractJAXWSMethodInvoker { } throw f; } finally { - //clear the WebServiceContextImpl's ThreadLocal variable - WebServiceContextImpl.clear(); + //restore the WebServiceContextImpl's ThreadLocal variable to the previous value + if (oldCtx == null) { + WebServiceContextImpl.clear(); + } else { + WebServiceContextImpl.setMessageContext(oldCtx); + } addHandlerProperties(ctx, handlerScopedStuff); } http://git-wip-us.apache.org/repos/asf/cxf/blob/9fa052b1/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WebServiceContextImpl.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WebServiceContextImpl.java b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WebServiceContextImpl.java index eafa9a0..7d19630 100644 --- a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WebServiceContextImpl.java +++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WebServiceContextImpl.java @@ -133,8 +133,16 @@ public class WebServiceContextImpl implements WebServiceContext { } } - public static void setMessageContext(MessageContext ctx) { + /** + * Sets reference to the specified MessageContext and returns the previous reference, if any. + * + * @param ctx The MessageContext to set + * @return The former MessageContext reference, if any. + */ + public static MessageContext setMessageContext(MessageContext ctx) { + MessageContext oldCtx = context.get(); context.set(ctx); + return oldCtx; } public static void clear() { http://git-wip-us.apache.org/repos/asf/cxf/blob/9fa052b1/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainInvoker.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainInvoker.java b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainInvoker.java index 5f75ed5..4d51df7 100644 --- a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainInvoker.java +++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerChainInvoker.java @@ -249,11 +249,17 @@ public class HandlerChainInvoker { } boolean continueProcessing = true; + MessageContext oldCtx = null; try { - WebServiceContextImpl.setMessageContext(ctx); + oldCtx = WebServiceContextImpl.setMessageContext(ctx); continueProcessing = invokeHandleMessage(handlerChain, ctx); } finally { - WebServiceContextImpl.clear(); + // restore the WebServiceContextImpl's ThreadLocal variable to the previous value + if (oldCtx == null) { + WebServiceContextImpl.clear(); + } else { + WebServiceContextImpl.setMessageContext(oldCtx); + } } return continueProcessing; @@ -300,11 +306,17 @@ public class HandlerChainInvoker { } boolean continueProcessing = true; + MessageContext oldCtx = null; try { - WebServiceContextImpl.setMessageContext(ctx); + oldCtx = WebServiceContextImpl.setMessageContext(ctx); continueProcessing = invokeHandleFault(handlerChain, ctx); } finally { - WebServiceContextImpl.clear(); + // restore the WebServiceContextImpl's ThreadLocal variable to the previous value + if (oldCtx == null) { + WebServiceContextImpl.clear(); + } else { + WebServiceContextImpl.setMessageContext(oldCtx); + } } return continueProcessing;
