Author: ningjiang
Date: Thu May 30 02:22:03 2013
New Revision: 1487707

URL: http://svn.apache.org/r1487707
Log:
SMX4-1472 servicemix-camel component should hornor the synchronous option

Modified:
    
servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixConsumer.java
    
servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixEndpoint.java
    
servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/ServiceMixComponentTest.java

Modified: 
servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixConsumer.java
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixConsumer.java?rev=1487707&r1=1487706&r2=1487707&view=diff
==============================================================================
--- 
servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixConsumer.java
 (original)
+++ 
servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixConsumer.java
 Thu May 30 02:22:03 2013
@@ -75,13 +75,17 @@ public class ServiceMixConsumer extends 
             try {
                 org.apache.camel.Exchange camelExchange = 
getEndpoint().createExchange(exchange);
                 camelExchange.addOnCompletion(this);
-
-                getAsyncProcessor().process(camelExchange, new AsyncCallback() 
{
-
-                    public void done(boolean doneSync) {
-                        // this is handled by the onComplete/onFailure method
-                    }
-                });
+                if (getEndpoint().isSynchronous()) {
+                    getProcessor().process(camelExchange);
+                    // need to send the response back here
+                    onComplete(camelExchange);
+                } else {
+                    getAsyncProcessor().process(camelExchange, new 
AsyncCallback() {
+                        public void done(boolean doneSync) {
+                            // this is handled by the onComplete/onFailure 
method
+                        }
+                    });
+                }
             } catch (Exception e) {
                 exchange.setError(e);
                 exchange.setStatus(Status.Error);

Modified: 
servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixEndpoint.java
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixEndpoint.java?rev=1487707&r1=1487706&r2=1487707&view=diff
==============================================================================
--- 
servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixEndpoint.java
 (original)
+++ 
servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixEndpoint.java
 Thu May 30 02:22:03 2013
@@ -24,6 +24,7 @@ import org.apache.camel.Exchange;
 import org.apache.camel.Producer;
 import org.apache.camel.Consumer;
 import org.apache.camel.Processor;
+import org.apache.camel.impl.SynchronousDelegateProducer;
 
 /**
  * A Camel {@link Endpoint} to interact with the ServiceMix NMR from within a 
Camel route
@@ -87,7 +88,11 @@ public class ServiceMixEndpoint extends 
 
     
     public Producer createProducer() throws Exception {
-        return new ServiceMixProducer(this, getComponent().getNmr());
+        if (isSynchronous()) {
+            return new SynchronousDelegateProducer(new 
ServiceMixProducer(this, getComponent().getNmr()));
+        } else {
+            return new ServiceMixProducer(this, getComponent().getNmr());
+        }
     }
 
     public Consumer createConsumer(Processor processor) throws Exception {

Modified: 
servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/ServiceMixComponentTest.java
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/ServiceMixComponentTest.java?rev=1487707&r1=1487706&r2=1487707&view=diff
==============================================================================
--- 
servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/ServiceMixComponentTest.java
 (original)
+++ 
servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/ServiceMixComponentTest.java
 Thu May 30 02:22:03 2013
@@ -17,12 +17,9 @@
 package org.apache.servicemix.camel.nmr;
 
 import org.apache.camel.CamelContext;
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.Producer;
 import org.apache.camel.impl.DefaultCamelContext;
-import org.apache.servicemix.nmr.api.AbortedException;
+import org.apache.camel.impl.SynchronousDelegateProducer;
 import org.junit.Test;
 
 /**
@@ -39,6 +36,14 @@ public class ServiceMixComponentTest ext
     }
 
     @Test
+    public void testSyncOperation() throws Exception {
+        ServiceMixEndpoint endpoint = (ServiceMixEndpoint) 
context.getEndpoint("nmr:Test?synchronous=true");
+        assertNotNull(endpoint);
+        Producer producer = endpoint.createProducer();
+        assertTrue("It should be the instance of ", producer instanceof 
SynchronousDelegateProducer);
+    }
+
+    @Test
     public void testUriRunAsSubject() {
         ServiceMixEndpoint endpoint = (ServiceMixEndpoint) 
context.getEndpoint("nmr:Test");
         assertNotNull(endpoint);


Reply via email to