cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1440061 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Tue, 29 Jan 2013 19:03:59 GMT
Author: sergeyb
Date: Tue Jan 29 19:03:59 2013
New Revision: 1440061

URL: http://svn.apache.org/viewvc?rev=1440061&view=rev
Log:
Initial attempt at enforcing method name bindings must contain all of filter name bindings

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=1440061&r1=1440060&r2=1440061&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
Tue Jan 29 19:03:59 2013
@@ -53,6 +53,7 @@ import javax.ws.rs.core.Feature;
 import javax.ws.rs.core.FeatureContext;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.ContextResolver;
 import javax.ws.rs.ext.ExceptionMapper;
 import javax.ws.rs.ext.MessageBodyReader;
@@ -75,6 +76,7 @@ import org.apache.cxf.jaxrs.ext.Paramete
 import org.apache.cxf.jaxrs.ext.RequestHandler;
 import org.apache.cxf.jaxrs.ext.ResponseHandler;
 import org.apache.cxf.jaxrs.impl.HttpHeadersImpl;
+import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.impl.ReaderInterceptorMBR;
 import org.apache.cxf.jaxrs.impl.RequestPreprocessor;
 import org.apache.cxf.jaxrs.impl.ResourceInfoImpl;
@@ -596,15 +598,22 @@ public final class ProviderFactory {
         if (boundFilters.isEmpty()) {
             return Collections.emptyList();
         }
-        boolean namesEmpty = names == null || names.isEmpty();
+        names = names == null ? Collections.<String>emptyList() : names;
         
-        List<ProviderInfo<T>> list = new LinkedList<ProviderInfo<T>>();
-        // TODO: Replace with a plain array
+        MultivaluedMap<ProviderInfo<T>, String> map = 
+            new MetadataMap<ProviderInfo<T>, String>();
         for (Map.Entry<NameKey, ProviderInfo<T>> entry : boundFilters.entrySet())
{
             String entryName = entry.getKey().getName();
-            if (!namesEmpty && names.contains(entryName)
-                || entryName.equals(DEFAULT_FILTER_NAME_BINDING)) {
-                list.add(entry.getValue());                    
+            if (entryName.equals(DEFAULT_FILTER_NAME_BINDING)) {
+                map.put(entry.getValue(), Collections.<String>emptyList());
+            } else {
+                map.add(entry.getValue(), entryName);
+            }
+        }
+        List<ProviderInfo<T>> list = new LinkedList<ProviderInfo<T>>();
+        for (Map.Entry<ProviderInfo<T>, List<String>> entry : map.entrySet())
{
+            if (names.containsAll(entry.getValue())) {
+                list.add(entry.getKey());
             }
         }
         return list;

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java?rev=1440061&r1=1440060&r2=1440061&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
Tue Jan 29 19:03:59 2013
@@ -75,6 +75,7 @@ public class BookServer20 extends Abstra
         providers.add(new CustomWriterInterceptor());
         providers.add(new CustomDynamicFeature());
         providers.add(new PostMatchContainerRequestFilter());
+        providers.add(new FaultyContainerRequestFilter());
         sf.setProviders(providers);
         sf.setResourceProvider(BookStore.class,
                                new SingletonResourceProvider(new BookStore(), true));
@@ -162,6 +163,16 @@ public class BookServer20 extends Abstra
         
     }
     
+    @Faulty
+    private static class FaultyContainerRequestFilter implements ContainerRequestFilter {
+
+        @Override
+        public void filter(ContainerRequestContext context) throws IOException {
+            throw new RuntimeException();
+        }
+        
+    }
+    
     @BindingPriority(3)
     public static class PostMatchContainerResponseFilter implements ContainerResponseFilter
{
 
@@ -190,6 +201,7 @@ public class BookServer20 extends Abstra
     }
     @BindingPriority(4)
     @CustomHeaderAdded
+    @PostMatchMode
     public static class PostMatchContainerResponseFilter3 implements ContainerResponseFilter
{
 
         @Override
@@ -224,6 +236,20 @@ public class BookServer20 extends Abstra
         
     }
     
+    @Target({ ElementType.TYPE, ElementType.METHOD })
+    @Retention(value = RetentionPolicy.RUNTIME)
+    @NameBinding
+    public @interface PostMatchMode { 
+        
+    }
+    
+    @Target({ ElementType.TYPE, ElementType.METHOD })
+    @Retention(value = RetentionPolicy.RUNTIME)
+    @NameBinding
+    public @interface Faulty { 
+        
+    }
+    
     public static class CustomReaderInterceptor implements ReaderInterceptor {
         @Context
         private ResourceInfo ri;

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1440061&r1=1440060&r2=1440061&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Tue
Jan 29 19:03:59 2013
@@ -88,6 +88,7 @@ import org.apache.cxf.jaxrs.ext.xml.XSIS
 import org.apache.cxf.jaxrs.impl.ResourceContextImpl;
 import org.apache.cxf.phase.PhaseInterceptorChain;
 import org.apache.cxf.systest.jaxrs.BookServer20.CustomHeaderAdded;
+import org.apache.cxf.systest.jaxrs.BookServer20.PostMatchMode;
 
 @Path("/bookstore")
 @GZIP(threshold = 1)
@@ -493,6 +494,7 @@ public class BookStore {
     @GET
     @Path("/bookheaders/simple/")
     @CustomHeaderAdded
+    @PostMatchMode
     public Response getBookByHeaderSimple(@HeaderParam("BOOK") String headerBook,
         @HeaderParam("Simple") String headerSimple) throws Exception {
         
@@ -503,6 +505,7 @@ public class BookStore {
     @POST
     @Path("/bookheaders/simple/")
     @CustomHeaderAdded
+    @PostMatchMode
     public Response echoBookByHeaderSimple(Book book,
         @HeaderParam("BOOK") String headerBook,
         @HeaderParam("Simple") String headerSimple,



Mime
View raw message