summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/interface-java-jaxrs/src
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/trunk/modules/interface-java-jaxrs/src')
-rw-r--r--sca-java-2.x/trunk/modules/interface-java-jaxrs/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/RootResourceClassGenerator.java23
-rw-r--r--sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/MockedResource.java7
-rw-r--r--sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/Resource.java6
-rw-r--r--sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/ResourceWrapper.java9
-rw-r--r--sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/RootResourceClassGeneratorTestCase.java21
5 files changed, 60 insertions, 6 deletions
diff --git a/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/RootResourceClassGenerator.java b/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/RootResourceClassGenerator.java
index c3d1ec4421..c9fc8aafe3 100644
--- a/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/RootResourceClassGenerator.java
+++ b/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/RootResourceClassGenerator.java
@@ -89,8 +89,14 @@ public class RootResourceClassGenerator implements Opcodes {
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 implements Opcodes {
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) {
diff --git a/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/MockedResource.java b/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/MockedResource.java
index 46d501d4be..7940a9e145 100644
--- a/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/MockedResource.java
+++ b/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/MockedResource.java
@@ -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 Resource {
public void update(String value) {
this.value = value;
}
+
+ @Override
+ public String getList(List<String> names) {
+ return value;
+ }
}
diff --git a/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/Resource.java b/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/Resource.java
index ac9fd514bd..00d0fe9264 100644
--- a/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/Resource.java
+++ b/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/Resource.java
@@ -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);
diff --git a/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/ResourceWrapper.java b/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/ResourceWrapper.java
index 23b674778e..40e0bf7d2a 100644
--- a/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/ResourceWrapper.java
+++ b/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/ResourceWrapper.java
@@ -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 Resource {
super();
}
-
public String get() {
return delegate.get();
}
@@ -51,4 +51,9 @@ public class ResourceWrapper implements Resource {
delegate.update(value);
}
+ @Override
+ public String getList(List<String> names) {
+ return delegate.getList(names);
+ }
+
}
diff --git a/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/RootResourceClassGeneratorTestCase.java b/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/RootResourceClassGeneratorTestCase.java
index aa6abcd5f6..0a761df6b8 100644
--- a/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/RootResourceClassGeneratorTestCase.java
+++ b/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/RootResourceClassGeneratorTestCase.java
@@ -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 RootResourceClassGeneratorTestCase {
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);