Author: ningjiang
Date: Thu Feb 11 14:04:49 2010
New Revision: 908979

URL: http://svn.apache.org/viewvc?rev=908979&view=rev
Log:
CAMEL-2457 camel-cxf producer support to get the BindingOperationInfo by 
looking up the operation name from the client service model

Modified:
    
camel/branches/camel-1.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
    
camel/branches/camel-1.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayLoadMessageRouterTest.java

Modified: 
camel/branches/camel-1.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java?rev=908979&r1=908978&r2=908979&view=diff
==============================================================================
--- 
camel/branches/camel-1.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
 (original)
+++ 
camel/branches/camel-1.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
 Thu Feb 11 14:04:49 2010
@@ -18,7 +18,9 @@
 
 import java.lang.reflect.Proxy;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.logging.Logger;
@@ -201,8 +203,8 @@
             Map<Class, Object> params = 
invokingContext.getRequestContent(inMessage);
             // invoke the stream message with the exchange context
             CxfClient cxfClient = (CxfClient)client;
-            // need to get the binding object to create the message
-            BindingOperationInfo boi = ex.get(BindingOperationInfo.class);
+            // need to get the BindingOperationInfo object to create the 
message
+            BindingOperationInfo boi = getBindingOperationInfo(exchange);
             Message response = null;
             if (boi == null) {
                 // it should be the raw message
@@ -211,6 +213,8 @@
                 // create the message here
                 Endpoint ep = ex.get(Endpoint.class);
                 response = ep.getBinding().createMessage();
+                // set the BindingOperationInfo object here
+                ex.put(BindingOperationInfo.class, boi);
             }
             response.setExchange(ex);
             // invoke the message prepare the context
@@ -226,6 +230,36 @@
         }
 
     }
+    
+    private BindingOperationInfo getBindingOperationInfo(CxfExchange ex) {
+
+        BindingOperationInfo answer = null;
+        String lp = ex.getIn().getHeader(CxfConstants.OPERATION_NAME, 
String.class);
+        
+        if (lp == null) {
+            // try to get the BindingOperationInfo from cxfExchange
+            // make sure the old cxf payload code still working
+            LOG.fine("Try get the BindingOperationInfo from cxfExchange.");
+            org.apache.cxf.message.Exchange cxfExchange = ex.getExchange();
+            answer = cxfExchange.get(BindingOperationInfo.class);           
+            
+        } else {
+            String ns = ex.getIn().getHeader(CxfConstants.OPERATION_NAMESPACE, 
String.class);
+            if (ns == null) {
+                ns = 
client.getEndpoint().getService().getName().getNamespaceURI();
+                
+                LOG.finer("Operation namespace not in header.  Set it to: " + 
ns);
+                
+            }
+
+            QName qname = new QName(ns, lp);
+            
+            LOG.finer("Operation qname = " + qname.toString());            
+            
+            answer = 
client.getEndpoint().getEndpointInfo().getBinding().getOperation(qname);
+        }
+        return answer;
+    }
 
     @Override
     protected void doStart() throws Exception {

Modified: 
camel/branches/camel-1.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayLoadMessageRouterTest.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayLoadMessageRouterTest.java?rev=908979&r1=908978&r2=908979&view=diff
==============================================================================
--- 
camel/branches/camel-1.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayLoadMessageRouterTest.java
 (original)
+++ 
camel/branches/camel-1.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayLoadMessageRouterTest.java
 Thu Feb 11 14:04:49 2010
@@ -24,6 +24,7 @@
 import org.apache.camel.Message;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.cxf.service.model.BindingOperationInfo;
 
 public class CxfPayLoadMessageRouterTest extends CxfSimpleRouterTest {
     private String routerEndpointURI = "cxf://" + ROUTER_ADDRESS + "?" + 
SERVICE_CLASS + "&dataFormat=PAYLOAD";
@@ -41,6 +42,14 @@
                             assertNotNull("We should get the elements here" , 
elements);
                             assertEquals("Get the wrong elements size" , 
elements.size(), 1);
                             assertEquals("Get the wrong namespace URI" , 
elements.get(0).getNamespaceURI(), "http://cxf.component.camel.apache.org/";);
+                            // get the BindingOperationInfo object
+                            BindingOperationInfo bindingOperationInfo = 
((CxfExchange)exchange).getExchange().get(BindingOperationInfo.class);
+                            assertNotNull("We should get the 
BindingOperationInfo here", bindingOperationInfo);
+                            // set the operation name from the bindingInfo , 
from camel 1.6.3 this feature is ported from camel 2.x  
+                            message.setHeader(CxfConstants.OPERATION_NAME, 
bindingOperationInfo.getOperationInfo().getName().getLocalPart());
+                            // removed the bindingOperationInfo, and let the 
cxf producer lookup the BindingOperationInfo with OPERATION_NAME header
+                            
((CxfExchange)exchange).getExchange().remove(BindingOperationInfo.class.getName());
+                            
                         }                        
                     }
                     


Reply via email to