camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r930866 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/builder/ camel-core/src/main/java/org/apache/camel/component/bean/ camel-core/src/test/java/org/apache/camel/component/bean/ components/camel-spring/src/main/java/org/apac...
Date Mon, 05 Apr 2010 14:25:22 GMT
Author: davsclaus
Date: Mon Apr  5 14:25:21 2010
New Revision: 930866

URL: http://svn.apache.org/viewvc?rev=930866&view=rev
Log:
CAMEL-2613: Added ProxyBuilder to Java DSL. Added voidAsInOnly option to Camel Proxy to let
methods that has void return type act as InOnly (fire and forget) instead of default as InOut.

Added:
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ProxyBuilder.java   (with
props)
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelProxyVoidAsInOnlyTest.java
      - copied, changed from r930692, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/AnotherCamelProxyTest.java
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelProxyVoidAsInOutTest.java
  (with props)
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/MyOtherProxySender.java
      - copied, changed from r930692, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/MyProxySender.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/CamelProxyVoidAsInOnlyTest.xml
      - copied, changed from r930692, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/AnotherCamelProxyTest.xml
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/CamelProxyVoidAsInOutTest.xml
  (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfoCache.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ProxyHelper.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanProxyTest.java
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelProxyFactoryDefinition.java
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/remoting/CamelProxyFactoryBean.java

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ProxyBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ProxyBuilder.java?rev=930866&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ProxyBuilder.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ProxyBuilder.java Mon Apr
 5 14:25:21 2010
@@ -0,0 +1,81 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.builder;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.component.bean.ProxyHelper;
+
+/**
+ * A build to create Camel proxies.
+ *
+ * @version $Revision$
+ */
+public final class ProxyBuilder {
+
+    private final CamelContext camelContext;
+    private Endpoint endpoint;
+    private boolean voidAsInOnly;
+
+    public ProxyBuilder(CamelContext camelContext) {
+        this.camelContext = camelContext;
+    }
+
+    /**
+     * Send the proxied message to this endpoint
+     *
+     * @param url  uri of endpoint
+     * @return the builder
+     */
+    public ProxyBuilder endpoint(String url) {
+        this.endpoint = camelContext.getEndpoint(url);
+        return this;
+    }
+
+    /**
+     * Send the proxied message to this endpoint
+     *
+     * @param endpoint  the endpoint
+     * @return the builder
+     */
+    public ProxyBuilder endpoint(Endpoint endpoint) {
+        this.endpoint = endpoint;
+        return this;
+    }
+
+    /**
+     * Let methods which return <tt>void</tt> be regarded as <tt>InOnly</tt>
methods (eg Fire and forget).
+     *
+     * @return the builder
+     */
+    public ProxyBuilder voidAsInOnly() {
+        voidAsInOnly = true;
+        return this;
+    }
+
+    /**
+     * Builds the proxy.
+     *
+     * @param interfaceClasses  the service interface(s)
+     * @return the proxied bean
+     * @throws Exception is thrown if error creating the proxy
+     */
+    public <T> T build(Class<T>... interfaceClasses) throws Exception {
+        return ProxyHelper.createProxy(endpoint, voidAsInOnly, interfaceClasses);
+    }
+
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ProxyBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ProxyBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java?rev=930866&r1=930865&r2=930866&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java Mon
Apr  5 14:25:21 2010
@@ -72,15 +72,25 @@ public class BeanInfo {
     private final Map<Method, MethodInfo> methodMap = new ConcurrentHashMap<Method,
MethodInfo>();
     private MethodInfo defaultMethod;
     private BeanInfo superBeanInfo;
+    private final boolean voidAsInOnly;
 
     public BeanInfo(CamelContext camelContext, Class<?> type) {
-        this(camelContext, type, createParameterMappingStrategy(camelContext));
+        this(camelContext, type, false);
+    }
+
+    public BeanInfo(CamelContext camelContext, Class<?> type, boolean voidAsInOnly)
{
+        this(camelContext, type, createParameterMappingStrategy(camelContext), voidAsInOnly);
     }
 
     public BeanInfo(CamelContext camelContext, Class<?> type, ParameterMappingStrategy
strategy) {
+        this(camelContext, type, strategy, false);
+    }
+
+    public BeanInfo(CamelContext camelContext, Class<?> type, ParameterMappingStrategy
strategy, boolean voidAsInOnly) {
         this.camelContext = camelContext;
         this.type = type;
         this.strategy = strategy;
+        this.voidAsInOnly = voidAsInOnly;
 
         // configure the default excludes methods
         synchronized (EXCLUDED_METHODS) {
@@ -340,7 +350,7 @@ public class BeanInfo {
         }
 
         // now lets add the method to the repository
-        return new MethodInfo(camelContext, clazz, method, parameters, bodyParameters, hasCustomAnnotation,
hasHandlerAnnotation);
+        return new MethodInfo(camelContext, clazz, method, parameters, bodyParameters, hasCustomAnnotation,
hasHandlerAnnotation, voidAsInOnly);
     }
 
     /**

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java?rev=930866&r1=930865&r2=930866&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java Mon
Apr  5 14:25:21 2010
@@ -61,7 +61,7 @@ public class MethodInfo {
     private RecipientList recipientList;
 
     public MethodInfo(CamelContext camelContext, Class<?> type, Method method, List<ParameterInfo>
parameters, List<ParameterInfo> bodyParameters,
-                      boolean hasCustomAnnotation, boolean hasHandlerAnnotation) {
+                      boolean hasCustomAnnotation, boolean hasHandlerAnnotation, boolean
voidAsInOnly) {
         this.camelContext = camelContext;
         this.type = type;
         this.method = method;
@@ -71,10 +71,14 @@ public class MethodInfo {
         this.hasHandlerAnnotation = hasHandlerAnnotation;
         this.parametersExpression = createParametersExpression();
 
+        // prefer annotations
         Pattern oneway = findOneWayAnnotation(method);
         if (oneway != null) {
             pattern = oneway.value();
-        }
+        } else if (voidAsInOnly && isReturnTypeVoid()) {
+            // okay its a void method and we are configured to let that be InOnly
+            pattern = ExchangePattern.InOnly;
+        } 
 
         if (method.getAnnotation(org.apache.camel.RecipientList.class) != null
                 && matchContext(method.getAnnotation(org.apache.camel.RecipientList.class).context()))
{
@@ -115,8 +119,6 @@ public class MethodInfo {
         return true;
     }
 
-
-
     public String toString() {
         return method.toString();
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfoCache.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfoCache.java?rev=930866&r1=930865&r2=930866&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfoCache.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfoCache.java
Mon Apr  5 14:25:21 2010
@@ -33,6 +33,7 @@ public class MethodInfoCache {
     private final CamelContext camelContext;
     private Map<Method, MethodInfo> methodCache;
     private Map<Class<?>, BeanInfo> classCache;
+    private boolean voidAsInOnly;
 
     public MethodInfoCache(CamelContext camelContext) {
         this(camelContext, 1000, 10000);
@@ -74,7 +75,7 @@ public class MethodInfoCache {
     }
 
     protected BeanInfo createBeanInfo(Class<?> declaringClass) {
-        return new BeanInfo(camelContext, declaringClass);
+        return new BeanInfo(camelContext, declaringClass, voidAsInOnly);
     }
 
     protected static Map<Object, Object> createLruCache(int size) {
@@ -88,4 +89,12 @@ public class MethodInfoCache {
     private static Map<Method, MethodInfo> createMethodCache(int size) {
         return CastUtils.cast(createLruCache(size));
     }
+
+    public boolean isVoidAsInOnly() {
+        return voidAsInOnly;
+    }
+
+    public void setVoidAsInOnly(boolean voidAsInOnly) {
+        this.voidAsInOnly = voidAsInOnly;
+    }
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ProxyHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ProxyHelper.java?rev=930866&r1=930865&r2=930866&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ProxyHelper.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ProxyHelper.java
Mon Apr  5 14:25:21 2010
@@ -59,6 +59,13 @@ public final class ProxyHelper {
         return (T) createProxy(endpoint, cl, interfaceClasses, createMethodInfoCache(endpoint));
     }
 
+    /**
+     * Creates a Proxy which sends PojoExchange to the endpoint.
+     */
+    @SuppressWarnings("unchecked")
+    public static <T> T createProxy(Endpoint endpoint, boolean voidAsInOnly, ClassLoader
cl, Class<T>... interfaceClasses) throws Exception {
+        return (T) createProxy(endpoint, cl, interfaceClasses, createMethodInfoCache(endpoint,
voidAsInOnly));
+    }
 
     /**
      * Creates a Proxy which sends PojoExchange to the endpoint.
@@ -72,11 +79,27 @@ public final class ProxyHelper {
      * Creates a Proxy which sends PojoExchange to the endpoint.
      */
     @SuppressWarnings("unchecked")
+    public static <T> T createProxy(Endpoint endpoint, boolean voidAsInOnly, Class<T>...
interfaceClasses) throws Exception {
+        return (T) createProxy(endpoint, voidAsInOnly, getClassLoader(interfaceClasses),
interfaceClasses);
+    }
+
+    /**
+     * Creates a Proxy which sends PojoExchange to the endpoint.
+     */
+    @SuppressWarnings("unchecked")
     public static <T> T createProxy(Endpoint endpoint, Producer producer, Class<T>...
interfaceClasses) throws Exception {
         return (T) createProxyObject(endpoint, producer, getClassLoader(interfaceClasses),
interfaceClasses, createMethodInfoCache(endpoint));
     }
 
     /**
+     * Creates a Proxy which sends PojoExchange to the endpoint.
+     */
+    @SuppressWarnings("unchecked")
+    public static <T> T createProxy(Endpoint endpoint, Producer producer, boolean voidAsInOnly,
Class<T>... interfaceClasses) throws Exception {
+        return (T) createProxyObject(endpoint, producer, getClassLoader(interfaceClasses),
interfaceClasses, createMethodInfoCache(endpoint, voidAsInOnly));
+    }
+
+    /**
      * Returns the class loader of the first interface or throws {@link IllegalArgumentException}
if there are no interfaces specified
      */
     protected static ClassLoader getClassLoader(Class<?>... interfaces) {
@@ -89,4 +112,10 @@ public final class ProxyHelper {
     protected static MethodInfoCache createMethodInfoCache(Endpoint endpoint) {
         return new MethodInfoCache(endpoint.getCamelContext());
     }
+
+    protected static MethodInfoCache createMethodInfoCache(Endpoint endpoint, boolean voidAsInOnly)
{
+        MethodInfoCache cache = new MethodInfoCache(endpoint.getCamelContext());
+        cache.setVoidAsInOnly(voidAsInOnly);
+        return cache;
+    }
 }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanProxyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanProxyTest.java?rev=930866&r1=930865&r2=930866&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanProxyTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanProxyTest.java
Mon Apr  5 14:25:21 2010
@@ -21,6 +21,7 @@ import org.w3c.dom.Document;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Endpoint;
 import org.apache.camel.InvalidPayloadException;
+import org.apache.camel.builder.ProxyBuilder;
 import org.apache.camel.builder.RouteBuilder;
 import static org.apache.camel.builder.xml.XPathBuilder.xpath;
 
@@ -83,6 +84,7 @@ public class BeanProxyTest extends Conte
     }
 
     // TODO: Does not pass on JDK6
+
     public void disabledtestBeanProxyFailureNullBody() throws Exception {
         Endpoint endpoint = context.getEndpoint("direct:start");
         OrderService service = ProxyHelper.createProxy(endpoint, OrderService.class);
@@ -132,6 +134,16 @@ public class BeanProxyTest extends Conte
         assertEquals("Hello World", reply);
     }
 
+    // START SNIPPET: e4
+    public void testProxyBuilderProxyCallAnotherBean() throws Exception {
+        // use ProxyBuilder to easily create the proxy
+        OrderService service = new ProxyBuilder(context).endpoint("direct:bean").build(OrderService.class);
+
+        String reply = service.submitOrderStringReturnString("World");
+        assertEquals("Hello World", reply);
+    }
+    // END SNIPPET: e4
+
     public void testBeanProxyCallAnotherBeanWithNoArgs() throws Exception {
         Endpoint endpoint = context.getEndpoint("direct:bean");
         OrderService service = ProxyHelper.createProxy(endpoint, OrderService.class);
@@ -140,6 +152,50 @@ public class BeanProxyTest extends Conte
         assertEquals("Hi nobody", reply);
     }
 
+    public void testProxyBuilderProxyCallAnotherBeanWithNoArgs() throws Exception {
+        Endpoint endpoint = context.getEndpoint("direct:bean");
+        OrderService service = new ProxyBuilder(context).endpoint(endpoint).build(OrderService.class);
+
+        String reply = service.doAbsolutelyNothing();
+        assertEquals("Hi nobody", reply);
+    }
+
+    public void testBeanProxyVoidAsInOut() throws Exception {
+        Endpoint endpoint = context.getEndpoint("seda:delay");
+        // will by default let all exchanges be InOut
+        OrderService service = ProxyHelper.createProxy(endpoint, OrderService.class);
+
+        getMockEndpoint("mock:delay").expectedBodiesReceived("Hello World", "Bye World");
+        service.doNothing("Hello World");
+        template.sendBody("mock:delay", "Bye World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testProxyBuilderVoidAsInOut() throws Exception {
+        // will by default let all exchanges be InOut
+        OrderService service = new ProxyBuilder(context).endpoint("seda:delay").build(OrderService.class);
+
+        getMockEndpoint("mock:delay").expectedBodiesReceived("Hello World", "Bye World");
+        service.doNothing("Hello World");
+        template.sendBody("mock:delay", "Bye World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testBeanProxyVoidAsInOnly() throws Exception {
+        // let void be InOnly which is a fire and forget method
+        OrderService service = new ProxyBuilder(context).endpoint("seda:delay").voidAsInOnly().build(OrderService.class);
+
+        getMockEndpoint("mock:delay").expectedBodiesReceived("Bye World", "Hello World");
+        service.doNothing("Hello World");
+        // since its a fire and forget it should return faster so we can send
+        // a Bye World message to the mock which arrives before the Hello World msg
+        template.sendBody("mock:delay", "Bye World");
+
+        assertMockEndpointsSatisfied();
+    }
+
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
@@ -147,10 +203,10 @@ public class BeanProxyTest extends Conte
             public void configure() throws Exception {
                 // START SNIPPET: e1
                 from("direct:start")
-                    .choice()
+                        .choice()
                         .when(xpath("/order/@type = 'book'")).to("direct:book")
                         .otherwise().to("direct:other")
-                    .end();
+                        .end();
 
                 from("direct:book").transform(constant("<order id=\"123\">OK</order>"));
 
@@ -158,7 +214,11 @@ public class BeanProxyTest extends Conte
                 // END SNIPPET: e1
 
                 from("direct:bean")
-                    .bean(MyFooBean.class, "hello");
+                        .bean(MyFooBean.class, "hello");
+
+                from("seda:delay")
+                        .delay(1000)
+                        .to("mock:delay");
             }
         };
     }

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelProxyFactoryDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelProxyFactoryDefinition.java?rev=930866&r1=930865&r2=930866&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelProxyFactoryDefinition.java
(original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelProxyFactoryDefinition.java
Mon Apr  5 14:25:21 2010
@@ -25,7 +25,7 @@ import org.apache.camel.model.Identified
  * The &lt;proxy&gt; tag element.
  *
  * @version $Revision$
-*/ // to fudge the XSD generation
+ */
 @XmlRootElement(name = "proxy")
 public class CamelProxyFactoryDefinition extends IdentifiedType {
     @XmlAttribute
@@ -36,5 +36,7 @@ public class CamelProxyFactoryDefinition
     private Class serviceInterface;
     @XmlAttribute
     private String camelContextId;
+    @XmlAttribute
+    private Boolean voidAsInOnly = Boolean.FALSE;
 
 }

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/remoting/CamelProxyFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/remoting/CamelProxyFactoryBean.java?rev=930866&r1=930865&r2=930866&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/remoting/CamelProxyFactoryBean.java
(original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/remoting/CamelProxyFactoryBean.java
Mon Apr  5 14:25:21 2010
@@ -41,6 +41,7 @@ public class CamelProxyFactoryBean exten
     private Endpoint endpoint;
     private Object serviceProxy;
     private Producer producer;
+    private boolean voidAsInOnly;
 
     @Override
     @SuppressWarnings("unchecked")
@@ -73,7 +74,7 @@ public class CamelProxyFactoryBean exten
         try {
             this.producer = endpoint.createProducer();
             this.producer.start();
-            this.serviceProxy = ProxyHelper.createProxy(endpoint, producer, getServiceInterface());
+            this.serviceProxy = ProxyHelper.createProxy(endpoint, producer, voidAsInOnly,
getServiceInterface());
         } catch (Exception e) {
             throw new FailedToCreateProducerException(endpoint, e);
         }
@@ -133,4 +134,11 @@ public class CamelProxyFactoryBean exten
         this.applicationContext = applicationContext;
     }
 
+    public boolean isVoidAsInOnly() {
+        return voidAsInOnly;
+    }
+
+    public void setVoidAsInOnly(boolean voidAsInOnly) {
+        this.voidAsInOnly = voidAsInOnly;
+    }
 }

Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelProxyVoidAsInOnlyTest.java
(from r930692, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/AnotherCamelProxyTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelProxyVoidAsInOnlyTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelProxyVoidAsInOnlyTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/AnotherCamelProxyTest.java&r1=930692&r2=930866&rev=930866&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/AnotherCamelProxyTest.java
(original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelProxyVoidAsInOnlyTest.java
Mon Apr  5 14:25:21 2010
@@ -16,24 +16,31 @@
  */
 package org.apache.camel.spring.config;
 
-import junit.framework.TestCase;
-import org.springframework.context.ApplicationContext;
+import org.apache.camel.spring.SpringTestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 /**
  * @version $Revision$
  */
-public class AnotherCamelProxyTest extends TestCase {
+public class CamelProxyVoidAsInOnlyTest extends SpringTestSupport {
 
-    public void testAnotherCamelProxy() throws Exception {
-        // START SNIPPET: e1
-        ApplicationContext ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/AnotherCamelProxyTest.xml");
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/spring/config/CamelProxyVoidAsInOnlyTest.xml");
+    }
+
+    public void testVoidAsInOnlyCamelProxy() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Bye World", "Hello World");
+
+        // this one should be InOnly and act as fire and forget
+        MyOtherProxySender sender = context.getRegistry().lookup("myOtherSender", MyOtherProxySender.class);
+        sender.greeting("Hello World");
 
-        MyProxySender sender = (MyProxySender) ac.getBean("myProxySender");
-        String reply = sender.hello("Camel");
+        // so sending this message should arrive before the former message
+        template.sendBody("mock:result", "Bye World");
 
-        assertEquals("Bye Camel", reply);
-        // END SNIPPET: e1
+        assertMockEndpointsSatisfied();
     }
 
 }
\ No newline at end of file

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelProxyVoidAsInOutTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelProxyVoidAsInOutTest.java?rev=930866&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelProxyVoidAsInOutTest.java
(added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelProxyVoidAsInOutTest.java
Mon Apr  5 14:25:21 2010
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.spring.config;
+
+import org.apache.camel.spring.SpringTestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision$
+ */
+public class CamelProxyVoidAsInOutTest extends SpringTestSupport {
+
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/spring/config/CamelProxyVoidAsInOutTest.xml");
+    }
+
+    public void testVoidAsInOutCamelProxy() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Hello World", "Bye World");
+
+        // this one should be InOut and act as request/reply
+        MyOtherProxySender sender = context.getRegistry().lookup("myOtherSender", MyOtherProxySender.class);
+        sender.greeting("Hello World");
+
+        // so sending this message should NOT arrive before the former message
+        template.sendBody("mock:result", "Bye World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelProxyVoidAsInOutTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelProxyVoidAsInOutTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/MyOtherProxySender.java
(from r930692, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/MyProxySender.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/MyOtherProxySender.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/MyOtherProxySender.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/MyProxySender.java&r1=930692&r2=930866&rev=930866&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/MyProxySender.java
(original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/MyOtherProxySender.java
Mon Apr  5 14:25:21 2010
@@ -16,17 +16,13 @@
  */
 package org.apache.camel.spring.config;
 
-import org.apache.camel.ExchangePattern;
-import org.apache.camel.Pattern;
-
 /**
  * @version $Revision$
  */
-public interface MyProxySender {
+public interface MyOtherProxySender {
 
     String hello(String name);
-    
-    @Pattern(value = ExchangePattern.InOnly)
+
     void greeting(String message);
 
-}
+}
\ No newline at end of file

Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/CamelProxyVoidAsInOnlyTest.xml
(from r930692, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/AnotherCamelProxyTest.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/CamelProxyVoidAsInOnlyTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/CamelProxyVoidAsInOnlyTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/AnotherCamelProxyTest.xml&r1=930692&r2=930866&rev=930866&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/AnotherCamelProxyTest.xml
(original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/CamelProxyVoidAsInOnlyTest.xml
Mon Apr  5 14:25:21 2010
@@ -25,18 +25,20 @@
     <!-- START SNIPPET: e1 -->
     <camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring">
 
-        <!-- create a proxy that will route to the direct:start endpoint when invoked
-->
-        <proxy id="myProxySender"
-               serviceInterface="org.apache.camel.spring.config.MyProxySender"
-               serviceUrl="direct:start"/>
+        <!-- create a proxy that will route to the seda:start endpoint when invoked
+             and it should let the methods which returns void act as InOnly messages -->
+        <proxy id="myOtherSender"
+               serviceInterface="org.apache.camel.spring.config.MyOtherProxySender"
+               serviceUrl="seda:start"
+               voidAsInOnly="true"/>
 
-        <!-- this is the route that our proxy will routed when invoked
-             and the output from this route is returned as reply on the proxy --> 
+        <!-- this is the route that our proxy will routed when invoked -->
         <route>
-            <from uri="direct:start"/>
-            <transform>
-                <simple>Bye ${body}</simple>
-            </transform>
+            <from uri="seda:start"/>
+            <delay>
+                <constant>2000</constant>
+            </delay>
+            <to uri="mock:result"/>
         </route>
 
     </camelContext>

Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/CamelProxyVoidAsInOutTest.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/CamelProxyVoidAsInOutTest.xml?rev=930866&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/CamelProxyVoidAsInOutTest.xml
(added)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/CamelProxyVoidAsInOutTest.xml
Mon Apr  5 14:25:21 2010
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+    <!-- START SNIPPET: e1 -->
+    <camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring">
+
+        <!-- create a proxy that will route to the seda:start endpoint when invoked
+             and all methods will act as InOut unless annotated -->
+        <proxy id="myOtherSender"
+               serviceInterface="org.apache.camel.spring.config.MyOtherProxySender"
+               serviceUrl="seda:start"/>
+
+        <!-- this is the route that our proxy will routed when invoked -->
+        <route>
+            <from uri="seda:start"/>
+            <delay>
+                <constant>2000</constant>
+            </delay>
+            <to uri="mock:result"/>
+        </route>
+
+    </camelContext>
+    <!-- END SNIPPET: e1 -->
+
+</beans>

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/CamelProxyVoidAsInOutTest.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/CamelProxyVoidAsInOutTest.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/CamelProxyVoidAsInOutTest.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message