wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jra...@apache.org
Subject svn commit: r938078 - in /incubator/wink/trunk/wink-common/src: main/java/org/apache/wink/common/internal/registry/metadata/ main/resources/org/apache/wink/common/internal/i18n/ test/java/org/apache/wink/common/internal/registry/metadata/
Date Mon, 26 Apr 2010 15:02:49 GMT
Author: jramos
Date: Mon Apr 26 15:02:48 2010
New Revision: 938078

URL: http://svn.apache.org/viewvc?rev=938078&view=rev
Log:
[WINK-275] Ingore interfaces and abstract classes with Provider annotation. Handle interface
implemntations without NPE

Added:
    incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/registry/metadata/ProviderMetadataCollectorTest.java
Modified:
    incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/registry/metadata/ProviderMetadataCollector.java
    incubator/wink/trunk/wink-common/src/main/resources/org/apache/wink/common/internal/i18n/resource.properties

Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/registry/metadata/ProviderMetadataCollector.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/registry/metadata/ProviderMetadataCollector.java?rev=938078&r1=938077&r2=938078&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/registry/metadata/ProviderMetadataCollector.java
(original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/registry/metadata/ProviderMetadataCollector.java
Mon Apr 26 15:02:48 2010
@@ -21,6 +21,7 @@ package org.apache.wink.common.internal.
 
 import java.lang.reflect.AccessibleObject;
 import java.lang.reflect.Member;
+import java.lang.reflect.Modifier;
 import java.lang.reflect.Type;
 
 import javax.ws.rs.core.Context;
@@ -52,16 +53,21 @@ public class ProviderMetadataCollector e
             return false;
         }
 
+        if (Modifier.isInterface(cls.getModifiers()) || Modifier.isAbstract(cls.getModifiers()))
{
+            logger.warn(Messages.getMessage("providerIsInterfaceOrAbstract", cls));
+            return false;
+        }
+
         if (cls.getAnnotation(Provider.class) != null) {
             return true;
         }
 
         Class<?> declaringClass = cls;
 
-        while (!declaringClass.equals(Object.class)) {
+        while (declaringClass != null && !declaringClass.equals(Object.class)) {
             // try a superclass
             Class<?> superclass = declaringClass.getSuperclass();
-            if (superclass.getAnnotation(Provider.class) != null) {
+            if (superclass != null && superclass.getAnnotation(Provider.class) !=
null) {
                 // issue warning
                 logger.warn(Messages.getMessage("providerShouldBeAnnotatedDirectly", cls));
                 return true;

Modified: incubator/wink/trunk/wink-common/src/main/resources/org/apache/wink/common/internal/i18n/resource.properties
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/resources/org/apache/wink/common/internal/i18n/resource.properties?rev=938078&r1=938077&r2=938078&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/resources/org/apache/wink/common/internal/i18n/resource.properties
(original)
+++ incubator/wink/trunk/wink-common/src/main/resources/org/apache/wink/common/internal/i18n/resource.properties
Mon Apr 26 15:02:48 2010
@@ -226,3 +226,4 @@ missingClientAuthenticationCredentialFor
 serviceFailedToAuthenticateUser=Service failed to authenticate user: {0}
 providerShouldBeAnnotatedDirectly=@javax.ws.rs.ext.Provider was found on a superclass or
interface on class {0}.  Annotate @javax.ws.rs.ext.Provider on the provider class directly
to ensure portability between environments.
 rootResourceShouldBeAnnotatedDirectly=@javax.ws.rs.Path was found on a superclass or interface
on class {0}.  Annotate @javax.ws.rs.Path on the root resource class directly to ensure portability
between environments.
+providerIsInterfaceOrAbstract=@javax.ws.rs.ext.Provider found on interface or abstract class
{0} and is being ignored. Annotate @javax.ws.rs.ext.Provider on the provider implementation
or base class directly and return that in your javax.ws.rs.core.Application subclass.

Added: incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/registry/metadata/ProviderMetadataCollectorTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/registry/metadata/ProviderMetadataCollectorTest.java?rev=938078&view=auto
==============================================================================
--- incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/registry/metadata/ProviderMetadataCollectorTest.java
(added)
+++ incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/registry/metadata/ProviderMetadataCollectorTest.java
Mon Apr 26 15:02:48 2010
@@ -0,0 +1,63 @@
+package org.apache.wink.common.internal.registry.metadata;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.ext.Provider;
+
+import junit.framework.TestCase;
+
+public class ProviderMetadataCollectorTest extends TestCase {
+
+    @Path("/")
+    public interface Interface {
+
+        @GET
+        @Produces("text/plain")
+        public String method();
+
+    }
+    
+    @Path("/")
+    public class Class {
+        
+        @GET
+        @Produces("text/plain")
+        public String method() {
+            return "method";
+        }
+    }
+    
+    @Provider
+    public interface ProviderInterface {
+        
+    }
+    
+    public class ProviderInterfaceImpl implements ProviderInterface {
+        
+    }
+    
+    @Provider
+    public abstract class AbstractProvider {
+        
+    }
+    
+    public class ProviderBaseClass extends AbstractProvider {
+        
+    }
+    
+    @Provider
+    public static class ProviderStandalone {
+        
+    }
+    
+    public void testIsProvider() {
+        assertFalse(ProviderMetadataCollector.isProvider(Interface.class));
+        assertFalse(ProviderMetadataCollector.isProvider(Class.class));
+        assertFalse(ProviderMetadataCollector.isProvider(ProviderInterface.class));
+        assertTrue(ProviderMetadataCollector.isProvider(ProviderInterfaceImpl.class));
+        assertFalse(ProviderMetadataCollector.isProvider(AbstractProvider.class));
+        assertTrue(ProviderMetadataCollector.isProvider(ProviderBaseClass.class));
+        assertTrue(ProviderMetadataCollector.isProvider(ProviderStandalone.class));
+    }
+}



Mime
View raw message