camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r562364 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/ components/camel-spring/src/test/java/org/apache/camel/spring/example/
Date Fri, 03 Aug 2007 07:16:12 GMT
Author: jstrachan
Date: Fri Aug  3 00:16:11 2007
New Revision: 562364

URL: http://svn.apache.org/viewvc?view=rev&rev=562364
Log:
added a little interface which makes the @EndpointInject a bit more readable

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelTemplate.java
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/example/MySender.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelTemplate.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelTemplate.java?view=diff&rev=562364&r1=562363&r2=562364
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelTemplate.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelTemplate.java Fri
Aug  3 00:16:11 2007
@@ -31,7 +31,7 @@
  *
  * @version $Revision$
  */
-public class CamelTemplate<E extends Exchange> extends ServiceSupport {
+public class CamelTemplate<E extends Exchange> extends ServiceSupport implements ProducerTemplate<E>
{
     private CamelContext context;
     private ProducerCache<E> producerCache = new ProducerCache<E>();
     private boolean useEndpointCache = true;
@@ -137,7 +137,20 @@
      * @return the result
      */
     public Object sendBody(String endpointUri, final Object body, final String header, final
Object headerValue) {
-        E result = send(endpointUri, new Processor() {
+        return sendBody(resolveMandatoryEndpoint(endpointUri), body, header, headerValue);
+    }
+    
+    /**
+     * Sends the body to an endpoint with a specified header and header value
+     *
+     * @param endpoint the Endpoint to send to
+     * @param body        the payload send
+     * @param header      the header name
+     * @param headerValue the header value
+     * @return the result
+     */
+    public Object sendBody(Endpoint endpoint, final Object body, final String header, final
Object headerValue) {
+        E result = send(endpoint, new Processor() {
             public void process(Exchange exchange) {
                 Message in = exchange.getIn();
                 in.setHeader(header, headerValue);
@@ -146,7 +159,7 @@
         });
         return extractResultBody(result);
     }
-    
+
     /**
      * Sends the body to an endpoint with the specified headers and header values
      *
@@ -155,7 +168,18 @@
      * @return the result
      */
     public Object sendBody(String endpointUri, final Object body, final Map<String, Object>
headers) {
-        E result = send(endpointUri, new Processor() {
+        return sendBody(resolveMandatoryEndpoint(endpointUri), body, headers);
+    }
+
+    /**
+     * Sends the body to an endpoint with the specified headers and header values
+     *
+     * @param endpoint the endpoint URI to send to
+     * @param body        the payload send
+     * @return the result
+     */
+    public Object sendBody(Endpoint endpoint, final Object body, final Map<String, Object>
headers) {
+        E result = send(endpoint, new Processor() {
             public void process(Exchange exchange) {
                 Message in = exchange.getIn();
                 for (Map.Entry<String, Object> header : headers.entrySet()) {
@@ -199,6 +223,13 @@
         return send(getMandatoryDefaultEndpoint(), processor);
     }
 
+    public Object sendBody(Object body, String header, Object headerValue) {
+        return sendBody(getMandatoryDefaultEndpoint(), body, header, headerValue);
+    }
+
+    public Object sendBody(Object body, Map<String, Object> headers) {
+        return sendBody(getMandatoryDefaultEndpoint(), body, headers);
+    }
 
     // Properties
     //-----------------------------------------------------------------------

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java?view=auto&rev=562364
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java Fri
Aug  3 00:16:11 2007
@@ -0,0 +1,126 @@
+/*
+ * 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;
+
+import java.util.Map;
+
+/**
+ * @version $Revision: $
+ */
+public interface ProducerTemplate<E extends Exchange> extends Service {
+
+
+    /**
+     * Sends the exchange to the default endpoint
+     *
+     * @param exchange the exchange to send
+     */
+    E send(E exchange);
+
+    /**
+     * Sends an exchange to the default endpoint
+     * using a supplied @{link Processor} to populate the exchange
+     *
+     * @param processor the transformer used to populate the new exchange
+     */
+    E send(Processor processor);
+
+
+    /**
+     * Sends the body to the default endpoint and returns the result content
+     *
+     * @param body the body to send
+     * @return the returned message body
+     */
+    Object sendBody(Object body);
+
+
+    /**
+     * Sends the body to the default endpoint with a specified header and header value
+     *
+     * @param body        the payload send
+     * @param header      the header name
+     * @param headerValue the header value
+     * @return the result
+     */
+    Object sendBody(Object body, String header, Object headerValue);
+
+    /**
+     * Sends the body to the default endpoint with the specified headers and header values
+     *
+     * @param body        the payload send
+     * @return the result
+     */
+    Object sendBody(Object body, Map<String, Object> headers);
+
+
+
+    // Allow sending to arbitrary endpoints
+    //-----------------------------------------------------------------------
+
+    /**
+     * Sends the exchange to the given endpoint
+     *
+     * @param endpointUri the endpoint URI to send the exchange to
+     * @param exchange    the exchange to send
+     */
+    E send(String endpointUri, E exchange);
+
+    /**
+     * Sends an exchange to an endpoint using a supplied @{link Processor} to populate the
exchange
+     *
+     * @param endpointUri the endpoint URI to send the exchange to
+     * @param processor   the transformer used to populate the new exchange
+     */
+    E send(String endpointUri, Processor processor);
+
+    /**
+     * Sends the exchange to the given endpoint
+     *
+     * @param endpoint the endpoint to send the exchange to
+     * @param exchange the exchange to send
+     */
+    E send(Endpoint<E> endpoint, E exchange);
+
+    /**
+     * Sends an exchange to an endpoint using a supplied @{link Processor} to populate the
exchange
+     *
+     * @param endpoint  the endpoint to send the exchange to
+     * @param processor the transformer used to populate the new exchange
+     */
+    E send(Endpoint<E> endpoint, Processor processor);
+
+    /**
+     * Send the body to an endpoint
+     *
+     * @param endpoint
+     * @param body     = the payload
+     * @return the result
+     */
+    Object sendBody(Endpoint<E> endpoint, Object body);
+
+    /**
+     * Send the body to an endpoint
+     *
+     * @param endpointUri
+     * @param body        = the payload
+     * @return the result
+     */
+    Object sendBody(String endpointUri, Object body);
+
+
+}

Modified: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/example/MySender.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/example/MySender.java?view=diff&rev=562364&r1=562363&r2=562364
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/example/MySender.java
(original)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/example/MySender.java
Fri Aug  3 00:16:11 2007
@@ -18,6 +18,7 @@
 
 import org.apache.camel.CamelTemplate;
 import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
 import static org.apache.camel.util.ObjectHelper.notNull;
 
 /**
@@ -27,9 +28,9 @@
  */
 public class MySender {
     @EndpointInject(uri = "mock:a")
-    private CamelTemplate successDesetination;
+    private ProducerTemplate successDesetination;
     @EndpointInject(uri = "mock:b")
-    private CamelTemplate failureDesetination;
+    private ProducerTemplate failureDesetination;
 
     public void doSomething(String name) {
         notNull(successDesetination, "successDesetination");



Mime
View raw message