You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2013/09/27 18:31:31 UTC

svn commit: r1526976 - in /cxf/branches/2.7.x-fixes: ./ 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/tes...

Author: sergeyb
Date: Fri Sep 27 16:31:30 2013
New Revision: 1526976

URL: http://svn.apache.org/r1526976
Log:
Merged revisions 1526974 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1526974 | sergeyb | 2013-09-27 17:17:01 +0100 (Fri, 27 Sep 2013) | 1 line
  
  [CXF-4934] In some cases the type erasure results in JAXRSInvoker failing to find a proxy method
........

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

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1526974

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=1526976&r1=1526975&r2=1526976&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java Fri Sep 27 16:31:30 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.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -168,8 +169,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/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/MethodDispatcher.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/MethodDispatcher.java?rev=1526976&r1=1526975&r2=1526976&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/MethodDispatcher.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/MethodDispatcher.java Fri Sep 27 16:31:30 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/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=1526976&r1=1526975&r2=1526976&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java Fri Sep 27 16:31:30 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/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSSpringSecurityInterfaceTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSSpringSecurityInterfaceTest.java?rev=1526976&r1=1526975&r2=1526976&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSSpringSecurityInterfaceTest.java (original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSSpringSecurityInterfaceTest.java Fri Sep 27 16:31:30 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/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookInterfaceGenerics.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookInterfaceGenerics.java?rev=1526976&view=auto
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookInterfaceGenerics.java (added)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookInterfaceGenerics.java Fri Sep 27 16:31:30 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/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookInterfaceGenerics.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStoreGenerics.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStoreGenerics.java?rev=1526976&view=auto
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStoreGenerics.java (added)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStoreGenerics.java Fri Sep 27 16:31:30 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/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStoreGenerics.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Modified: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/resources/jaxrs_security/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/resources/jaxrs_security/WEB-INF/beans.xml?rev=1526976&r1=1526975&r2=1526976&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/resources/jaxrs_security/WEB-INF/beans.xml (original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/resources/jaxrs_security/WEB-INF/beans.xml Fri Sep 27 16:31:30 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>