Author: ptahchiev
Date: Thu May 22 10:38:54 2008
New Revision: 659171

URL: http://svn.apache.org/viewvc?rev=659171&view=rev
Log:
Initial JMS components added.

Added:
    
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/JmsRequest.java
   (with props)
    
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/JmsTestCase.java
   (with props)
    
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/ServiceDefinition.java
   (with props)
    
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/internal/client/connector/http/JmsProtocolHandler.java
   (with props)
    
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/internal/client/connector/http/JmsProtocolState.java
   (with props)
    
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/internal/client/jms/
    
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/internal/client/jms/JmsClient.java
   (with props)
    
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/internal/client/jms/JmsClientHelper.java
   (with props)
    
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/spi/server/MessageDrivenBeanImplicitObjects.java
   (with props)
    
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/spi/server/MessageDrivenBeanRedirector.java
   (with props)
    
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/util/JmsConfiguration.java
   (with props)

Added: 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/JmsRequest.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/JmsRequest.java?rev=659171&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/JmsRequest.java
 (added)
+++ 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/JmsRequest.java
 Thu May 22 10:38:54 2008
@@ -0,0 +1,135 @@
+/* 
+ * ========================================================================
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * ========================================================================
+ */
+package org.apache.cactus;
+
+import javax.jms.QueueSession;
+import javax.jms.Message;
+import javax.jms.TextMessage;
+import javax.jms.JMSException;
+
+import org.apache.cactus.util.ChainedRuntimeException;
+
+/**
+ * Contains all JMS request data for a test case. It is the data that
+ * will be sent to the server redirector and that will be available to the test
+ * methods.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
+ *
+ * @since 1.4
+ *
+ * @version $Id$
+ */
+public class JmsRequest implements Request
+{
+    /**
+     * The JMS Queue Session that will be used to send JMS messages to the
+     * server side.
+     */
+    private QueueSession queueSession;
+
+    /**
+     * The JNDI queue name  of the queue to use to send the JMS message.
+     */
+    private String queueName;
+
+    /**
+     * The Message to send.
+     */
+    private Message message;
+
+    /**
+     * @param theQueueSession the JMS Queue Session that we will use to send
+     *        JMS messages to the server side
+     */
+    public JmsRequest(QueueSession theQueueSession)
+    {
+        this.queueSession = theQueueSession;
+    }
+
+    /**
+     * @return the Queue Session that is used to send messages to the server
+     *         side
+     */
+    private QueueSession getQueueSession()
+    {
+        return this.queueSession;
+    }
+
+    /**
+     * Creates a text message with a text.
+     *
+     * @param theText the text message
+     * @return the created text message
+     */
+    public TextMessage createTextMessage(String theText)
+    {
+        try {
+            this.message = getQueueSession().createTextMessage(theText);
+        } catch (JMSException e) {
+            throw new ChainedRuntimeException(
+                "Failed to create text message", e);
+        }
+        return (TextMessage) this.message;
+    }
+
+    /**
+     * Creates an empty text message.
+     *
+     * @return the created text message
+     */
+    public TextMessage createTextMessage()
+    {
+        try {
+            this.message = getQueueSession().createTextMessage();
+        } catch (JMSException e) {
+            throw new ChainedRuntimeException(
+                "Failed to create text message", e);
+        }
+        return (TextMessage) this.message;
+    }
+
+    /**
+     * @return the JMS Message to send
+     */
+    public Message getMessage()
+    {
+        return this.message;
+    }
+
+    /**
+     * Sets the Queue name to use to send the JMS message.
+     *
+     * @param theQueueName the JNDI queue name
+     */
+    public void setQueueName(String theQueueName)
+    {
+        this.queueName = theQueueName;
+    }
+
+    /**
+     * @return the JNDI queue name to use to send the JMS message
+     */
+    public String getQueueName()
+    {
+        return this.queueName;
+    }
+}

Propchange: 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/JmsRequest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/JmsTestCase.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/JmsTestCase.java?rev=659171&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/JmsTestCase.java
 (added)
+++ 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/JmsTestCase.java
 Thu May 22 10:38:54 2008
@@ -0,0 +1,99 @@
+/* 
+ * ========================================================================
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * ========================================================================
+ */
+package org.apache.cactus;
+
+import javax.jms.Message;
+import javax.ejb.MessageDrivenContext;
+
+import junit.framework.Test;
+
+import org.apache.cactus.internal.AbstractCactusTestCase;
+import org.apache.cactus.internal.client.connector.http.JmsProtocolHandler;
+import org.apache.cactus.spi.client.connector.ProtocolHandler;
+import org.apache.cactus.util.JmsConfiguration;
+
+/**
+ * TestCase class to test Message Driven Beans (or any JMS listener for that
+ * matter).
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
+ *
+ * @since 1.4
+ *
+ * @version $Id$
+ */
+public class JmsTestCase extends AbstractCactusTestCase
+{
+    /**
+     * Valid <code>Message</code> object that you can access from
+     * the <code>testXXX()</code>, <code>setUp</code> and
+     * <code>tearDown()</code> methods. If you try to access it from either the
+     * <code>beginXXX()</code> or <code>endXXX()</code> methods it will
+     * have the <code>null</code> value.
+     */
+    public Message message;
+
+    /**
+     * Valid <code>MessageDrivenContext</code> object that you can access from
+     * the <code>testXXX()</code>, <code>setUp</code> and
+     * <code>tearDown()</code> methods. If you try to access it from either the
+     * <code>beginXXX()</code> or <code>endXXX()</code> methods it will
+     * have the <code>null</code> value.
+     */
+    public MessageDrivenContext context;
+    
+    /**
+     * @see AbstractCactusTestCase#AbstractCactusTestCase()
+     */
+    public JmsTestCase()
+    {
+        super();
+    }
+
+    /**
+     * Constructs a JUnit test case with the given name.
+     *
+     * @param theName the name of the test case
+     */
+    public JmsTestCase(String theName)
+    {
+        super(theName);
+    }
+    
+    /**
+     * Constructs a JUnit test case with the given name.
+     *
+     * @param theName the name of the test case
+     */
+    public JmsTestCase(String theName, Test theTest)
+    {
+        super(theName, theTest);
+    }
+
+    /**
+     * [EMAIL PROTECTED]
+     * @see AbstractCactusTestCase#createProtocolHandler()
+     */
+    protected ProtocolHandler createProtocolHandler()
+    {
+        return new JmsProtocolHandler(new JmsConfiguration());
+    }
+}

Propchange: 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/JmsTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/ServiceDefinition.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/ServiceDefinition.java?rev=659171&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/ServiceDefinition.java
 (added)
+++ 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/ServiceDefinition.java
 Thu May 22 10:38:54 2008
@@ -0,0 +1,67 @@
+/* 
+ * ========================================================================
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * ========================================================================
+ */
+package org.apache.cactus;
+
+/**
+ * Constants that define HTTP parameters required for defining a service that
+ * is performed by the <code>ServletTestRedirector</code> servlet.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
+ *
+ * @version $Id$
+ */
+public class ServiceDefinition
+{
+    /**
+     * Name of the parameter in the HTTP request that represents the name of 
the
+     * Test class to call. The name is voluntarily long so that it will not
+     * clash with a user-defined parameter.
+     */
+    public static final String CLASS_NAME_PARAM =
+        "Cactus_TestClass";
+
+    /**
+     * Name of the parameter in the HTTP request that represents the name of 
the
+     * Test method to call. The name is voluntarily long so that it will not
+     * clash with a user-defined parameter.
+     */
+    public static final String METHOD_NAME_PARAM =
+        "Cactus_TestMethod";
+
+    /**
+     * Name of the parameter in the HTTP request that specify if a session
+     * should be automatically created for the user or not.
+     */
+    public static final String AUTOSESSION_NAME_PARAM =
+        "Cactus_AutomaticSession";
+
+    /**
+     * Name of the parameter in the HTTP request that specify the service asked
+     * to the Redirector Servlet. It can be either to ask the Redirector 
Servlet
+     * to call the test method or to ask the Redirector Servlet to return the
+     * result of the last test.
+     *
+     * @see ServiceEnumeration
+     */
+    public static final String SERVICE_NAME_PARAM =
+        "Cactus_Service";
+
+}

Propchange: 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/ServiceDefinition.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/internal/client/connector/http/JmsProtocolHandler.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/internal/client/connector/http/JmsProtocolHandler.java?rev=659171&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/internal/client/connector/http/JmsProtocolHandler.java
 (added)
+++ 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/internal/client/connector/http/JmsProtocolHandler.java
 Thu May 22 10:38:54 2008
@@ -0,0 +1,92 @@
+package org.apache.cactus.internal.client.connector.http;
+
+import javax.jms.QueueSession;
+
+import junit.framework.Test;
+
+import org.apache.cactus.JmsRequest;
+import org.apache.cactus.Request;
+import org.apache.cactus.ServiceDefinition;
+import org.apache.cactus.internal.client.jms.JmsClient;
+import org.apache.cactus.internal.client.jms.JmsClientHelper;
+import org.apache.cactus.internal.util.JUnitVersionHelper;
+import org.apache.cactus.spi.client.ResponseObjectFactory;
+import org.apache.cactus.spi.client.connector.ProtocolHandler;
+import org.apache.cactus.spi.client.connector.ProtocolState;
+import org.apache.cactus.util.JmsConfiguration;
+
+public class JmsProtocolHandler implements ProtocolHandler
+{
+    /**
+     * Cactus configuration data to use. In particular contains useful 
+     * configuration data for the HTTP connector (e.g. redirector URL).
+     */
+    private JmsConfiguration configuration;
+    
+    private QueueSession session;
+
+    /**
+     * @param theConfiguration configuration data
+     */
+    public JmsProtocolHandler(JmsConfiguration theConfiguration)
+    {
+        this.configuration = theConfiguration;
+    }
+    
+       public void afterTest(ProtocolState theState) throws Exception 
+       {
+               // We simply do nothing here.           
+       }
+
+       public Request createRequest() {
+               return new JmsRequest(session);
+       }
+
+       public ResponseObjectFactory createResponseObjectFactory(
+                       ProtocolState theState) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       public ProtocolState runTest(Test theDelegatedTest, Test theWrappedTest,
+                       Request theRequest) throws Throwable 
+       {
+        // Create the JMS Request object and creates necessary JMS objects
+        // so that the user can get them in his beginXXX method, so that he
+        // can create the message to send.
+        JmsRequest request = new JmsRequest(
+            JmsClientHelper.getQueueSession());
+
+        // Add Cactus information to the JMS Message
+        request.getMessage().setStringProperty(
+            ServiceDefinition.CLASS_NAME_PARAM, 
theDelegatedTest.getClass().getName());
+        request.getMessage().setStringProperty(
+            ServiceDefinition.METHOD_NAME_PARAM, 
(getCurrentTestName(theDelegatedTest)));
+
+        // Start the test
+        new JmsClient().doTest(request);
+        
+        return new JmsProtocolState();
+       }
+       
+       
+    /**
+     * @return configuration data
+     */
+    private JmsConfiguration getConfiguration()
+    {
+        return this.configuration;
+    }
+    
+    /**
+     * @param theDelegatedTest the Cactus test to execute
+     * @return the name of the current test case being executed (it corresponds
+     *         to the name of the test method with the "test" prefix removed.
+     *         For example, for "testSomeTestOk" would return "someTestOk".
+     */
+    private String getCurrentTestName(Test theDelegatedTest)
+    {
+        return JUnitVersionHelper.getTestCaseName(theDelegatedTest);        
+    }
+
+}
\ No newline at end of file

Propchange: 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/internal/client/connector/http/JmsProtocolHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/internal/client/connector/http/JmsProtocolState.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/internal/client/connector/http/JmsProtocolState.java?rev=659171&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/internal/client/connector/http/JmsProtocolState.java
 (added)
+++ 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/internal/client/connector/http/JmsProtocolState.java
 Thu May 22 10:38:54 2008
@@ -0,0 +1,25 @@
+/* 
+ * ========================================================================
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * ========================================================================
+ */
+package org.apache.cactus.internal.client.connector.http;
+
+import org.apache.cactus.spi.client.connector.ProtocolState;
+
+public class JmsProtocolState implements ProtocolState {}

Propchange: 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/internal/client/connector/http/JmsProtocolState.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/internal/client/jms/JmsClient.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/internal/client/jms/JmsClient.java?rev=659171&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/internal/client/jms/JmsClient.java
 (added)
+++ 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/internal/client/jms/JmsClient.java
 Thu May 22 10:38:54 2008
@@ -0,0 +1,61 @@
+/* 
+ * ========================================================================
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * ========================================================================
+ */
+package org.apache.cactus.internal.client.jms;
+
+import javax.jms.QueueSender;
+
+import org.apache.cactus.JmsRequest;
+
+/**
+ * JMS class for performing the steps necessary to run a test. It involves
+ * sending a first JMS message to a queue on which the Cactus MDB Redirector
+ * is listening.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
+ *
+ * @since 1.4
+ *
+ * @version $Id$
+ */
+public class JmsClient
+{
+    /**
+     * Calls the test method indirectly by calling the Redirector MDB (by
+     * sending a JMS Message on a queue it is listening to).
+     *
+     * @param theRequest the request containing data to be sent using JMS to
+     *        the server side
+     * @exception Throwable if an error occured in the test method or in the
+     *                      redirector servlet.
+     */
+    public void doTest(JmsRequest theRequest) throws Throwable
+    {
+        // 1 - Create a sender
+        QueueSender sender =
+            JmsClientHelper.createQueueSender(theRequest.getQueueName());
+
+        this.getClass().getName();
+        
+        
+        // 2 - Send the JMS Message
+        sender.send(theRequest.getMessage());
+    }
+}

Propchange: 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/internal/client/jms/JmsClient.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/internal/client/jms/JmsClientHelper.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/internal/client/jms/JmsClientHelper.java?rev=659171&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/internal/client/jms/JmsClientHelper.java
 (added)
+++ 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/internal/client/jms/JmsClientHelper.java
 Thu May 22 10:38:54 2008
@@ -0,0 +1,176 @@
+/* 
+ * ========================================================================
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * ========================================================================
+ */
+package org.apache.cactus.internal.client.jms;
+
+import java.util.Hashtable;
+import javax.jms.QueueConnection;
+import javax.jms.JMSException;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.Queue;
+import javax.jms.QueueSender;
+import javax.naming.InitialContext;
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import org.apache.cactus.util.JmsConfiguration;
+import org.apache.cactus.util.ChainedRuntimeException;
+
+/**
+ * Helper class to send a JMS message.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
+ *
+ * @since 1.4
+ *
+ * @version $Id$
+ */
+public class JmsClientHelper
+{
+    /**
+     * The JMS queue session used to send messages to the server side.
+     */
+    private static QueueSession queueSession;
+
+    /**
+     * Create a JMS Queue Connection to be able to send messages later on.
+     *
+     * @return the created queue connection
+     * @exception JMSException if an error occurred
+     */
+    protected static QueueConnection createQueueConnection()
+        throws JMSException
+    {
+        QueueConnection queueConnection =
+            getQueueConnnectionFactory().createQueueConnection();
+        return queueConnection;
+    }
+
+    /**
+     * Return the Queue session that we will use to send all JMS messages
+     * (the Session is created if it is the first time this method is
+     * called).
+     *
+     * @return the created Queue Session
+     */
+    public static synchronized QueueSession getQueueSession()
+    {
+        if (queueSession == null) {
+            try {
+                queueSession =
+                    createQueueConnection().createQueueSession(false,
+                        Session.AUTO_ACKNOWLEDGE);
+            } catch (JMSException e) {
+                throw new ChainedRuntimeException(
+                    "Failed to create JMS Queue Session", e);
+            }
+        }
+        return queueSession;
+    }
+
+    /**
+     * @return the JNDI Initial Context as defined in the Cactus configuration
+     *         file (used to retrieve the JMS Queue Connection Factory)
+     */
+    public static InitialContext getInitialContext()
+    {
+        InitialContext context = null;
+        try {
+            Hashtable env = new Hashtable();
+            env.put(Context.INITIAL_CONTEXT_FACTORY,
+                JmsConfiguration.getJndiInitialContextFactory());
+            env.put(Context.PROVIDER_URL,
+                JmsConfiguration.getJndiProviderURL());
+            env.put(Context.SECURITY_PRINCIPAL,
+                JmsConfiguration.getJndiSecurityPrincipal());
+            env.put(Context.SECURITY_CREDENTIALS,
+                JmsConfiguration.getJndiSecurityCredentials());
+            context = new InitialContext(env);
+        } catch (NamingException e) {
+            throw new ChainedRuntimeException(
+                "Failed to create JNDI initial context", e);
+        }
+
+        return context;
+    }
+
+    /**
+     * @return the JMS Queue Connection Factory from which to retrieve Queues
+     */
+    public static QueueConnectionFactory getQueueConnnectionFactory()
+    {
+        QueueConnectionFactory queueConnectionFactory = null;
+        try {
+            queueConnectionFactory =
+                (QueueConnectionFactory) (getInitialContext().
+                    
lookup(JmsConfiguration.getJmsConnectionFactoryJndiName()));
+        } catch (NamingException e) {
+            throw new ChainedRuntimeException(
+                "Failed to lookup [" +
+                JmsConfiguration.getJmsConnectionFactoryJndiName() +
+                "] Connection Factory in JNDI", e);
+        }
+
+        return queueConnectionFactory;
+    }
+
+    /**
+     * Lookup a queue in JNDI.
+     *
+     * @param theQueueName the JNDI name of the queue to look up
+     * @return the queue object
+     */
+    public static Queue getQueue(String theQueueName)
+    {
+        Queue queue = null;
+        try {
+            queue = (Queue) (getInitialContext().lookup(theQueueName));
+        } catch (NamingException e) {
+            throw new ChainedRuntimeException(
+                "Failed to lookup [" + theQueueName + "] Queue in JNDI", e);
+        }
+        return queue;
+    }
+
+    /**
+     * Creates a Queue Sender to send JMS messages.
+     *
+     * @param theQueueName the JNDI name of the queue to use to send messages
+     * @return the queue sender object
+     */
+    public static QueueSender createQueueSender(String theQueueName)
+    {
+        Queue queue = getQueue(theQueueName);
+        QueueSession queueSession = getQueueSession();
+
+        QueueSender queueSender = null;
+        try {
+            queueSender = queueSession.createSender(queue);
+        } catch (JMSException e) {
+            throw new ChainedRuntimeException("Failed to create queue sender" +
+                "for queue [" + queue + "]", e);
+        }
+
+        return queueSender;
+    }
+
+}

Propchange: 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/internal/client/jms/JmsClientHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/spi/server/MessageDrivenBeanImplicitObjects.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/spi/server/MessageDrivenBeanImplicitObjects.java?rev=659171&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/spi/server/MessageDrivenBeanImplicitObjects.java
 (added)
+++ 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/spi/server/MessageDrivenBeanImplicitObjects.java
 Thu May 22 10:38:54 2008
@@ -0,0 +1,80 @@
+/* 
+ * ========================================================================
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * ========================================================================
+ */
+package org.apache.cactus.spi.server;
+
+import javax.jms.Message;
+import javax.ejb.MessageDrivenContext;
+
+/**
+ * Implicit objects for the Message Driven Bean redirector.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
+ *
+ * @version $Id$
+ */
+public class MessageDrivenBeanImplicitObjects implements ImplicitObjects
+{
+    /**
+     * The JMS Message to process.
+     */
+    private Message message;
+
+    /**
+     * The Message Driven Bean context.
+     */
+    private MessageDrivenContext context;
+
+    /**
+     * Sets the JMS Message as retrieved by the Cactus redirector.
+     *
+     * @param theMessage the JMS Message
+     */
+    public void setMessage(Message theMessage)
+    {
+        this.message = theMessage;
+    }
+
+    /**
+     * @return the JMS Message as retrieved by the Cactus redirector.
+     */
+    public Message getMessage()
+    {
+        return this.message;
+    }
+
+    /**
+     * Sets the Message Driven Bean context as set by the J2EE container.
+     *
+     * @param theContext the MDB context
+     */
+    public void setMessageDrivenBeanContext(MessageDrivenContext theContext)
+    {
+        this.context = theContext;
+    }
+
+    /**
+     * @return the MDB context
+     */
+    public MessageDrivenContext getMessageDrivenBeanContext()
+    {
+        return this.context;
+    }
+}

Propchange: 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/spi/server/MessageDrivenBeanImplicitObjects.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/spi/server/MessageDrivenBeanRedirector.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/spi/server/MessageDrivenBeanRedirector.java?rev=659171&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/spi/server/MessageDrivenBeanRedirector.java
 (added)
+++ 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/spi/server/MessageDrivenBeanRedirector.java
 Thu May 22 10:38:54 2008
@@ -0,0 +1,91 @@
+/* 
+ * ========================================================================
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * ========================================================================
+ */
+package org.apache.cactus.spi.server;
+
+import javax.ejb.MessageDrivenBean;
+import javax.ejb.MessageDrivenContext;
+import javax.ejb.CreateException;
+import javax.jms.Message;
+
+/**
+ * Generic Message Driven Bean redirector that calls a test method on the
+ * server side.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
+ *
+ * @since 1.4
+ *
+ * @version $Id$
+ */
+public class MessageDrivenBeanRedirector implements MessageDrivenBean
+{
+    /**
+     * The Message context.
+     */
+    private MessageDrivenContext context;
+
+    /**
+     * Sets the Message context (automatically called by the container).
+     *
+     * @param theContext the Message context
+     */
+    public void setMessageDrivenContext(MessageDrivenContext theContext)
+    {
+        this.context = theContext;
+    }
+
+    /**
+     * Called by the container to create an instance of this Message Driven
+     * bean.
+     *
+     * @exception CreateException see the EJB specification
+     */
+    public void ejbCreate() throws CreateException
+    {
+    }
+
+    /**
+     * The container invokes this method when the instance is about to be
+     * discarded. This might happens if the container needs to reduce the size
+     * of the pool.
+     */
+    public void ejbRemove()
+    {
+    }
+
+    /**
+     * Receives a message from a JMS Queue and make it available to the
+     * test case.
+     *
+     * @param theMessage the JMS Message
+     */
+    public void onMessage(Message theMessage)
+    {
+        // Gather MDB implicit objects
+        MessageDrivenBeanImplicitObjects implicitObjects =
+            new MessageDrivenBeanImplicitObjects();
+        implicitObjects.setMessage(theMessage);
+        implicitObjects.setMessageDrivenBeanContext(this.context);
+
+        // Call the controller to handle the message
+    }
+
+}

Propchange: 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/spi/server/MessageDrivenBeanRedirector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/util/JmsConfiguration.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/util/JmsConfiguration.java?rev=659171&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/util/JmsConfiguration.java
 (added)
+++ 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/util/JmsConfiguration.java
 Thu May 22 10:38:54 2008
@@ -0,0 +1,122 @@
+/* 
+ * ========================================================================
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * ========================================================================
+ */
+package org.apache.cactus.util;
+
+import org.apache.cactus.internal.configuration.ConfigurationInitializer;
+
+/**
+ * Provides access to the Cactus configuration parameters related to the
+ * JMS Redirector.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
+ *
+ * @since 1.4
+ *
+ * @version $Id$
+ */
+public class JmsConfiguration extends ConfigurationInitializer
+{
+    /**
+     * @return the JNDI Server Initial Context Factory class (from which the
+     *         Queue connection factory will be retrieved)
+     */
+    public static String getJndiInitialContextFactory()
+    {
+        initialize();
+
+        String property =
+            System.getProperty("cactus.jndi.initialContextFactory");
+        if (property == null) {
+            new ChainedRuntimeException("Missing Cactus property [" +
+                "cactus.jndi.initialContextFactory" + "]");
+        }
+        return property;
+    }
+
+    /**
+     * @return the JNDI Server URL (from which the Queue connection factory
+     *         will be retrieved)
+     */
+    public static String getJndiProviderURL()
+    {
+        initialize();
+
+        String property =
+            System.getProperty("cactus.jndi.providerUrl");
+        if (property == null) {
+            new ChainedRuntimeException("Missing Cactus property [" +
+                "cactus.jndi.providerUrl" + "]");
+        }
+        return property;
+    }
+
+    /**
+     * @return the JNDI Server user name (from which the Queue connection
+     *         factory will be retrieved)
+     */
+    public static String getJndiSecurityPrincipal()
+    {
+        initialize();
+
+        String property =
+            System.getProperty("cactus.jndi.securityPrincipal");
+        if (property == null) {
+            new ChainedRuntimeException("Missing Cactus property [" +
+                "cactus.jndi.securityPrincipal" + "]");
+        }
+        return property;
+    }
+
+    /**
+     * @return the JNDI Server user password (from which the Queue connection
+     *         factory will be retrieved)
+     */
+    public static String getJndiSecurityCredentials()
+    {
+        initialize();
+
+        String property =
+            System.getProperty("cactus.jndi.securityCredentials");
+        if (property == null) {
+            new ChainedRuntimeException("Missing Cactus property [" +
+                "cactus.jndi.securityCredentials" + "]");
+        }
+        return property;
+    }
+
+    /**
+     * @return the JNDI Name for the JMS Connection Factory to use (ex:
+     *         "javax.jms.QueueConnectionFactory")
+     */
+    public static String getJmsConnectionFactoryJndiName()
+    {
+        initialize();
+
+        String property =
+            System.getProperty("cactus.jms.connectionFactoryJndiName");
+        if (property == null) {
+            new ChainedRuntimeException("Missing Cactus property [" +
+                "cactus.jms.connectionFactoryJndiName" + "]");
+        }
+        return property;
+    }
+
+}

Propchange: 
jakarta/cactus/trunk/framework/framework-12-13-14/src/main/java/org/apache/cactus/util/JmsConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to