[jboss-svn-commits] JBL Code SVN: r13585 - in labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router: src and 8 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Jul 17 16:47:13 EDT 2007


Author: ldimaggi at redhat.com
Date: 2007-07-17 16:47:13 -0400 (Tue, 17 Jul 2007)
New Revision: 13585

Added:
   labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/
   labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/
   labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/
   labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/esb/
   labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/esb/samples/
   labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/esb/samples/quickstart/
   labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/esb/samples/quickstart/dynamicRouter/
   labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/esb/samples/quickstart/dynamicRouter/MyControlAction.java
   labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/esb/samples/quickstart/dynamicRouter/MyDynamicRouterAction.java
   labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/esb/samples/quickstart/dynamicRouter/test/
   labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/esb/samples/quickstart/dynamicRouter/test/QsHashtable.java
   labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/esb/samples/quickstart/dynamicRouter/test/ReceiveJMSMessage.java
   labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/esb/samples/quickstart/dynamicRouter/test/SendJMSMessage.java
Removed:
   labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/quickstart/
Modified:
   labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/build.xml
   labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/jboss-esb.xml
Log:
Reorganized source dir to match other quickstarts



Modified: labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/build.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/build.xml	2007-07-17 19:51:28 UTC (rev 13584)
+++ labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/build.xml	2007-07-17 20:47:13 UTC (rev 13585)
@@ -12,7 +12,7 @@
 
     <target name="runtest" depends="compile">
         <echo>Runs JMS Sender - to destination channels</echo>
-        <java fork="yes" classname="quickstart.dynamicRouter.test.SendJMSMessage" failonerror="true">
+        <java fork="yes" classname="org.jboss.soa.esb.samples.quickstart.dynamicRouter.test.SendJMSMessage" failonerror="true">
             <arg value="ESB dynamic router pattern quickstart - sending message to destination channels"/>
             <classpath refid="exec-classpath"/>
         </java>
@@ -20,7 +20,7 @@
 
     <target name="receive-destination3" depends="compile">
 	        <echo>Runs Test destination message receiver</echo>
-	        <java fork="yes" classname="quickstart.dynamicRouter.test.ReceiveJMSMessage" failonerror="true">
+	        <java fork="yes" classname="org.jboss.soa.esb.samples.quickstart.dynamicRouter.test.ReceiveJMSMessage" failonerror="true">
 	            <arg value="queue/qsdynamicrouter_3_Request"/>  
 	            <arg value=":OK"/>
 	            <classpath refid="exec-classpath"/>
@@ -29,7 +29,7 @@
 	
     <target name="receive-destination1" depends="compile">
 	        <echo>Runs Test destination 1 message receiver</echo>
-	        <java fork="yes" classname="quickstart.dynamicRouter.test.ReceiveJMSMessage" failonerror="true">
+	        <java fork="yes" classname="org.jboss.soa.esb.samples.quickstart.dynamicRouter.test.ReceiveJMSMessage" failonerror="true">
 	            <arg value="queue/qsdynamicrouter_1_Request"/>  
 	            <arg value=":OK"/>
 	            <classpath refid="exec-classpath"/>
@@ -38,9 +38,9 @@
 	
 	   <target name="receive-destination2" depends="compile">
 		        <echo>Runs Test destination 2 message receiver</echo>
-		        <java fork="yes" classname="quickstart.dynamicRouter.test.ReceiveJMSMessage" failonerror="true">
+		        <java fork="yes" classname="org.jboss.soa.esb.samples.quickstart.dynamicRouter.test.ReceiveJMSMessage" failonerror="true">
 		            <arg value="queue/qsdynamicrouter_2_Request"/>  
-		            <arg value=":OK"/>
+		            <arg value=":not_OK"/>
 		            <classpath refid="exec-classpath"/>
 		        </java>
 		    </target>		

Modified: labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/jboss-esb.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/jboss-esb.xml	2007-07-17 19:51:28 UTC (rev 13584)
+++ labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/jboss-esb.xml	2007-07-17 20:47:13 UTC (rev 13585)
@@ -38,7 +38,7 @@
             </listeners>
             <actions>             
                 <action name="action1" 
-                class="quickstart.dynamicRouter.MyDynamicRouterAction" 
+                class="org.jboss.soa.esb.samples.quickstart.dynamicRouter.MyDynamicRouterAction" 
                 process="processMessage"  />      
             </actions>   
         </service>
@@ -50,7 +50,7 @@
             </listeners>
             <actions>             
                 <action name="action2" 
-                class="quickstart.dynamicRouter.MyControlAction" 
+                class="org.jboss.soa.esb.samples.quickstart.dynamicRouter.MyControlAction" 
                 process="processControlMessage"  />      
             </actions>   
         </service>

Added: labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/esb/samples/quickstart/dynamicRouter/MyControlAction.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/esb/samples/quickstart/dynamicRouter/MyControlAction.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/esb/samples/quickstart/dynamicRouter/MyControlAction.java	2007-07-17 20:47:13 UTC (rev 13585)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+package  org.jboss.soa.esb.samples.quickstart.dynamicRouter;
+
+import org.jboss.soa.esb.actions.AbstractActionLifecycle;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+
+import org.jboss.soa.esb.samples.quickstart.dynamicRouter.test.*;
+import java.util.Hashtable;
+
+import java.util.Enumeration;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.FileOutputStream;
+import java.io.FileInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectInputStream;
+
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSession;
+import javax.jms.ObjectMessage;
+import javax.jms.TextMessage;
+import javax.naming.InitialContext;
+import javax.jms.JMSException;
+import javax.jms.TextMessage;
+import javax.jms.QueueSender;
+import javax.naming.NamingException;
+
+public class MyControlAction extends AbstractActionLifecycle {
+	protected ConfigTree _config;
+
+	public MyControlAction(ConfigTree config) {
+		_config = config;
+	}
+
+	public Message processControlMessage(Message message) throws Exception {
+
+		Hashtable theHashtable = QsHashtable.readHash();
+		String tm = new String(message.getBody().getByteArray());
+
+		try {
+			// The message contains the queue name and status separated by ":"
+			// for example - queue/queueName:OK - any queue associated with
+			// a value of "OK" is added to the dynamic router data store
+			String[] theStrings = tm.split(":");
+
+			// Make the data store dynamic - to reflect changes in queue status
+			if (theHashtable.containsKey(theStrings[0])) {
+				theHashtable.remove(theStrings[0]);
+			}
+
+			theHashtable.put(theStrings[0], theStrings[1]);
+
+		} catch (Throwable t) {
+			t.printStackTrace();
+		}
+		QsHashtable.writeHash(theHashtable);
+		return message;
+
+	} /* method */
+
+} /* class */

Added: labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/esb/samples/quickstart/dynamicRouter/MyDynamicRouterAction.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/esb/samples/quickstart/dynamicRouter/MyDynamicRouterAction.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/esb/samples/quickstart/dynamicRouter/MyDynamicRouterAction.java	2007-07-17 20:47:13 UTC (rev 13585)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+package  org.jboss.soa.esb.samples.quickstart.dynamicRouter;
+
+import org.jboss.soa.esb.actions.AbstractActionLifecycle;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSession;
+import javax.jms.ObjectMessage;
+import javax.jms.TextMessage;
+import javax.naming.InitialContext;
+import javax.jms.JMSException;
+import javax.jms.TextMessage;
+import javax.jms.QueueSender;
+import javax.naming.NamingException;
+
+import java.util.Enumeration;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.FileOutputStream;
+import java.io.FileInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectInputStream;
+import org.jboss.soa.esb.samples.quickstart.dynamicRouter.test.*;
+import java.util.Hashtable;
+
+public class MyDynamicRouterAction extends AbstractActionLifecycle
+{
+    
+  protected ConfigTree	_config;
+  public MyDynamicRouterAction(ConfigTree config) { _config = config; } 
+  public Message processMessage(Message message) throws Exception{
+	  
+	  Hashtable theHashtable = QsHashtable.readHash();
+		try {
+			TextMessage tm = null; 
+			
+			for (Enumeration e = theHashtable.keys(); e.hasMoreElements();) {
+				String theKey = (String) e.nextElement();
+				String theValue = (String) theHashtable.get(theKey);
+				
+				// If the queue is "OK" - send the incoming message to that queue 
+				if (theValue.equals("OK")) {
+					
+					// Set up the connection
+					QueueConnection conn1 = null;
+					Queue que;
+					QueueSession session;
+					InitialContext iniCtx = new InitialContext();
+					Object tmp = iniCtx.lookup("ConnectionFactory");
+					QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
+					conn1 = qcf.createQueueConnection();
+					que = (Queue) iniCtx.lookup(theKey);
+					session = conn1.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+					conn1.start();
+
+                    // Send the message                						
+					QueueSender send = session.createSender(que);
+					tm = session.createTextMessage(new String(message.getBody().getByteArray()));
+					send.send(tm);
+										
+					// Close the connection
+					send.close();
+					conn1.stop();
+					session.close();
+					conn1.close();
+				}
+			}
+		} 
+		catch (Throwable t) {
+			t.printStackTrace();
+		} /* try and catch */
+
+	  return message; 
+        		
+	} /* method */
+	
+} /* class */
\ No newline at end of file

Added: labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/esb/samples/quickstart/dynamicRouter/test/QsHashtable.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/esb/samples/quickstart/dynamicRouter/test/QsHashtable.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/esb/samples/quickstart/dynamicRouter/test/QsHashtable.java	2007-07-17 20:47:13 UTC (rev 13585)
@@ -0,0 +1,83 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+ 
+package  org.jboss.soa.esb.samples.quickstart.dynamicRouter.test;
+
+import java.util.Hashtable;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.FileOutputStream;
+import java.io.FileInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectInputStream;
+import java.util.Enumeration;
+
+public class QsHashtable {
+
+	public static void writeHash(Hashtable theHashtable) {
+		try {
+			FileOutputStream fileOut = new FileOutputStream("hashtable.ser");
+			ObjectOutputStream out = new ObjectOutputStream(fileOut);
+			out.writeObject(theHashtable);
+			
+			System.out.println("Writing Hashtable to disk");
+			for (Enumeration e = theHashtable.keys(); e.hasMoreElements();) {
+				String theKey = (String) e.nextElement();
+				String theValue = (String) theHashtable.get(theKey);
+				System.out.println("\tHashtable entry: key = " + theKey + ", value = " + theValue);
+            }
+			out.close();
+			fileOut.close();
+		} 
+		catch (FileNotFoundException E) {
+			E.printStackTrace();
+		} 
+		catch (IOException E) {
+			E.printStackTrace();
+		}
+
+	} /* method */
+
+	public static Hashtable readHash() {
+		Hashtable theHashtable = new Hashtable();
+
+		try {
+			FileInputStream fileIn = new FileInputStream("hashtable.ser");
+			ObjectInputStream in = new ObjectInputStream(fileIn);
+			theHashtable = (Hashtable) in.readObject();
+			in.close();
+			fileIn.close();
+		} 
+		catch (ClassNotFoundException E) {
+			E.printStackTrace();
+		} 
+		catch (FileNotFoundException E) {
+			// If the file is not there - it's not a problem as we'll create it
+		} 
+		catch (IOException E) {
+			E.printStackTrace();
+		}
+
+		return theHashtable;
+
+	} /* method */
+
+} /* class */
\ No newline at end of file

Added: labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/esb/samples/quickstart/dynamicRouter/test/ReceiveJMSMessage.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/esb/samples/quickstart/dynamicRouter/test/ReceiveJMSMessage.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/esb/samples/quickstart/dynamicRouter/test/ReceiveJMSMessage.java	2007-07-17 20:47:13 UTC (rev 13585)
@@ -0,0 +1,137 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+package  org.jboss.soa.esb.samples.quickstart.dynamicRouter.test;
+
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSession;
+import javax.jms.ObjectMessage;
+import javax.jms.TextMessage;
+import javax.naming.InitialContext;
+
+import javax.jms.MessageListener;
+import javax.jms.Message;
+
+import javax.jms.JMSException;
+import javax.jms.TextMessage;
+import javax.jms.QueueSender;
+import javax.naming.NamingException;
+
+public class ReceiveJMSMessage {
+	QueueConnection conn = null;
+	QueueSession receiverSession = null;
+	Queue receiverQueue = null;
+	QueueReceiver queueReceiver = null;
+	InitialContext iniCtx = null;
+	QueueConnectionFactory qcf = null;
+	String receiveQueueName = "queue/D"; // Default to queue/D
+
+	QueueConnection conn1 = null;
+	Queue que;
+	QueueSession session;
+		
+	// Ref:
+	// http://docs.jboss.org/jbossas/jboss4guide/r5/html/ch6.chapt.html#d0e12917
+	public static class ExListener implements MessageListener {
+		public void onMessage(Message msg) {
+			TextMessage tm = (TextMessage) msg;
+			try {
+				System.out.println("onMessage, control channel recv text=" + tm.getText());
+			} catch (Throwable t) {
+				t.printStackTrace();
+			}
+		} /* method */
+	} /* class */
+
+	public ReceiveJMSMessage() {
+	} /* method */
+
+	public void receiveOne() {
+		try {
+			if (iniCtx == null)
+				iniCtx = new InitialContext();
+			if (qcf == null)
+				qcf = (QueueConnectionFactory) iniCtx
+						.lookup("ConnectionFactory");
+			if (conn == null) {
+				conn = qcf.createQueueConnection();
+				conn.start();
+			}
+
+			receiverQueue = (Queue) iniCtx.lookup(receiveQueueName);
+			receiverSession = conn.createQueueSession(false,
+					QueueSession.AUTO_ACKNOWLEDGE);
+			queueReceiver = receiverSession.createReceiver(receiverQueue);
+			TextMessage msg = (TextMessage) queueReceiver.receive(2000);
+
+			// Ref:
+			// http://docs.jboss.org/jbossas/jboss4guide/r5/html/ch6.chapt.html#d0e12917
+			queueReceiver.setMessageListener(new ExListener());
+
+		} catch (Exception e) {
+			System.out.println(e);
+		}
+	} /* method */
+
+	public void setupConnection() throws JMSException, NamingException {
+		InitialContext iniCtx = new InitialContext();
+		Object tmp = iniCtx.lookup("ConnectionFactory");
+		QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
+		conn1 = qcf.createQueueConnection();
+		que = (Queue) iniCtx.lookup("queue/qsdynamicrouter_Control_Request");
+		session = conn1.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+		conn1.start();
+		System.out.println("Connection Started to register with control channel");
+	} /* method */
+
+	public void stop() throws JMSException {
+		conn1.stop();
+		session.close();
+		conn1.close();
+	} /* method */
+
+	public void sendAMessage(String msg) throws JMSException {
+		QueueSender send = session.createSender(que);
+		TextMessage tm = session.createTextMessage(msg);
+		send.send(tm);
+		send.close();
+	} /* method */
+
+	public static void main(String[] args) throws Exception {
+		ReceiveJMSMessage receiver = new ReceiveJMSMessage();
+		
+		// Send the message to the control channel
+		receiver.setupConnection();
+		receiver.sendAMessage(args[0] + args[1]);
+		receiver.stop();
+
+		if (args[0] != null) {
+			receiver.receiveQueueName = args[0];
+			System.out.println("Receiving on: " + receiver.receiveQueueName);
+		}
+		while (true) { // loop until I'm killed
+			receiver.receiveOne();
+		}
+	} /* method */
+
+} /* class */

Added: labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/esb/samples/quickstart/dynamicRouter/test/SendJMSMessage.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/esb/samples/quickstart/dynamicRouter/test/SendJMSMessage.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/samples/quickstarts/dynamic_router/src/org/jboss/soa/esb/samples/quickstart/dynamicRouter/test/SendJMSMessage.java	2007-07-17 20:47:13 UTC (rev 13585)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+package  org.jboss.soa.esb.samples.quickstart.dynamicRouter.test;
+
+import javax.jms.JMSException;
+import javax.jms.TextMessage;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+public class SendJMSMessage {
+	QueueConnection conn;
+	QueueSession session;
+	Queue que;
+
+	public void setupConnection() throws JMSException, NamingException {
+		InitialContext iniCtx = new InitialContext();
+		Object tmp = iniCtx.lookup("ConnectionFactory");
+		QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
+		conn = qcf.createQueueConnection();
+		que = (Queue) iniCtx.lookup("queue/qsdynamicrouter_Input_Request");
+		session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+		conn.start();
+		System.out.println("Connection Started");
+	} /* method */
+
+	public void stop() throws JMSException {
+		conn.stop();
+		session.close();
+		conn.close();
+	} /* method */
+
+	public void sendAMessage(String msg) throws JMSException {
+		QueueSender send = session.createSender(que);
+		TextMessage tm = session.createTextMessage(msg);
+		send.send(tm);
+		send.close();
+	} /* method */
+
+	public static void main(String args[]) throws Exception {
+		SendJMSMessage sm = new SendJMSMessage();
+		sm.setupConnection();
+		sm.sendAMessage(args[0]);
+		sm.stop();
+	} /* method */
+
+} /* class */




More information about the jboss-svn-commits mailing list