[jboss-cvs] JBoss Messaging SVN: r2337 - in trunk: docs/examples/mdb-failure and 9 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Feb 16 02:30:31 EST 2007


Author: ovidiu.feodorov at jboss.com
Date: 2007-02-16 02:30:31 -0500 (Fri, 16 Feb 2007)
New Revision: 2337

Added:
   trunk/docs/examples/mdb-failure/
   trunk/docs/examples/mdb-failure/README.html
   trunk/docs/examples/mdb-failure/build.xml
   trunk/docs/examples/mdb-failure/do-not-distribute.properties
   trunk/docs/examples/mdb-failure/etc/
   trunk/docs/examples/mdb-failure/etc/META-INF/
   trunk/docs/examples/mdb-failure/etc/META-INF/ejb-jar.xml
   trunk/docs/examples/mdb-failure/etc/META-INF/jboss.xml
   trunk/docs/examples/mdb-failure/etc/jndi.properties
   trunk/docs/examples/mdb-failure/etc/log4j.xml
   trunk/docs/examples/mdb-failure/src/
   trunk/docs/examples/mdb-failure/src/org/
   trunk/docs/examples/mdb-failure/src/org/jboss/
   trunk/docs/examples/mdb-failure/src/org/jboss/example/
   trunk/docs/examples/mdb-failure/src/org/jboss/example/jms/
   trunk/docs/examples/mdb-failure/src/org/jboss/example/jms/mdbfailure/
   trunk/docs/examples/mdb-failure/src/org/jboss/example/jms/mdbfailure/MDBFailureExample.java
   trunk/docs/examples/mdb-failure/src/org/jboss/example/jms/mdbfailure/Sender.java
Modified:
   trunk/tests/smoke/build.xml
Log:
adding mdb failure smoke test; http://jira.jboss.org/jira/browse/JBMESSAGING-849

Added: trunk/docs/examples/mdb-failure/README.html
===================================================================
--- trunk/docs/examples/mdb-failure/README.html	                        (rev 0)
+++ trunk/docs/examples/mdb-failure/README.html	2007-02-16 07:30:31 UTC (rev 2337)
@@ -0,0 +1,180 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+  <meta content="text/html; charset=ISO-8859-1"
+ http-equiv="content-type">
+  <title>JBoss Messaging Example - Message Driven Bean Failure</title>
+</head>
+<body>
+<br>
+<h1>Message Driven Bean Behavior on Failure Example</h1>
+$Revision: 1459 $
+<h2>Overview</h2>
+<br>
+This example deploys a simple Message Driven Bean that processes
+messages sent to a test queue. The Message Driven Bean is coded in such
+a way that upon the first arrival of a message, it throws a
+RuntimeException, simulating a runtime processing failure. <br>
+<br>
+The expected behavior of the MDB Container is to try to redeliver the
+message, which is what it hopefully does. Since the example framework
+took the precaution to insure that there is only one single type of MDB
+container listening on the example queue, the messages will be
+redelivered to an MDB of the same type. Upon the second arrival, the
+MDB
+instance will "let the message pass", will correctly "process" it and
+forward the result to temporary queue created by the sender for exactly
+this purpose. The
+example is considered&nbsp; successful if the sender receives the
+acknowledgment message. The successful example proves that message
+redelivery on failure works.<br>
+<br>
+This example relies on having access to a running JBoss Messaging
+instance.
+The JBoss Messaging instance must be installed and started according to
+the
+"Installation" paragraph from the release documentation.&nbsp; However,
+the example will automatically deploy its own queue, unless a queue
+with the same name is already deployed.<br>
+<br>
+This example also relies on having access to <span
+ style="font-family: monospace;">jboss-messaging-client.jar</span>
+archive that comes with the release bundle. If you run this example
+from
+an unzipped installation bundle, the example run script is correctly
+configured to find the client jar. Otherwise, you must modify example's
+<span style="font-family: monospace;">build.xml</span>
+accordingly.&nbsp;<br>
+<br>
+<span style="font-style: italic;">The example was designed to deploy
+its server-side artifacts </span><span
+ style="font-family: monospace; font-style: italic;"></span><span
+ style="font-style: italic;">under a JBoss' </span><span
+ style="font-family: monospace; font-style: italic;">messaging</span><span
+ style="font-style: italic;">
+configuration. If you intend to use the script with a JBoss
+configuration that is named differently, please modify the
+example's</span><span
+ style="font-family: monospace; font-style: italic;"> build.xml</span><span
+ style="font-style: italic;">
+accordingly.</span><span style="font-style: italic;"></span><br>
+<br>
+<h2>Running the example</h2>
+1. Set up the JBOSS_HOME environment variable to point to the JBoss
+instance you deployed JBoss Messaging into. For example, if you
+deployed JBoss Messaging in <span style="font-family: monospace;">C:\jboss-4.0.3SP1\server\default\deploy,</span>
+then your JBOSS_HOME value should be <span
+ style="font-family: monospace;">C:\</span><span
+ style="font-family: monospace;">jboss-4.0.3SP1.</span><br>
+<span style="font-family: monospace;"></span><br>
+2. Go to the example's home directory<br>
+<br>
+<div style="margin-left: 40px;"><span style="font-family: monospace;">cd
+...\examples\mdb-failure</span><br>
+</div>
+<br>
+3. Run the example:<br>
+<br>
+<div style="margin-left: 40px;"><span style="font-family: monospace;">ant</span>
+<br>
+<br>
+<br>
+</div>
+The output of a successful run should be similar to:<br>
+<div style="margin-left: 40px;"><br>
+</div>
+<table
+ style="width: 90%; text-align: left; font-family: monospace; background-color: rgb(204, 204, 204); margin-left: 40px;"
+ border="1" cellpadding="2" cellspacing="2">
+  <tbody>
+    <tr>
+      <td style="vertical-align: top;">
+      <div style="margin-left: 40px;"><br>
+      </div>
+$ ant<br>
+Buildfile: build.xml<br>
+      <br>
+identify:<br>
+&nbsp;&nbsp;&nbsp;&nbsp; [echo]
+###########################################################################<br>
+&nbsp;&nbsp;&nbsp;&nbsp; [echo]
+#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+Running the MDB Failure
+example&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+#<br>
+&nbsp;&nbsp;&nbsp;&nbsp; [echo]
+###########################################################################<br>
+&nbsp;&nbsp;&nbsp;&nbsp; [echo] The
+queue:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; testQueue<br>
+&nbsp;&nbsp;&nbsp;&nbsp; [echo] The client jar:
+../../../output/lib/jboss-messaging-client.jar<br>
+      <br>
+sanity-check:<br>
+      <br>
+init:<br>
+&nbsp;&nbsp;&nbsp; [mkdir] Created dir:
+C:\work\src\svn\messaging-Branch_1_0_1_SP\docs\examples\mdb-failure\output\classes\META-INF<br>
+&nbsp;&nbsp;&nbsp; [mkdir] Created dir:
+C:\work\src\svn\messaging-Branch_1_0_1_SP\docs\examples\mdb-failure\output\lib\META-INF<br>
+&nbsp;&nbsp;&nbsp; [mkdir] Created dir:
+C:\work\src\svn\messaging-Branch_1_0_1_SP\docs\examples\common\output<br>
+      <br>
+compile:<br>
+&nbsp;&nbsp;&nbsp; [javac] Compiling 2 source files to
+C:\work\src\svn\messaging-Branch_1_0_1_SP\docs\examples\common\output<br>
+&nbsp;&nbsp;&nbsp; [javac] Compiling 2 source files to
+C:\work\src\svn\messaging-Branch_1_0_1_SP\docs\examples\mdb-failure\output\classes<br>
+      <br>
+jar:<br>
+&nbsp;&nbsp;&nbsp;&nbsp; [copy] Copying 2 files to
+C:\work\src\svn\messaging-Branch_1_0_1_SP\docs\examples\mdb-failure\output\classes\META-INF<br>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [jar] Building jar:
+C:\work\src\svn\messaging-Branch_1_0_1_SP\docs\examples\mdb-failure\output\lib\mdb-failure-example.jar<br>
+      <br>
+deploy:<br>
+&nbsp;&nbsp;&nbsp;&nbsp; [copy] Copying 1 file to
+C:\work\src\jboss-4.0.5.GA-src\build\output\jboss-4.0.5.GA\server\messaging\deploy<br>
+      <br>
+sleep:<br>
+&nbsp;&nbsp;&nbsp;&nbsp; [echo] Sleeping for 5 seconds ...<br>
+      <br>
+run:<br>
+      <br>
+send:<br>
+&nbsp;&nbsp;&nbsp;&nbsp; [java] Queue /queue/testQueue exists<br>
+&nbsp;&nbsp;&nbsp;&nbsp; [java] The "Hello!" message was successfully
+sent to the testQueue queue<br>
+&nbsp;&nbsp;&nbsp;&nbsp; [java] Received message: !olleH<br>
+&nbsp;&nbsp;&nbsp;&nbsp; [java] The example connected to JBoss
+Messaging version 1.0.1.SP4 (1.0)<br>
+      <br>
+&nbsp;&nbsp;&nbsp;&nbsp; [java] #####################<br>
+&nbsp;&nbsp;&nbsp;&nbsp; [java] ###&nbsp;&nbsp;&nbsp;
+SUCCESS!&nbsp;&nbsp; ###<br>
+&nbsp;&nbsp;&nbsp;&nbsp; [java] #####################<br>
+      <br>
+undeploy:<br>
+&nbsp;&nbsp; [delete] Deleting:
+C:\work\src\jboss-4.0.5.GA-src\build\output\jboss-4.0.5.GA\server\messaging\deploy\mdb-failure-example.jar<br>
+      <br>
+BUILD SUCCESSFUL<br>
+Total time: 9 seconds<br>
+      <br>
+      <br>
+      <br>
+      </td>
+    </tr>
+  </tbody>
+</table>
+<br>
+<br style="font-family: courier new,courier,monospace;">
+<hr
+ style="width: 100%; height: 2px; font-family: courier new,courier,monospace;"><br>
+<br>
+<br>
+<br>
+<br>
+<br>
+<br>
+</body>
+</html>

Added: trunk/docs/examples/mdb-failure/build.xml
===================================================================
--- trunk/docs/examples/mdb-failure/build.xml	                        (rev 0)
+++ trunk/docs/examples/mdb-failure/build.xml	2007-02-16 07:30:31 UTC (rev 2337)
@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+
+   To run the example, set JBOSS_HOME and run ant (with no parameters)
+
+   $Id: build.xml 974 2006-05-23 03:35:38Z ovidiu $
+
+ -->
+
+<project name="MDBFailureExample" default="run">
+
+   <property environment="ENV"/>
+
+   <!--
+        If you don't find this file in the current directory, it's ok, it's intended to provide
+        defaults for in-workarea testing and it's not meant for distribution with the example bundle.
+   -->
+   <property file="do-not-distribute.properties"/>
+   <property name="undeploy.quiet" value="false"/>
+   <property name="undeploy.failonerror" value="true"/>
+
+   <!-- These properties may be overriden by calling ants when this example is used in a smoke test -->
+   <property name="messaging.client.jar.path" value="../.."/>
+   <property name="messaging.client.jar.name" value="jboss-messaging-client.jar"/>
+   <property name="jboss.home" value="${ENV.JBOSS_HOME}"/>
+   <property name="jboss.configuration" value="messaging"/>
+   <property name="example.queue.name" value="testQueue"/>
+
+   <path id="common.compilation.classpath">
+      <fileset file="${jboss.home}/client/jboss-j2ee.jar"/>
+      <fileset file="${jboss.home}/client/jboss-j2se.jar"/>
+   </path>
+
+   <path id="example.compilation.classpath">
+      <path refid="common.compilation.classpath"/>
+      <pathelement path="../common/output"/>
+   </path>
+
+   <path id="execution.classpath">
+      <pathelement path="./etc"/>
+      <pathelement path="../common/output"/>
+      <pathelement path="./output"/>
+      <pathelement path="./output/classes"/>
+      <fileset file="${messaging.client.jar.path}/${messaging.client.jar.name}"/>
+
+      <!--
+          If you want to run the example with JBossMQ, comment the line above, uncomment the line
+          below, and use a "default" configuration.
+      -->
+      <!--
+      <fileset file="${jboss.home}/client/jbossall-client.jar"/>
+      -->
+   </path>
+
+   <target name="identify">
+      <echo message="###########################################################################"/>
+      <echo message="#                    Running the MDB Failure example                      #"/>
+      <echo message="###########################################################################"/>
+      <echo message="The queue:      ${example.queue.name}"/>
+      <echo message="The client jar: ${messaging.client.jar.path}/${messaging.client.jar.name}"/>
+   </target>
+
+   <target name="sanity-check" depends="identify">
+      <available property="client.jar.present" file="${messaging.client.jar.path}/${messaging.client.jar.name}"/>
+      <fail message="Could not find client jar ${messaging.client.jar.path}/${messaging.client.jar.name}"
+            unless="client.jar.present"/>
+   </target>
+
+   <target name="init" depends="sanity-check">
+      <mkdir dir="./output/classes/META-INF"/>
+      <mkdir dir="./output/lib/META-INF"/>
+      <mkdir dir="../common/output"/>
+   </target>
+
+   <target name="compile" depends="init">
+      <javac destdir="../common/output" debug="on" debuglevel="lines,vars,source">
+         <src path="../common/src"/>
+         <classpath refid="common.compilation.classpath"/>
+      </javac>
+      <javac destdir="./output/classes" debug="on" debuglevel="lines,vars,source">
+         <src path="./src"/>
+         <classpath refid="example.compilation.classpath"/>
+      </javac>
+   </target>
+
+   <target name="jar" depends="compile">
+      <copy todir="./output/classes/META-INF" filtering="true">
+         <fileset dir="./etc/META-INF" includes="*"/>
+         <filterset>
+            <filter token="QUEUE_NAME" value="${example.queue.name}"/>
+         </filterset>
+      </copy>
+      <jar destfile="./output/lib/mdb-failure-example.jar"
+           basedir="./output/classes"
+           includes="META-INF/**,org/jboss/example/**/MDBFailureExample.class"/>
+   </target>
+
+   <target name="deploy" depends="jar">
+      <copy file="./output/lib/mdb-failure-example.jar"
+            todir="${jboss.home}/server/${jboss.configuration}/deploy"/>
+      <antcall target="sleep"><param name="sleep.interval" value="5"/></antcall>
+   </target>
+
+   <target name="run" depends="deploy">
+      <antcall target="send"/>
+      <antcall target="sleep"><param name="sleep.interval" value="15"/></antcall>
+      <antcall target="undeploy">
+         <param name="undeploy.quiet" value="false"/>
+         <param name="undeploy.failonerror" value="true"/>
+      </antcall>
+   </target>
+
+   <target name="send">
+      <!-- MDBFailureExample expects to find the name of the queue to connect to as value of the
+           'example.queue.name' property, which *may* be defined by calling ants when this example
+            is used in a smoke test -->
+      <java classname="org.jboss.example.jms.mdbfailure.Sender"
+         classpathref="execution.classpath" fork="yes" failonerror="true">
+         <sysproperty key="example.queue.name" value="${example.queue.name}"/>
+         <!--
+         <jvmarg line="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_shmem,server=y,suspend=y,address=example"/>
+          -->
+      </java>
+   </target>
+
+   <target name="undeploy">
+      <delete file="${jboss.home}/server/${jboss.configuration}/deploy/mdb-failure-example.jar"
+              quiet="${undeploy.quiet}" failonerror="${undeploy.failonerror}"/>
+   </target>
+
+   <target name="clean" depends="undeploy">
+      <delete dir="./output" quiet="true"/>
+      <delete dir="../common/output" quiet="true"/>
+   </target>
+
+   <target name="sleep">
+      <echo message="Sleeping for ${sleep.interval} seconds ..."/>
+      <sleep seconds="${sleep.interval}"/>
+   </target>
+
+</project>
+


Property changes on: trunk/docs/examples/mdb-failure/build.xml
___________________________________________________________________
Name: svn:keywords
   + "Id LastChangedDate Author Revision"

Added: trunk/docs/examples/mdb-failure/do-not-distribute.properties
===================================================================
--- trunk/docs/examples/mdb-failure/do-not-distribute.properties	                        (rev 0)
+++ trunk/docs/examples/mdb-failure/do-not-distribute.properties	2007-02-16 07:30:31 UTC (rev 2337)
@@ -0,0 +1,9 @@
+#
+# This file provides values for in-workarea example testing.
+# DO NOT DISTRIBUTE!
+#
+messaging.client.jar.path=../../../output/lib
+messaging.client.jar.name=jboss-messaging-client.jar
+#jboss.configuration=default
+jboss.configuration=messaging
+

Added: trunk/docs/examples/mdb-failure/etc/META-INF/ejb-jar.xml
===================================================================
--- trunk/docs/examples/mdb-failure/etc/META-INF/ejb-jar.xml	                        (rev 0)
+++ trunk/docs/examples/mdb-failure/etc/META-INF/ejb-jar.xml	2007-02-16 07:30:31 UTC (rev 2337)
@@ -0,0 +1,26 @@
+<?xml version='1.0' encoding='UTF-8' ?>
+<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
+    "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
+
+<ejb-jar>
+    <enterprise-beans>
+        <message-driven>
+            <ejb-name>MDBFailureExample</ejb-name>
+            <ejb-class>org.jboss.example.jms.mdbfailure.MDBFailureExample</ejb-class>
+            <transaction-type>Container</transaction-type>
+            <message-driven-destination>
+               <destination-type>javax.jms.Queue</destination-type>
+            </message-driven-destination>
+        </message-driven>
+    </enterprise-beans>
+
+ <assembly-descriptor>
+        <container-transaction>
+            <method>
+                <ejb-name>MDBFailureExample</ejb-name>
+                <method-name>*</method-name>
+            </method>
+            <trans-attribute>Required</trans-attribute>
+        </container-transaction>
+    </assembly-descriptor>
+</ejb-jar>
\ No newline at end of file


Property changes on: trunk/docs/examples/mdb-failure/etc/META-INF/ejb-jar.xml
___________________________________________________________________
Name: svn:keywords
   + "Id LastChangedDate Author Revision"

Added: trunk/docs/examples/mdb-failure/etc/META-INF/jboss.xml
===================================================================
--- trunk/docs/examples/mdb-failure/etc/META-INF/jboss.xml	                        (rev 0)
+++ trunk/docs/examples/mdb-failure/etc/META-INF/jboss.xml	2007-02-16 07:30:31 UTC (rev 2337)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE jboss PUBLIC
+   "-//JBoss//DTD JBOSS 3.0//EN"
+   "http://www.jboss.org/j2ee/dtd/jboss_3_0.dtd">
+<jboss>
+
+   <enterprise-beans>
+      <message-driven>
+         <ejb-name>MDBFailureExample</ejb-name>
+         <destination-jndi-name>queue/@QUEUE_NAME@</destination-jndi-name>
+      </message-driven>
+   </enterprise-beans>
+
+</jboss>


Property changes on: trunk/docs/examples/mdb-failure/etc/META-INF/jboss.xml
___________________________________________________________________
Name: svn:keywords
   + "Id LastChangedDate Author Revision"

Added: trunk/docs/examples/mdb-failure/etc/jndi.properties
===================================================================
--- trunk/docs/examples/mdb-failure/etc/jndi.properties	                        (rev 0)
+++ trunk/docs/examples/mdb-failure/etc/jndi.properties	2007-02-16 07:30:31 UTC (rev 2337)
@@ -0,0 +1,4 @@
+### JBossNS properties
+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/docs/examples/mdb-failure/etc/log4j.xml
===================================================================
--- trunk/docs/examples/mdb-failure/etc/log4j.xml	                        (rev 0)
+++ trunk/docs/examples/mdb-failure/etc/log4j.xml	2007-02-16 07:30:31 UTC (rev 2337)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- $Id: log4j.xml 536 2005-12-22 06:28:39Z ovidiu $ -->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+   <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+      <param name="Target" value="System.out"/>
+      <param name="Threshold" value="INFO"/>
+      <layout class="org.apache.log4j.PatternLayout">
+         <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p @%t [%c{1}] %m%n"/>
+      </layout>
+   </appender>
+
+   <root>
+      <appender-ref ref="CONSOLE"/>
+   </root>
+
+</log4j:configuration>


Property changes on: trunk/docs/examples/mdb-failure/etc/log4j.xml
___________________________________________________________________
Name: svn:keywords
   + "Id LastChangedDate Author Revision"

Added: trunk/docs/examples/mdb-failure/src/org/jboss/example/jms/mdbfailure/MDBFailureExample.java
===================================================================
--- trunk/docs/examples/mdb-failure/src/org/jboss/example/jms/mdbfailure/MDBFailureExample.java	                        (rev 0)
+++ trunk/docs/examples/mdb-failure/src/org/jboss/example/jms/mdbfailure/MDBFailureExample.java	2007-02-16 07:30:31 UTC (rev 2337)
@@ -0,0 +1,198 @@
+/**
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.example.jms.mdbfailure;
+
+import javax.jms.*;
+import javax.ejb.MessageDrivenBean;
+import javax.ejb.MessageDrivenContext;
+import javax.ejb.EJBException;
+import javax.naming.InitialContext;
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
+ * @version <tt>$Revision: 849 $</tt>
+
+ * $Id: MDBFailureExample.java 849 2006-03-31 17:17:09Z ltexier $
+ */
+public class MDBFailureExample implements MessageDrivenBean, MessageListener
+{
+
+   private MessageDrivenContext ctx;
+
+   private ConnectionFactory cf = null;
+
+   private static Set messageIDs = new HashSet();
+
+   public void onMessage(Message m)
+   {
+      Session session = null;
+      Connection conn = null;
+
+      try
+      {
+
+         TextMessage tm = (TextMessage)m;
+
+         String text = tm.getText();
+
+         System.out.println("message " + text + " received");
+
+         System.out.println("message " + (tm.getJMSRedelivered() ? "" : "NOT ")+ "marked as \"redelivered\"");
+
+
+         // if it is the first time any of the MDB instances from the pool sees the message, the
+         // message will cause the MDB instance to "crash"
+
+         synchronized(messageIDs)
+         {
+            if (!messageIDs.contains(tm.getJMSMessageID()))
+            {
+               messageIDs.add(m.getJMSMessageID());
+
+               System.out.println("The message has \"broken\" our MDB ...");
+
+               // "crashing" the MDB. The exception won't be caught by our catch clause and it will
+               // bubble up
+
+               throw new RuntimeException("Unfortunate events happen ...");
+
+            }
+            else
+            {
+               System.out.println("The message is already \"known\", so let it be processed");
+            }
+         }
+
+         String result = process(text);
+         System.out.println("message processed, result: " + result);
+
+         conn = getConnection();
+         session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         Destination replyTo = m.getJMSReplyTo();
+         MessageProducer producer = session.createProducer(replyTo);
+         TextMessage reply = session.createTextMessage(result);
+
+         producer.send(reply);
+         producer.close();
+
+      }
+      catch(JMSException e)
+      {
+         ctx.setRollbackOnly();
+         e.printStackTrace();
+         System.out.println("The Message Driven Bean failed!");
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            try
+            {
+                closeConnection(conn);
+            }
+            catch(Exception e)
+            {
+                System.out.println("Could not close the connection!" +e);
+            }
+         }
+      }
+   }
+
+   private String process(String text)
+   {
+      // flip the string
+
+      String result = "";
+
+      for(int i = 0; i < text.length(); i++)
+      {
+         result = text.charAt(i) + result;
+      }
+      return result;
+   }
+
+   public Connection getConnection() throws JMSException
+   {
+
+        Connection connection = null;
+
+        try
+        {
+            connection = cf.createConnection();
+            connection.start();
+
+        }
+        catch(JMSException e)
+        {
+           if(connection != null)
+           {
+               closeConnection(connection);
+           }
+           System.out.println("Failed to get connection... exception is " + e);
+           throw e;
+        }
+
+        return connection;
+    }
+
+    public void closeConnection(Connection con) throws JMSException
+    {
+
+       try
+       {
+           con.close();
+
+       }
+       catch(JMSException jmse)
+       {
+           System.out.println("Could not close connection " + con +" exception was " +jmse);
+           throw jmse;
+       }
+    }
+
+    public void ejbCreate()
+    {
+       try
+       {
+          InitialContext ic = new InitialContext();
+
+          cf = (ConnectionFactory)ic.lookup("java:/JmsXA");
+
+          ic.close();
+       }
+       catch(Exception e)
+       {
+          e.printStackTrace();
+          throw new EJBException("Failure to get connection factory: " + e.getMessage());
+       }
+    }
+
+    public void ejbRemove() throws EJBException
+    {
+       try
+       {
+          if(cf != null)
+          {
+              cf = null;
+          }
+       }
+       catch(Exception e)
+       {
+          throw new EJBException("ejbRemove", e);
+       }
+    }
+
+    public void setMessageDrivenContext(MessageDrivenContext ctx)
+    {
+       this.ctx = ctx;
+    }
+
+
+}


Property changes on: trunk/docs/examples/mdb-failure/src/org/jboss/example/jms/mdbfailure/MDBFailureExample.java
___________________________________________________________________
Name: svn:keywords
   + "Id LastChangedDate Author Revision"

Added: trunk/docs/examples/mdb-failure/src/org/jboss/example/jms/mdbfailure/Sender.java
===================================================================
--- trunk/docs/examples/mdb-failure/src/org/jboss/example/jms/mdbfailure/Sender.java	                        (rev 0)
+++ trunk/docs/examples/mdb-failure/src/org/jboss/example/jms/mdbfailure/Sender.java	2007-02-16 07:30:31 UTC (rev 2337)
@@ -0,0 +1,142 @@
+/*
+* 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.
+*/
+package org.jboss.example.jms.mdbfailure;
+
+import org.jboss.example.jms.common.ExampleSupport;
+
+import javax.naming.InitialContext;
+import javax.jms.ConnectionFactory;
+import javax.jms.Connection;
+import javax.jms.Session;
+import javax.jms.MessageProducer;
+import javax.jms.TextMessage;
+import javax.jms.Queue;
+import javax.jms.MessageConsumer;
+
+/**
+ * This example deploys a simple Message Driven Bean that processes messages sent to a test queue.
+ * The MDB container is configured to use CMT.
+ *
+ * We send a special tagged message (we do this by adding a custom property to the message) to the
+ * MDB. The MDB is programmed to "fail" when handling such a message, by throwing a
+ * RuntimeException, but not before "clearing" the failure-inducing tag.
+ *
+ * The expected behavior for the JMS provider is to redeliver the message, this time without the
+ * "failure tag". The MDB is supposed to process it and put it on response queue, from were it will
+ * be read by the client.
+ *
+ * The example is considered successful if the client receives the "processed" message.
+ *
+ * Since this example is also used by the smoke test, it is essential that the VM exits with exit
+ * code 0 in case of successful execution and a non-zero value on failure.
+ *
+ * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
+ * @version <tt>$Revision: 884 $</tt>
+ *
+ * $Id: Sender.java 884 2006-04-12 01:04:10Z ovidiu $
+ */
+public class Sender extends ExampleSupport
+{
+   public void example() throws Exception
+   {
+
+      String destinationName = getDestinationJNDIName();
+
+      InitialContext ic = new InitialContext();
+
+      ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
+      Queue queue = (Queue)ic.lookup(destinationName);
+
+
+
+      log("Queue " + destinationName + " exists");
+
+
+
+      Connection connection = cf.createConnection();
+      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      MessageProducer sender = session.createProducer(queue);
+
+
+
+      Queue temporaryQueue = session.createTemporaryQueue();
+      MessageConsumer consumer = session.createConsumer(temporaryQueue);
+
+
+
+      TextMessage message = session.createTextMessage("Hello!");
+      message.setJMSReplyTo(temporaryQueue);
+
+
+
+      sender.send(message);
+
+
+
+      log("The \"" + message.getText() + "\" message was successfully sent to the " + queue.getQueueName() + " queue");
+
+
+
+      connection.start();
+
+
+
+      message = (TextMessage)consumer.receive(5000);
+
+
+      if (message == null)
+      {
+         throw new Exception("Have not received any reply. The example failed!");
+      }
+
+
+      log("Received message: " + message.getText());
+
+
+
+      assertEquals("!olleH", message.getText());
+
+
+
+      displayProviderInfo(connection.getMetaData());
+
+
+      connection.close();
+   }
+
+
+
+
+   protected boolean isQueueExample()
+   {
+      return true;
+   }
+
+
+
+
+   public static void main(String[] args)
+   {
+      new Sender().run();
+   }
+
+}


Property changes on: trunk/docs/examples/mdb-failure/src/org/jboss/example/jms/mdbfailure/Sender.java
___________________________________________________________________
Name: svn:keywords
   + "Id LastChangedDate Author Revision"

Modified: trunk/tests/smoke/build.xml
===================================================================
--- trunk/tests/smoke/build.xml	2007-02-16 07:26:01 UTC (rev 2336)
+++ trunk/tests/smoke/build.xml	2007-02-16 07:30:31 UTC (rev 2337)
@@ -30,6 +30,7 @@
    <property name="run.queue.example" value="true"/>
    <property name="run.topic.example" value="true"/>
    <property name="run.mdb.example" value="true"/>
+   <property name="run.mdb-failure.example" value="true"/>
    <property name="run.http.example" value="true"/>
    <property name="run.stateless.example" value="true"/>
    <property name="run.ejb3mdb.example" value="false"/>
@@ -144,6 +145,7 @@
          <param name="jboss.home" value="${jboss403SP1.home}"/>
          <param name="release.admin.target" value="standalone"/>
          <param name="run.mdb.example" value="false"/>
+         <param name="run.mdb-failure.example" value="false"/>
          <param name="run.stateless.example" value="false"/>
          <param name="run.secure-socket.example" value="false"/>
       </antcall>
@@ -165,6 +167,7 @@
          <param name="jboss.home" value="${jboss404GA.home}"/>
          <param name="release.admin.target" value="standalone"/>
          <param name="run.mdb.example" value="false"/>
+         <param name="run.mdb-failure.example" value="false"/>
          <param name="run.stateless.example" value="false"/>
          <param name="run.secure-socket.example" value="false"/>
       </antcall>
@@ -185,6 +188,7 @@
          <param name="jboss.home" value="${jboss405GA.home}"/>
          <param name="release.admin.target" value="standalone"/>
          <param name="run.mdb.example" value="false"/>
+         <param name="run.mdb-failure.example" value="false"/>
          <param name="run.stateless.example" value="false"/>
          <param name="run.secure-socket.example" value="false"/>
       </antcall>
@@ -205,7 +209,6 @@
       <!--                                                       -->
       <!-- ====================================================  -->
 
-
       <!--
 
            http://jira.jboss.com/jira/browse/JBMESSAGING-427
@@ -320,6 +323,12 @@
       </antcall>
 
       <antcall target="run-example">
+         <param name="example.name" value="mdb-failure"/>
+         <param name="example.queue.name" value="SmokeTestQueue"/>
+         <param name="jboss.home" value="${jboss.home}"/>
+      </antcall>
+
+      <antcall target="run-example">
          <param name="example.name" value="stateless"/>
          <param name="example.queue.name" value="SmokeTestQueue"/>
          <param name="jboss.home" value="${jboss.home}"/>
@@ -494,6 +503,13 @@
       </antcall>
 
       <antcall target="run-example">
+         <param name="example.name" value="mdb-failure"/>
+         <param name="example.queue.name" value="SmokeTestQueue"/>
+         <param name="jboss.configuration" value="${jboss.configuration}-node0"/>
+         <param name="clustered" value="true"/>
+      </antcall>
+
+      <antcall target="run-example">
          <param name="example.name" value="stateless"/>
          <param name="example.queue.name" value="SmokeTestQueue"/>
          <param name="jboss.configuration" value="${jboss.configuration}-node0"/>
@@ -582,6 +598,10 @@
                <istrue value="${run.mdb.example}"/>
             </and>
             <and>
+               <equals arg1="${example.name}" arg2="mdb-failure"/>
+               <istrue value="${run.mdb-failure.example}"/>
+            </and>
+            <and>
                <equals arg1="${example.name}" arg2="stateless"/>
                <istrue value="${run.stateless.example}"/>
             </and>




More information about the jboss-cvs-commits mailing list