cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1551639 - in /cxf/branches/2.6.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
Date Tue, 17 Dec 2013 17:37:01 GMT
Author: sergeyb
Date: Tue Dec 17 17:37:01 2013
New Revision: 1551639

URL: http://svn.apache.org/r1551639
Log:
Merged revisions 1551632 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes

................
  r1551632 | sergeyb | 2013-12-17 17:08:29 +0000 (Tue, 17 Dec 2013) | 9 lines
  
  Merged revisions 1551612 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1551612 | sergeyb | 2013-12-17 16:41:06 +0000 (Tue, 17 Dec 2013) | 1 line
    
    [CXF-5423] Setting correct bus and loader before the client invocation
  ........
................

Modified:
    cxf/branches/2.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/branches/2.7.x-fixes:r1551632
  Merged /cxf/trunk:r1551612

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

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=1551639&r1=1551638&r2=1551639&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
Tue Dec 17 17:37:01 2013
@@ -44,6 +44,10 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 import javax.xml.stream.XMLStreamWriter;
 
+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.endpoint.Endpoint;
@@ -504,49 +508,63 @@ 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);
-        
-        outMessage.getExchange().setOneWay(ori.isOneway());
-        outMessage.setContent(OperationResourceInfo.class, ori);
-        setPlainOperationNameProperty(outMessage, ori.getMethodToInvoke().getName());
-        outMessage.getExchange().put(Method.class, ori.getMethodToInvoke());
-        
-        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    
-        try {
-            outMessage.getInterceptorChain().doIntercept(outMessage);
-        } catch (Exception ex) {
-            outMessage.setContent(Exception.class, ex);
-        }
-        
-        Object[] results = preProcessResult(outMessage);
-        if (results != null && results.length == 1) {
-            // this can happen if a connection exception has occurred and
-            // failover feature used this client to invoke on a different address  
-            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);
+            
+            outMessage.getExchange().setOneWay(ori.isOneway());
+            outMessage.setContent(OperationResourceInfo.class, ori);
+            setPlainOperationNameProperty(outMessage, ori.getMethodToInvoke().getName());
+            outMessage.getExchange().put(Method.class, ori.getMethodToInvoke());
+            
+            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    
+            try {
+                outMessage.getInterceptorChain().doIntercept(outMessage);
+            } catch (Exception ex) {
+                outMessage.setContent(Exception.class, ex);
+            }
+            
+            Object[] results = preProcessResult(outMessage);
+            if (results != null && results.length == 1) {
+                // this can happen if a connection exception has occurred and
+                // failover feature used this client to invoke on a different address  
+                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);
+            }
         }
-        
     }
     
     @Override

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=1551639&r1=1551638&r2=1551639&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
Tue Dec 17 17:37:01 2013
@@ -42,7 +42,10 @@ import javax.ws.rs.core.UriBuilder;
 import javax.xml.stream.XMLStreamWriter;
 
 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.AbstractFeature;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
@@ -820,53 +823,69 @@ public class WebClient extends AbstractC
                                            Exchange exchange,
                                            Map<String, Object> invContext) {
     //CHECKSTYLE:ON    
-        URI uri = getCurrentURI();
-        Message m = createMessage(body, httpMethod, headers, uri, exchange, 
-                invContext, false);
-        
-        Map<String, Object> reqContext = getRequestContext(m);
-        reqContext.put(Message.HTTP_REQUEST_METHOD, httpMethod);
-        reqContext.put(REQUEST_CLASS, requestClass);
-        reqContext.put(REQUEST_TYPE, inGenericType);
-        reqContext.put(RESPONSE_CLASS, responseClass);
-        reqContext.put(RESPONSE_TYPE, outGenericType);
-        
-        if (body != null) {
-            m.getInterceptorChain().add(new BodyWriter());
-        }
-        setPlainOperationNameProperty(m, httpMethod + ":" + uri.toString());
-        
-        try {
-            m.getInterceptorChain().doIntercept(m);
-        } catch (Exception ex) {
-            m.setContent(Exception.class, ex);
-        }
-        try {
-            Object[] results = preProcessResult(m);
-            if (results != null && results.length == 1) {
-                // this can happen if a connection exception has occurred and
-                // failover feature used this client to invoke on a different address  
-                return (Response)results[0];
-            }
-        } catch (Exception ex) {
-            throw ex instanceof ServerWebApplicationException 
-                ? (ServerWebApplicationException)ex 
-                : ex instanceof ClientWebApplicationException 
-                ? new ClientWebApplicationException(ex) : new RuntimeException(ex); 
-        }
-        
-        Response response = null;
-        Object entity = null;
+        Bus configuredBus = getConfiguration().getBus();
+        Bus origBus = BusFactory.getAndSetThreadDefaultBus(configuredBus);
+        ClassLoaderHolder origLoader = null;
         try {
-            response = handleResponse(m, responseClass, outGenericType);
-            entity = response.getEntity();
-            return response;
-        } catch (RuntimeException ex) {
-            entity = ex;
-            throw ex;
+            ClassLoader loader = configuredBus.getExtension(ClassLoader.class);
+            if (loader != null) {
+                origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
+            }
+            URI uri = getCurrentURI();
+            Message m = createMessage(body, httpMethod, headers, uri, exchange, 
+                    invContext, false);
+            
+            Map<String, Object> reqContext = getRequestContext(m);
+            reqContext.put(Message.HTTP_REQUEST_METHOD, httpMethod);
+            reqContext.put(REQUEST_CLASS, requestClass);
+            reqContext.put(REQUEST_TYPE, inGenericType);
+            reqContext.put(RESPONSE_CLASS, responseClass);
+            reqContext.put(RESPONSE_TYPE, outGenericType);
+            
+            if (body != null) {
+                m.getInterceptorChain().add(new BodyWriter());
+            }
+            setPlainOperationNameProperty(m, httpMethod + ":" + uri.toString());
+            
+            try {
+                m.getInterceptorChain().doIntercept(m);
+            } catch (Exception ex) {
+                m.setContent(Exception.class, ex);
+            }
+            try {
+                Object[] results = preProcessResult(m);
+                if (results != null && results.length == 1) {
+                    // this can happen if a connection exception has occurred and
+                    // failover feature used this client to invoke on a different address
 
+                    return (Response)results[0];
+                }
+            } catch (Exception ex) {
+                throw ex instanceof ServerWebApplicationException 
+                    ? (ServerWebApplicationException)ex 
+                    : ex instanceof ClientWebApplicationException 
+                    ? new ClientWebApplicationException(ex) : new RuntimeException(ex); 
+            }
+            
+            Response response = null;
+            Object entity = null;
+            try {
+                response = handleResponse(m, responseClass, outGenericType);
+                entity = response.getEntity();
+                return response;
+            } catch (RuntimeException ex) {
+                entity = ex;
+                throw ex;
+            } finally {
+                completeExchange(entity, m.getExchange(), false);
+            }
         } finally {
-            completeExchange(entity, m.getExchange(), false);
-        }
+            if (origLoader != null) {
+                origLoader.reset();
+            }
+            if (origBus != configuredBus) {
+                BusFactory.setThreadDefaultBus(origBus);
+            }
+        }    
     }
     
     protected Response handleResponse(Message outMessage, Class<?> responseClass, Type
genericType) {



Mime
View raw message