cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r752280 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java
Date Tue, 10 Mar 2009 21:47:47 GMT
Author: sergeyb
Date: Tue Mar 10 21:47:47 2009
New Revision: 752280

URL: http://svn.apache.org/viewvc?rev=752280&view=rev
Log:
CXF-2085 : optionally setting a thread context loader to that of the service object class
loader

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=752280&r1=752279&r2=752280&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java Tue Mar
10 21:47:47 2009
@@ -57,7 +57,8 @@
 public class JAXRSInvoker extends AbstractInvoker {
     private static final Logger LOG = LogUtils.getL7dLogger(JAXRSServiceFactoryBean.class);
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(JAXRSInvoker.class);
-
+    private static final String SERVICE_LOADER_AS_CONTEXT = "org.apache.cxf.serviceloader-context";
+    
     private List<Object> resourceObjects;
 
     public JAXRSInvoker() {
@@ -115,7 +116,11 @@
         }
 
         Object result = null;
+        ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
         try {
+            if (setServiceLoaderAsContextLoader(exchange.getInMessage())) {
+                Thread.currentThread().setContextClassLoader(resourceObject.getClass().getClassLoader());
+            }
             result = invoke(exchange, resourceObject, methodToInvoke, params);
         } catch (Fault ex) {
             Response excResponse = JAXRSUtils.convertFaultToResponse(ex.getCause(), 
@@ -131,6 +136,8 @@
                 throw ex;
             }
             return new MessageContentsList(excResponse);
+        } finally {
+            Thread.currentThread().setContextClassLoader(contextLoader);
         }
 
         if (ori.isSubResourceLocator()) {
@@ -194,6 +201,11 @@
         return result;
     }
 
+    private boolean setServiceLoaderAsContextLoader(Message inMessage) {
+        Object en = inMessage.getContextualProperty(SERVICE_LOADER_AS_CONTEXT);
+        return Boolean.TRUE.equals(en) || "true".equals(en);
+    }
+    
     public Object getServiceObject(Exchange exchange) {
         return getServiceObject(exchange, resourceObjects);
     }

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java?rev=752280&r1=752279&r2=752280&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java
Tue Mar 10 21:47:47 2009
@@ -20,6 +20,8 @@
 package org.apache.cxf.systest.jaxrs;
 
 import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.Unmarshaller;
@@ -51,7 +53,9 @@
             p.setEnableStreaming(true);
             sf.setProvider(p);
             sf.setAddress("http://localhost:9080/");
-
+            Map<String, Object> properties = new HashMap<String, Object>();
+            properties.put("org.apache.cxf.serviceloader-context", "true");
+            sf.setProperties(properties);
             sf.create();
 
         }



Mime
View raw message