cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r827857 - in /cxf/trunk: api/src/main/java/org/apache/cxf/message/ rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ rt/core/src/main/java/org/apache/cxf/endpoint/ rt/core/src/main/java/org/apache/cxf/interceptor/ rt/core/src/ma...
Date Wed, 21 Oct 2009 00:33:19 GMT
Author: dkulp
Date: Wed Oct 21 00:33:19 2009
New Revision: 827857

URL: http://svn.apache.org/viewvc?rev=827857&view=rev
Log:
[CXF-2015] Add support to add interceptors per request as well as allow
Destinations to be InterceptorProviders

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/message/Message.java
    cxf/trunk/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocUtil.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/InFaultChainInitiatorObserver.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/OutFaultChainInitiatorObserver.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/OutgoingChainInterceptor.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/ChainInitiationObserver.java
    cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/ClientServerTest.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/message/Message.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/message/Message.java?rev=827857&r1=827856&r2=827857&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/message/Message.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/message/Message.java Wed Oct 21 00:33:19 2009
@@ -99,7 +99,21 @@
     String WSDL_INTERFACE = "javax.xml.ws.wsdl.interface";
     String WSDL_OPERATION = "javax.xml.ws.wsdl.operation";
 
-    
+    /**
+     * Some properties to allow adding interceptors to the chain
+     * on a per-request basis.  All are a Collection<Interceptor> 
+     * These are NOT contextual properties (ie: not searched outside the message).
+     * They must exist on the message itself at time of Chain creation
+     */
+    String IN_INTERCEPTORS = Message.class.getName() + ".IN_INTERCEPTORS";
+    String OUT_INTERCEPTORS = Message.class.getName() + ".OUT_INTERCEPTORS";
+    String FAULT_IN_INTERCEPTORS = Message.class.getName() + ".FAULT_IN_INTERCEPTORS";
+    String FAULT_OUT_INTERCEPTORS = Message.class.getName() + ".FAULT_OUT_INTERCEPTORS";
+    /**
+     * As above, but Collection<InterceptorProvider> 
+     */
+    String INTERCEPTOR_PROVIDERS = Message.class.getName() + ".INTERCEPTOR_PROVIDER";
+
     String getId();
     void setId(String id);
     

Modified: cxf/trunk/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocUtil.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocUtil.java?rev=827857&r1=827856&r2=827857&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocUtil.java
(original)
+++ cxf/trunk/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocUtil.java
Wed Oct 21 00:33:19 2009
@@ -28,10 +28,12 @@
 import org.apache.cxf.Bus;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.interceptor.InterceptorChain;
 import org.apache.cxf.interceptor.InterceptorProvider;
 import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.Phase;
 import org.apache.cxf.phase.PhaseInterceptorChain;
 import org.apache.cxf.service.model.FaultInfo;
@@ -91,8 +93,8 @@
                 LOG.fine("Interceptors contributed by databinding: " + il);
             }
             chain.add(il);
-
         }
+        modifyChain(chain, ex, false);
 
         return chain;
     }
@@ -126,10 +128,35 @@
             chain.add(il);
         }
         chain.setFaultObserver(new ColocOutFaultObserver(bus));
-
+        modifyChain(chain, ex, true);
         return chain;
     }    
-    
+    private static void modifyChain(PhaseInterceptorChain chain, Exchange ex, boolean in)
{
+        modifyChain(chain, ex.getInMessage(), in);
+        modifyChain(chain, ex.getOutMessage(), in);
+    }
+    private static void modifyChain(PhaseInterceptorChain chain, Message m, boolean in) {
+        if (m == null) {
+            return;
+        }
+        Collection<InterceptorProvider> providers 
+            = CastUtils.cast((Collection<?>)m.get(Message.INTERCEPTOR_PROVIDERS));
+        if (providers != null) {
+            for (InterceptorProvider p : providers) {
+                if (in) {
+                    chain.add(p.getInInterceptors());
+                } else {
+                    chain.add(p.getOutInterceptors());
+                }
+            }
+        }
+        String key = in ? Message.IN_INTERCEPTORS : Message.OUT_INTERCEPTORS;
+        Collection<Interceptor> is = CastUtils.cast((Collection<?>)m.get(key));
+        if (is != null) {
+            chain.add(is);
+        }
+    }
+
     public static boolean isSameOperationInfo(OperationInfo oi1, OperationInfo oi2) {
         return  oi1.getName().equals(oi2.getName())
                 && isSameMessageInfo(oi1.getInput(), oi2.getInput())

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java?rev=827857&r1=827856&r2=827857&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java Wed Oct 21 00:33:19
2009
@@ -22,6 +22,7 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -408,11 +409,13 @@
             PhaseInterceptorChain chain = setupInterceptorChain(endpoint);
             message.setInterceptorChain(chain);
 
-            modifyChain(chain, reqContext);
             chain.setFaultObserver(outFaultObserver);
 
             // setup conduit selector
             prepareConduitSelector(message);
+            
+            // add additional interceptors and such
+            modifyChain(chain, message, false);
 
             // execute chain
             chain.doIntercept(message);
@@ -468,12 +471,14 @@
             PhaseInterceptorChain chain = setupInterceptorChain(endpoint);
             message.setInterceptorChain(chain);
 
-            modifyChain(chain, reqContext);
             chain.setFaultObserver(outFaultObserver);
 
             // setup conduit selector
             prepareConduitSelector(message);
 
+            // add additional interceptors and such
+            modifyChain(chain, message, false);
+            
             // execute chain
             chain.doIntercept(message);
 
@@ -636,7 +641,9 @@
         message.setInterceptorChain(chain);
 
         chain.setFaultObserver(outFaultObserver);
-
+        modifyChain(chain, message, true);
+        modifyChain(chain, message.getExchange().getOutMessage(), true);
+        
         Bus origBus = BusFactory.getThreadDefaultBus(false);
         BusFactory.setThreadDefaultBus(bus);
         // execute chain
@@ -812,8 +819,26 @@
         return outboundChainCache.get(pm.getOutPhases(), i1, i2, i3, i4);
     }
 
-    protected void modifyChain(InterceptorChain chain, Map<String, Object> ctx) {
-        // no-op
+    protected void modifyChain(InterceptorChain chain, Message ctx, boolean in) {
+        if (ctx == null) {
+            return;
+        }
+        Collection<InterceptorProvider> providers 
+            = CastUtils.cast((Collection<?>)ctx.get(Message.INTERCEPTOR_PROVIDERS));
+        if (providers != null) {
+            for (InterceptorProvider p : providers) {
+                if (in) {
+                    chain.add(p.getInInterceptors());
+                } else {
+                    chain.add(p.getOutInterceptors());
+                }
+            }
+        }
+        String key = in ? Message.IN_INTERCEPTORS : Message.OUT_INTERCEPTORS;
+        Collection<Interceptor> is = CastUtils.cast((Collection<?>)ctx.get(key));
+        if (is != null) {
+            chain.add(is);
+        }
     }
 
     protected void setEndpoint(Endpoint e) {

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/InFaultChainInitiatorObserver.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/InFaultChainInitiatorObserver.java?rev=827857&r1=827856&r2=827857&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/InFaultChainInitiatorObserver.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/InFaultChainInitiatorObserver.java
Wed Oct 21 00:33:19 2009
@@ -18,12 +18,15 @@
  */
 package org.apache.cxf.interceptor;
 
+import java.util.Collection;
 import java.util.SortedSet;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.Phase;
 import org.apache.cxf.phase.PhaseInterceptorChain;
 import org.apache.cxf.phase.PhaseManager;
@@ -51,6 +54,22 @@
         if (e.getService().getDataBinding() instanceof InterceptorProvider) {
             chain.add(((InterceptorProvider)e.getService().getDataBinding()).getInFaultInterceptors());
         }
+        
+        addToChain(chain, ex.getInFaultMessage());
+        addToChain(chain, ex.getOutMessage());
+    }
+    private void addToChain(PhaseInterceptorChain chain, Message m) {
+        Collection<InterceptorProvider> providers 
+            = CastUtils.cast((Collection<?>)m.get(Message.INTERCEPTOR_PROVIDERS));
+        if (providers != null) {
+            for (InterceptorProvider p : providers) {
+                chain.add(p.getInFaultInterceptors());
+            }
+        }
+        Collection<Interceptor> is = CastUtils.cast((Collection<?>)m.get(Message.FAULT_IN_INTERCEPTORS));
+        if (is != null) {
+            chain.add(is);
+        }
     }
     
     protected SortedSet<Phase> getPhases() {

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/OutFaultChainInitiatorObserver.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/OutFaultChainInitiatorObserver.java?rev=827857&r1=827856&r2=827857&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/OutFaultChainInitiatorObserver.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/OutFaultChainInitiatorObserver.java
Wed Oct 21 00:33:19 2009
@@ -18,12 +18,15 @@
  */
 package org.apache.cxf.interceptor;
 
+import java.util.Collection;
 import java.util.SortedSet;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.Phase;
 import org.apache.cxf.phase.PhaseInterceptorChain;
 import org.apache.cxf.phase.PhaseManager;
@@ -48,6 +51,25 @@
         if (e.getService().getDataBinding() instanceof InterceptorProvider) {
             chain.add(((InterceptorProvider)e.getService().getDataBinding()).getOutFaultInterceptors());
         }
+        
+        addToChain(chain, ex.getInMessage());
+        addToChain(chain, ex.getOutFaultMessage());
+    }
+    private void addToChain(PhaseInterceptorChain chain, Message m) {
+        Collection<InterceptorProvider> providers 
+            = CastUtils.cast((Collection<?>)m.get(Message.INTERCEPTOR_PROVIDERS));
+        if (providers != null) {
+            for (InterceptorProvider p : providers) {
+                chain.add(p.getOutFaultInterceptors());
+            }
+        }
+        Collection<Interceptor> is = CastUtils.cast((Collection<?>)m.get(Message.FAULT_OUT_INTERCEPTORS));
+        if (is != null) {
+            chain.add(is);
+        }
+        if (m.getDestination() instanceof InterceptorProvider) {
+            chain.add(((InterceptorProvider)m.getDestination()).getOutFaultInterceptors());
+        }
     }
     
     protected SortedSet<Phase> getPhases() {

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/OutgoingChainInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/OutgoingChainInterceptor.java?rev=827857&r1=827856&r2=827857&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/OutgoingChainInterceptor.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/OutgoingChainInterceptor.java
Wed Oct 21 00:33:19 2009
@@ -20,6 +20,7 @@
 package org.apache.cxf.interceptor;
 
 import java.io.IOException;
+import java.util.Collection;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -30,6 +31,7 @@
 import org.apache.cxf.endpoint.ConduitSelector;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.endpoint.PreexistingConduitSelector;
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
@@ -123,10 +125,33 @@
             }
             chain.add(il);
         }
+        modifyChain(chain, ex);
         chain.setFaultObserver(ep.getOutFaultObserver());
         return chain;
     }
-
+    private static void modifyChain(PhaseInterceptorChain chain, Exchange ex) {
+        modifyChain(chain, ex.getInMessage());
+        modifyChain(chain, ex.getOutMessage());
+    }
+    private static void modifyChain(PhaseInterceptorChain chain, Message m) {
+        if (m == null) {
+            return;
+        }
+        Collection<InterceptorProvider> providers 
+            = CastUtils.cast((Collection<?>)m.get(Message.INTERCEPTOR_PROVIDERS));
+        if (providers != null) {
+            for (InterceptorProvider p : providers) {
+                chain.add(p.getOutInterceptors());
+            }
+        }
+        Collection<Interceptor> is = CastUtils.cast((Collection<?>)m.get(Message.OUT_INTERCEPTORS));
+        if (is != null) {
+            chain.add(is);
+        }
+        if (m.getDestination() instanceof InterceptorProvider) {
+            chain.add(((InterceptorProvider)m.getDestination()).getOutInterceptors());
+        }
+    }
     private PhaseInterceptorChain getChain(Exchange ex) {
         Bus bus = ex.get(Bus.class);
         Binding binding = ex.get(Binding.class);
@@ -175,6 +200,7 @@
                                    i1, i2, i3);
         }
         
+        modifyChain(chain, ex);
         chain.setFaultObserver(ep.getOutFaultObserver());
         return chain;
     }

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/ChainInitiationObserver.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/ChainInitiationObserver.java?rev=827857&r1=827856&r2=827857&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/ChainInitiationObserver.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/ChainInitiationObserver.java
Wed Oct 21 00:33:19 2009
@@ -22,6 +22,7 @@
 
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.util.Collection;
 
 import javax.xml.namespace.QName;
 
@@ -29,6 +30,8 @@
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.binding.Binding;
 import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.interceptor.InterceptorChain;
 import org.apache.cxf.interceptor.InterceptorProvider;
 import org.apache.cxf.message.Exchange;
@@ -101,12 +104,29 @@
             
             phaseChain.setFaultObserver(endpoint.getOutFaultObserver());
            
+            addToChain(phaseChain, message);
+            
             phaseChain.doIntercept(message);
         } finally {
             BusFactory.setThreadDefaultBus(origBus);
         }
     }
-
+    private void addToChain(PhaseInterceptorChain chain, Message m) {
+        Collection<InterceptorProvider> providers 
+            = CastUtils.cast((Collection<?>)m.get(Message.INTERCEPTOR_PROVIDERS));
+        if (providers != null) {
+            for (InterceptorProvider p : providers) {
+                chain.add(p.getInInterceptors());
+            }
+        }
+        Collection<Interceptor> is = CastUtils.cast((Collection<?>)m.get(Message.IN_INTERCEPTORS));
+        if (is != null) {
+            chain.add(is);
+        }
+        if (m.getDestination() instanceof InterceptorProvider) {
+            chain.add(((InterceptorProvider)m.getDestination()).getInInterceptors());
+        }
+    }
 
     protected Binding getBinding() {
         return endpoint.getBinding();

Modified: cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/ClientServerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/ClientServerTest.java?rev=827857&r1=827856&r2=827857&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/ClientServerTest.java
(original)
+++ cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/ClientServerTest.java
Wed Oct 21 00:33:19 2009
@@ -17,9 +17,18 @@
  * under the License.
  */
 package org.apache.cxf.frontend.spring;
+import java.util.Arrays;
+
 import junit.framework.Assert;
 
 import org.apache.cxf.BusFactory;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.frontend.ClientProxy;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
 import org.apache.cxf.service.factory.HelloService;
 import org.junit.Test;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -39,6 +48,39 @@
         
         String result = greeter.sayHello();
         assertEquals("We get the wrong sayHello result", result, "hello");
+        
+        
+        Client c = ClientProxy.getClient(greeter);
+        TestInterceptor out = new TestInterceptor();
+        TestInterceptor in = new TestInterceptor();
+        c.getRequestContext().put(Message.OUT_INTERCEPTORS, Arrays.asList(new Interceptor[]
{out}));
+        result = greeter.sayHello();
+        assertTrue(out.wasCalled());
+        out.reset();
+
+        c.getRequestContext().put(Message.IN_INTERCEPTORS, Arrays.asList(new Interceptor[]
{in}));
+        result = greeter.sayHello();
+        assertTrue(out.wasCalled());
+        assertTrue(in.wasCalled());
+    }
+    
+    private class TestInterceptor extends AbstractPhaseInterceptor<Message> {
+        boolean called;
+        
+        public TestInterceptor() {
+            super(Phase.USER_LOGICAL);
+        }
+        
+        public void handleMessage(Message message) throws Fault {
+            called = true;
+        }
+        public boolean wasCalled() {
+            return called;
+        }
+        public void reset() {
+            called = false;
+        }
     }
+    
 
 }



Mime
View raw message