2011/08/05 - Jakarta Cactus has been retired.

For more information, please explore the Attic.

View Javadoc

1   /* 
2    * ========================================================================
3    * 
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   * 
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * 
19   * ========================================================================
20   */
21  package org.apache.cactus;
22  
23  import javax.jms.QueueSession;
24  import javax.jms.Message;
25  import javax.jms.TextMessage;
26  import javax.jms.JMSException;
27  
28  import org.apache.cactus.util.ChainedRuntimeException;
29  
30  /**
31   * Contains all JMS request data for a test case. It is the data that
32   * will be sent to the server redirector and that will be available to the test
33   * methods.
34   *
35   * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
36   *
37   * @since 1.4
38   *
39   * @version $Id$
40   */
41  public class JmsRequest implements Request
42  {
43      /**
44       * The JMS Queue Session that will be used to send JMS messages to the
45       * server side.
46       */
47      private QueueSession queueSession;
48  
49      /**
50       * The JNDI queue name  of the queue to use to send the JMS message.
51       */
52      private String queueName;
53  
54      /**
55       * The Message to send.
56       */
57      private Message message;
58  
59      /**
60       * @param theQueueSession the JMS Queue Session that we will use to send
61       *        JMS messages to the server side
62       */
63      public JmsRequest(QueueSession theQueueSession)
64      {
65          this.queueSession = theQueueSession;
66      }
67  
68      /**
69       * @return the Queue Session that is used to send messages to the server
70       *         side
71       */
72      private QueueSession getQueueSession()
73      {
74          return this.queueSession;
75      }
76  
77      /**
78       * Creates a text message with a text.
79       *
80       * @param theText the text message
81       * @return the created text message
82       */
83      public TextMessage createTextMessage(String theText)
84      {
85          try 
86          {
87              this.message = getQueueSession().createTextMessage(theText);
88          } 
89          catch (JMSException e) 
90          {
91              throw new ChainedRuntimeException(
92                  "Failed to create text message", e);
93          }
94          return (TextMessage) this.message;
95      }
96  
97      /**
98       * Creates an empty text message.
99       *
100      * @return the created text message
101      */
102     public TextMessage createTextMessage()
103     {
104         try 
105         {
106             this.message = getQueueSession().createTextMessage();
107         } 
108         catch (JMSException e) 
109         {
110             throw new ChainedRuntimeException(
111                 "Failed to create text message", e);
112         }
113         return (TextMessage) this.message;
114     }
115 
116     /**
117      * @return the JMS Message to send
118      */
119     public Message getMessage()
120     {
121         return this.message;
122     }
123 
124     /**
125      * Sets the Queue name to use to send the JMS message.
126      *
127      * @param theQueueName the JNDI queue name
128      */
129     public void setQueueName(String theQueueName)
130     {
131         this.queueName = theQueueName;
132     }
133 
134     /**
135      * @return the JNDI queue name to use to send the JMS message
136      */
137     public String getQueueName()
138     {
139         return this.queueName;
140     }
141 }