tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r1104536 - in /tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src: main/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/ test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/
Date Tue, 17 May 2011 20:36:54 GMT
Author: rfeng
Date: Tue May 17 20:36:53 2011
New Revision: 1104536

URL: http://svn.apache.org/viewvc?rev=1104536&view=rev
Log:
Make sure the generics are generated into the Resource implementation class so that Wink won't
get confused

Modified:
    tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/RootResourceClassGenerator.java
    tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/MockedResource.java
    tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/Resource.java
    tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/ResourceWrapper.java
    tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/RootResourceClassGeneratorTestCase.java

Modified: tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/RootResourceClassGenerator.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/RootResourceClassGenerator.java?rev=1104536&r1=1104535&r2=1104536&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/RootResourceClassGenerator.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/RootResourceClassGenerator.java
Tue May 17 20:36:53 2011
@@ -89,8 +89,14 @@ public class RootResourceClassGenerator 
                                        String produces) {
         String methodDescriptor = Type.getMethodDescriptor(method);
 
+        String signatureString = getSignature(method);
+
         MethodVisitor mv =
-            cw.visitMethod(ACC_PUBLIC, method.getName(), methodDescriptor, null, getExceptionInternalNames(method));
+            cw.visitMethod(ACC_PUBLIC,
+                           method.getName(),
+                           methodDescriptor,
+                           signatureString,
+                           getExceptionInternalNames(method));
 
         mv.visitCode();
         mv.visitFieldInsn(GETSTATIC, className, DELEGATE_FIELD, getSignature(interfaceName));
@@ -108,6 +114,21 @@ public class RootResourceClassGenerator 
         mv.visitEnd();
     }
 
+    /**
+     * [rfeng] A hack to get the generic method signature
+     * @param method
+     * @return
+     */
+    private static String getSignature(Method method) {
+        try {
+            Field field = method.getClass().getDeclaredField("signature");
+            field.setAccessible(true);
+            return (String)field.get(method);
+        } catch (Throwable e) {
+            return null;
+        }
+    }
+
     private static String[] getExceptionInternalNames(Method method) {
         Class<?>[] types = method.getExceptionTypes();
         if (types.length == 0) {

Modified: tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/MockedResource.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/MockedResource.java?rev=1104536&r1=1104535&r2=1104536&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/MockedResource.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/MockedResource.java
Tue May 17 20:36:53 2011
@@ -19,6 +19,8 @@
 
 package org.apache.tuscany.sca.interfacedef.java.jaxrs;
 
+import java.util.List;
+
 public class MockedResource implements Resource {
     private String value;
 
@@ -41,4 +43,9 @@ public class MockedResource implements R
     public void update(String value) {
         this.value = value;
     }
+
+    @Override
+    public String getList(List<String> names) {
+        return value;
+    }
 }

Modified: tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/Resource.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/Resource.java?rev=1104536&r1=1104535&r2=1104536&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/Resource.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/Resource.java
Tue May 17 20:36:53 2011
@@ -19,10 +19,13 @@
 
 package org.apache.tuscany.sca.interfacedef.java.jaxrs;
 
+import java.util.List;
+
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 import javax.ws.rs.PUT;
+import javax.ws.rs.QueryParam;
 
 import org.oasisopen.sca.annotation.Remotable;
 
@@ -31,6 +34,9 @@ public interface Resource {
 
     @GET
     String get();
+    
+    @GET
+    String getList(@QueryParam("list") List<String> names);
 
     @PUT
     void update(String value);

Modified: tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/ResourceWrapper.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/ResourceWrapper.java?rev=1104536&r1=1104535&r2=1104536&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/ResourceWrapper.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/ResourceWrapper.java
Tue May 17 20:36:53 2011
@@ -19,11 +19,12 @@
 
 package org.apache.tuscany.sca.interfacedef.java.jaxrs;
 
+import java.util.List;
+
 import javax.ws.rs.Consumes;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 
-
 @Path("myURI")
 @Produces({"application/xml", "application/json"})
 @Consumes({"application/xml", "application/json"})
@@ -34,7 +35,6 @@ public class ResourceWrapper implements 
         super();
     }
 
-
     public String get() {
         return delegate.get();
     }
@@ -51,4 +51,9 @@ public class ResourceWrapper implements 
         delegate.update(value);
     }
 
+    @Override
+    public String getList(List<String> names) {
+        return delegate.getList(names);
+    }
+
 }

Modified: tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/RootResourceClassGeneratorTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/RootResourceClassGeneratorTestCase.java?rev=1104536&r1=1104535&r2=1104536&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/RootResourceClassGeneratorTestCase.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/RootResourceClassGeneratorTestCase.java
Tue May 17 20:36:53 2011
@@ -20,7 +20,11 @@
 package org.apache.tuscany.sca.interfacedef.java.jaxrs;
 
 import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.List;
 
 import javax.ws.rs.Consumes;
 import javax.ws.rs.Path;
@@ -35,17 +39,21 @@ import org.junit.Test;
 public class RootResourceClassGeneratorTestCase {
     @Test
     public void testGenerator() throws Exception {
-        Class<?> cls = RootResourceClassGenerator.generateRootResourceClass(Resource.class,
"myURI", "application/xml,application/json", "application/xml,application/json");
+        Class<?> cls =
+            RootResourceClassGenerator.generateRootResourceClass(Resource.class,
+                                                                 "myURI",
+                                                                 "application/xml,application/json",
+                                                                 "application/xml,application/json");
         Assert.assertTrue(cls.isAnnotationPresent(Path.class));
         Path path = cls.getAnnotation(Path.class);
         Assert.assertEquals("myURI", path.value());
-        
+
         Produces produces = cls.getAnnotation(Produces.class);
         Assert.assertEquals("application/xml", produces.value()[0]);
 
         Consumes consumes = cls.getAnnotation(Consumes.class);
         Assert.assertEquals("application/json", consumes.value()[1]);
-        
+
         Field field = cls.getField("delegate");
         Assert.assertSame(Resource.class, field.getType());
 
@@ -54,6 +62,13 @@ public class RootResourceClassGeneratorT
 
         Assert.assertTrue(Resource.class.isAssignableFrom(cls));
 
+        Method m = cls.getMethod("getList", List.class);
+        System.out.println(m.toGenericString());
+        Type type = m.getGenericParameterTypes()[0];
+        Assert.assertTrue(type instanceof ParameterizedType);
+        ParameterizedType pType = (ParameterizedType)type;
+        Assert.assertEquals(String.class, pType.getActualTypeArguments()[0]);
+
         Resource resource = new MockedResource();
         field.set(null, resource);
 



Mime
View raw message