cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r779897 - in /cxf/dosgi/trunk: dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ samples/greeter/client/ samples/greeter/impl/ systests/common/
Date Fri, 29 May 2009 09:09:01 GMT
Author: davidb
Date: Fri May 29 09:08:40 2009
New Revision: 779897

URL: http://svn.apache.org/viewvc?rev=779897&view=rev
Log:
Fixing problem with Client-side proxies. 
Method from java.lang.Object are now invoked on the InvocationHandler rather than sent over
the wire.

Also included some small clean-ups on the greeter demo poms.

Added:
    cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandlerTest.java
  (with props)
Modified:
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandler.java
    cxf/dosgi/trunk/samples/greeter/client/pom.xml
    cxf/dosgi/trunk/samples/greeter/impl/pom.xml
    cxf/dosgi/trunk/systests/common/pom.xml

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandler.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandler.java?rev=779897&r1=779896&r2=779897&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandler.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandler.java
Fri May 29 09:08:40 2009
@@ -22,6 +22,8 @@
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -29,12 +31,13 @@
 import org.osgi.framework.ServiceException;
 
 public class ServiceInvocationHandler implements InvocationHandler {
-
     private final static String REMOTE_EXCEPTION_TYPE = "REMOTE";
-    
+    private static final Collection<Method> OBJECT_METHODS = 
+        Arrays.asList(Object.class.getMethods());
+
     private Map<Method, List<Class<?>>> exceptionsMap
         = new HashMap<Method, List<Class<?>>>();
-    private Object serviceObject;    
+    private Object serviceObject;
     
     public ServiceInvocationHandler(Object serviceObject, Class<?> iType) {
         this.serviceObject = serviceObject;
@@ -42,8 +45,12 @@
     }
     
     public Object invoke(Object proxy, Method m, Object[] params) throws Throwable {
+        if (OBJECT_METHODS.contains(m)) {
+            return m.invoke(this, params);
+        }
+
         ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
-        try {
+        try {            
             Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
             return m.invoke(serviceObject, params); 
         } catch (Throwable ex) {

Added: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandlerTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandlerTest.java?rev=779897&view=auto
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandlerTest.java
(added)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandlerTest.java
Fri May 29 09:08:40 2009
@@ -0,0 +1,56 @@
+package org.apache.cxf.dosgi.dsw.handlers;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+public class ServiceInvocationHandlerTest extends TestCase {
+    private static final Map<String, Method> OBJECT_METHODS = new HashMap<String,
Method>(); {
+        for (Method m : Object.class.getMethods()) {
+            OBJECT_METHODS.put(m.getName(), m);
+        }
+    }
+    
+    public void testInvoke() throws Throwable {
+        ServiceInvocationHandler sih = new ServiceInvocationHandler("hello", String.class);
+        Method m = String.class.getMethod("length", new Class [] {});
+        assertEquals(5, sih.invoke(null, m, new Object [] {}));
+    }
+    
+    public void testInvokeObjectMethod() throws Throwable {
+        final List<String> called = new ArrayList<String>();
+        ServiceInvocationHandler sih = new ServiceInvocationHandler("hi", String.class) {
+            public boolean equals(Object obj) {
+                called.add("equals");
+                return super.equals(obj);
+            }
+
+            public int hashCode() {
+                called.add("hashCode");
+                return super.hashCode();
+            }
+
+            public String toString() {
+                called.add("toString");
+                return "somestring";
+            }            
+        };
+
+        assertEquals(true, 
+                sih.invoke(null, OBJECT_METHODS.get("equals"), new Object [] {sih}));
+        assertEquals(System.identityHashCode(sih), 
+                sih.invoke(null, OBJECT_METHODS.get("hashCode"), new Object [] {}));
+        assertEquals("somestring", 
+                sih.invoke(null, OBJECT_METHODS.get("toString"), new Object [] {}));
+        assertEquals(Arrays.asList("equals", "hashCode", "toString"), called);
+//        assertEquals("This one used to throw an exception", sih, sih);
+//        assertEquals(System.identityHashCode(sih), sih.hashCode());
+//        assertEquals("somestring", sih.toString());
+        
+    }
+}

Propchange: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandlerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandlerTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/dosgi/trunk/samples/greeter/client/pom.xml
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/samples/greeter/client/pom.xml?rev=779897&r1=779896&r2=779897&view=diff
==============================================================================
--- cxf/dosgi/trunk/samples/greeter/client/pom.xml (original)
+++ cxf/dosgi/trunk/samples/greeter/client/pom.xml Fri May 29 09:08:40 2009
@@ -38,11 +38,6 @@
     </properties>
     
     <dependencies>
-        <dependency>
-            <groupId>org.apache.cxf</groupId>
-            <artifactId>cxf-bundle-minimal</artifactId>
-            <version>${cxf.version}</version>
-        </dependency>
         <dependency> 
             <groupId>org.apache.cxf.dosgi.samples</groupId>
             <artifactId>cxf-dosgi-ri-samples-greeter-interface</artifactId>
@@ -59,16 +54,6 @@
                 </exclusion>
             </exclusions>
         </dependency> 
-        <dependency>
-           <groupId>junit</groupId>
-           <artifactId>junit</artifactId>
-           <scope>test</scope>
-        </dependency>  
-        <dependency>
-           <groupId>org.easymock</groupId>
-           <artifactId>easymockclassextension</artifactId>
-           <scope>test</scope>
-         </dependency>
     </dependencies> 
 
     <build>

Modified: cxf/dosgi/trunk/samples/greeter/impl/pom.xml
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/samples/greeter/impl/pom.xml?rev=779897&r1=779896&r2=779897&view=diff
==============================================================================
--- cxf/dosgi/trunk/samples/greeter/impl/pom.xml (original)
+++ cxf/dosgi/trunk/samples/greeter/impl/pom.xml Fri May 29 09:08:40 2009
@@ -40,24 +40,20 @@
     <dependencies>
         <dependency> 
             <groupId>org.apache.felix</groupId>
-            <artifactId>org.osgi.core</artifactId>
-            <version>1.2.0</version>
+            <artifactId>org.apache.felix.framework</artifactId>
+            <version>${felix.version}</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.apache.felix</groupId>
+                    <artifactId>org.osgi.foundation</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency> 
         <dependency> 
             <groupId>org.apache.cxf.dosgi.samples</groupId>
             <artifactId>cxf-dosgi-ri-samples-greeter-interface</artifactId>
             <version>${project.version}</version>
         </dependency> 
-        <dependency>
-           <groupId>junit</groupId>
-           <artifactId>junit</artifactId>
-           <scope>test</scope>
-        </dependency>  
-        <dependency>
-           <groupId>org.easymock</groupId>
-           <artifactId>easymockclassextension</artifactId>
-           <scope>test</scope>
-         </dependency>
     </dependencies> 
 
     <build>

Modified: cxf/dosgi/trunk/systests/common/pom.xml
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests/common/pom.xml?rev=779897&r1=779896&r2=779897&view=diff
==============================================================================
--- cxf/dosgi/trunk/systests/common/pom.xml (original)
+++ cxf/dosgi/trunk/systests/common/pom.xml Fri May 29 09:08:40 2009
@@ -61,6 +61,12 @@
       </exclusions>
     </dependency>
 
+    <dependency>
+      <groupId>org.apache.cxf</groupId>
+      <artifactId>cxf-bundle-minimal</artifactId>
+      <version>${cxf.version}</version>
+    </dependency>
+
     <dependency> 
       <groupId>org.apache.cxf.dosgi.samples</groupId>
       <artifactId>cxf-dosgi-ri-samples-greeter-interface</artifactId>



Mime
View raw message