cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1526974 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ systests/jaxrs/src/test/java/org/apache/...
Date Fri, 27 Sep 2013 16:17:02 GMT
Author: sergeyb
Date: Fri Sep 27 16:17:01 2013
New Revision: 1526974

URL: http://svn.apache.org/r1526974
Log:
[CXF-4934] In some cases the type erasure results in JAXRSInvoker failing to find a proxy
method

Added:
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookInterfaceGenerics.java
  (with props)
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStoreGenerics.java
  (with props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/MethodDispatcher.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSSpringSecurityInterfaceTest.java
    cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_security/WEB-INF/beans.xml

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=1526974&r1=1526973&r2=1526974&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java Fri Sep
27 16:17:01 2013
@@ -22,6 +22,7 @@ package org.apache.cxf.jaxrs;
 
 import java.io.IOException;
 import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
 import java.util.Collections;
 import java.util.List;
 import java.util.ResourceBundle;
@@ -167,9 +168,18 @@ public class JAXRSInvoker extends Abstra
         }
         
         
-
-        Method methodToInvoke = InjectionUtils.checkProxy(
-            cri.getMethodDispatcher().getMethod(ori), resourceObject);
+        Method resourceMethod = cri.getMethodDispatcher().getMethod(ori);
+        
+        Method methodToInvoke = null;
+        if (Proxy.class.isInstance(resourceObject)) {
+            methodToInvoke = cri.getMethodDispatcher().getProxyMethod(resourceMethod);
+            if (methodToInvoke == null) {
+                methodToInvoke = InjectionUtils.checkProxy(resourceMethod, resourceObject);
+                cri.getMethodDispatcher().addProxyMethod(resourceMethod, methodToInvoke);
+            }
+        } else {
+            methodToInvoke = resourceMethod;
+        }
         
         List<Object> params = null;
         if (request instanceof List) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/MethodDispatcher.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/MethodDispatcher.java?rev=1526974&r1=1526973&r2=1526974&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/MethodDispatcher.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/MethodDispatcher.java
Fri Sep 27 16:17:01 2013
@@ -22,6 +22,7 @@ import java.lang.reflect.Method;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
 
 
 public class MethodDispatcher {
@@ -29,7 +30,8 @@ public class MethodDispatcher {
         new LinkedHashMap<OperationResourceInfo, Method>();
     private Map<Method, OperationResourceInfo> methodToOri = 
         new LinkedHashMap<Method, OperationResourceInfo>();
-
+    private ConcurrentHashMap<Method, Method> proxyMethodMap = new ConcurrentHashMap<Method,
Method>();
+    
     public MethodDispatcher() {
         
     }
@@ -63,4 +65,12 @@ public class MethodDispatcher {
     public Method getMethod(OperationResourceInfo op) {
         return oriToMethod.get(op);
     }
+    
+    public Method getProxyMethod(Method m) {
+        return proxyMethodMap.get(m);
+    }
+    
+    public void addProxyMethod(Method m, Method proxyM) {
+        proxyMethodMap.putIfAbsent(m, proxyM);
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=1526974&r1=1526973&r2=1526974&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Fri Sep 27 16:17:01 2013
@@ -155,19 +155,35 @@ public final class InjectionUtils {
     
     public static Method checkProxy(Method methodToInvoke, Object resourceObject) {
         if (Proxy.class.isInstance(resourceObject)) {
+            String methodToInvokeName = methodToInvoke.getName();
+            Class<?>[] methodToInvokeTypes = methodToInvoke.getParameterTypes();
+            
             for (Class<?> c : resourceObject.getClass().getInterfaces()) {
                 try {
-                    Method m = c.getMethod(
-                        methodToInvoke.getName(), methodToInvoke.getParameterTypes());
-                    if (m != null) {
-                        return m;
-                    }
+                    return c.getMethod(methodToInvokeName, methodToInvokeTypes);
                 } catch (NoSuchMethodException ex) {
                     //ignore
                 }
+                if (methodToInvokeTypes.length > 0) {
+                    for (Method m : c.getMethods()) {    
+                        if (m.getName().equals(methodToInvokeName)
+                            && m.getParameterTypes().length == methodToInvokeTypes.length)
{
+                            Class<?>[] methodTypes = m.getParameterTypes();
+                            for (int i = 0; i < methodTypes.length; i++) {
+                                if (!methodTypes[i].isAssignableFrom(methodToInvokeTypes[i]))
{
+                                    break;
+                                }
+                            }
+                            return m;    
+                        }
+                        
+                    }
+                }
+                
             }
         }
-        return methodToInvoke; 
+        return methodToInvoke;
+        
     }
  
     public static void injectFieldValue(final Field f, 

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSSpringSecurityInterfaceTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSSpringSecurityInterfaceTest.java?rev=1526974&r1=1526973&r2=1526974&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSSpringSecurityInterfaceTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSSpringSecurityInterfaceTest.java
Fri Sep 27 16:17:01 2013
@@ -54,6 +54,14 @@ public class JAXRSSpringSecurityInterfac
     }
     
     @Test
+    public void testGetBookGenericsUserAdmin() throws Exception {
+        String endpointAddress =
+            "http://localhost:" + PORT + "/bookstoregenerics/thosebooks/123"; 
+        getBook(endpointAddress, "foo", "bar", 200);
+        getBook(endpointAddress, "bob", "bobspassword", 200);
+    }
+    
+    @Test
     public void testGetBookUser() throws Exception {
         String endpointAddress =
             "http://localhost:" + PORT + "/bookstorestorage/thosebooks/123/123"; 

Added: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookInterfaceGenerics.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookInterfaceGenerics.java?rev=1526974&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookInterfaceGenerics.java
(added)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookInterfaceGenerics.java
Fri Sep 27 16:17:01 2013
@@ -0,0 +1,38 @@
+/**
+ * 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.cxf.systest.jaxrs.security;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+
+import org.apache.cxf.systest.jaxrs.Book;
+import org.apache.cxf.systest.jaxrs.BookNotFoundFault;
+import org.springframework.security.annotation.Secured;
+
+public interface SecureBookInterfaceGenerics<T> {
+
+    @GET
+    @Path("/thosebooks/{bookId}/")
+    @Produces("application/xml")
+    @Secured({"ROLE_USER", "ROLE_ADMIN" })
+    Book getThatBook(@PathParam("bookId") T id) throws BookNotFoundFault;
+}

Propchange: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookInterfaceGenerics.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookInterfaceGenerics.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStoreGenerics.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStoreGenerics.java?rev=1526974&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStoreGenerics.java
(added)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStoreGenerics.java
Fri Sep 27 16:17:01 2013
@@ -0,0 +1,43 @@
+/**
+ * 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.cxf.systest.jaxrs.security;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.Path;
+
+import org.apache.cxf.systest.jaxrs.Book;
+
+@Path("/bookstoregenerics/")
+public class SecureBookStoreGenerics implements SecureBookInterfaceGenerics<Long> {
+    private Map<Long, Book> books = new HashMap<Long, Book>();
+    
+    public SecureBookStoreGenerics() {
+        Book book = new Book();
+        book.setId(123L);
+        book.setName("CXF in Action");
+        books.put(book.getId(), book);
+    }
+    
+    public Book getThatBook(Long id) {
+        return books.get(id);
+    }
+}

Propchange: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStoreGenerics.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStoreGenerics.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_security/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_security/WEB-INF/beans.xml?rev=1526974&r1=1526973&r2=1526974&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_security/WEB-INF/beans.xml (original)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_security/WEB-INF/beans.xml Fri Sep 27
16:17:01 2013
@@ -46,6 +46,7 @@ http://cxf.apache.org/schemas/jaxrs.xsd"
 		        address="/">
     <jaxrs:serviceBeans>
       <ref bean="bookstore"/>
+      <ref bean="bookstoreGenerics"/>
     </jaxrs:serviceBeans>
     <jaxrs:providers>
         <bean class="org.apache.cxf.systest.jaxrs.security.SecurityExceptionMapper"/>
@@ -70,6 +71,8 @@ http://cxf.apache.org/schemas/jaxrs.xsd"
   <security:http auto-config='true'>
     <security:http-basic />
   </security:http>
+
+  <bean id="bookstoreGenerics" class="org.apache.cxf.systest.jaxrs.security.SecureBookStoreGenerics"/>
   
   <security:authentication-provider>
     <security:user-service>



Mime
View raw message