wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r997926 - in /incubator/wink/trunk: wink-common/src/main/java/org/apache/wink/common/internal/registry/metadata/ wink-server/src/test/java/org/apache/wink/server/internal/registry/
Date Thu, 16 Sep 2010 21:06:37 GMT
Author: bluk
Date: Thu Sep 16 21:06:36 2010
New Revision: 997926

URL: http://svn.apache.org/viewvc?rev=997926&view=rev
Log:
Fix issue with metadata collector

If a JAX-RS resource had non-resource methods with
more than 1 parameter, then the resource would
not be registered due to an IllegalStateException.

Added:
    incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/InvalidContextMethodTest.java
Modified:
    incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/registry/metadata/MethodMetadata.java
    incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/registry/metadata/ResourceMetadataCollector.java

Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/registry/metadata/MethodMetadata.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/registry/metadata/MethodMetadata.java?rev=997926&r1=997925&r2=997926&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/registry/metadata/MethodMetadata.java
(original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/registry/metadata/MethodMetadata.java
Thu Sep 16 21:06:36 2010
@@ -71,12 +71,6 @@ public class MethodMetadata extends Abst
         return formalParameters;
     }
     
-    public void setFormalParameters(List<Injectable> formalParameters) {
-        logger.trace("setFormalParameters({}) entry", formalParameters);
-        this.formalParameters = formalParameters;
-        logger.trace("setFormalParameters() exit");
-    }
-
     @Override
     public Set<MediaType> getConsumes() {
         Set<MediaType> set = super.getConsumes();

Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/registry/metadata/ResourceMetadataCollector.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/registry/metadata/ResourceMetadataCollector.java?rev=997926&r1=997925&r2=997926&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/registry/metadata/ResourceMetadataCollector.java
(original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/registry/metadata/ResourceMetadataCollector.java
Thu Sep 16 21:06:36 2010
@@ -203,7 +203,7 @@ public class ResourceMetadataCollector e
             if (declaringClass == Object.class) {
                 continue F1;
             }
-            MethodMetadata methodMetadata = createMethodMetadata(method, null);
+            MethodMetadata methodMetadata = createMethodMetadata(method);
             if (methodMetadata != null) {
                 String path = methodMetadata.getPath();
                 String httpMethod = methodMetadata.getHttpMethod();
@@ -248,7 +248,7 @@ public class ResourceMetadataCollector e
         }
     }
 
-    private MethodMetadata createMethodMetadata(Method method, MethodMetadata implMethodMetadata)
{
+    private MethodMetadata createMethodMetadata(Method method) {
 
         int modifiers = method.getModifiers();
         // only public, non-static methods
@@ -257,6 +257,7 @@ public class ResourceMetadataCollector e
         }
         
         MethodMetadata metadata = new MethodMetadata(getMetadata());
+        metadata.setReflectionMethod(method);
 
         boolean hasAnnotation = false;
 
@@ -294,16 +295,6 @@ public class ResourceMetadataCollector e
             metadata.setEncoded(true);
             hasAnnotation = true;
         }
-
-        if (implMethodMetadata == null) {
-            parseMethodParameters(method, metadata);
-            metadata.setReflectionMethod(method);
-        } else {
-            // 'method' being processed is a super (abstract or interface),
-            // but we already have some concrete metadata, so:
-            metadata.setFormalParameters(implMethodMetadata.getFormalParameters());
-            metadata.setReflectionMethod(implMethodMetadata.getReflectionMethod());
-        }
     
         // if the method has no annotation at all,
         // then it may override a method in a superclass or interface that has
@@ -317,9 +308,12 @@ public class ResourceMetadataCollector e
             // try a superclass
             Class<?> superclass = declaringClass.getSuperclass();
             if (superclass != null && superclass != Object.class) {
-                MethodMetadata createdMetadata = createMethodMetadata(superclass, method,
implMethodMetadata);
+                MethodMetadata createdMetadata = createMethodMetadata(superclass, method);
                 // stop with if the method found
                 if (createdMetadata != null) {
+                    createdMetadata.getFormalParameters().clear();
+                    createdMetadata.setReflectionMethod(method);
+                    parseMethodParameters(method, createdMetadata);
                     return createdMetadata;
                 }
             }
@@ -327,9 +321,12 @@ public class ResourceMetadataCollector e
             // try interfaces
             Class<?>[] interfaces = declaringClass.getInterfaces();
             for (Class<?> interfaceClass : interfaces) {
-                MethodMetadata createdMetadata = createMethodMetadata(interfaceClass, method,
implMethodMetadata);
+                MethodMetadata createdMetadata = createMethodMetadata(interfaceClass, method);
                 // stop with the first method found
                 if (createdMetadata != null) {
+                    createdMetadata.getFormalParameters().clear();
+                    createdMetadata.setReflectionMethod(method);
+                    parseMethodParameters(method, createdMetadata);
                     return createdMetadata;
                 }
             }
@@ -354,15 +351,17 @@ public class ResourceMetadataCollector e
             }
             return null;
         }
+        
+        parseMethodParameters(method, metadata);
 
         return metadata;
     }
 
-    private MethodMetadata createMethodMetadata(Class<?> declaringClass, Method method,
MethodMetadata implMethodMetadata) {
+    private MethodMetadata createMethodMetadata(Class<?> declaringClass, Method method)
{
         try {
             Method declaredMethod =
                 declaringClass.getDeclaredMethod(method.getName(), method.getParameterTypes());
-            return createMethodMetadata(declaredMethod, implMethodMetadata);
+            return createMethodMetadata(declaredMethod);
         } catch (SecurityException e) {
             // can't get to overriding method
             return null;
@@ -380,7 +379,7 @@ public class ResourceMetadataCollector e
                                 break;  // signature doesn't match, otherwise it would have
been found in getDeclaredMethod above
                             }
                             if (clazz.isAssignableFrom(method.getParameterTypes()[i])) {
-                                return createMethodMetadata(candidateMethod, implMethodMetadata);
+                                return createMethodMetadata(candidateMethod);
                             }
                         }
                     }

Added: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/InvalidContextMethodTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/InvalidContextMethodTest.java?rev=997926&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/InvalidContextMethodTest.java
(added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/InvalidContextMethodTest.java
Thu Sep 16 21:06:36 2010
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *  
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.wink.server.internal.registry;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.SecurityContext;
+
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+import org.apache.wink.test.mock.MockRequestConstructor;
+import org.junit.Test;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+public class InvalidContextMethodTest extends MockServletInvocationTest {
+
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class[] {TestResource.class};
+    }
+
+    @Path("abcd")
+    public static class TestResource {
+        
+        public void foo(String a, Object b) {
+            
+        }
+
+        @Context
+        public void setSecurityContext(SecurityContext context, SecurityContext anotherContext)
{
+            /* do nothing */
+        }
+
+        public void doSomething(String a) {
+
+        }
+
+        public void bah() {
+
+        }
+
+        @GET
+        @Produces( {MediaType.TEXT_PLAIN})
+        public String getCollection() {
+            return "Hello world";
+        }
+
+    }
+
+    @Test
+    public void testStillValidResource() throws Exception {
+        MockHttpServletRequest mockRequest =
+            MockRequestConstructor.constructMockRequest("GET", "/abcd", MediaType.TEXT_PLAIN);
+        MockHttpServletResponse response = invoke(mockRequest);
+        assertEquals("Hello world", response.getContentAsString());
+        assertEquals(200, response.getStatus());
+    }
+
+}



Mime
View raw message