cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r707140 - in /cxf/branches/2.0.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, 22 Oct 2008 17:20:08 GMT
Author: dkulp
Date: Wed Oct 22 10:20:07 2008
New Revision: 707140

URL: http://svn.apache.org/viewvc?rev=707140&view=rev
Log:
Merged revisions 704998 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.1.x-fixes

................
  r704998 | dkulp | 2008-10-15 15:28:38 -0400 (Wed, 15 Oct 2008) | 10 lines
  
  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.0.x-fixes/   (props changed)
    cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/endpoint/Client.java
    cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java
    cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
    cxf/branches/2.0.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java
    cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSAsyncCallable.java
    cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
    cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WrappedMessageContext.java
    cxf/branches/2.0.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientProxy.java
    cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/JaxWsClientThreadTest.java

Propchange: cxf/branches/2.0.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Oct 22 10:20:07 2008
@@ -1,3 +1,3 @@
-/cxf/branches/2.1.x-fixes:673548,674485,674547,674551,674562,674601,674649,674764,674887,675644,675653,677048,677385,678004,678009,678559,678629,678808,678852,678891,678893,679248,679597,680435,681060,681165,681813,681816,682902,682951,683089,683290,683318,684099,684790-684793,684842,684862,684895-684918,685205,685253,686237,686283,686299,686333-686364,686765,686827,687097,687464-687465,689109,689112,689122,691316,691357,691491,691711,691715,691745,692162-692163,692468,692500,694466-694469,694472,694717,694748-694749,694870,695503,695509,695553,695555,695563,695875-695877,695940,695980,696436,696455,696721,697086,698129,701526,701634,702275,702443,702527,702582,702604,702610,702642-702643,702649,702760,702870,702873,702959,703193,703242,703523,704303,704587,704738,705153
-/cxf/trunk:651669-686342,686344-686363,686764,686820,687096,687387,687463,688086,688102,688735,691271,691355,691488,691602,691706,691728,692116,692157,692466,692499,693653,693819,694179,694263,694417,694716,694744,694747,694869,695396,695484,695537,695552,695561,695619,695684,695835,695935,695977,696094,696433,696720,697085,698128,700261,700602,701783,701830,701862,702267,702580,702602,702609,702616,702656,702957,703191,703239,703501,704584,705150
+/cxf/branches/2.1.x-fixes:673548,674485,674547,674551,674562,674601,674649,674764,674887,675644,675653,677048,677385,678004,678009,678559,678629,678808,678852,678891,678893,679248,679597,680435,681060,681165,681813,681816,682902,682951,683089,683290,683318,684099,684790-684793,684842,684862,684895-684918,685205,685253,686237,686283,686299,686333-686364,686765,686827,687097,687464-687465,689109,689112,689122,691316,691357,691491,691711,691715,691745,692162-692163,692468,692500,694466-694469,694472,694717,694748-694749,694870,695503,695509,695553,695555,695563,695875-695877,695940,695980,696436,696455,696721,697086,698129,701526,701634,702275,702443,702527,702582,702604,702610,702642-702643,702649,702760,702870,702873,702959,703193,703242,703523,704303,704587,704738,704998,705153
+/cxf/trunk:651669-686342,686344-686363,686764,686820,687096,687387,687463,688086,688102,688735,691271,691355,691488,691602,691706,691728,692116,692157,692466,692499,693653,693819,694179,694263,694417,694716,694744,694747,694869,695396,695484,695537,695552,695561,695619,695684,695835,695935,695977,696094,696433,696720,697085,698128,700261,700602,701783,701830,701862,702267,702580,702602,702609,702616,702656,702957,703191,703239,703501,704584,704997,705150
 /incubator/cxf/trunk:434594-651668

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

Modified: cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/endpoint/Client.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/endpoint/Client.java?rev=707140&r1=707139&r2=707140&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/endpoint/Client.java (original)
+++ cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/endpoint/Client.java Wed Oct
22 10:20:07 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.0.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java?rev=707140&r1=707139&r2=707140&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java
(original)
+++ cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java
Wed Oct 22 10:20:07 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.0.x-fixes/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java?rev=707140&r1=707139&r2=707140&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
(original)
+++ cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
Wed Oct 22 10:20:07 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);
@@ -176,6 +189,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);
     }
@@ -215,44 +263,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);
     
@@ -266,7 +334,7 @@
             PhaseInterceptorChain chain = setupInterceptorChain(endpoint);
             message.setInterceptorChain(chain);
             
-            modifyChain(chain, requestContext);
+            modifyChain(chain, reqContext);
             chain.setFaultObserver(outFaultObserver);
             
             // setup conduit selector
@@ -306,8 +374,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);
                     }
@@ -571,4 +639,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.0.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java?rev=707140&r1=707139&r2=707140&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java
(original)
+++ cxf/branches/2.0.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java
Wed Oct 22 10:20:07 2008
@@ -27,8 +27,10 @@
 import java.net.URLClassLoader;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Set;
 import java.util.StringTokenizer;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -49,6 +51,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;
@@ -129,6 +132,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
@@ -142,16 +148,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();
         }
@@ -166,9 +187,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();
@@ -262,6 +288,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;
@@ -311,8 +355,11 @@
         int num = 1;
         for (SchemaInfo schema : schemas) {
             Element el = schema.getElement();
-            
-            compiler.parseSchema(wsdlUrl + "#types" + num, el);
+            String key = schema.getSystemId();
+            if (StringUtils.isEmpty(key)) {
+                key = wsdlUrl + "#types" + num;
+            }
+            compiler.parseSchema(key, el);
             num++;
         }
         
@@ -494,4 +541,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.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSAsyncCallable.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSAsyncCallable.java?rev=707140&r1=707139&r2=707140&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSAsyncCallable.java
(original)
+++ cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSAsyncCallable.java
Wed Oct 22 10:20:07 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.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java?rev=707140&r1=707139&r2=707140&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
(original)
+++ cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
Wed Oct 22 10:20:07 2008
@@ -25,7 +25,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;
 
     public JaxWsClientProxy(Client c, Binding b) {
@@ -113,7 +75,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());
         }
     }
@@ -138,37 +100,16 @@
             throw new WebServiceException(msg.toString());
         }
 
-        Object[] params = args;
-        if (null == params) {
-            params = new Object[0];
-        }
-
-        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>();
 
-        // 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, 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();
@@ -202,7 +143,7 @@
         }
         
         // need to do context mapping from cxf message to jax-ws
-        ContextPropertiesMapping.mapResponsefromCxf2Jaxws(respContext);
+        ContextPropertiesMapping.mapResponsefromCxf2Jaxws(client.getResponseContext());
         Map<String, Scope> scopes = CastUtils.cast((Map<?, ?>)respContext.get(WrappedMessageContext.SCOPES));
         if (scopes != null) {
             for (Map.Entry<String, Scope> scope : scopes.entrySet()) {
@@ -266,9 +207,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));
 
@@ -286,54 +227,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,
-                                                              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 HashMap<String, Object>());
-        }        
-        return responseContext.get();
+        return new WrappedMessageContext(this.getClient().getResponseContext(),
+                                                          null,
+                                                          Scope.APPLICATION);
     }
 
     public Binding getBinding() {

Modified: cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WrappedMessageContext.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WrappedMessageContext.java?rev=707140&r1=707139&r2=707140&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WrappedMessageContext.java
(original)
+++ cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WrappedMessageContext.java
Wed Oct 22 10:20:07 2008
@@ -92,6 +92,9 @@
     public final Message getWrappedMessage() {
         return message;
     }
+    public final Map<String, Object> getWrappedMap() {
+        return message;
+    }
     
     public void clear() {
         contextMap.clear();      
@@ -148,7 +151,11 @@
 
     public final Object remove(Object key) {
         scopes.remove(key);
-        return contextMap.remove(key);
+        if (BindingProvider.PASSWORD_PROPERTY.equals(key) 
+            || BindingProvider.USERNAME_PROPERTY.equals(key)) {
+            message.remove(AuthorizationPolicy.class.getName());
+        }
+        return message.remove(key);
     }
 
     public final int size() {

Modified: cxf/branches/2.0.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientProxy.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientProxy.java?rev=707140&r1=707139&r2=707140&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientProxy.java
(original)
+++ cxf/branches/2.0.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientProxy.java
Wed Oct 22 10:20:07 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.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/JaxWsClientThreadTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/JaxWsClientThreadTest.java?rev=707140&r1=707139&r2=707140&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/JaxWsClientThreadTest.java
(original)
+++ cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/JaxWsClientThreadTest.java
Wed Oct 22 10:20:07 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