cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ajaypai...@apache.org
Subject svn commit: r529704 - in /incubator/cxf/trunk/rt/bindings/coloc/src: main/java/org/apache/cxf/binding/coloc/ test/java/org/apache/cxf/binding/coloc/
Date Tue, 17 Apr 2007 18:38:24 GMT
Author: ajaypaibir
Date: Tue Apr 17 11:38:22 2007
New Revision: 529704

URL: http://svn.apache.org/viewvc?view=rev&rev=529704
Log:
Updated coloc binding to check for same OperationInfo and Class instance of parts on sender/receiver
end.

Modified:
    incubator/cxf/trunk/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocMessageObserver.java
    incubator/cxf/trunk/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocOutInterceptor.java
    incubator/cxf/trunk/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocUtil.java
    incubator/cxf/trunk/rt/bindings/coloc/src/test/java/org/apache/cxf/binding/coloc/ColocOutInterceptorTest.java
    incubator/cxf/trunk/rt/bindings/coloc/src/test/java/org/apache/cxf/binding/coloc/ColocUtilTest.java

Modified: incubator/cxf/trunk/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocMessageObserver.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocMessageObserver.java?view=diff&rev=529704&r1=529703&r2=529704
==============================================================================
--- incubator/cxf/trunk/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocMessageObserver.java
(original)
+++ incubator/cxf/trunk/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocMessageObserver.java
Tue Apr 17 11:38:22 2007
@@ -59,6 +59,10 @@
         Message inMsg = endpoint.getBinding().createMessage();
         MessageImpl.copyContent(m, inMsg);
         
+        //Copy Request Context to Server inBound Message
+        //TODO a Context Filter Strategy required. 
+        inMsg.putAll(m);
+
         inMsg.put(COLOCATED, Boolean.TRUE);
         inMsg.put(Message.REQUESTOR_ROLE, Boolean.FALSE);
         inMsg.put(Message.INBOUND_MESSAGE, Boolean.TRUE);

Modified: incubator/cxf/trunk/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocOutInterceptor.java?view=diff&rev=529704&r1=529703&r2=529704
==============================================================================
--- incubator/cxf/trunk/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocOutInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocOutInterceptor.java
Tue Apr 17 11:38:22 2007
@@ -45,6 +45,7 @@
 import org.apache.cxf.service.Service;
 import org.apache.cxf.service.model.BindingOperationInfo;
 import org.apache.cxf.service.model.EndpointInfo;
+//import org.apache.cxf.service.model.OperationInfo;
 import org.apache.cxf.transport.MessageObserver;
 
 public class ColocOutInterceptor extends AbstractPhaseInterceptor<Message> {
@@ -120,6 +121,11 @@
         Message m = getInBoundMessage(ex);
         Message inMsg = ep.getBinding().createMessage();
         MessageImpl.copyContent(m, inMsg);
+        
+        //Copy Response Context to Client inBound Message
+        //TODO a Context Filter Strategy required. 
+        inMsg.putAll(m);
+        
         inMsg.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
         inMsg.put(Message.INBOUND_MESSAGE, Boolean.TRUE);
         inMsg.setExchange(ex);
@@ -153,7 +159,7 @@
     protected void setMessageObserver(MessageObserver observer) {
         colocObserver = observer;
     }
-    
+
     protected Server isColocated(List<Server> servers, Endpoint endpoint, BindingOperationInfo
boi) {
         if (servers != null) {
             Service senderService = endpoint.getService();
@@ -163,15 +169,24 @@
                 Service receiverService = receiverEndpoint.getService();
                 EndpointInfo receiverEI = receiverEndpoint.getEndpointInfo();
                 if (receiverService.getName().equals(senderService.getName())
-                    && receiverEI.getName().equals(senderEI.getName())
-                    && receiverEI.getBinding().getOperation(boi.getName()) != null)
{
-                    return s;
-                    //TODO Do a Strict check on the SEI Method from the implementor. 
+                    && receiverEI.getName().equals(senderEI.getName())) {
+                    //Check For Operation Match.
+                    BindingOperationInfo receiverOI = receiverEI.getBinding().getOperation(boi.getName());
+                    if (receiverOI != null 
+                        && isSameOperationInfo(boi, receiverOI)) {
+                        return s;
+                    }
                 }
             }
         }
         
         return null;
+    }
+    
+    protected boolean isSameOperationInfo(BindingOperationInfo sender,
+                                          BindingOperationInfo receiver) {
+        return ColocUtil.isSameOperationInfo(sender.getOperationInfo(), 
+                                             receiver.getOperationInfo());
     }
     
     public void setExchangeProperties(Exchange exchange, Endpoint ep) {

Modified: incubator/cxf/trunk/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocUtil.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocUtil.java?view=diff&rev=529704&r1=529703&r2=529704
==============================================================================
--- incubator/cxf/trunk/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocUtil.java
(original)
+++ incubator/cxf/trunk/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocUtil.java
Tue Apr 17 11:38:22 2007
@@ -18,6 +18,8 @@
  */
 package org.apache.cxf.binding.coloc;
 
+import java.util.Collection;
+import java.util.Iterator;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.logging.Level;
@@ -30,6 +32,10 @@
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.phase.Phase;
 import org.apache.cxf.phase.PhaseInterceptorChain;
+import org.apache.cxf.service.model.FaultInfo;
+import org.apache.cxf.service.model.MessageInfo;
+import org.apache.cxf.service.model.MessagePartInfo;
+import org.apache.cxf.service.model.OperationInfo;
 
 public final class ColocUtil {
     //private static final ResourceBundle BUNDLE = BundleUtils.getBundle(ColocInInterceptor.class);
@@ -106,4 +112,69 @@
         return chain;
     }    
     
+    public static boolean isSameOperationInfo(OperationInfo oi1, OperationInfo oi2) {
+        return  oi1.getName().equals(oi2.getName())
+                && isSameMessageInfo(oi1.getInput(), oi2.getInput())
+                && isSameMessageInfo(oi1.getOutput(), oi2.getOutput())
+                && isSameFaultInfo(oi1.getFaults(), oi2.getFaults());
+    }
+    
+    public static boolean isSameMessageInfo(MessageInfo mi1, MessageInfo mi2) {
+        if ((mi1 == null && mi2 != null)
+            || (mi1 != null && mi2 == null)) {
+            return false;
+        }
+        
+        if (mi1 != null && mi2 != null) {
+            List<MessagePartInfo> mpil1 = mi1.getMessageParts();
+            List<MessagePartInfo> mpil2 = mi2.getMessageParts();
+            if (mpil1.size() != mpil2.size()) {
+                return false;
+            }
+            int idx = 0;
+            for (MessagePartInfo mpi1 : mpil1) {
+                MessagePartInfo mpi2 = mi2.getMessagePartByIndex(idx);
+                if (!mpi1.getTypeClass().equals(mpi2.getTypeClass())) {
+                    return false;
+                }
+                ++idx;
+            }
+        }
+        return true;
+    }
+    
+    public static boolean isSameFaultInfo(Collection<FaultInfo> fil1, 
+                                          Collection<FaultInfo> fil2) {
+        if ((fil1 == null && fil2 != null)
+            || (fil1 != null && fil2 == null)) {
+            return false;
+        }
+        
+        if (fil1 != null && fil2 != null) {
+            if (fil1.size() != fil2.size()) {
+                return false;
+            }
+            for (FaultInfo fi1 : fil1) {
+                Iterator<FaultInfo> iter = fil2.iterator();
+                Class<?> fiClass1 = fi1.getProperty(Class.class.getName(), 
+                                                    Class.class);
+                boolean match = false;
+                while (iter.hasNext()) {
+                    FaultInfo fi2 = iter.next();
+                    Class<?> fiClass2 = fi2.getProperty(Class.class.getName(), 
+                                                        Class.class);
+                    //Sender/Receiver Service Model not same for faults wr.t message names.
+                    //So Compare Exception Class Instance.
+                    if (fiClass1.equals(fiClass2)) {
+                        match = true;
+                        break;
+                    }
+                }
+                if (!match) {
+                    return false;        
+                }
+            }
+        }
+        return true;
+    }
 }

Modified: incubator/cxf/trunk/rt/bindings/coloc/src/test/java/org/apache/cxf/binding/coloc/ColocOutInterceptorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/coloc/src/test/java/org/apache/cxf/binding/coloc/ColocOutInterceptorTest.java?view=diff&rev=529704&r1=529703&r2=529704
==============================================================================
--- incubator/cxf/trunk/rt/bindings/coloc/src/test/java/org/apache/cxf/binding/coloc/ColocOutInterceptorTest.java
(original)
+++ incubator/cxf/trunk/rt/bindings/coloc/src/test/java/org/apache/cxf/binding/coloc/ColocOutInterceptorTest.java
Tue Apr 17 11:38:22 2007
@@ -372,6 +372,7 @@
     }
 
     private void verifyIsColocatedWithSameOperation() {
+        colocOut = new TestColocOutInterceptor1();
         //Funtion Param
         Server s1 = control.createMock(Server.class);
         List<Server> list = new ArrayList<Server>();
@@ -421,6 +422,10 @@
         
         public void invokeInboundChain(Exchange exchange, Endpoint ep) {
             //No Op
-        }        
+        }
+        
+        protected boolean isSameOperationInfo(BindingOperationInfo s, BindingOperationInfo
r) {
+            return true;
+        }
     }
 }

Modified: incubator/cxf/trunk/rt/bindings/coloc/src/test/java/org/apache/cxf/binding/coloc/ColocUtilTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/coloc/src/test/java/org/apache/cxf/binding/coloc/ColocUtilTest.java?view=diff&rev=529704&r1=529703&r2=529704
==============================================================================
--- incubator/cxf/trunk/rt/bindings/coloc/src/test/java/org/apache/cxf/binding/coloc/ColocUtilTest.java
(original)
+++ incubator/cxf/trunk/rt/bindings/coloc/src/test/java/org/apache/cxf/binding/coloc/ColocUtilTest.java
Tue Apr 17 11:38:22 2007
@@ -22,6 +22,8 @@
 import java.util.Iterator;
 import java.util.List;
 
+import javax.xml.namespace.QName;
+
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.endpoint.Endpoint;
@@ -34,6 +36,14 @@
 import org.apache.cxf.phase.PhaseManager;
 import org.apache.cxf.phase.PhaseManagerImpl;
 import org.apache.cxf.service.Service;
+import org.apache.cxf.service.model.FaultInfo;
+import org.apache.cxf.service.model.MessageInfo;
+import org.apache.cxf.service.model.MessagePartInfo;
+import org.apache.cxf.service.model.OperationInfo;
+import org.apache.headers.coloc.types.FaultDetailT;
+import org.apache.headers.coloc.types.InHeaderT;
+import org.apache.headers.coloc.types.OutHeaderT;
+import org.apache.headers.rpc_lit.PingMeFault;
 import org.easymock.classextension.EasyMock;
 import org.easymock.classextension.IMocksControl;
 
@@ -151,6 +161,70 @@
                      false,
                      iter.hasNext());
         assertNotNull("OutFaultObserver should be set", chain.getFaultObserver());
+    }
+    
+    @Test
+    public void testIsSameFaultInfo() {
+        OperationInfo oi = control.createMock(OperationInfo.class);
+        
+        boolean match = ColocUtil.isSameFaultInfo(null, null);
+        assertEquals("Should return true", true, match);
+        List<FaultInfo> fil1 = new ArrayList<FaultInfo>();
+        match = ColocUtil.isSameFaultInfo(fil1, null);
+        assertEquals("Should not find a match", false, match);
+        match = ColocUtil.isSameFaultInfo(null, fil1);
+        assertEquals("Should not find a match", false, match);
+        
+        List<FaultInfo> fil2 = new ArrayList<FaultInfo>();
+        match = ColocUtil.isSameFaultInfo(fil1, fil2);
+        
+        QName fn1 = new QName("A", "B");
+        QName fn2 = new QName("C", "D");
+        
+        FaultInfo fi1 = new FaultInfo(fn1, null, oi);
+        fi1.setProperty(Class.class.getName(), PingMeFault.class);
+        fil1.add(fi1);
+        FaultInfo fi2 = new FaultInfo(fn2, null, oi);
+        fi2.setProperty(Class.class.getName(), FaultDetailT.class);
+        match = ColocUtil.isSameFaultInfo(fil1, fil2);
+        assertEquals("Should not find a match", false, match);
+
+        FaultInfo fi3 = new FaultInfo(fn2, null, oi);
+        fi3.setProperty(Class.class.getName(), PingMeFault.class);
+        fil2.add(fi3);
+        match = ColocUtil.isSameFaultInfo(fil1, fil2);
+        assertEquals("Should find a match", true, match);
+    }
+    
+    @Test
+    public void testIsSameMessageInfo() {
+        OperationInfo oi = control.createMock(OperationInfo.class);
+        boolean match = ColocUtil.isSameMessageInfo(null, null);
+        assertEquals("Should return true", true, match);
+        QName mn1 = new QName("A", "B");
+        QName mn2 = new QName("C", "D");
+
+        MessageInfo mi1 = new MessageInfo(oi, mn1);
+        MessageInfo mi2 = new MessageInfo(oi, mn2);
+        match = ColocUtil.isSameMessageInfo(mi1, null);
+        assertEquals("Should not find a match", false, match);
+        match = ColocUtil.isSameMessageInfo(null, mi2);
+        assertEquals("Should not find a match", false, match);
+        
+        MessagePartInfo mpi = new MessagePartInfo(new QName("", "B"), null);
+        mpi.setTypeClass(InHeaderT.class);
+        mi1.addMessagePart(mpi);
+        
+        mpi = new MessagePartInfo(new QName("", "D"), null);
+        mpi.setTypeClass(OutHeaderT.class);
+        mi2.addMessagePart(mpi);
+        
+        match = ColocUtil.isSameMessageInfo(mi1, mi2);
+        assertEquals("Should not find a match", false, match);
+        
+        mpi.setTypeClass(InHeaderT.class);
+        match = ColocUtil.isSameMessageInfo(mi1, mi2);
+        assertEquals("Should find a match", true, match);
     }
     
 }



Mime
View raw message