cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r704998 - in /cxf/branches/2.1.x-fixes: ./ api/src/main/java/org/apache/cxf/endpoint/ rt/core/src/main/java/org/apache/cxf/clustering/ rt/core/src/main/java/org/apache/cxf/endpoint/ rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/...
Date Wed, 15 Oct 2008 19:28:38 GMT
Author: dkulp
Date: Wed Oct 15 12:28:38 2008
New Revision: 704998

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

........
  r704997 | dkulp | 2008-10-15 15:27:11 -0400 (Wed, 15 Oct 2008) | 3 lines
  
  [CXF-932, CXF-1654] Promote request/response contexts up into simple frontend
  Add ability to specify binding files for DynamicClient.  Add ClassNameAllocator to dynamic
client to automatically resolve some of those issues.
........

Modified:
    cxf/branches/2.1.x-fixes/   (props changed)
    cxf/branches/2.1.x-fixes/api/src/main/java/org/apache/cxf/endpoint/Client.java
    cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java
    cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
    cxf/branches/2.1.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java
    cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSAsyncCallable.java
    cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
    cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WrappedMessageContext.java
    cxf/branches/2.1.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientProxy.java
    cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/JaxWsClientThreadTest.java

Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Oct 15 12:28:38 2008
@@ -1 +1 @@
-/cxf/trunk:686333-686363,686764,686820,687096,687194,687363,687387,687463,687543,687722,687798,687814,687817,687891,687910,687914,688086,688102,688133,688596,688735,688870,689572,689596,689855,689924,690067,690289,691246,691271,691295,691338,691355,691488,691602,691646,691706,691728,692116,692157,692310,692466,692499,693653,693819,694179,694263,694417,694716,694744,694747,694795,694869,694981,694987,694993,695041,695096,695396,695484,695537,695552,695561,695619,695684,695835,695840,695868,695935,695977,696016,696094,696433,696720,697085,697868,698128,699289,700261,700507,700602,700981,701316,701783,701830,701862,702187,702205-702248,702267,702547,702561,702580,702602,702609,702616,702653,702656,702957,703191,703239,703309,703501,703513,703548,704584,704937
+/cxf/trunk:686333-686363,686764,686820,687096,687194,687363,687387,687463,687543,687722,687798,687814,687817,687891,687910,687914,688086,688102,688133,688596,688735,688870,689572,689596,689855,689924,690067,690289,691246,691271,691295,691338,691355,691488,691602,691646,691706,691728,692116,692157,692310,692466,692499,693653,693819,694179,694263,694417,694716,694744,694747,694795,694869,694981,694987,694993,695041,695096,695396,695484,695537,695552,695561,695619,695684,695835,695840,695868,695935,695977,696016,696094,696433,696720,697085,697868,698128,699289,700261,700507,700602,700981,701316,701783,701830,701862,702187,702205-702248,702267,702547,702561,702580,702602,702609,702616,702653,702656,702957,703191,703239,703309,703501,703513,703548,704584,704937,704997

Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.1.x-fixes/api/src/main/java/org/apache/cxf/endpoint/Client.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/api/src/main/java/org/apache/cxf/endpoint/Client.java?rev=704998&r1=704997&r2=704998&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/api/src/main/java/org/apache/cxf/endpoint/Client.java (original)
+++ cxf/branches/2.1.x-fixes/api/src/main/java/org/apache/cxf/endpoint/Client.java Wed Oct
15 12:28:38 2008
@@ -31,7 +31,7 @@
 public interface Client extends InterceptorProvider, MessageObserver {
     String REQUEST_CONTEXT = "RequestContext";
     String RESPONSE_CONTEXT = "ResponseContext";
-    String REQUEST_METHOD = "RequestMethod";
+
     /**
      * Invokes an operation syncronously
      * @param operationName The name of the operation to be invoked. The service namespace
will be used
@@ -94,6 +94,34 @@
     Object[] invoke(BindingOperationInfo oi,
                     Object[] params,
                     Map<String, Object> context) throws Exception;
+    
+    
+    /**
+     * Gets the request context used for future invocations
+     * @return context The context
+     */
+    Map<String, Object> getRequestContext();
+    /**
+     * Gets the response context from the last invocation on this thread
+     * @return context The context
+     */
+    Map<String, Object> getResponseContext();
+    
+    /**
+     * Sets whether the request context is thread local or global to this client.  By 
+     * default, the request context is "global" in that any values set in the context
+     * are seen by all threads using this client.  If set to true, the context is changed

+     * to be a ThreadLocal and values set are not seen by other threads.
+     * @param b
+     */
+    void setThreadLocalRequestContext(boolean b);
+    
+    /**
+     * Checks if the Request context is thread local or global.
+     * @return
+     */
+    boolean isThreadLocalRequestContext();
+
 
     Endpoint getEndpoint();
 

Modified: cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java?rev=704998&r1=704997&r2=704998&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java
Wed Oct 15 12:28:38 2008
@@ -134,7 +134,7 @@
                         retry.invoke(invocation.getBindingOperationInfo(),
                                      invocation.getParams(),
                                      invocation.getContext(),
-                                      exchange);
+                                     exchange);
                     } catch (Exception e) {
                         if (exchange.get(Exception.class) != null) {
                             exchange.put(Exception.class, prevExchangeFault);

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=704998&r1=704997&r2=704998&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
Wed Oct 15 12:28:38 2008
@@ -22,8 +22,10 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -66,6 +68,9 @@
     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);
@@ -77,6 +82,14 @@
     
     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 <Map<String, Object>> responseContext =
+            new ThreadLocal<Map<String, Object>>();
+
 
     public ClientImpl(Bus b, Endpoint e) {
         this(b, e, (ConduitSelector)null);
@@ -196,6 +209,41 @@
         return getConduitSelector().getEndpoint();
     }
 
+    
+    public Map<String, Object> getRequestContext() {
+        if (isThreadLocalRequestContext()) {
+            if (null == requestContext.get()) {
+                requestContext.set(new EchoContext(currentRequestContext));
+            }
+            return requestContext.get();
+        }
+        return currentRequestContext;
+    }
+    public Map<String, Object> getResponseContext() {
+        if (null == responseContext.get()) {
+            responseContext.set(new HashMap<String, Object>());
+        }        
+        return responseContext.get();
+
+    }
+    public boolean isThreadLocalRequestContext() {
+        if (currentRequestContext.containsKey(THREAD_LOCAL_REQUEST_CONTEXT)) {
+            Object o = currentRequestContext.get(THREAD_LOCAL_REQUEST_CONTEXT);
+            boolean local = false;
+            if (o instanceof Boolean) {
+                local = ((Boolean)o).booleanValue();
+            } else {
+                local = Boolean.parseBoolean(o.toString());
+            }
+            return local;
+        }
+        return false;
+    }
+    public void setThreadLocalRequestContext(boolean b) {
+        currentRequestContext.put(THREAD_LOCAL_REQUEST_CONTEXT, b);
+    }
+
+    
     public Object[] invoke(BindingOperationInfo oi, Object... params) throws Exception {
         return invoke(oi, params, null);
     }
@@ -235,44 +283,64 @@
         return invoke(op, params);
     }
 
-    
-    
-    public Object[] invoke(BindingOperationInfo oi, Object[] params, 
+    public Object[] invoke(BindingOperationInfo oi,
+                           Object[] params, 
+                           Exchange exchange) throws Exception {
+        Map<String, Object> context = new HashMap<String, Object>();
+        Map<String, Object> resp = getResponseContext();
+        resp.clear();
+        Map<String, Object> req = new HashMap<String, Object>(getRequestContext());
+        context.put(RESPONSE_CONTEXT, resp);
+        context.put(REQUEST_CONTEXT, req);
+        try {
+            return invoke(oi, params, context, exchange);
+        } finally {
+            responseContext.set(resp);
+        }
+    }
+    public Object[] invoke(BindingOperationInfo oi,
+                           Object[] params, 
                            Map<String, Object> context) throws Exception {
-        return invoke(oi, params, context, null);
-    }        
-    
+        try {
+            return invoke(oi, params, context, (Exchange)null);
+        } finally {
+            if (context != null) {
+                Map<String, Object> resp = CastUtils.cast((Map<?, ?>)context.get(RESPONSE_CONTEXT));
+                if (resp != null) {
+                    responseContext.set(resp);
+                }
+            }
+        }
+    }
     public Object[] invoke(BindingOperationInfo oi,
                            Object[] params, 
                            Map<String, Object> context,
                            Exchange exchange) throws Exception {
-                
         Bus origBus = BusFactory.getThreadDefaultBus(false);
         BusFactory.setThreadDefaultBus(bus);
         try {
-        
             if (exchange == null) {
                 exchange = new ExchangeImpl();
             }
             Endpoint endpoint = getEndpoint();
-    
-            Map<String, Object> requestContext = null;
-            Map<String, Object> responseContext = null;
+            
+            Map<String, Object> reqContext = null;
+            Map<String, Object> resContext = null;
             if (LOG.isLoggable(Level.FINE)) {
                 LOG.fine("Invoke, operation info: " + oi + ", params: " + params);
             }
             Message message = endpoint.getBinding().createMessage();
             if (null != context) {
-                requestContext = CastUtils.cast((Map)context.get(REQUEST_CONTEXT));
-                responseContext = CastUtils.cast((Map)context.get(RESPONSE_CONTEXT));
+                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(requestContext, message);
+            setContext(reqContext, message);
             setParameters(params, message);
     
-            if (null != requestContext) {
-                exchange.putAll(requestContext);
+            if (null != reqContext) {
+                exchange.putAll(reqContext);
             }
             exchange.setOneWay(oi.getOutput() == null);
     
@@ -286,7 +354,7 @@
             PhaseInterceptorChain chain = setupInterceptorChain(endpoint);
             message.setInterceptorChain(chain);
             
-            modifyChain(chain, requestContext);
+            modifyChain(chain, reqContext);
             chain.setFaultObserver(outFaultObserver);
             
             // setup conduit selector
@@ -326,8 +394,8 @@
             List resList = null;
             Message inMsg = exchange.getInMessage();
             if (inMsg != null) {
-                if (null != responseContext) {                   
-                    responseContext.putAll(inMsg);
+                if (null != resContext) {                   
+                    resContext.putAll(inMsg);
                     if (LOG.isLoggable(Level.FINE)) {
                         LOG.fine("set responseContext to be" + responseContext);
                     }
@@ -591,4 +659,36 @@
     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; 
+        public EchoContext(Map<String, Object> sharedMap) {
+            super(sharedMap);
+            shared = sharedMap;
+        }
+
+        public Object put(String key, Object value) {
+            shared.put(key, value);
+            return super.put(key, value);
+        }
+
+        public void putAll(Map<? extends String, ? extends Object> t) {
+            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);
+        }
+    }
 }

Modified: cxf/branches/2.1.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java?rev=704998&r1=704997&r2=704998&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java
Wed Oct 15 12:28:38 2008
@@ -29,9 +29,11 @@
 import java.net.URLClassLoader;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.StringTokenizer;
 import java.util.jar.Attributes;
 import java.util.jar.JarFile;
@@ -54,6 +56,7 @@
 import com.sun.codemodel.JPackage;
 import com.sun.codemodel.writer.FileCodeWriter;
 import com.sun.tools.xjc.Options;
+import com.sun.tools.xjc.api.ClassNameAllocator;
 import com.sun.tools.xjc.api.ErrorListener;
 import com.sun.tools.xjc.api.S2JJAXBModel;
 import com.sun.tools.xjc.api.SchemaCompiler;
@@ -144,6 +147,9 @@
     public Client createClient(String wsdlUrl) {
         return createClient(wsdlUrl, (QName)null, (QName)null);
     }
+    public Client createClient(String wsdlUrl, List<String> bindingFiles) {
+        return createClient(wsdlUrl, (QName)null, (QName)null, bindingFiles);
+    }
 
     /**
      * Create a new <code>Client</code> instance using the WSDL to be loaded
@@ -157,16 +163,31 @@
     public Client createClient(String wsdlUrl, ClassLoader classLoader) {
         return createClient(wsdlUrl, null, classLoader, null);
     }
+    public Client createClient(String wsdlUrl, ClassLoader classLoader, List<String>
bindingFiles) {
+        return createClient(wsdlUrl, null, classLoader, null, bindingFiles);
+    }
 
     public Client createClient(String wsdlUrl, QName service) {
-        return createClient(wsdlUrl, service, null);
+        return createClient(wsdlUrl, service, (QName)null);
+    }
+    public Client createClient(String wsdlUrl, QName service, List<String> bindingFiles)
{
+        return createClient(wsdlUrl, service, null, bindingFiles);
     }
 
     public Client createClient(String wsdlUrl, QName service, QName port) {
         return createClient(wsdlUrl, service, null, port);
     }
+    public Client createClient(String wsdlUrl, QName service, QName port, List<String>
bindingFiles) {
+        return createClient(wsdlUrl, service, null, port, bindingFiles);
+    }
 
     public Client createClient(String wsdlUrl, QName service, ClassLoader classLoader, QName
port) {
+        return createClient(wsdlUrl, service, classLoader, port, null);
+    }
+    public Client createClient(String wsdlUrl, QName service,
+                               ClassLoader classLoader, QName port,
+                               List<String> bindingFiles) {
+            
         if (classLoader == null) {
             classLoader = Thread.currentThread().getContextClassLoader();
         }
@@ -182,9 +203,14 @@
         SchemaCompiler compiler = XJC.createSchemaCompiler();
         ErrorListener elForRun = new InnerErrorListener(wsdlUrl);
         compiler.setErrorListener(elForRun);
+        
+        ClassNameAllocator allocator 
+            = new ClassNameAllocatorImpl();
+
+        compiler.setClassNameAllocator(allocator);
 
         addSchemas(wsdlUrl, schemas, compiler);
-        
+        addBindingFiles(bindingFiles, compiler);
         S2JJAXBModel intermediateModel = compiler.bind();
         JCodeModel codeModel = intermediateModel.generateCode(null, elForRun);
         StringBuilder sb = new StringBuilder();
@@ -277,6 +303,24 @@
         return client;
     }
 
+    @SuppressWarnings("deprecation")
+    private void addBindingFiles(List<String> bindingFiles, SchemaCompiler compiler)
{
+        if (bindingFiles != null) {
+            for (String s : bindingFiles) {
+                URL url = composeUrl(s);
+                try {
+                    InputStream ins = url.openStream();
+                    InputSource is = new InputSource(ins);
+                    is.setSystemId(url.toString());
+                    is.setPublicId(url.toString());
+                    compiler.getOptions().addBindFile(is);
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        }
+    }
+
     private boolean isValidPackage(JPackage jpackage) {
         if (jpackage == null) {
             return false;
@@ -327,14 +371,18 @@
         int num = 1;
         for (SchemaInfo schema : schemas) {
             Element el = schema.getElement();
+            String key = schema.getSystemId();
+            if (StringUtils.isEmpty(key)) {
+                key = wsdlUrl + "#types" + num;
+            }
 
             //For JAXB 2.1.8
             InputSource is = new InputSource((InputStream)null);
-            is.setSystemId(wsdlUrl + "#types" + num);
-            is.setPublicId(wsdlUrl + "#types" + num);
+            is.setSystemId(key);
+            is.setPublicId(key);
             compiler.getOptions().addGrammar(is);
 
-            compiler.parseSchema(wsdlUrl + "#types" + num, el);
+            compiler.parseSchema(key, el);
             num++;
         }
         
@@ -554,4 +602,27 @@
     public void setJaxbContextProperties(Map<String, Object> jaxbContextProperties)
{
         this.jaxbContextProperties = jaxbContextProperties;
     }
+    
+    
+    
+    private static class ClassNameAllocatorImpl implements ClassNameAllocator {
+        private final Set<String> typesClassNames = new HashSet<String>();
+
+        public ClassNameAllocatorImpl() {
+        }
+
+        public String assignClassName(String packageName, String className) {
+            String fullClassName = className;
+            String fullPckClass = packageName + "." + fullClassName;
+            int cnt = 0;
+            while (typesClassNames.contains(fullPckClass)) {
+                cnt++;
+                fullClassName = className + cnt;
+                fullPckClass = packageName + "." + fullClassName;
+            }
+            typesClassNames.add(fullPckClass);
+            return fullClassName;
+        }
+       
+    }
 }

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSAsyncCallable.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSAsyncCallable.java?rev=704998&r1=704997&r2=704998&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSAsyncCallable.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSAsyncCallable.java
Wed Oct 15 12:28:38 2008
@@ -47,7 +47,8 @@
     }
     
     public Object call() throws Exception {
-        return endPointInvocationHandler.invokeSync(method, oi, params, context);
+        endPointInvocationHandler.getRequestContext().putAll(context);
+        return endPointInvocationHandler.invokeSync(method, oi, params);
     }
 
 }

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java?rev=704998&r1=704997&r2=704998&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
Wed Oct 15 12:28:38 2008
@@ -26,7 +26,6 @@
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.FutureTask;
 import java.util.logging.Logger;
 
@@ -60,48 +59,11 @@
 
 public class JaxWsClientProxy extends org.apache.cxf.frontend.ClientProxy implements
     InvocationHandler, BindingProvider {
- 
-    /*
-     * modification are echoed back to the shared map
-     */
-    public static class EchoContext extends HashMap<String, Object> {
-        final Map<String, Object> shared; 
-        public EchoContext(Map<String, Object> sharedMap) {
-            super(sharedMap);
-            shared = sharedMap;
-        }
-
-        public Object put(String key, Object value) {
-            shared.put(key, value);
-            return super.put(key, value);
-        }
-
-        public void putAll(Map<? extends String, ? extends Object> t) {
-            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);
-        }
-    }
 
     public static final String THREAD_LOCAL_REQUEST_CONTEXT = "thread.local.request.context";
+    
     private static final Logger LOG = LogUtils.getL7dLogger(JaxWsClientProxy.class);
 
-    protected Map<String, Object> currentRequestContext = new ConcurrentHashMap<String,
Object>();
-    protected ThreadLocal <EchoContext> requestContext =
-        new ThreadLocal<EchoContext>();
-
-    protected ThreadLocal <Map<String, Object>> responseContext =
-            new ThreadLocal<Map<String, Object>>();
-
     private final Binding binding;
     private final EndpointReferenceBuilder builder;
 
@@ -115,7 +77,7 @@
     private void setupEndpointAddressContext(Endpoint endpoint) {
         // NOTE for jms transport the address would be null
         if (null != endpoint && null != endpoint.getEndpointInfo().getAddress())
{
-            currentRequestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, 
+            getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, 
                                       endpoint.getEndpointInfo().getAddress());
         }
     }
@@ -149,29 +111,15 @@
             throw new WebServiceException(msg.toString());
         }
 
-        Map<String, Object> reqContext = this.getRequestContextCopy();        
-        Map<String, Object> respContext = this.getResponseContext();
-        
-        // 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>();
-
-        context.put(Client.REQUEST_CONTEXT, reqContext);
-        context.put(Client.RESPONSE_CONTEXT, respContext);
-       
-        reqContext.put(Method.class.getName(), method);
-        reqContext.put(Client.REQUEST_METHOD, method);
+        client.getRequestContext().put(Method.class.getName(), method);
         boolean isAsync = method.getName().endsWith("Async");
 
         Object result = null;
         try {
             if (isAsync) {
-                result = invokeAsync(method, oi, params, context);
+                result = invokeAsync(method, oi, params);
             } else {
-                result = invokeSync(method, oi, params, context);
+                result = invokeSync(method, oi, params);
             }
         } catch (WebServiceException wex) {
             throw wex.fillInStackTrace();
@@ -204,6 +152,7 @@
             }
         }
         
+        Map<String, Object> respContext = client.getResponseContext();
         Map<String, Scope> scopes = CastUtils.cast((Map<?, ?>)respContext.get(WrappedMessageContext.SCOPES));
         if (scopes != null) {
             for (Map.Entry<String, Scope> scope : scopes.entrySet()) {
@@ -267,9 +216,9 @@
                  || address.equals(getClient().getEndpoint().getEndpointInfo().getAddress()));
     }
 
-    private Object invokeAsync(Method method, BindingOperationInfo oi, Object[] params,
-                               Map<String, Object> context) {
+    private Object invokeAsync(Method method, BindingOperationInfo oi, Object[] params) {
 
+        Map<String, Object> context = new HashMap<String, Object>(client.getRequestContext());
         FutureTask<Object> f = new FutureTask<Object>(new JAXWSAsyncCallable(this,
method, oi, params,
                                                                              context));
 
@@ -287,57 +236,16 @@
         }
     }
 
-    public boolean isThreadLocalRequestContext() {
-        if (currentRequestContext.containsKey(THREAD_LOCAL_REQUEST_CONTEXT)) {
-            Object o = currentRequestContext.get(THREAD_LOCAL_REQUEST_CONTEXT);
-            boolean local = false;
-            if (o instanceof Boolean) {
-                local = ((Boolean)o).booleanValue();
-            } else {
-                local = Boolean.parseBoolean(o.toString());
-            }
-            return local;
-        }
-        return false;
-    }
-    public void setThreadLocalRequestContext(boolean b) {
-        currentRequestContext.put(THREAD_LOCAL_REQUEST_CONTEXT, b);
-    }
-
     
-    private Map<String, Object> getRequestContextCopy() {
-        Map<String, Object> realMap = new HashMap<String, Object>();
-        WrappedMessageContext ctx = new WrappedMessageContext(realMap,
-                                                              null,
-                                                              Scope.APPLICATION);
-        // thread local contexts reflect currentRequestContext as of 
-        // last call to getRequestContext()
-        if (isThreadLocalRequestContext()
-            && null != requestContext.get()) {
-            ctx.putAll(requestContext.get());
-        } else {
-            ctx.putAll(currentRequestContext);
-        }
-        return realMap;
-    }
-
     public Map<String, Object> getRequestContext() {
-        if (isThreadLocalRequestContext()) {
-            if (null == requestContext.get()) {
-                requestContext.set(new EchoContext(currentRequestContext));
-            }
-            return requestContext.get();
-        }
-        return currentRequestContext;
+        return new WrappedMessageContext(this.getClient().getRequestContext(),
+                                         null,
+                                         Scope.APPLICATION);
     }
-
     public Map<String, Object> getResponseContext() {
-        if (null == responseContext.get()) {
-            responseContext.set(new WrappedMessageContext(new HashMap<String, Object>(),
+        return new WrappedMessageContext(this.getClient().getResponseContext(),
                                                           null,
-                                                          Scope.APPLICATION));
-        }        
-        return responseContext.get();
+                                                          Scope.APPLICATION);
     }
 
     public Binding getBinding() {

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WrappedMessageContext.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WrappedMessageContext.java?rev=704998&r1=704997&r2=704998&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WrappedMessageContext.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WrappedMessageContext.java
Wed Oct 15 12:28:38 2008
@@ -173,6 +173,9 @@
     public final Message getWrappedMessage() {
         return message instanceof Message ? (Message)message : null;
     }
+    public final Map<String, Object> getWrappedMap() {
+        return message;
+    }
     
     public void clear() {
         //just clear the JAXWS things....
@@ -403,6 +406,10 @@
     public final Object remove(Object key) {
         key = mapKey((String)key);
         scopes.remove(key);
+        if (BindingProvider.PASSWORD_PROPERTY.equals(key) 
+            || BindingProvider.USERNAME_PROPERTY.equals(key)) {
+            message.remove(AuthorizationPolicy.class.getName());
+        }
         return message.remove(key);
     }
 

Modified: cxf/branches/2.1.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientProxy.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientProxy.java?rev=704998&r1=704997&r2=704998&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientProxy.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientProxy.java
Wed Oct 15 12:28:38 2008
@@ -36,9 +36,9 @@
 
     private static final Logger LOG = LogUtils.getL7dLogger(ClientProxy.class);
 
+    protected Client client;
     private Endpoint endpoint;
 
-    private Client client;
 
     public ClientProxy(Client c) {
         endpoint = c.getEndpoint();
@@ -65,12 +65,12 @@
             params = new Object[0];
         }
 
-        return invokeSync(method, oi, params, null);
+        return invokeSync(method, oi, params);
     }
 
-    public Object invokeSync(Method method, BindingOperationInfo oi, Object[] params,
-                             Map<String, Object> context) throws Exception {
-        Object rawRet[] = client.invoke(oi, params, context);
+    public Object invokeSync(Method method, BindingOperationInfo oi, Object[] params)
+        throws Exception {
+        Object rawRet[] = client.invoke(oi, params);
 
         if (rawRet != null && rawRet.length > 0) {
             return rawRet[0];
@@ -78,6 +78,12 @@
             return null;
         }
     }
+    public Map<String, Object> getRequestContext() {
+        return client.getRequestContext();
+    }
+    public Map<String, Object> getResponseContext() {
+        return client.getResponseContext();
+    }
 
     public Client getClient() {
         return client;

Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/JaxWsClientThreadTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/JaxWsClientThreadTest.java?rev=704998&r1=704997&r2=704998&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/JaxWsClientThreadTest.java
(original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/JaxWsClientThreadTest.java
Wed Oct 15 12:28:38 2008
@@ -29,7 +29,9 @@
 import javax.xml.ws.BindingProvider;
 import javax.xml.ws.soap.SOAPFaultException;
 
+import org.apache.cxf.endpoint.ClientImpl;
 import org.apache.cxf.jaxws.JaxWsClientProxy;
+import org.apache.cxf.jaxws.context.WrappedMessageContext;
 import org.apache.cxf.test.AbstractCXFTest;
 import org.apache.hello_world_soap_http.Greeter;
 import org.junit.Test;
@@ -60,7 +62,7 @@
             public void run() {
                 try {
                     final String protocol = "http-" + Thread.currentThread().getId();
-                    for (int i = 0; i < 70; i++) {
+                    for (int i = 0; i < 10; i++) {
                         String threadSpecificaddress = protocol + "://localhost:80/" + i;
                         Map<String, Object> requestContext = ((BindingProvider)handler)
                                     .getRequestContext();
@@ -110,7 +112,8 @@
             .get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY)));
 
         // get the latest values
-        ((JaxWsClientProxy.EchoContext)requestContext).reload();
+        
+        ((ClientImpl.EchoContext)((WrappedMessageContext)requestContext).getWrappedMap()).reload();
         assertTrue("address is different", !address.equals(requestContext
             .get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY)));
         // verify value reflects what other threads were doing



Mime
View raw message