cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1551612 - in /cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client: ClientProxyImpl.java WebClient.java
Date Tue, 17 Dec 2013 16:41:06 GMT
Author: sergeyb
Date: Tue Dec 17 16:41:06 2013
New Revision: 1551612

URL: http://svn.apache.org/r1551612
Log:
[CXF-5423] Setting correct bus and loader before the client invocation

Modified:
    cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
    cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=1551612&r1=1551611&r2=1551612&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
(original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
Tue Dec 17 16:41:06 2013
@@ -53,6 +53,10 @@ import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.PropertyUtils;
@@ -605,46 +609,61 @@ public class ClientProxyImpl extends Abs
                                        int bodyIndex,
                                        Exchange exchange,
                                        Map<String, Object> invocationContext) throws
Throwable {
-        
-        Message outMessage = createMessage(body, ori.getHttpMethod(), headers, uri, 
-                                           exchange, invocationContext, true);
-        if (bodyIndex != -1) {
-            outMessage.put(Type.class, ori.getMethodToInvoke().getGenericParameterTypes()[bodyIndex]);
-        }
-        outMessage.getExchange().setOneWay(ori.isOneway());
-        outMessage.setContent(OperationResourceInfo.class, ori);
-        setPlainOperationNameProperty(outMessage, ori.getMethodToInvoke().getName());
-        outMessage.getExchange().put(Method.class, ori.getMethodToInvoke());
-        
-        outMessage.put(Annotation.class.getName(), 
-                       getMethodAnnotations(ori.getAnnotatedMethod(), bodyIndex));
-        
-        if (body != null) {
-            outMessage.put("BODY_INDEX", bodyIndex);
-            outMessage.getInterceptorChain().add(new BodyWriter());
-        }
-
-        Map<String, Object> reqContext = getRequestContext(outMessage);
-        reqContext.put(OperationResourceInfo.class.getName(), ori);
-        reqContext.put("BODY_INDEX", bodyIndex);
-        
-        // execute chain    
-        doRunInterceptorChain(outMessage);
-        
-        Object[] results = preProcessResult(outMessage);
-        if (results != null && results.length == 1) {
-            return results[0];
-        }
-        
-        Object response = null;
+        Bus configuredBus = getConfiguration().getBus();
+        Bus origBus = BusFactory.getAndSetThreadDefaultBus(configuredBus);
+        ClassLoaderHolder origLoader = null;
         try {
-            response = handleResponse(outMessage, ori.getClassResourceInfo().getServiceClass());
-            return response;
-        } catch (Exception ex) {
-            response = ex;
-            throw ex;
+            ClassLoader loader = configuredBus.getExtension(ClassLoader.class);
+            if (loader != null) {
+                origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
+            }
+            Message outMessage = createMessage(body, ori.getHttpMethod(), headers, uri, 
+                                               exchange, invocationContext, true);
+            if (bodyIndex != -1) {
+                outMessage.put(Type.class, ori.getMethodToInvoke().getGenericParameterTypes()[bodyIndex]);
+            }
+            outMessage.getExchange().setOneWay(ori.isOneway());
+            outMessage.setContent(OperationResourceInfo.class, ori);
+            setPlainOperationNameProperty(outMessage, ori.getMethodToInvoke().getName());
+            outMessage.getExchange().put(Method.class, ori.getMethodToInvoke());
+            
+            outMessage.put(Annotation.class.getName(), 
+                           getMethodAnnotations(ori.getAnnotatedMethod(), bodyIndex));
+            
+            if (body != null) {
+                outMessage.put("BODY_INDEX", bodyIndex);
+                outMessage.getInterceptorChain().add(new BodyWriter());
+            }
+    
+            Map<String, Object> reqContext = getRequestContext(outMessage);
+            reqContext.put(OperationResourceInfo.class.getName(), ori);
+            reqContext.put("BODY_INDEX", bodyIndex);
+            
+            // execute chain    
+            doRunInterceptorChain(outMessage);
+            
+            Object[] results = preProcessResult(outMessage);
+            if (results != null && results.length == 1) {
+                return results[0];
+            }
+            
+            Object response = null;
+            try {
+                response = handleResponse(outMessage, ori.getClassResourceInfo().getServiceClass());
+                return response;
+            } catch (Exception ex) {
+                response = ex;
+                throw ex;
+            } finally {
+                completeExchange(response, outMessage.getExchange(), true);
+            }
         } finally {
-            completeExchange(response, outMessage.getExchange(), true);
+            if (origLoader != null) {
+                origLoader.reset();
+            }
+            if (origBus != configuredBus) {
+                BusFactory.setThreadDefaultBus(origBus);
+            }
         }
         
     }

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=1551612&r1=1551611&r2=1551612&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java (original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java Tue Dec
17 16:41:06 2013
@@ -51,7 +51,10 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
 import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
 import org.apache.cxf.feature.Feature;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.Fault;
@@ -1058,10 +1061,26 @@ public class WebClient extends AbstractC
                                            Exchange exchange,
                                            Map<String, Object> invContext) {
     //CHECKSTYLE:ON    
-        Message m = finalizeMessage(httpMethod, headers, body, requestClass, inType, 
-                                    inAnns, respClass, outType, exchange, invContext);
-        doRunInterceptorChain(m);
-        return doResponse(m, respClass, outType);
+        Bus configuredBus = getConfiguration().getBus();
+        Bus origBus = BusFactory.getAndSetThreadDefaultBus(configuredBus);
+        ClassLoaderHolder origLoader = null;
+        try {
+            ClassLoader loader = configuredBus.getExtension(ClassLoader.class);
+            if (loader != null) {
+                origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
+            }
+            Message m = finalizeMessage(httpMethod, headers, body, requestClass, inType,

+                                        inAnns, respClass, outType, exchange, invContext);
+            doRunInterceptorChain(m);
+            return doResponse(m, respClass, outType);
+        } finally {
+            if (origLoader != null) {
+                origLoader.reset();
+            }
+            if (origBus != configuredBus) {
+                BusFactory.setThreadDefaultBus(origBus);
+            }
+        }    
     }
     
     //CHECKSTYLE:OFF



Mime
View raw message