[jboss-svn-commits] JBL Code SVN: r22488 - in labs/jbossesb/workspace/skeagh/routing/jms: src/main/java/org/jboss/esb/jms and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Sep 7 13:31:25 EDT 2008
Author: beve
Date: 2008-09-07 13:31:24 -0400 (Sun, 07 Sep 2008)
New Revision: 22488
Added:
labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsPayloadExtractor.java
labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/JmsPayloadExtractorTest.java
Modified:
labs/jbossesb/workspace/skeagh/routing/jms/pom.xml
labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsInboundRouter.java
Log:
Adding test and a JMS specific payload extractor.
Modified: labs/jbossesb/workspace/skeagh/routing/jms/pom.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/jms/pom.xml 2008-09-07 17:22:19 UTC (rev 22487)
+++ labs/jbossesb/workspace/skeagh/routing/jms/pom.xml 2008-09-07 17:31:24 UTC (rev 22488)
@@ -51,6 +51,12 @@
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>com.mockrunner</groupId>
+ <artifactId>mockrunner</artifactId>
+ <version>0.3.1</version>
+ </dependency>
+
</dependencies>
<repositories>
Modified: labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsInboundRouter.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsInboundRouter.java 2008-09-07 17:22:19 UTC (rev 22487)
+++ labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsInboundRouter.java 2008-09-07 17:31:24 UTC (rev 22488)
@@ -36,8 +36,8 @@
import org.jboss.esb.message.Message;
import org.jboss.esb.routing.InboundRouter;
import org.jboss.esb.routing.MessageDispatcher;
+import org.jboss.esb.routing.PayloadExtractorException;
import org.jboss.esb.routing.RoutingException;
-import org.jboss.esb.util.AssertArgument;
/**
* Inbound router for JMS.
@@ -51,48 +51,50 @@
* Logger.
*/
private final Logger log = Logger.getLogger(JmsInboundRouter.class);
-
/**
* MessageDispatcher used to dipatch the message to the ESB.
*/
private MessageDispatcher dispatcher;
-
/**
* JMS destination name.
*/
@Property(use = Use.REQUIRED, name = "jmsDestination")
private String destination;
-
- public String getDestination()
- {
- return destination;
- }
-
/**
* JMS properties.
*/
@org.jboss.esb.annotations.Properties
private final Properties jmsProperties = getDefaultProperties();
-
+ /**
+ * JmsMessageListener that takes care of the JMS connection
+ */
private JmsMessageListener messageListener;
+ /**
+ *
+ */
+ private JmsPayloadExtractor payloadExtractor;
/**
- * Initializes this instance.
+ * Sets up the JmsMesssageListener of this class.
+ *
* @throws JMSException
*/
@Initialize
public final void initialize() throws JMSException
{
- // this will be handled by the annotation constraint later
- AssertArgument.isNotNullAndNotEmpty(destination, "destination");
- log.info("JMSProperties : " + jmsProperties);
- log.info("Destination : " + destination);
+ log.info("JMSProperties : " + jmsProperties + "," + destination);
// add this class as a JMS message listener...
messageListener = new JmsMessageListener(destination, jmsProperties, dispatcher);
messageListener.connect();
+
+ // TODO: make this configurable
+ payloadExtractor = new JmsPayloadExtractor();
}
+ /**
+ * Closes the underlying JMS connection
+ */
@Uninitialize
public final void uninitialize()
{
@@ -128,6 +130,11 @@
return "[dispatcher=" + dispatcher + ", jmsProperties=" + jmsProperties + "]";
}
+ public String getDestination()
+ {
+ return destination;
+ }
+
/**
* Returns the default JMS properties.
*
@@ -161,16 +168,20 @@
public void onMessage(final javax.jms.Message jmsMessage)
{
- Message esbMessage = new Message();
- esbMessage.setPayload("testing");
+ System.out.println("jmsMessage recieved.....");
try
{
+ Message esbMessage = payloadExtractor.extractPayload(jmsMessage);
dispatcher.dispatch(esbMessage, new InvocationContext());
}
catch (RoutingException e)
{
e.printStackTrace();
}
+ catch (PayloadExtractorException e)
+ {
+ e.printStackTrace();
+ }
}
}
Added: labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsPayloadExtractor.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsPayloadExtractor.java (rev 0)
+++ labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsPayloadExtractor.java 2008-09-07 17:31:24 UTC (rev 22488)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
+ * LLC, and individual contributors by the @authors tag. See the copyright.txt
+ * in the distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.esb.jms;
+
+import javax.jms.BytesMessage;
+import javax.jms.JMSException;
+import javax.jms.MapMessage;
+import javax.jms.ObjectMessage;
+import javax.jms.StreamMessage;
+import javax.jms.TextMessage;
+
+import org.apache.log4j.Logger;
+import org.jboss.esb.message.Message;
+import org.jboss.esb.routing.PayloadExctractor;
+import org.jboss.esb.routing.PayloadExtractorException;
+
+/**
+ *
+ * @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
+ *
+ */
+public class JmsPayloadExtractor implements PayloadExctractor<javax.jms.Message>
+{
+ private final Logger log = Logger.getLogger(JmsPayloadExtractor.class);
+
+ public Message extractPayload(javax.jms.Message t) throws PayloadExtractorException
+ {
+ final Message esbMessage = new Message();
+ try
+ {
+ if ( t instanceof TextMessage )
+ {
+ final String text = ((TextMessage) t).getText();
+ if ( text != null )
+ {
+ esbMessage.setPayload(((TextMessage) t).getText());
+ }
+ else
+ {
+ throw new PayloadExtractorException("Content in JMSMessage [" + t + "] was null");
+ }
+ }
+ else if ( t instanceof ObjectMessage )
+ {
+ log.info("ObjectMessage");
+ }
+ else if ( t instanceof BytesMessage )
+ {
+ log.info("BytesMessage");
+ }
+ else if ( t instanceof MapMessage )
+ {
+ log.info("MapMessage");
+ }
+ else if ( t instanceof StreamMessage )
+ {
+ log.info("StreamMessage");
+ }
+ else if ( t instanceof Message )
+ {
+ log.info("Message");
+ }
+ else
+ throw new PayloadExtractorException("Could not determine the type of JMSMessage.");
+ }
+ catch ( final JMSException e )
+ {
+ throw new PayloadExtractorException("Could not extract content from JMSMessage: " + t, e);
+ }
+ return esbMessage;
+ }
+
+
+}
Added: labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/JmsPayloadExtractorTest.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/JmsPayloadExtractorTest.java (rev 0)
+++ labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/JmsPayloadExtractorTest.java 2008-09-07 17:31:24 UTC (rev 22488)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
+ * LLC, and individual contributors by the @authors tag. See the copyright.txt
+ * in the distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.esb.jms;
+
+import static org.junit.Assert.assertEquals;
+
+import javax.jms.JMSException;
+
+import org.jboss.esb.message.Message;
+import org.jboss.esb.routing.PayloadExtractorException;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import com.mockrunner.mock.jms.MockObjectMessage;
+import com.mockrunner.mock.jms.MockTextMessage;
+
+/**
+ * Test for {@link JmsPayloadExtractor}.
+ *
+ * @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
+ *
+ */
+public class JmsPayloadExtractorTest
+{
+ private final JmsPayloadExtractor extractor = new JmsPayloadExtractor();
+
+ @Test
+ public void extractContentTextMessage() throws PayloadExtractorException, JMSException
+ {
+ final String content = "testing text message content";
+ final MockTextMessage textMessage = new MockTextMessage();
+ textMessage.setText(content);
+ final Message esbMessage = extractor.extractPayload(textMessage);
+ assertEquals( content, esbMessage.getPayload());
+ }
+
+ @Test ( expected = PayloadExtractorException.class )
+ public void extractContentTextMessageNullPayload() throws PayloadExtractorException, JMSException
+ {
+ final String content = null;
+ final MockTextMessage textMessage = new MockTextMessage();
+ textMessage.setText(content);
+ extractor.extractPayload(textMessage);
+ }
+
+ @Test
+ @Ignore
+ public void extractContentObjectMessage() throws PayloadExtractorException, JMSException
+ {
+ final String content = "testing text message content";
+ final MockObjectMessage objectMessage = new MockObjectMessage();
+ objectMessage.setObject(content);
+ final Message esbMessage = extractor.extractPayload(objectMessage);
+ assertEquals( content, esbMessage.getPayload());
+ }
+}
More information about the jboss-svn-commits
mailing list