cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1535038 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Wed, 23 Oct 2013 14:45:57 GMT
Author: sergeyb
Date: Wed Oct 23 14:45:57 2013
New Revision: 1535038

URL: http://svn.apache.org/r1535038
Log:
[CXF-5346] Making sure shared dynamic filters do not interfere with non-target operation bindings

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/FilterProviderInfo.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.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/JAXRS20ClientServerBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/FilterProviderInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/FilterProviderInfo.java?rev=1535038&r1=1535037&r2=1535038&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/FilterProviderInfo.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/FilterProviderInfo.java
Wed Oct 23 14:45:57 2013
@@ -30,20 +30,23 @@ public class FilterProviderInfo<T> exten
 
     private Set<String> nameBinding;
     private Map<Class<?>, Integer> supportedContracts;
+    private boolean dynamic;
     
     public FilterProviderInfo(T provider,
                               Bus bus,
                               Map<Class<?>, Integer> supportedContracts) {
-        this(provider, bus, ProviderFactory.DEFAULT_FILTER_NAME_BINDING, supportedContracts);
       
+        this(provider, bus, ProviderFactory.DEFAULT_FILTER_NAME_BINDING, false, supportedContracts);
       
     }
     
     public FilterProviderInfo(T provider,
                               Bus bus,
                               String nameBinding,
+                              boolean dynamic,
                               Map<Class<?>, Integer> supportedContracts) {
         super(provider, bus);
         this.nameBinding = Collections.singleton(nameBinding);
-        this.supportedContracts = supportedContracts;        
+        this.supportedContracts = supportedContracts;
+        this.dynamic = dynamic;
     }
 
     public Set<String> getNameBinding() {
@@ -53,6 +56,10 @@ public class FilterProviderInfo<T> exten
     public int getPriority(Class<?> contract) {
         return supportedContracts.get(contract);
     }
+    
+    public boolean isDynamic() {
+        return dynamic;
+    }
 
     public Set<Class<?>> getSupportedContracts() {
         return supportedContracts.keySet();

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=1535038&r1=1535037&r2=1535038&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
Wed Oct 23 14:45:57 2013
@@ -898,11 +898,17 @@ public abstract class ProviderFactory {
             new MetadataMap<ProviderInfo<T>, String>();
         for (Map.Entry<NameKey, ProviderInfo<T>> entry : boundFilters.entrySet())
{
             String entryName = entry.getKey().getName();
+            ProviderInfo<T> provider = entry.getValue();
             if (entryName.equals(DEFAULT_FILTER_NAME_BINDING)) {
-                ProviderInfo<T> provider = entry.getValue(); 
                 map.put(provider, Collections.<String>emptyList());
             } else {
-                map.add(entry.getValue(), entryName);
+                if (provider instanceof FilterProviderInfo) {
+                    FilterProviderInfo<?> fpi = (FilterProviderInfo<?>)provider;
+                    if (fpi.isDynamic() && !names.containsAll(fpi.getNameBinding()))
{
+                        continue;
+                    }
+                }
+                map.add(provider, entryName);
             }
         }
         List<ProviderInfo<T>> list = new LinkedList<ProviderInfo<T>>();

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java?rev=1535038&r1=1535037&r2=1535038&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
Wed Oct 23 14:45:57 2013
@@ -440,6 +440,7 @@ public final class ServerProviderFactory
                 registerUserProvider(new FilterProviderInfo<Object>(provider, 
                     getBus(),
                     nameBinding,
+                    true,
                     actualContracts));
                 ori.addNameBindings(Collections.singletonList(nameBinding));
             }

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=1535038&r1=1535037&r2=1535038&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
Wed Oct 23 14:45:57 2013
@@ -304,7 +304,9 @@ public class BookServer20 extends Abstra
             if (!responseContext.getHeaders().containsKey("Response")) {
                 throw new RuntimeException();
             }
-            if (!responseContext.getHeaders().containsKey("DynamicResponse")
+        
+            if ((!responseContext.getHeaders().containsKey("DynamicResponse")
+                || !responseContext.getHeaders().containsKey("DynamicResponse2"))
                 && !"Prematch filter error".equals(responseContext.getEntity()))
{
                 throw new RuntimeException();
             }
@@ -330,7 +332,7 @@ public class BookServer20 extends Abstra
         
     }
     
-    public static class PostMatchDynamicContainerResponseFilter 
+    public static class PostMatchDynamicContainerRequestResponseFilter 
         implements ContainerRequestFilter, ContainerResponseFilter {
 
         @Override
@@ -339,7 +341,7 @@ public class BookServer20 extends Abstra
             if (!responseContext.getHeaders().containsKey("Response")) {
                 throw new RuntimeException();
             }
-            responseContext.getHeaders().add("DynamicResponse", "Dynamic");
+            responseContext.getHeaders().add("DynamicResponse2", "Dynamic2");
             
         }
 
@@ -351,6 +353,22 @@ public class BookServer20 extends Abstra
         
     }
     
+    @Priority(2)
+    public static class PostMatchDynamicContainerResponseFilter 
+        implements ContainerResponseFilter {
+    
+        @Override
+        public void filter(ContainerRequestContext requestContext,
+                           ContainerResponseContext responseContext) throws IOException {
+            if (!responseContext.getHeaders().containsKey("Response")) {
+                throw new RuntimeException();
+            }
+            responseContext.getHeaders().add("DynamicResponse", "Dynamic");
+            
+        }
+        
+    }
+    
     @Target({ ElementType.TYPE, ElementType.METHOD })
     @Retention(value = RetentionPolicy.RUNTIME)
     @NameBinding
@@ -441,13 +459,17 @@ public class BookServer20 extends Abstra
     
     public static class CustomDynamicFeature implements DynamicFeature {
 
+        private static final ContainerResponseFilter RESPONSE_FILTER =
+            new PostMatchDynamicContainerResponseFilter();
+        
         @Override
         public void configure(ResourceInfo resourceInfo, FeatureContext configurable) {
             
             configurable.register(new PreMatchDynamicContainerRequestFilter());
+            configurable.register(RESPONSE_FILTER);
             Map<Class<?>, Integer> contracts = new HashMap<Class<?>,
Integer>();
             contracts.put(ContainerResponseFilter.class, 2);
-            configurable.register(new PostMatchDynamicContainerResponseFilter(), 
+            configurable.register(new PostMatchDynamicContainerRequestResponseFilter(), 
                                   contracts);
         }
         

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java?rev=1535038&r1=1535037&r2=1535038&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
Wed Oct 23 14:45:57 2013
@@ -493,6 +493,7 @@ public class JAXRS20ClientServerBookTest
         assertEquals("OK", response.getHeaderString("Response"));
         assertEquals("OK2", response.getHeaderString("Response2"));
         assertEquals("Dynamic", response.getHeaderString("DynamicResponse"));
+        assertEquals("Dynamic2", response.getHeaderString("DynamicResponse2"));
         assertEquals("custom", response.getHeaderString("Custom"));
         assertEquals("simple", response.getHeaderString("Simple"));
         assertEquals("serverWrite", response.getHeaderString("ServerWriterInterceptor"));



Mime
View raw message