activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r520457 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/builder/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/pojo/ camel-core/src...
Date Tue, 20 Mar 2007 16:13:55 GMT
Author: jstrachan
Date: Tue Mar 20 09:13:51 2007
New Revision: 520457

URL: http://svn.apache.org/viewvc?view=rev&rev=520457
Log:
added a Message and Headers interface to the Exchange making it easy to process messages in
a generic way, in addition to using a custom Exchange type to access the underlying transport
information

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Headers.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultHeaders.java
  (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultMessage.java
  (with props)
    activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/DefaultJmsMessage.java
  (with props)
    activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsHeaders.java   (with
props)
    activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsMessage.java   (with
props)
Removed:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Expressions.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Message.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoEndpoint.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoExchange.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RecipientList.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/RouteBuilderTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/queue/QueueRouteTest.java
    activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/DefaultJmsExchange.java
    activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsExchange.java
    activemq/camel/trunk/camel-jms/src/test/java/org/apache/camel/jms/JmsRouteTest.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java?view=diff&rev=520457&r1=520456&r2=520457
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java Tue Mar 20
09:13:51 2007
@@ -19,14 +19,11 @@
 import java.util.Map;
 
 /**
- * Represents the base interface of an exchange
+ * Represents the base exchange interface providing access to the request, response and fault
{@link Message} instances.
  *
  * @version $Revision$
- * @param <M> message or payload type
- * @param <R> message or payload type for a response (for request/response exchange)
- * @param <F> fault type
  */
-public interface Exchange<M,R,F> {
+public interface Exchange  {
     
     /**
      * Returns the exchange id
@@ -41,60 +38,45 @@
     void setExchangeId(String id);
 
     /**
-     * Accesses a specific header
-     * @param name 
-     * @return object header associated with the name
+     * Returns the exchange headers
      */
-    Object getHeader(String name);
+    Headers getHeaders();
 
     /**
-     * Sets a header on the exchange
-     * @param name of the header 
-     * @param value to associate with the name
-     */
-    void setHeader(String name, Object value);
-
-    /**
-     * Returns all of the headers associated with the request
-     * @return all the headers in a Map
-     */
-    Map<String,Object> getHeaders();
-
-    /**
-     * Returns the request message
+     * Returns the inbound request message
      * @return the message
      */
-    M getRequest();
+    Message getIn();
 
     /**
-     * Returns the response message
+     * Returns the aresponse message
      * @return the response
      */
-    R getResponse();
+    Message getOut();
 
     /**
      * Returns the fault message
      * @return the fault
      */
-    F getFault();
+    Message getFault();
 
     /**
      * Returns the exception associated with this exchange
      * @return the exception (or null if no faults)
      */
-    Exception getException();
+    Throwable getException();
 
     /**
      * Sets the exception associated with this exchange
-     * @param e 
+     * @param e
      */
-    void setException(Exception e);
+    void setException(Throwable e);
 
     /**
      * Returns the container so that a processor can resolve endpoints from URIs
      *
      * @return the container which owns this exchange
      */
-    CamelContext<Exchange> getContainer();
+    CamelContext<Exchange> getContext();
 
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Expressions.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Expressions.java?view=diff&rev=520457&r1=520456&r2=520457
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Expressions.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Expressions.java Tue Mar
20 09:13:51 2007
@@ -30,7 +30,12 @@
     public static <E extends Exchange> Expression<E> headerExpression(final String
headerName) {
         return new Expression<E>() {
             public Object evaluate(E exchange) {
-                return exchange.getHeader(headerName);
+                Object header = exchange.getIn().getHeaders().getHeader(headerName);
+                if (header == null) {
+                    // lets try the exchange header
+                    header = exchange.getHeaders().getHeader(headerName);
+                }
+                return header;
             }
 
             @Override

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Headers.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Headers.java?view=auto&rev=520457
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Headers.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Headers.java Tue Mar 20
09:13:51 2007
@@ -0,0 +1,51 @@
+/**
+ *
+ * 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;
+
+/**
+ * Represents the available headers on a message or message exchange.
+ *
+ * @version $Revision$
+ */
+public interface Headers {
+    
+    /**
+     * Accesses a specific header
+     *
+     * @param name
+     * @return object header associated with the name
+     */
+    Object getHeader(String name);
+
+    /**
+     * Sets a header on the exchange
+     *
+     * @param name  of the header
+     * @param value to associate with the name
+     */
+    void setHeader(String name, Object value);
+
+    /**
+     * Returns all of the headers associated with the request
+     *
+     * @return all the headers in a Map
+     */
+    Map<String, Object> getHeaders();
+}

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

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Headers.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Headers.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Message.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Message.java?view=diff&rev=520457&r1=520456&r2=520457
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Message.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Message.java Tue Mar 20
09:13:51 2007
@@ -27,6 +27,11 @@
 public interface Message {
 
     /**
+     * Access the headers on the message
+     */
+    public Headers getHeaders();
+
+    /**
      * Returns the body of the message as a POJO
      *
      * @returns the body of the message
@@ -51,26 +56,4 @@
      */
     public <T> void setBody(Object body, Class<T> type);
 
-    /**
-     * Accesses a specific header
-     *
-     * @param name
-     * @return object header associated with the name
-     */
-    Object getHeader(String name);
-
-    /**
-     * Sets a header on the exchange
-     *
-     * @param name  of the header
-     * @param value to associate with the name
-     */
-    void setHeader(String name, Object value);
-
-    /**
-     * Returns all of the headers associated with the request
-     *
-     * @return all the headers in a Map
-     */
-    Map<String, Object> getHeaders();
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java?view=diff&rev=520457&r1=520456&r2=520457
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
Tue Mar 20 09:13:51 2007
@@ -72,20 +72,6 @@
         return answer;
     }
 
-    // Helper methods
-    //-----------------------------------------------------------------------
-    public Predicate<E> headerEquals(final String header, final Object value) {
-        return new Predicate<E>() {
-            public boolean evaluate(E exchange) {
-                return ObjectHelper.equals(value, exchange.getHeader(header));
-            }
-
-            @Override
-            public String toString() {
-                return "header[" + header + "] == " + value;
-            }
-        };
-    }
 
     // Properties
     //-----------------------------------------------------------------------

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultHeaders.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultHeaders.java?view=auto&rev=520457
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultHeaders.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultHeaders.java
Tue Mar 20 09:13:51 2007
@@ -0,0 +1,56 @@
+/**
+ *
+ * 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.impl;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Headers;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * A default implementation of {@link Headers}
+ *
+ * @version $Revision$
+ */
+public class DefaultHeaders implements Headers {
+    private Map<String, Object> headers;
+
+    public Object getHeader(String name) {
+        if (headers != null) {
+            return headers.get(name);
+        }
+        return null;
+    }
+
+    public void setHeader(String name, Object value) {
+        getHeaders().put(name, value);
+    }
+
+    public Map<String, Object> getHeaders() {
+        if (headers == null) {
+            headers = new HashMap<String, Object>();
+        }
+        return headers;
+    }
+
+    public void setHeaders(Map<String, Object> headers) {
+        this.headers = headers;
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultHeaders.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultHeaders.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultHeaders.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultMessage.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultMessage.java?view=auto&rev=520457
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultMessage.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultMessage.java
Tue Mar 20 09:13:51 2007
@@ -0,0 +1,61 @@
+/**
+ *
+ * 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.impl;
+
+import org.apache.camel.Message;
+import org.apache.camel.Headers;
+
+/**
+ * @version $Revision$
+ */
+public class DefaultMessage implements Message {
+    private Headers headers;
+    private Object body;
+
+    public Object getBody() {
+        return body;
+    }
+
+    public void setBody(Object body) {
+        this.body = body;
+    }
+
+    @SuppressWarnings({"unchecked"})
+    public <T> T getBody(Class<T> type) {
+        return (T) getBody();
+    }
+
+    public <T> void setBody(Object body, Class<T> type) {
+        setBody(body);
+    }
+
+    public Headers getHeaders() {
+        if (headers == null) {
+            headers = createHeaders();
+        }
+        return headers;
+    }
+
+    public void setHeaders(Headers headers) {
+        this.headers = headers;
+    }
+
+    protected Headers createHeaders() {
+        return new DefaultHeaders();
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultMessage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultMessage.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultMessage.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoEndpoint.java?view=diff&rev=520457&r1=520456&r2=520457
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoEndpoint.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoEndpoint.java
Tue Mar 20 09:13:51 2007
@@ -45,12 +45,12 @@
 	 *  This causes us to invoke the endpoint Pojo using reflection.
 	 */
     public void onExchange(PojoExchange exchange) {
-        PojoInvocation invocation = exchange.getRequest();
+        PojoInvocation invocation = exchange.getInvocation();
         try {
 			Object response = invocation.getMethod().invoke(pojo, invocation.getArgs());
-			exchange.setResponse(response);
+			exchange.getOut().setBody(response);
 		} catch (InvocationTargetException e) {
-			exchange.setFault(e.getCause());
+			exchange.setException(e.getCause());
 		} catch ( RuntimeException e ) {
 			throw e;
 		} catch ( Throwable e ) {
@@ -88,13 +88,13 @@
 				if( !activated.get() ) {
 					PojoInvocation invocation = new PojoInvocation(proxy, method, args);
 					PojoExchange exchange = createExchange();
-					exchange.setRequest(invocation);
+					exchange.setInvocation(invocation);
 					endpoint.getInboundProcessor().onExchange(exchange);
-					Throwable fault = exchange.getFault();
+					Throwable fault = exchange.getException();
 					if ( fault != null ) {
 						throw new InvocationTargetException(fault);
 					}
-					return exchange.getResponse();
+					return exchange.getOut();
 				}
 				throw new IllegalStateException("The endpoint is not active: "+getEndpointUri());
 			}

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoExchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoExchange.java?view=diff&rev=520457&r1=520456&r2=520457
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoExchange.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoExchange.java
Tue Mar 20 09:13:51 2007
@@ -22,9 +22,18 @@
 /**
  * @version $Revision: 519901 $
  */
-public class PojoExchange extends DefaultExchange<PojoInvocation, Object, Throwable>
{
+public class PojoExchange extends DefaultExchange {
+    private PojoInvocation invocation;
 
     public PojoExchange(CamelContext container) {
         super(container);
+    }
+
+    public PojoInvocation getInvocation() {
+        return getIn().getBody(PojoInvocation.class);
+    }
+
+    public void setInvocation(PojoInvocation invocation) {
+        getIn().setBody(invocation);
     }
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RecipientList.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RecipientList.java?view=diff&rev=520457&r1=520456&r2=520457
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RecipientList.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RecipientList.java
Tue Mar 20 09:13:51 2007
@@ -64,7 +64,7 @@
         }
         else {
             String uri = recipient.toString();
-            endpoint = exchange.getContainer().endpoint(uri);
+            endpoint = (Endpoint<E>) exchange.getContext().endpoint(uri);
             if (endpoint == null) {
                 throw new NoSuchEndpointException(uri);
             }

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/RouteBuilderTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/RouteBuilderTest.java?view=diff&rev=520457&r1=520456&r2=520457
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/RouteBuilderTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/RouteBuilderTest.java Tue
Mar 20 09:13:51 2007
@@ -79,7 +79,7 @@
 		// START SNIPPET: e2
         RouteBuilder<Exchange> builder = new RouteBuilder<Exchange>() {
             public void configure() {
-                from("queue:a").filter(headerEquals("foo", "bar")).to("queue:b");
+                from("queue:a").filter(header("foo").isEqualTo("bar")).to("queue:b");
             }
         };
         // END SNIPPET: e2
@@ -112,8 +112,8 @@
         RouteBuilder<Exchange> builder = new RouteBuilder<Exchange>() {
             public void configure() {
                 from("queue:a").choice()
-                        .when(headerEquals("foo", "bar")).to("queue:b")
-                        .when(headerEquals("foo", "cheese")).to("queue:c")
+                        .when(header("foo").isEqualTo("bar")).to("queue:b")
+                        .when(header("foo").isEqualTo("cheese")).to("queue:c")
                         .otherwise().to("queue:d");
             }
         };
@@ -188,7 +188,7 @@
 		// START SNIPPET: e5
         RouteBuilder<Exchange> builder = new RouteBuilder<Exchange>() {
             public void configure() {
-                from("queue:a").filter(headerEquals("foo", "bar")).process(myProcessor);
+                from("queue:a").filter(header("foo").isEqualTo("bar")).process(myProcessor);
             }
         };
         // END SNIPPET: e5

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/queue/QueueRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/queue/QueueRouteTest.java?view=diff&rev=520457&r1=520456&r2=520457
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/queue/QueueRouteTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/queue/QueueRouteTest.java
Tue Mar 20 09:13:51 2007
@@ -25,19 +25,14 @@
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Processor;
+import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.impl.DefaultExchange;
 
 /**
  * @version $Revision: 520220 $
  */
 public class QueueRouteTest extends TestCase {
-	
-	static class StringExchange extends DefaultExchange<String, String, String> {
-        public StringExchange(CamelContext container) {
-            super(container);
-        }
-    }
+
 	
     public void testJmsRoute() throws Exception {
         final CountDownLatch latch = new CountDownLatch(1);
@@ -48,9 +43,9 @@
         container.routes(new RouteBuilder() {
             public void configure() {
                 from("queue:test.a").to("queue:test.b");
-                from("queue:test.b").process(new Processor<StringExchange>() {
-                    public void onExchange(StringExchange exchange) {
-                        System.out.println("Received exchange: " + exchange.getRequest());
+                from("queue:test.b").process(new Processor<Exchange>() {
+                    public void onExchange(Exchange e) {
+                        System.out.println("Received exchange: " + e.getIn());
                         latch.countDown();
                     }
                 });
@@ -61,9 +56,9 @@
         container.activateEndpoints();
         
         // now lets fire in a message
-        Endpoint<StringExchange> endpoint = container.endpoint("queue:test.a");
-        StringExchange exchange = new StringExchange(container);
-        exchange.setHeader("cheese", 123);
+        Endpoint<Exchange> endpoint = container.endpoint("queue:test.a");
+        Exchange exchange = endpoint.createExchange();
+        exchange.getIn().getHeaders().setHeader("cheese", 123);
         endpoint.onExchange(exchange);
 
         // now lets sleep for a while

Modified: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/DefaultJmsExchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/DefaultJmsExchange.java?view=diff&rev=520457&r1=520456&r2=520457
==============================================================================
--- activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/DefaultJmsExchange.java
(original)
+++ activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/DefaultJmsExchange.java
Tue Mar 20 09:13:51 2007
@@ -18,7 +18,7 @@
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.InvalidHeaderTypeException;
-import org.apache.camel.impl.ExchangeSupport;
+import org.apache.camel.impl.DefaultExchange;
 
 import javax.jms.JMSException;
 import javax.jms.Message;
@@ -30,8 +30,7 @@
 /**
  * @version $Revision$
  */
-public class DefaultJmsExchange extends ExchangeSupport<Message, Message, Message>
implements JmsExchange {
-    private Map<String, Object> lazyHeaders;
+public class DefaultJmsExchange extends DefaultExchange implements JmsExchange {
 
     public DefaultJmsExchange(CamelContext container) {
         super(container);
@@ -39,86 +38,41 @@
 
     public DefaultJmsExchange(CamelContext container, Message message) {
         super(container);
-        setRequest(message);
-    }
-
-    public Object getHeader(String name) {
-        Message request = getRequest();
-        if (request != null) {
-            try {
-                Object value = request.getObjectProperty(name);
-                try {
-                    return value;
-                }
-                catch (ClassCastException e) {
-                    throw new InvalidHeaderTypeException(e.getMessage(), value);
-                }
-            }
-            catch (JMSException e) {
-                throw new MessagePropertyAcessException(name, e);
-            }
-        }
-        return null;
-    }
-
-    public void setHeader(String name, Object value) {
-        Message request = getRequest();
-        if (request != null) {
-            try {
-                request.setObjectProperty(name, value);
-            }
-            catch (JMSException e) {
-                throw new MessagePropertyAcessException(name, e);
-            }
-        }
-        else {
-            if (lazyHeaders == null) {
-                lazyHeaders = new HashMap<String, Object>();
-            }
-            lazyHeaders.put(name, value);
-        }
-    }
-
-    public Map<String, Object> getHeaders() {
-        Message request = getRequest();
-        if (request != null) {
-            Map<String, Object> answer = new HashMap<String, Object>();
-            Enumeration names;
-            try {
-                names = request.getPropertyNames();
-            }
-            catch (JMSException e) {
-                throw new MessagePropertyNamesAcessException(e);
-            }
-            while (names.hasMoreElements()) {
-                String name = names.nextElement().toString();
-                try {
-                    Object value = request.getObjectProperty(name);
-                    answer.put(name, value);
-                }
-                catch (JMSException e) {
-                    throw new MessagePropertyAcessException(name, e);
-                }
-            }
-            return answer;
-        }
-        else {
-            return lazyHeaders;
-        }
+        setIn(new DefaultJmsMessage(message));
     }
 
     public Message createMessage(Session session) throws JMSException {
-        Message request = getRequest();
+        Message request = getInMessage();
         if (request == null) {
             request = session.createMessage();
 
+            /** TODO
             if (lazyHeaders != null) {
                 // lets add any lazy headers
                 for (Map.Entry<String, Object> entry : lazyHeaders.entrySet()) {
                     request.setObjectProperty(entry.getKey(), entry.getValue());
                 }
             }
+             */
         }
         return request;
+    }
+
+    public Message getInMessage() {
+        JmsMessage jmsMessage = (JmsMessage) getIn();
+        if (jmsMessage != null) {
+            return jmsMessage.getJmsMessage();
+        }
+        return null;
+    }
+
+    @Override
+    protected org.apache.camel.Message createInMessage() {
+        return new DefaultJmsMessage();
+    }
+
+    @Override
+    protected org.apache.camel.Message createOutMessage() {
+        return new DefaultJmsMessage();
     }
 }

Added: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/DefaultJmsMessage.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/DefaultJmsMessage.java?view=auto&rev=520457
==============================================================================
--- activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/DefaultJmsMessage.java
(added)
+++ activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/DefaultJmsMessage.java
Tue Mar 20 09:13:51 2007
@@ -0,0 +1,52 @@
+/**
+ *
+ * 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.jms;
+
+import org.apache.camel.impl.DefaultMessage;
+import org.apache.camel.Headers;
+
+import javax.jms.Message;
+
+/**
+ * @version $Revision$
+ */
+public class DefaultJmsMessage extends DefaultMessage implements JmsMessage {
+    private Message jmsMessage;
+
+    public DefaultJmsMessage() {
+    }
+
+    public DefaultJmsMessage(Message jmsMessage) {
+        this.jmsMessage = jmsMessage;
+    }
+
+    public Message getJmsMessage() {
+        return jmsMessage;
+    }
+
+    public void setJmsMessage(Message jmsMessage) {
+        this.jmsMessage = jmsMessage;
+    }
+
+    @Override
+    protected Headers createHeaders() {
+        return new JmsHeaders(this);
+    }
+
+
+}

Propchange: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/DefaultJmsMessage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/DefaultJmsMessage.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/DefaultJmsMessage.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsExchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsExchange.java?view=diff&rev=520457&r1=520456&r2=520457
==============================================================================
--- activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsExchange.java (original)
+++ activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsExchange.java Tue
Mar 20 09:13:51 2007
@@ -25,7 +25,7 @@
 /**
  * @version $Revision$
  */
-public interface JmsExchange extends Exchange<Message,Message,Message> {
+public interface JmsExchange extends Exchange {
 
     /**
      * Creates the JMS message for this exchange so that it can be sent to

Added: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsHeaders.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsHeaders.java?view=auto&rev=520457
==============================================================================
--- activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsHeaders.java (added)
+++ activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsHeaders.java Tue
Mar 20 09:13:51 2007
@@ -0,0 +1,104 @@
+/**
+ *
+ * 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.jms;
+
+import org.apache.camel.Headers;
+import org.apache.camel.InvalidHeaderTypeException;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @version $Revision$
+ */
+public class JmsHeaders implements Headers {
+    private final DefaultJmsMessage message;
+    private Map<String, Object> lazyHeaders;
+
+    public JmsHeaders(DefaultJmsMessage message) {
+        this.message = message;
+    }
+
+    public Object getHeader(String name) {
+        Message request = message.getJmsMessage();
+        if (request != null) {
+            try {
+                Object value = request.getObjectProperty(name);
+                try {
+                    return value;
+                }
+                catch (ClassCastException e) {
+                    throw new InvalidHeaderTypeException(e.getMessage(), value);
+                }
+            }
+            catch (JMSException e) {
+                throw new MessagePropertyAcessException(name, e);
+            }
+        }
+        return null;
+    }
+
+    public void setHeader(String name, Object value) {
+        Message request = message.getJmsMessage();
+        if (request != null) {
+            try {
+                request.setObjectProperty(name, value);
+            }
+            catch (JMSException e) {
+                throw new MessagePropertyAcessException(name, e);
+            }
+        }
+        else {
+            if (lazyHeaders == null) {
+                lazyHeaders = new HashMap<String, Object>();
+            }
+            lazyHeaders.put(name, value);
+        }
+    }
+
+    public Map<String, Object> getHeaders() {
+        Message request = message.getJmsMessage();
+        if (request != null) {
+            Map<String, Object> answer = new HashMap<String, Object>();
+            Enumeration names;
+            try {
+                names = request.getPropertyNames();
+            }
+            catch (JMSException e) {
+                throw new MessagePropertyNamesAcessException(e);
+            }
+            while (names.hasMoreElements()) {
+                String name = names.nextElement().toString();
+                try {
+                    Object value = request.getObjectProperty(name);
+                    answer.put(name, value);
+                }
+                catch (JMSException e) {
+                    throw new MessagePropertyAcessException(name, e);
+                }
+            }
+            return answer;
+        }
+        else {
+            return lazyHeaders;
+        }
+    }
+}

Propchange: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsHeaders.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsHeaders.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsHeaders.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsMessage.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsMessage.java?view=auto&rev=520457
==============================================================================
--- activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsMessage.java (added)
+++ activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsMessage.java Tue
Mar 20 09:13:51 2007
@@ -0,0 +1,33 @@
+/**
+ *
+ * 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.jms;
+
+import org.apache.camel.Message;
+
+/**
+ * @version $Revision$
+ */
+public interface JmsMessage extends Message {
+
+    /**
+     * Accesses the underlying JMS message
+     */
+    public javax.jms.Message getJmsMessage();
+
+    void setJmsMessage(javax.jms.Message jmsMessage);
+}

Propchange: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsMessage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsMessage.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsMessage.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: activemq/camel/trunk/camel-jms/src/test/java/org/apache/camel/jms/JmsRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jms/src/test/java/org/apache/camel/jms/JmsRouteTest.java?view=diff&rev=520457&r1=520456&r2=520457
==============================================================================
--- activemq/camel/trunk/camel-jms/src/test/java/org/apache/camel/jms/JmsRouteTest.java (original)
+++ activemq/camel/trunk/camel-jms/src/test/java/org/apache/camel/jms/JmsRouteTest.java Tue
Mar 20 09:13:51 2007
@@ -48,7 +48,7 @@
                 from("jms:activemq:test.a").to("jms:activemq:test.b");
                 from("jms:activemq:test.b").process(new Processor<JmsExchange>() {
                     public void onExchange(JmsExchange exchange) {
-                        System.out.println("Received exchange: " + exchange.getRequest());
+                        System.out.println("Received exchange: " + exchange.getIn());
                         latch.countDown();
                     }
                 });
@@ -62,7 +62,7 @@
         Endpoint<JmsExchange> endpoint = container.endpoint("jms:activemq:test.a");
         JmsExchange exchange2 = endpoint.createExchange();
         //exchange2.setInBody("Hello there!")
-        exchange2.setHeader("cheese", 123);
+        exchange2.getIn().getHeaders().setHeader("cheese", 123);
         endpoint.onExchange(exchange2);
 
         // now lets sleep for a while



Mime
View raw message