cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r520299 - in /incubator/cxf/trunk: rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ systests/src/test/java/org/apache/cxf/systest/jaxws/
Date Tue, 20 Mar 2007 07:07:14 GMT
Author: ningjiang
Date: Tue Mar 20 00:07:12 2007
New Revision: 520299

URL: http://svn.apache.org/viewvc?view=rev&rev=520299
Log:
[CXF-470] Changed the requestContext and responseContext to ThreadLocal Objects

Modified:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/BindingProviderImpl.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerXMLTest.java

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/BindingProviderImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/BindingProviderImpl.java?view=diff&rev=520299&r1=520298&r2=520299
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/BindingProviderImpl.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/BindingProviderImpl.java
Tue Mar 20 00:07:12 2007
@@ -22,8 +22,6 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.AtomicReference;
 
 import javax.xml.ws.Binding;
 import javax.xml.ws.BindingProvider;
@@ -33,9 +31,10 @@
 
 public class BindingProviderImpl implements BindingProvider {
    
-    protected AtomicReference<Map<String, Object>> requestContext =
-            new AtomicReference<Map<String, Object>>();
-    protected Map<String, Object> responseContext;
+    protected ThreadLocal <Map<String, Object>> requestContext = 
+        new ThreadLocal<Map<String, Object>>();
+    protected ThreadLocal <Map<String, Object>> responseContext =
+        new ThreadLocal<Map<String, Object>>();
     private final Binding binding;
        
     public BindingProviderImpl() {
@@ -48,16 +47,20 @@
     
     public Map<String, Object> getRequestContext() {
         if (null == requestContext.get()) {
-            requestContext.compareAndSet(null, new ConcurrentHashMap<String, Object>(4));
-        }      
-        return (Map<String, Object>)requestContext.get();
+            requestContext.set(new HashMap<String, Object>());
+        }
+        return requestContext.get();
     }
-    
+
     public Map<String, Object> getResponseContext() {
-        if (responseContext == null) {
-            responseContext = new HashMap<String, Object>();
+        if (null == responseContext.get()) {
+            responseContext.set(new HashMap<String, Object>());
         }
-        return responseContext;
+        return responseContext.get();
+    }
+    
+    protected void clearContext(ThreadLocal<Map<String, Object>> context) {
+        context.set(null);
     }
 
     public Binding getBinding() {

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java?view=diff&rev=520299&r1=520298&r2=520299
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
Tue Mar 20 00:07:12 2007
@@ -114,9 +114,16 @@
             message.setContent(JAXBContext.class, context);
         }
         
-        Map<String, Object> requestContext = this.getRequestContext();
-        Map<String, Object> responseContext = this.getResponseContext();
-        message.putAll(requestContext);
+        
+        Map<String, Object> reqContext = this.getRequestContext();
+        Map<String, Object> respContext = this.getResponseContext();
+        // cleanup the requestContext threadlocal variable
+        clearContext(requestContext);
+        // clear the response context's hold information
+        // Not call the clear Context is to avoid the error 
+        // that getResponseContext() would be called by Client code first
+        respContext.clear();
+        message.putAll(reqContext);
         //need to do context mapping from jax-ws to cxf message
         ContextPropertiesMapping.mapRequestfromJaxws2Cxf(message);
         
@@ -140,7 +147,7 @@
 
         // execute chain
         chain.doIntercept(message);
-
+                
         if (message.getContent(Exception.class) != null) {
             throw new RuntimeException(message.get(Exception.class));
         }
@@ -156,9 +163,9 @@
         if (!isOneWay) {
             synchronized (exchange) {
                 Message inMsg = waitResponse(exchange);
-                responseContext.putAll(inMsg);
+                respContext.putAll(inMsg);
                 //need to do context mapping from cxf message to jax-ws 
-                ContextPropertiesMapping.mapResponsefromCxf2Jaxws(responseContext);
+                ContextPropertiesMapping.mapResponsefromCxf2Jaxws(respContext);
                 return cl.cast(inMsg.getContent(Object.class));
             }
         }

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java?view=diff&rev=520299&r1=520298&r2=520299
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
Tue Mar 20 00:07:12 2007
@@ -24,9 +24,7 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.FutureTask;
-import java.util.concurrent.atomic.AtomicReference;
 import java.util.logging.Logger;
 
 import javax.xml.ws.AsyncHandler;
@@ -52,9 +50,10 @@
 
     private static final Logger LOG = LogUtils.getL7dLogger(JaxWsClientProxy.class);
 
-    protected AtomicReference<Map<String, Object>> requestContext = 
-            new AtomicReference<Map<String, Object>>();
-    protected Map<String, Object> responseContext;
+    protected ThreadLocal <Map<String, Object>> requestContext = 
+            new ThreadLocal<Map<String, Object>>();
+    protected ThreadLocal <Map<String, Object>> responseContext =
+            new ThreadLocal<Map<String, Object>>();
 
     private Endpoint endpoint;
     private final Binding binding;
@@ -96,16 +95,22 @@
         if (null == params) {
             params = new Object[0];
         }
-
-        Map<String, Object> reqContext = this.getRequestContext();
-        Map<String, Object> resContext = this.getResponseContext();
+        Map<String, Object> reqContext = this.getRequestContext();        
+        Map<String, Object> respContext = this.getResponseContext();
+        // Clear the request ThreadLocal variable        
+        clearContext(requestContext);
+        // Clear the response context's hold information
+        // Not call the clear Context is to avoid the error 
+        // that getResponseContext() could be called by Client code first
+        respContext.clear();
+        
         Map<String, Object> context = new HashMap<String, Object>();
 
         // need to do context mapping from jax-ws to cxf message
         ContextPropertiesMapping.mapRequestfromJaxws2Cxf(reqContext);
 
         context.put(Client.REQUEST_CONTEXT, reqContext);
-        context.put(Client.RESPONSE_CONTEXT, resContext);
+        context.put(Client.RESPONSE_CONTEXT, respContext);
 
         reqContext.put(Method.class.getName(), method);
 
@@ -118,7 +123,7 @@
             result = invokeSync(method, oi, params, context);
         }
         // need to do context mapping from cxf message to jax-ws
-        ContextPropertiesMapping.mapResponsefromCxf2Jaxws(resContext);
+        ContextPropertiesMapping.mapResponsefromCxf2Jaxws(respContext);
         return result;
 
     }
@@ -142,19 +147,25 @@
             return r;
         }
     }
+    
+    private void clearContext(ThreadLocal<Map<String, Object>> context) {
+        if (null != context.get()) {
+            context.set(null);
+        }
+    }
 
     public Map<String, Object> getRequestContext() {
         if (null == requestContext.get()) {
-            requestContext.compareAndSet(null, new ConcurrentHashMap<String, Object>(4));
+            requestContext.set(new HashMap<String, Object>());
         }
-        return (Map<String, Object>)requestContext.get();
+        return requestContext.get();
     }
 
     public Map<String, Object> getResponseContext() {
-        if (responseContext == null) {
-            responseContext = new HashMap<String, Object>();
-        }
-        return responseContext;
+        if (null == responseContext.get()) {
+            responseContext.set(new HashMap<String, Object>());
+        }        
+        return responseContext.get();
     }
 
     public Binding getBinding() {

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerXMLTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerXMLTest.java?view=diff&rev=520299&r1=520298&r2=520299
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerXMLTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerXMLTest.java
Tue Mar 20 00:07:12 2007
@@ -228,16 +228,18 @@
             reply = greeter.sayHi();
             assertNotNull("no response received from service", reply);
             assertEquals(response2, reply);
+            
+            BindingProvider bp = (BindingProvider) greeter;
+            Map<String, Object> responseContext = bp.getResponseContext();
+            Integer responseCode = (Integer) responseContext.get(Message.RESPONSE_CODE);
+            assertEquals(200, responseCode.intValue());
 
             greeter.greetMeOneWay(System.getProperty("user.name"));
 
         } catch (UndeclaredThrowableException ex) {
             throw (Exception) ex.getCause();
         }
-        BindingProvider bp = (BindingProvider) greeter;
-        Map<String, Object> responseContext = bp.getResponseContext();
-        Integer responseCode = (Integer) responseContext.get(Message.RESPONSE_CODE);
-        assertEquals(200, responseCode.intValue());
+       
     }
 
     @Test



Mime
View raw message