activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r583184 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/camel/component/ main/java/org/apache/activemq/camel/converter/ main/resources/META-INF/services/org/apache/camel/ test/java/org/apache/activemq/camel/component/ ...
Date Tue, 09 Oct 2007 14:44:21 GMT
Author: jstrachan
Date: Tue Oct  9 07:44:20 2007
New Revision: 583184

URL: http://svn.apache.org/viewvc?rev=583184&view=rev
Log:
added a plugin to support invocation of MessageListener classes as a bean in Camel; for more
information see: http://cwiki.apache.org/CAMEL/activemq.html

Added:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/converter/
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/converter/ActiveMQConverter.java
  (contents, props changed)
      - copied, changed from r583111, activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/component/ActiveMQConverter.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/converter/ActiveMQMessageConverter.java
  (contents, props changed)
      - copied, changed from r583111, activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/component/ActiveMQMessageConverter.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/converter/package.html
      - copied, changed from r583114, activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/component/package.html
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/camel/converter/
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/camel/converter/InvokeMessageListenerTest.java
      - copied, changed from r583111, activemq/trunk/activemq-core/src/test/java/org/apache/activemq/camel/component/ActiveMQRouteTest.java
Removed:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/component/ActiveMQConverter.java
Modified:
    activemq/trunk/activemq-core/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/camel/component/ActiveMQReplyToHeaderUsingConverterTest.java

Copied: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/converter/ActiveMQConverter.java
(from r583111, activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/component/ActiveMQConverter.java)
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/converter/ActiveMQConverter.java?p2=activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/converter/ActiveMQConverter.java&p1=activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/component/ActiveMQConverter.java&r1=583111&r2=583184&rev=583184&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/component/ActiveMQConverter.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/converter/ActiveMQConverter.java
Tue Oct  9 07:44:20 2007
@@ -15,7 +15,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.activemq.camel.component;
+package org.apache.activemq.camel.converter;
 
 import org.apache.activemq.command.ActiveMQDestination;
 import org.apache.camel.Converter;

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

Propchange: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/converter/ActiveMQConverter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/converter/ActiveMQMessageConverter.java
(from r583111, activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/component/ActiveMQMessageConverter.java)
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/converter/ActiveMQMessageConverter.java?p2=activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/converter/ActiveMQMessageConverter.java&p1=activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/component/ActiveMQMessageConverter.java&r1=583111&r2=583184&rev=583184&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/component/ActiveMQMessageConverter.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/converter/ActiveMQMessageConverter.java
Tue Oct  9 07:44:20 2007
@@ -15,18 +15,22 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.activemq.camel.component;
+package org.apache.activemq.camel.converter;
+
+import java.io.Serializable;
+
+import javax.jms.JMSException;
+import javax.jms.MessageListener;
+import javax.jms.Message;
 
 import org.apache.activemq.command.ActiveMQMessage;
-import org.apache.activemq.command.*;
+import org.apache.activemq.command.ActiveMQObjectMessage;
+import org.apache.activemq.command.ActiveMQTextMessage;
 import org.apache.camel.Converter;
 import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
 import org.apache.camel.component.jms.JmsBinding;
 
-import javax.jms.MessageNotWriteableException;
-import javax.jms.JMSException;
-import java.io.Serializable;
-
 /**
  * @version $Revision$
  */
@@ -44,6 +48,30 @@
         ActiveMQMessage message = createActiveMQMessage(exchange);
         getBinding().appendJmsProperties(message, exchange);
         return message;
+    }
+
+    /**
+     * Allows a JMS {@link MessageListener} to be converted to a Camel {@link Processor}
+     * so that we can provide better
+     * <a href="">Bean Integration</a> so that we can use any JMS MessageListener
in
+     * in Camel as a bean
+     * @param listener the JMS message listener
+     * @return a newly created Camel Processor which when invoked will invoke
+     * {@link MessageListener#onMessage(Message)}
+     */
+    @Converter
+    public Processor toProcessor(final MessageListener listener) {
+        return new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                Message message = toMessage(exchange);
+                listener.onMessage(message);
+            }
+
+            @Override
+            public String toString() {
+                return "Processor of MessageListener: " + listener;
+            }
+        };
     }
 
     private static ActiveMQMessage createActiveMQMessage(Exchange exchange) throws JMSException
{

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

Propchange: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/converter/ActiveMQMessageConverter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/converter/package.html
(from r583114, activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/component/package.html)
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/converter/package.html?p2=activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/converter/package.html&p1=activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/component/package.html&r1=583114&r2=583184&rev=583184&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/component/package.html
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/camel/converter/package.html
Tue Oct  9 07:44:20 2007
@@ -19,10 +19,9 @@
 </head>
 <body>
 
-Defines the <a href="http://activemq.apache.org/camel/activemq.html">ActiveMQ Component</a>
for
-<a href="http://activemq.apache.org/camel/">Camel</a> to provide great
+Defines the <a href="http://activemq.apache.org/camel/type-converter.html">Type Converters</a>
for working
+with JMS and ActiveMQ with <a href="http://activemq.apache.org/camel/">Camel</a>
 <a href="http://activemq.apache.org/camel/enterprise-integration-patterns.html">Enterprise
Integration Patterns</a>
-integration for ActiveMQ users.
 
 
 </body>

Modified: activemq/trunk/activemq-core/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/resources/META-INF/services/org/apache/camel/TypeConverter?rev=583184&r1=583183&r2=583184&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
(original)
+++ activemq/trunk/activemq-core/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
Tue Oct  9 07:44:20 2007
@@ -15,4 +15,4 @@
 # limitations under the License.
 #
 
-org.apache.activemq.camel.component
\ No newline at end of file
+org.apache.activemq.camel.converter
\ No newline at end of file

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/camel/component/ActiveMQReplyToHeaderUsingConverterTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/camel/component/ActiveMQReplyToHeaderUsingConverterTest.java?rev=583184&r1=583183&r2=583184&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/camel/component/ActiveMQReplyToHeaderUsingConverterTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/camel/component/ActiveMQReplyToHeaderUsingConverterTest.java
Tue Oct  9 07:44:20 2007
@@ -16,13 +16,13 @@
  */
 package org.apache.activemq.camel.component;
 
-import org.apache.activemq.command.ActiveMQQueue;
 import org.apache.camel.CamelContext;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.builder.RouteBuilder;
 import static org.apache.activemq.camel.component.ActiveMQComponent.activeMQComponent;
+import org.apache.activemq.camel.converter.ActiveMQConverter;
 import org.apache.camel.component.mock.AssertionClause;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.commons.logging.Log;

Copied: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/camel/converter/InvokeMessageListenerTest.java
(from r583111, activemq/trunk/activemq-core/src/test/java/org/apache/activemq/camel/component/ActiveMQRouteTest.java)
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/camel/converter/InvokeMessageListenerTest.java?p2=activemq/trunk/activemq-core/src/test/java/org/apache/activemq/camel/converter/InvokeMessageListenerTest.java&p1=activemq/trunk/activemq-core/src/test/java/org/apache/activemq/camel/component/ActiveMQRouteTest.java&r1=583111&r2=583184&rev=583184&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/camel/component/ActiveMQRouteTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/camel/converter/InvokeMessageListenerTest.java
Tue Oct  9 07:44:20 2007
@@ -14,69 +14,55 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.activemq.camel.component;
+package org.apache.activemq.camel.converter;
 
-import org.springframework.jms.connection.JmsTransactionManager;
+import java.util.List;
+
+import javax.jms.Message;
+import javax.jms.TextMessage;
+
+import static org.apache.activemq.camel.component.ActiveMQComponent.activeMQComponent;
+import org.apache.activemq.spring.ConsumerBean;
 import org.apache.camel.CamelContext;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
-import static org.apache.activemq.camel.component.ActiveMQComponent.activeMQComponent;
-import org.apache.camel.component.jms.JmsEndpoint;
 import org.apache.camel.component.mock.MockEndpoint;
 
 /**
  * @version $Revision$
  */
-public class ActiveMQRouteTest extends ContextTestSupport {
-    protected MockEndpoint resultEndpoint;
+public class InvokeMessageListenerTest extends ContextTestSupport {    protected MockEndpoint
resultEndpoint;
     protected String startEndpointUri = "activemq:queue:test.a";
+    protected ConsumerBean listener = new ConsumerBean();
 
-    public void testJmsRouteWithTextMessage() throws Exception {
+    public void testSendTextMessage() throws Exception {
         String expectedBody = "Hello there!";
 
-        resultEndpoint.expectedBodiesReceived(expectedBody);
-        resultEndpoint.message(0).header("cheese").isEqualTo(123);
-
-        sendExchange(expectedBody);
+        template.sendBodyAndHeader(startEndpointUri, expectedBody, "cheese", 123);
 
-        resultEndpoint.assertIsSatisfied();
-    }
+        listener.assertMessagesArrived(1);
 
-    protected void sendExchange(final Object expectedBody) {
-        template.sendBodyAndHeader(startEndpointUri, expectedBody, "cheese", 123);
-    }
+        List<Message> list = listener.flushMessages();
+        assertTrue("Should have received some messages!", !list.isEmpty());
+        Message message = list.get(0);
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
+        log.debug("Received: " + message);
 
-        resultEndpoint = (MockEndpoint) context.getEndpoint("mock:result");
+        TextMessage textMessage = assertIsInstanceOf(TextMessage.class, message);
+        assertEquals("Text mesage body: " + textMessage, expectedBody, textMessage.getText());
     }
 
     protected CamelContext createCamelContext() throws Exception {
         CamelContext camelContext = super.createCamelContext();
-
-        // START SNIPPET: example
-        camelContext.addComponent("activemq", activeMQComponent("vm://localhost?broker.persistent=false"));
-        // END SNIPPET: example
-
+        camelContext.addComponent("activemq",
+                activeMQComponent("vm://localhost?broker.persistent=false"));
         return camelContext;
     }
 
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                from(startEndpointUri).to("activemq:queue:test.b");
-                from("activemq:queue:test.b").to("mock:result");
-
-                JmsEndpoint endpoint1 = (JmsEndpoint) endpoint("activemq:topic:quote.IONA");
-                endpoint1.getConfiguration().setTransactionManager(new JmsTransactionManager());
-                endpoint1.getConfiguration().setTransacted(true);
-                from(endpoint1).to("mock:transactedClient");
-
-                JmsEndpoint endpoint2 = (JmsEndpoint) endpoint("activemq:topic:quote.IONA");
-                endpoint2.getConfiguration().setTransacted(false);
-                from(endpoint2).to("mock:nonTrasnactedClient");
+                from(startEndpointUri).bean(listener);
             }
         };
     }



Mime
View raw message