[jboss-cvs] JBoss Messaging SVN: r6430 - in trunk/examples/javaee: servlet-transport and 8 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Apr 15 03:38:07 EDT 2009
Author: gaohoward
Date: 2009-04-15 03:38:07 -0400 (Wed, 15 Apr 2009)
New Revision: 6430
Added:
trunk/examples/javaee/servlet-transport/
trunk/examples/javaee/servlet-transport/build.xml
trunk/examples/javaee/servlet-transport/config/
trunk/examples/javaee/servlet-transport/config/jms-servlet.war/
trunk/examples/javaee/servlet-transport/config/jms-servlet.war/WEB-INF/
trunk/examples/javaee/servlet-transport/config/jms-servlet.war/WEB-INF/web.xml
trunk/examples/javaee/servlet-transport/config/jndi.properties
trunk/examples/javaee/servlet-transport/readme.html
trunk/examples/javaee/servlet-transport/src/
trunk/examples/javaee/servlet-transport/src/org/
trunk/examples/javaee/servlet-transport/src/org/jboss/
trunk/examples/javaee/servlet-transport/src/org/jboss/javaee/
trunk/examples/javaee/servlet-transport/src/org/jboss/javaee/example/
trunk/examples/javaee/servlet-transport/src/org/jboss/javaee/example/ServletTransportExample.java
Log:
temporarily commit the servlet example
Added: trunk/examples/javaee/servlet-transport/build.xml
===================================================================
--- trunk/examples/javaee/servlet-transport/build.xml (rev 0)
+++ trunk/examples/javaee/servlet-transport/build.xml 2009-04-15 07:38:07 UTC (rev 6430)
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- =========================================================================================== -->
+<!-- -->
+<!-- JBoss, Home of Professional Open Source -->
+<!-- Copyright 2005, JBoss Inc., and individual contributors as indicated -->
+<!-- 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. -->
+<!-- -->
+<!-- =========================================================================================== -->
+
+
+<project default="run" name="JBoss Messaging Servlet Transport Example">
+
+ <import file="../common/build.xml"/>
+
+ <target name="deploy-servlet">
+ <copy todir="${jboss.home}/server/jbm2_default/deploy/jms-servlet.war">
+ <fileset dir="config/jms-servlet.war"/>
+ </copy>
+ <sleep seconds="5"/>
+ </target>
+
+ <target name="undeploy-servlet">
+ <delete dir="${jboss.home}/server/jbm2_default/deploy/jms-servlet.war" quiet="true"/>
+ </target>
+
+ <target name="run">
+ <antcall target="runExample">
+ <param name="example.classname" value="org.jboss.javaee.example.ServletTransportExample"/>
+ </antcall>
+ <antcall target="undeploy-servlet"/>
+ </target>
+
+</project>
Added: trunk/examples/javaee/servlet-transport/config/jms-servlet.war/WEB-INF/web.xml
===================================================================
--- trunk/examples/javaee/servlet-transport/config/jms-servlet.war/WEB-INF/web.xml (rev 0)
+++ trunk/examples/javaee/servlet-transport/config/jms-servlet.war/WEB-INF/web.xml 2009-04-15 07:38:07 UTC (rev 6430)
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
+ version="2.4">
+ <context-param>
+ <param-name>serverChannelName</param-name>
+ <param-value>org.jboss.jbm</param-value>
+ </context-param>
+
+ <context-param>
+ <param-name>streaming</param-name>
+ <param-value>true</param-value>
+ </context-param>
+
+ <context-param>
+ <param-name>reconnectTimeout</param-name>
+ <param-value>3000</param-value>
+ </context-param>
+
+ <listener>
+ <listener-class>org.jboss.netty.channel.socket.http.HttpTunnelingSessionListener</listener-class>
+ </listener>
+
+ <listener>
+ <listener-class>org.jboss.netty.channel.socket.http.HttpTunnelingContextListener</listener-class>
+ </listener>
+
+ <servlet>
+ <servlet-name>NettyServlet</servlet-name>
+ <servlet-class>org.jboss.netty.channel.socket.http.HttpTunnelingServlet</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>NettyServlet</servlet-name>
+ <url-pattern>/JBMServlet</url-pattern>
+ </servlet-mapping>
+</web-app>
Added: trunk/examples/javaee/servlet-transport/config/jndi.properties
===================================================================
--- trunk/examples/javaee/servlet-transport/config/jndi.properties (rev 0)
+++ trunk/examples/javaee/servlet-transport/config/jndi.properties 2009-04-15 07:38:07 UTC (rev 6430)
@@ -0,0 +1,3 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.provider.url=jnp://localhost:1099
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
Added: trunk/examples/javaee/servlet-transport/readme.html
===================================================================
--- trunk/examples/javaee/servlet-transport/readme.html (rev 0)
+++ trunk/examples/javaee/servlet-transport/readme.html 2009-04-15 07:38:07 UTC (rev 6430)
@@ -0,0 +1,95 @@
+<html>
+ <head>
+ <title>JBoss Messaging Java EE MDB Example</title>
+ <link rel="stylesheet" type="text/css" href="../../jms/common/common.css">
+ </head>
+ <body>
+ <h1>Java EE MDB Example</h1>
+ <br>
+ <p>This example shows you how to end a message to an MDB</p>
+ <p>
+ The example will send deploy a simple MDB and demonstrate sending a message and the MDB consuming it
+ </p>
+ <h2>Example step-by-step</h2>
+ <p><i>To deploy the example, simply type <code>ant deploy</code> from this directory **</i></p>
+ <p><i>To run the example, simply type <code>ant</code> from this directory</i></p>
+ <p><i>To undeploy the example, simply type <code>ant undeploy</code> from this directory **</i></p>
+ <p><i> ** make sure that JBOSS_HOME is set to the Jboss installation directory</i></p>
+ <br>
+ <ol>
+ <li>First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the <code>jndi.properties</code> file in the directory <code>config</code></li>
+ <pre>
+ <code>initialContext = new InitialContext();</code>
+ </pre>
+
+ <li>We look up the JMS queue object from JNDI</li>
+ <pre>
+ <code>Queue queue = (Queue) initialContext.lookup("/queue/testQueue");</code>
+ </pre>
+
+ <li>We look up the JMS connection factory object from JNDI</li>
+ <pre>
+ <code>ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");</code>
+ </pre>
+
+ <li>We create a JMS connection</li>
+ <pre>
+ <code>connection = cf.createConnection();</code>
+ </pre>
+
+ <li>We create a JMS session. The session is created as non transacted and will auto acknowledge messages.</li>
+ <pre>
+ <code>Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);</code>
+ </pre>
+
+ <li>We create a JMS message producer on the session. This will be used to send the messages.</li>
+ <pre>
+ <code>MessageProducer messageProducer = session.createProducer(queue);</code>
+ </pre>
+
+ <li>We create a JMS text messages that we are going to send.</li>
+ <pre>
+ <code> TextMessage message = session.createTextMessage("This is a text message");</code>
+ </pre>
+
+ <li>We send messages to the queue</li>
+ <pre>
+ <code>messageProducer.send(message);</code>
+ </pre>
+
+ <li>The MDB receives the message<br />
+ We know the message is a TextMessage so we cast to it.
+ </li>
+ <pre>
+ <code>TextMessage tm = (TextMessage)message;</code>
+ </pre>
+
+ <li>The MDB gets the text and prints it
+ </li>
+ <pre>
+ <code>String text = tm.getText();
+ System.out.println("message " + text + " received");
+ </code>
+ </pre>
+
+ <li>And finally, <b>always</b> remember to close your JMS connections and resources after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects</li>
+
+ <pre>
+ <code>finally
+ {
+ if (initialContext != null)
+ {
+ initialContext.close();
+ }
+ if (connection != null)
+ {
+ connection.close();
+ }
+ }</code>
+ </pre>
+
+
+
+ </ol>
+ </body>
+</html>
\ No newline at end of file
Added: trunk/examples/javaee/servlet-transport/src/org/jboss/javaee/example/ServletTransportExample.java
===================================================================
--- trunk/examples/javaee/servlet-transport/src/org/jboss/javaee/example/ServletTransportExample.java (rev 0)
+++ trunk/examples/javaee/servlet-transport/src/org/jboss/javaee/example/ServletTransportExample.java 2009-04-15 07:38:07 UTC (rev 6430)
@@ -0,0 +1,100 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-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.javaee.example;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.InitialContext;
+
+/**
+ * A simple JMS Queue example that uses servlet protocol.
+ *
+ * @author <a href="hgao at redhat.com">Howard Gao</a>
+ */
+public class ServletTransportExample
+{
+ public static void main(String[] args) throws Exception
+ {
+ Connection connection = null;
+ InitialContext initialContext = null;
+ try
+ {
+ //Step 1. Create an initial context to perform the JNDI lookup.
+ initialContext = new InitialContext();
+
+ //Step 2. Perfom a lookup on the queue
+ Queue queue = (Queue) initialContext.lookup("/queue/testQueue");
+
+ //Step 3. Perform a lookup on the Connection Factory
+ ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ServletConnectionFactory");
+
+ //Step 4.Create a JMS Connection
+ connection = cf.createConnection();
+
+ System.out.println("connection created: " + connection);
+
+ //Step 5. Create a JMS Session
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ //Step 6. Create a JMS Message Producer
+ MessageProducer producer = session.createProducer(queue);
+
+ //Step 7. Create a Text Message
+ TextMessage message = session.createTextMessage("This is a text message");
+
+ System.out.println("Sent message: " + message.getText());
+
+ //Step 8. Send the Message
+ producer.send(message);
+
+ //Step 9. Create a JMS Message Consumer
+ MessageConsumer messageConsumer = session.createConsumer(queue);
+
+ //Step 10. Start the Connection
+ connection.start();
+
+ //Step 11. Receive the message
+ TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
+
+ System.out.println("Received message: " + messageReceived.getText());
+
+ }
+ finally
+ {
+ //Step 12. Be sure to close our JMS resources!
+ if (initialContext != null)
+ {
+ initialContext.close();
+ }
+ if(connection != null)
+ {
+ connection.close();
+ }
+ }
+ }
+
+}
More information about the jboss-cvs-commits
mailing list