Author: rmannibucau
Date: Fri Sep 14 18:38:51 2012
New Revision: 1384879

URL: http://svn.apache.org/viewvc?rev=1384879&view=rev
Log:
rest using interface to hold rest annotations

Added:
    
openejb/trunk/openejb/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/RsWithInterfaceTest.java
      - copied, changed from r1384655, 
openejb/trunk/openejb/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/RsInjectionTest.java
Modified:
    
openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java

Copied: 
openejb/trunk/openejb/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/RsWithInterfaceTest.java
 (from r1384655, 
openejb/trunk/openejb/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/RsInjectionTest.java)
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/RsWithInterfaceTest.java?p2=openejb/trunk/openejb/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/RsWithInterfaceTest.java&p1=openejb/trunk/openejb/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/RsInjectionTest.java&r1=1384655&r2=1384879&rev=1384879&view=diff
==============================================================================
--- 
openejb/trunk/openejb/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/RsInjectionTest.java
 (original)
+++ 
openejb/trunk/openejb/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/RsWithInterfaceTest.java
 Fri Sep 14 18:38:51 2012
@@ -17,8 +17,6 @@
 package org.apache.openejb.server.cxf.rs;
 
 import org.apache.openejb.OpenEjbContainer;
-import org.apache.openejb.jee.Empty;
-import org.apache.openejb.jee.SingletonBean;
 import org.apache.openejb.junit.ApplicationComposer;
 import org.apache.openejb.junit.Configuration;
 import org.apache.openejb.junit.Module;
@@ -27,23 +25,25 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 
 import javax.ejb.Singleton;
+import javax.ws.rs.ApplicationPath;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
+import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Context;
-import javax.ws.rs.ext.Providers;
+import javax.ws.rs.core.SecurityContext;
 import java.io.IOException;
 import java.net.URL;
+import java.util.HashSet;
 import java.util.Properties;
+import java.util.Set;
 
 import static org.junit.Assert.assertEquals;
 
 @RunWith(ApplicationComposer.class)
-public class RsInjectionTest {
+public class RsWithInterfaceTest {
     @Module
-    public static SingletonBean service() throws Exception {
-        final SingletonBean bean = new SingletonBean(RsInjection.class);
-        bean.setLocalBean(new Empty());
-        return bean;
+    public static Class<?>[] service() throws Exception {
+        return new Class<?>[] { RsImpl.class, App.class };
     }
 
     @Configuration
@@ -55,20 +55,32 @@ public class RsInjectionTest {
 
     @Test
     public void rest() throws IOException {
-        final String response = IO.slurp(new 
URL("http://127.0.0.1:4204/RsInjectionTest/injections/check";));
+        final String response = IO.slurp(new 
URL("http://127.0.0.1:4204/RsWithInterfaceTest/itf/check";));
         assertEquals("true", response);
     }
 
+    @ApplicationPath("/")
+    public static class App extends Application {
+        @Override
+        public Set<Class<?>> getClasses() {
+            return new HashSet<Class<?>>() {{
+                add(RsImpl.class);
+            }};
+        }
+
+    }
+
+    @Path("/itf")
     @Singleton
-    @Path("/injections")
-    public static class RsInjection {
-        @Context
-        private Providers providers;
+    public static class RsImpl implements Rs {
+        public boolean check(final SecurityContext sc) {
+            return sc != null;
+        }
+    }
 
+    public static interface Rs {
         @GET
         @Path("/check")
-        public boolean check() {
-            return providers != null;
-        }
+        boolean check(@Context final SecurityContext sc);
     }
 }

Modified: 
openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java?rev=1384879&r1=1384878&r2=1384879&view=diff
==============================================================================
--- 
openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
 (original)
+++ 
openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
 Fri Sep 14 18:38:51 2012
@@ -387,6 +387,14 @@ public abstract class RESTService implem
         }
     }
 
+    private Class<?> findPath(final Class<?> clazz) {
+        Class<?> usedClass = clazz;
+        while (usedClass.getAnnotation(Path.class) == null && 
usedClass.getSuperclass() != null) {
+            usedClass = usedClass.getSuperclass();
+        }
+        return usedClass;
+    }
+
     private String getAddress(String context, Class<?> clazz) {
         String root = NOPATH_PREFIX;
         if (context != null) {
@@ -397,9 +405,18 @@ public abstract class RESTService implem
             }
         }
 
-        Class<?> usedClass = clazz;
-        while (usedClass.getAnnotation(Path.class) == null && 
usedClass.getSuperclass() != null) {
-            usedClass = usedClass.getSuperclass();
+        Class<?> usedClass = findPath(clazz);
+        if (usedClass == null || Object.class.equals(usedClass)) { // try 
interfaces
+            final Class<?>[] itfs = clazz.getInterfaces();
+            if (itfs != null) {
+                for (Class<?> c : itfs) {
+                    usedClass = findPath(c);
+                    if (usedClass.getAnnotation(Path.class) != null ) {
+                        break;
+                    }
+                }
+            }
+
         }
         if (usedClass == null || usedClass.getAnnotation(Path.class) == null) {
             throw new IllegalArgumentException("no @Path annotation on " + 
clazz.getName());


Reply via email to