You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2009/04/21 19:21:20 UTC

svn commit: r767231 - in /cxf/branches/2.1.x-fixes/rt: core/src/main/java/org/apache/cxf/endpoint/ frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/

Author: dkulp
Date: Tue Apr 21 17:21:19 2009
New Revision: 767231

URL: http://svn.apache.org/viewvc?rev=767231&view=rev
Log:
Merged revisions 767191 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r767191 | dkulp | 2009-04-21 11:40:48 -0400 (Tue, 21 Apr 2009) | 2 lines
  
  [CXF-2180] Catch throwable so ClassNotFoundException and NoClassDefFoundErrors can both be caught
........

Modified:
    cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
    cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/BindingProviderImpl.java
    cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WebServiceContextImpl.java

Modified: cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java?rev=767231&r1=767230&r2=767231&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java (original)
+++ cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java Tue Apr 21 17:21:19 2009
@@ -19,6 +19,8 @@
 
 package org.apache.cxf.endpoint;
 
+import java.lang.ref.WeakReference;
+
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -68,29 +70,29 @@
 public class ClientImpl
     extends AbstractBasicInterceptorProvider
     implements Client, Retryable, MessageObserver {
-    
+
     public static final String THREAD_LOCAL_REQUEST_CONTEXT = "thread.local.request.context";
 
-    
+
     public static final String FINISHED = "exchange.finished";
-    
+
     private static final Logger LOG = LogUtils.getL7dLogger(ClientImpl.class);
-    
+
     protected Bus bus;
     protected ConduitSelector conduitSelector;
-    protected ClientOutFaultObserver outFaultObserver; 
+    protected ClientOutFaultObserver outFaultObserver;
     protected int synchronousTimeout = 60000; // default 60 second timeout
-    
+
     protected PhaseChainCache outboundChainCache = new PhaseChainCache();
     protected PhaseChainCache inboundChainCache = new PhaseChainCache();
-    
+
     protected Map<String, Object> currentRequestContext = new ConcurrentHashMap<String, Object>();
-    protected ThreadLocal <EchoContext> requestContext =
-        new ThreadLocal<EchoContext>();
+    protected ThreadLocal <WeakReference<EchoContext>> requestContext =
+        new ThreadLocal<WeakReference<EchoContext>>();
+
+    protected ThreadLocal <WeakReference<Map<String, Object>>> responseContext =
+            new ThreadLocal<WeakReference<Map<String, Object>>>();
 
-    protected ThreadLocal <Map<String, Object>> responseContext =
-            new ThreadLocal<Map<String, Object>>();
-    
     protected Executor executor;
 
 
@@ -101,7 +103,7 @@
     public ClientImpl(Bus b, Endpoint e, Conduit c) {
        this(b, e, new PreexistingConduitSelector(c));
     }
-    
+
     public ClientImpl(Bus b, Endpoint e, ConduitSelector sc) {
         bus = b;
         outFaultObserver = new ClientOutFaultObserver(bus);
@@ -112,7 +114,7 @@
     public ClientImpl(URL wsdlUrl) {
         this(BusFactory.getThreadDefaultBus(), wsdlUrl, null, null, SimpleEndpointImplFactory.getSingleton());
     }
-    
+
     public ClientImpl(URL wsdlUrl, QName port) {
         this(BusFactory.getThreadDefaultBus(), wsdlUrl, null, port, SimpleEndpointImplFactory.getSingleton());
     }
@@ -136,14 +138,14 @@
      * @param port
      * @param endpointImplFactory
      */
-    public ClientImpl(Bus bus, URL wsdlUrl, QName service, 
+    public ClientImpl(Bus bus, URL wsdlUrl, QName service,
                       QName port, EndpointImplFactory endpointImplFactory) {
         this.bus = bus;
-        
+
         WSDLServiceFactory sf = (service == null)
             ? (new WSDLServiceFactory(bus, wsdlUrl)) : (new WSDLServiceFactory(bus, wsdlUrl, service));
         Service svc = sf.create();
-    
+
         EndpointInfo epfo = findEndpoint(svc, port);
 
         try {
@@ -153,17 +155,17 @@
         }
         notifyLifecycleManager();
     }
-    
+
     public void destroy() {
-        
+
         // TODO: also inform the conduit so it can shutdown any response listeners
-        
+
         ClientLifeCycleManager mgr = bus.getExtension(ClientLifeCycleManager.class);
         if (null != mgr) {
             mgr.clientDestroyed(this);
         }
     }
-    
+
     private void notifyLifecycleManager() {
         ClientLifeCycleManager mgr = bus.getExtension(ClientLifeCycleManager.class);
         if (null != mgr) {
@@ -184,7 +186,7 @@
             for (ServiceInfo svcfo : svc.getServiceInfos()) {
                 for (EndpointInfo e : svcfo.getEndpoints()) {
                     BindingInfo bfo = e.getBinding();
-    
+
                     if (bfo.getBindingId().equals("http://schemas.xmlsoap.org/wsdl/soap/")) {
                         for (Object o : bfo.getExtensors().get()) {
                             if (o instanceof SOAPBindingImpl) {
@@ -195,7 +197,7 @@
                                 }
                             }
                         }
-    
+
                     }
                 }
             }
@@ -212,22 +214,15 @@
         return getConduitSelector().getEndpoint();
     }
 
-    
+
     public Map<String, Object> getRequestContext() {
         if (isThreadLocalRequestContext()) {
-            if (null == requestContext.get()) {
-                requestContext.set(new EchoContext(currentRequestContext));
-            }
-            return requestContext.get();
+            getThreadRequestContext();
         }
         return currentRequestContext;
     }
     public Map<String, Object> getResponseContext() {
-        if (null == responseContext.get()) {
-            responseContext.set(new HashMap<String, Object>());
-        }        
-        return responseContext.get();
-
+        return getThreadResponseContext();
     }
     public boolean isThreadLocalRequestContext() {
         if (currentRequestContext.containsKey(THREAD_LOCAL_REQUEST_CONTEXT)) {
@@ -246,37 +241,37 @@
         currentRequestContext.put(THREAD_LOCAL_REQUEST_CONTEXT, b);
     }
 
-    
+
     public Object[] invoke(BindingOperationInfo oi, Object... params) throws Exception {
         return invoke(oi, params, null);
     }
 
     public Object[] invoke(String operationName, Object... params) throws Exception {
         QName q = new QName(getEndpoint().getService().getName().getNamespaceURI(), operationName);
-       
+
         return invoke(q, params);
     }
-    
+
     public Object[] invoke(QName operationName, Object... params) throws Exception {
         BindingOperationInfo op = getEndpoint().getEndpointInfo().getBinding().getOperation(operationName);
         if (op == null) {
             throw new UncheckedException(
                 new org.apache.cxf.common.i18n.Message("NO_OPERATION", LOG, operationName));
         }
-        
+
         if (op.isUnwrappedCapable()) {
             op = op.getUnwrappedOperation();
         }
-        
+
         return invoke(op, params);
     }
 
     public Object[] invokeWrapped(String operationName, Object... params) throws Exception {
         QName q = new QName(getEndpoint().getService().getName().getNamespaceURI(), operationName);
-       
+
         return invokeWrapped(q, params);
     }
-    
+
     public Object[] invokeWrapped(QName operationName, Object... params) throws Exception {
         BindingOperationInfo op = getEndpoint().getEndpointInfo().getBinding().getOperation(operationName);
         if (op == null) {
@@ -287,7 +282,7 @@
     }
 
     public Object[] invoke(BindingOperationInfo oi,
-                           Object[] params, 
+                           Object[] params,
                            Exchange exchange) throws Exception {
         Map<String, Object> context = new HashMap<String, Object>();
         Map<String, Object> resp = getResponseContext();
@@ -298,11 +293,11 @@
         try {
             return invoke(oi, params, context, exchange);
         } finally {
-            responseContext.set(resp);
+            setThreadResponseContext(resp);
         }
     }
     public Object[] invoke(BindingOperationInfo oi,
-                           Object[] params, 
+                           Object[] params,
                            Map<String, Object> context) throws Exception {
         try {
             return invoke(oi, params, context, (Exchange)null);
@@ -310,46 +305,46 @@
             if (context != null) {
                 Map<String, Object> resp = CastUtils.cast((Map<?, ?>)context.get(RESPONSE_CONTEXT));
                 if (resp != null) {
-                    responseContext.set(resp);
+                    setThreadResponseContext(resp);
                 }
             }
         }
     }
-    
-    public void invoke(ClientCallback callback, 
-                       String operationName, 
+
+    public void invoke(ClientCallback callback,
+                       String operationName,
                        Object... params) throws Exception {
         QName q = new QName(getEndpoint().getService().getName().getNamespaceURI(), operationName);
-        invoke(callback, q, params);        
+        invoke(callback, q, params);
     }
 
-    public void invoke(ClientCallback callback, 
-                       QName operationName, 
+    public void invoke(ClientCallback callback,
+                       QName operationName,
                        Object... params) throws Exception {
         BindingOperationInfo op = getEndpoint().getEndpointInfo().getBinding().getOperation(operationName);
         if (op == null) {
             throw new UncheckedException(
                 new org.apache.cxf.common.i18n.Message("NO_OPERATION", LOG, operationName));
         }
-        
+
         if (op.isUnwrappedCapable()) {
             op = op.getUnwrappedOperation();
         }
-        
+
         invoke(callback, op, params);
     }
 
 
-    public void invokeWrapped(ClientCallback callback, 
-                              String operationName, 
+    public void invokeWrapped(ClientCallback callback,
+                              String operationName,
                               Object... params)
         throws Exception {
         QName q = new QName(getEndpoint().getService().getName().getNamespaceURI(), operationName);
-        invokeWrapped(callback, q, params);        
+        invokeWrapped(callback, q, params);
     }
 
-    public void invokeWrapped(ClientCallback callback, 
-                              QName operationName, 
+    public void invokeWrapped(ClientCallback callback,
+                              QName operationName,
                               Object... params)
         throws Exception {
         BindingOperationInfo op = getEndpoint().getEndpointInfo().getBinding().getOperation(operationName);
@@ -360,9 +355,9 @@
         invoke(callback, op, params);
     }
 
-    
-    public void invoke(ClientCallback callback, 
-                       BindingOperationInfo oi, 
+
+    public void invoke(ClientCallback callback,
+                       BindingOperationInfo oi,
                        Object... params) throws Exception {
         Bus origBus = BusFactory.getThreadDefaultBus(false);
         BusFactory.setThreadDefaultBus(bus);
@@ -379,42 +374,42 @@
 
             Message message = endpoint.getBinding().createMessage();
             message.put(Message.INVOCATION_CONTEXT, context);
-            
+
             //setup the message context
             setContext(reqContext, message);
             setParameters(params, message);
-    
+
             if (null != reqContext) {
                 exchange.putAll(reqContext);
             }
             exchange.setOneWay(oi.getOutput() == null);
             exchange.setOutMessage(message);
             exchange.put(ClientCallback.class, callback);
-            
+
             setOutMessageProperties(message, oi);
             setExchangeProperties(exchange, endpoint, oi);
-            
+
             // setup chain
-    
+
             PhaseInterceptorChain chain = setupInterceptorChain(endpoint);
             message.setInterceptorChain(chain);
-            
+
             modifyChain(chain, reqContext);
             chain.setFaultObserver(outFaultObserver);
-            
+
             // setup conduit selector
             prepareConduitSelector(message);
-            
-            // execute chain        
+
+            // execute chain
             chain.doIntercept(message);
 
         } finally {
             BusFactory.setThreadDefaultBus(origBus);
-        }       
+        }
     }
-    
+
     public Object[] invoke(BindingOperationInfo oi,
-                           Object[] params, 
+                           Object[] params,
                            Map<String, Object> context,
                            Exchange exchange) throws Exception {
         Bus origBus = BusFactory.getThreadDefaultBus(false);
@@ -425,7 +420,7 @@
             }
             exchange.setSynchronous(true);
             Endpoint endpoint = getEndpoint();
-            
+
             Map<String, Object> reqContext = null;
             Map<String, Object> resContext = null;
             if (LOG.isLoggable(Level.FINE)) {
@@ -436,46 +431,46 @@
                 reqContext = CastUtils.cast((Map)context.get(REQUEST_CONTEXT));
                 resContext = CastUtils.cast((Map)context.get(RESPONSE_CONTEXT));
                 message.put(Message.INVOCATION_CONTEXT, context);
-            }    
+            }
             //setup the message context
             setContext(reqContext, message);
             setParameters(params, message);
-    
+
             if (null != reqContext) {
                 exchange.putAll(reqContext);
             }
-            
+
             if (null != oi) {
                 exchange.setOneWay(oi.getOutput() == null);
             }
-    
+
             exchange.setOutMessage(message);
-            
+
             setOutMessageProperties(message, oi);
             setExchangeProperties(exchange, endpoint, oi);
-            
+
             // setup chain
-    
+
             PhaseInterceptorChain chain = setupInterceptorChain(endpoint);
             message.setInterceptorChain(chain);
-            
+
             modifyChain(chain, reqContext);
             chain.setFaultObserver(outFaultObserver);
-            
+
             // setup conduit selector
             prepareConduitSelector(message);
-            
-            // execute chain        
+
+            // execute chain
             chain.doIntercept(message);
-    
+
             return processResult(message, exchange, oi, resContext);
-            
+
         } finally {
             BusFactory.setThreadDefaultBus(origBus);
         }
     }
 
-    protected Object[] processResult(Message message, 
+    protected Object[] processResult(Message message,
                                    Exchange exchange,
                                    BindingOperationInfo oi,
                                    Map<String, Object> resContext) throws Exception {
@@ -496,14 +491,14 @@
             }
             throw ex;
         }
-        
+
         // Wait for a response if we need to
         if (oi != null && !oi.getOperationInfo().isOneWay()) {
             synchronized (exchange) {
                 waitResponse(exchange);
             }
         }
-        
+
         // leave the input stream open for the caller
         Boolean keepConduitAlive = (Boolean)exchange.get(Client.KEEP_CONDUIT_ALIVE);
         if (keepConduitAlive == null || !keepConduitAlive) {
@@ -514,7 +509,7 @@
         List resList = null;
         Message inMsg = exchange.getInMessage();
         if (inMsg != null) {
-            if (null != resContext) {                   
+            if (null != resContext) {
                 resContext.putAll(inMsg);
                 if (LOG.isLoggable(Level.FINE)) {
                     LOG.fine("set responseContext to be" + responseContext);
@@ -522,18 +517,18 @@
             }
             resList = inMsg.getContent(List.class);
         }
-        
+
         // check for an incoming fault
         ex = getException(exchange);
-        
+
         if (ex != null) {
             throw ex;
         }
-        
+
         if (resList != null) {
             return resList.toArray();
         }
-        
+
         return null;
     }
     protected Exception getException(Exchange exchange) {
@@ -541,17 +536,17 @@
             return exchange.getInFaultMessage().getContent(Exception.class);
         } else if (exchange.getOutFaultMessage() != null) {
             return exchange.getOutFaultMessage().getContent(Exception.class);
-        } 
+        }
         return null;
     }
 
     protected void setContext(Map<String, Object> ctx, Message message) {
-        if (ctx != null) {            
+        if (ctx != null) {
             message.putAll(ctx);
             if (LOG.isLoggable(Level.FINE)) {
                 LOG.fine("set requestContext to message be" + ctx);
             }
-        }        
+        }
     }
 
     protected void waitResponse(Exchange exchange) {
@@ -576,24 +571,24 @@
         MessageContentsList contents = new MessageContentsList(params);
         message.setContent(List.class, contents);
     }
-    
+
     public void onMessage(Message message) {
 
         Endpoint endpoint = message.getExchange().get(Endpoint.class);
         if (endpoint == null) {
             // in this case correlation will occur outside the transport,
-            // however there's a possibility that the endpoint may have been 
+            // however there's a possibility that the endpoint may have been
             // rebased in the meantime, so that the response will be mediated
             // via a set of in interceptors provided by a *different* endpoint
             //
             endpoint = getConduitSelector().getEndpoint();
-            message.getExchange().put(Endpoint.class, endpoint);            
+            message.getExchange().put(Endpoint.class, endpoint);
         }
         message = endpoint.getBinding().createMessage(message);
         message.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
         message.put(Message.INBOUND_MESSAGE, Boolean.TRUE);
         PhaseManager pm = bus.getExtension(PhaseManager.class);
-        
+
         List<Interceptor> i1 = bus.getInInterceptors();
         if (LOG.isLoggable(Level.FINE)) {
             LOG.fine("Interceptors contributed by bus: " + i1);
@@ -610,12 +605,12 @@
         if (LOG.isLoggable(Level.FINE)) {
             LOG.fine("Interceptors contributed by binding: " + i4);
         }
-        
-        PhaseInterceptorChain chain = inboundChainCache.get(pm.getInPhases(), i1, i2, i3, i4); 
+
+        PhaseInterceptorChain chain = inboundChainCache.get(pm.getInPhases(), i1, i2, i3, i4);
         message.setInterceptorChain(chain);
-        
+
         chain.setFaultObserver(outFaultObserver);
-        
+
         Bus origBus = BusFactory.getThreadDefaultBus(false);
         BusFactory.setThreadDefaultBus(bus);
         // execute chain
@@ -628,7 +623,7 @@
                 }
                 callback.start(message);
             }
-            
+
             String startingAfterInterceptorID = (String) message.get(
                 PhaseInterceptorChain.STARTING_AFTER_INTERCEPTOR_ID);
             String startingInterceptorID = (String) message.get(
@@ -640,9 +635,9 @@
             } else {
                 chain.doIntercept(message);
             }
-            
+
             callback = message.getExchange().get(ClientCallback.class);
-            
+
             if (callback != null && !isPartialResponse(message)) {
                 message.getExchange().setInMessage(message);
                 Map<String, Object> resCtx = CastUtils.cast((Map<?, ?>)message
@@ -650,11 +645,11 @@
                                                                 .getOutMessage()
                                                                 .get(Message.INVOCATION_CONTEXT));
                 resCtx = CastUtils.cast((Map<?, ?>)resCtx.get(RESPONSE_CONTEXT));
-                
+
                 try {
                     Object obj[] = processResult(message, message.getExchange(),
                                                  null, resCtx);
-                                        
+
                     callback.handleResponse(resCtx, obj);
                 } catch (Throwable ex) {
                     callback.handleException(resCtx, ex);
@@ -665,7 +660,7 @@
                 if (!isPartialResponse(message) && callback == null) {
                     message.getExchange().put(FINISHED, Boolean.TRUE);
                     message.getExchange().setInMessage(message);
-                    message.getExchange().notifyAll();                   
+                    message.getExchange().notifyAll();
                 }
             }
             BusFactory.setThreadDefaultBus(origBus);
@@ -693,7 +688,7 @@
             message.put(MessageInfo.class, boi.getOperationInfo().getInput());
         }
     }
-    
+
     protected void setExchangeProperties(Exchange exchange,
                                          Endpoint endpoint,
                                          BindingOperationInfo boi) {
@@ -711,7 +706,7 @@
             exchange.put(BindingOperationInfo.class, boi);
             exchange.put(OperationInfo.class, boi.getOperationInfo());
         }
-                
+
         if (exchange.isSynchronous() || executor == null) {
             exchange.put(MessageObserver.class, this);
         } else {
@@ -723,7 +718,7 @@
                         }
                     });
                 }
-            });            
+            });
         }
         exchange.put(Retryable.class, this);
         exchange.put(Client.class, this);
@@ -756,10 +751,10 @@
         }
     }
 
-    protected PhaseInterceptorChain setupInterceptorChain(Endpoint endpoint) { 
+    protected PhaseInterceptorChain setupInterceptorChain(Endpoint endpoint) {
 
         PhaseManager pm = bus.getExtension(PhaseManager.class);
-        
+
         List<Interceptor> i1 = bus.getOutInterceptors();
         if (LOG.isLoggable(Level.FINE)) {
             LOG.fine("Interceptors contributed by bus: " + i1);
@@ -794,17 +789,17 @@
     public void setSynchronousTimeout(int synchronousTimeout) {
         this.synchronousTimeout = synchronousTimeout;
     }
-    
+
     public final ConduitSelector getConduitSelector() {
         return getConduitSelector(null);
     }
-    
+
     protected final synchronized ConduitSelector getConduitSelector(
         ConduitSelector override
     ) {
         if (null == conduitSelector) {
             setConduitSelector(override != null
-                               ? override 
+                               ? override
                                : new UpfrontConduitSelector());
         }
         return conduitSelector;
@@ -817,13 +812,13 @@
     private boolean isPartialResponse(Message in) {
         return Boolean.TRUE.equals(in.get(Message.PARTIAL_RESPONSE_MESSAGE));
     }
-    
-    
+
+
     /*
      * modification are echoed back to the shared map
      */
     public static class EchoContext extends HashMap<String, Object> {
-        final Map<String, Object> shared; 
+        final Map<String, Object> shared;
         public EchoContext(Map<String, Object> sharedMap) {
             super(sharedMap);
             shared = sharedMap;
@@ -838,12 +833,12 @@
             shared.putAll(t);
             super.putAll(t);
         }
-        
+
         public Object remove(Object key) {
             shared.remove(key);
             return super.remove(key);
         }
-        
+
         public void reload() {
             super.clear();
             super.putAll(shared);
@@ -855,5 +850,29 @@
         this.executor = executor;
     }
 
+    protected Map<String, Object> getThreadRequestContext() {
+        WeakReference<EchoContext> r = requestContext.get();
+        if ((null == r) || (null == r.get())) {
+            r = new WeakReference<EchoContext>(new EchoContext(currentRequestContext));
+            requestContext.set(r);
+        }
+        return (r == null) ? null : r.get();
+    }
+
+    protected Map<String, Object> getThreadResponseContext() {
+        WeakReference<Map<String, Object>> r = responseContext.get();
+        if ((null == r) || (null == r.get())) {
+            r = new WeakReference<Map<String, Object>>(new HashMap<String, Object>());
+            responseContext.set(r);
+        }
+        return (r == null) ? null : r.get();
+
+    }
+
+    protected void setThreadResponseContext(Map<String, Object> resp) {
+        WeakReference<Map<String, Object>> r =
+            new WeakReference<Map<String, Object>>(resp);
+        responseContext.set(r);
+    }
 
 }

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/BindingProviderImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/BindingProviderImpl.java?rev=767231&r1=767230&r2=767231&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/BindingProviderImpl.java (original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/BindingProviderImpl.java Tue Apr 21 17:21:19 2009
@@ -19,6 +19,8 @@
 
 package org.apache.cxf.jaxws;
 
+import java.lang.ref.WeakReference;
+
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -33,13 +35,13 @@
 import org.apache.cxf.jaxws.support.JaxWsEndpointImpl;
 
 public class BindingProviderImpl implements BindingProvider {
-    protected ThreadLocal <Map<String, Object>> requestContext = 
-        new ThreadLocal<Map<String, Object>>();
-    protected ThreadLocal <Map<String, Object>> responseContext =
-        new ThreadLocal<Map<String, Object>>();
+    protected ThreadLocal <WeakReference<Map<String, Object>>> requestContext =
+        new ThreadLocal<WeakReference<Map<String, Object>>>();
+    protected ThreadLocal <WeakReference<Map<String, Object>>> responseContext =
+        new ThreadLocal<WeakReference<Map<String, Object>>>();
     private final Binding binding;
     private final EndpointReferenceBuilder builder;
-       
+
     public BindingProviderImpl() {
         this.binding = null;
         this.builder = null;
@@ -49,28 +51,20 @@
         this.binding = b;
         this.builder = null;
     }
-    
+
     public BindingProviderImpl(JaxWsEndpointImpl endpoint) {
         this.binding = endpoint.getJaxwsBinding();
         this.builder = new EndpointReferenceBuilder(endpoint);
     }
-    
+
     public Map<String, Object> getRequestContext() {
-        if (null == requestContext.get()) {
-            requestContext.set(new HashMap<String, Object>());
-        }
-        return requestContext.get();
+        return getThreadRequestContext();
     }
 
     public Map<String, Object> getResponseContext() {
-        if (null == responseContext.get()) {
-            responseContext.set(new WrappedMessageContext(new HashMap<String, Object>(),
-                                                          null,
-                                                          Scope.APPLICATION));
-        }
-        return responseContext.get();
+        return getThreadResponseContext();
     }
-    
+
     protected void clearContext(ThreadLocal<Map<String, Object>> context) {
         context.set(null);
     }
@@ -78,9 +72,9 @@
     public Binding getBinding() {
         return binding;
     }
-    
+
     protected void populateResponseContext(MessageContext ctx) {
-        
+
         Iterator<String> iter  = ctx.keySet().iterator();
         Map<String, Object> respCtx = getResponseContext();
         while (iter.hasNext()) {
@@ -91,11 +85,32 @@
         }
     }
 
-    public EndpointReference getEndpointReference() {            
+    public EndpointReference getEndpointReference() {
         return builder.getEndpointReference();
     }
 
     public <T extends EndpointReference> T getEndpointReference(Class<T> clazz) {
         return builder.getEndpointReference(clazz);
     }
+
+    protected Map<String, Object> getThreadRequestContext() {
+        WeakReference<Map<String, Object>> r = requestContext.get();
+        if ((null == r) || (null == r.get())) {
+            r = new WeakReference<Map<String, Object>>(new HashMap<String, Object>());
+            requestContext.set(r);
+        }
+        return (r != null) ? r.get() : null;
+    }
+
+    protected Map<String, Object> getThreadResponseContext() {
+        WeakReference<Map<String, Object>> r = responseContext.get();
+        if ((null == r) || (null == r.get())) {
+            r = new WeakReference<Map<String, Object>>(
+                    new WrappedMessageContext(
+                    new HashMap<String, Object>(), null, Scope.APPLICATION));
+            responseContext.set(r);
+        }
+        return (r != null) ? r.get() : null;
+    }
+
 }

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WebServiceContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WebServiceContextImpl.java?rev=767231&r1=767230&r2=767231&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WebServiceContextImpl.java (original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WebServiceContextImpl.java Tue Apr 21 17:21:19 2009
@@ -19,6 +19,8 @@
 
 package org.apache.cxf.jaxws.context;
 
+import java.lang.ref.WeakReference;
+
 import java.security.Principal;
 import java.util.logging.Logger;
 
@@ -39,19 +41,20 @@
 public class WebServiceContextImpl implements WebServiceContext {
     private static final Logger LOG = LogUtils.getL7dLogger(WebServiceContextImpl.class);
 
-    private static ThreadLocal<MessageContext> context = new ThreadLocal<MessageContext>();
+    private static ThreadLocal<WeakReference<MessageContext>> context =
+            new ThreadLocal<WeakReference<MessageContext>>();
 
-    public WebServiceContextImpl() { 
+    public WebServiceContextImpl() {
     }
 
-    public WebServiceContextImpl(MessageContext ctx) { 
+    public WebServiceContextImpl(MessageContext ctx) {
         setMessageContext(ctx);
-    } 
+    }
 
     // Implementation of javax.xml.ws.WebServiceContext
 
     public final MessageContext getMessageContext() {
-        return context.get();
+        return getThreadMessageContext();
     }
 
     public final Principal getUserPrincipal() {
@@ -69,7 +72,7 @@
         }
         return ctx.isUserInRole(role);
     }
-    
+
     //  TODO JAX-WS 2.1
     public EndpointReference getEndpointReference(Element... referenceParameters) {
         WrappedMessageContext ctx = (WrappedMessageContext)getMessageContext();
@@ -81,13 +84,13 @@
         builder.serviceName(ep.getService().getName());
         builder.endpointName(ep.getEndpointInfo().getName());
 
-//        builder.wsdlDocumentLocation(wsdlLocation);        
+//        builder.wsdlDocumentLocation(wsdlLocation);
         if (referenceParameters != null) {
             for (Element referenceParameter : referenceParameters) {
                 builder.referenceParameter(referenceParameter);
             }
         }
-        
+
         return builder.build();
     }
 
@@ -103,11 +106,21 @@
 
     public static void setMessageContext(MessageContext ctx) {
         //ContextPropertiesMapping.mapCxf2Jaxws(ctx);
-        context.set(ctx);
+        setThreadMessageContext(ctx);
     }
 
     public static void clear() {
         context.set(null);
     }
 
+    private static MessageContext getThreadMessageContext() {
+        WeakReference<MessageContext> r = context.get();
+        return (r != null) ? r.get() : null;
+    }
+
+    private static void setThreadMessageContext(MessageContext ctx) {
+        WeakReference<MessageContext> r = new WeakReference<MessageContext>(ctx);
+        context.set(r);
+    }
+
 }