You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2008/11/07 01:17:51 UTC

svn commit: r712018 - in /jakarta/jmeter/trunk: bin/ src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/ xdocs/ xdocs/usermanual/

Author: sebb
Date: Thu Nov  6 16:17:46 2008
New Revision: 712018

URL: http://svn.apache.org/viewvc?rev=712018&view=rev
Log:
Bug 45458 - Point to Point JMS in combination with authentication

Modified:
    jakarta/jmeter/trunk/bin/jmeter.properties
    jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java
    jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/Receiver.java
    jakarta/jmeter/trunk/xdocs/changes.xml
    jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml

Modified: jakarta/jmeter/trunk/bin/jmeter.properties
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/bin/jmeter.properties?rev=712018&r1=712017&r2=712018&view=diff
==============================================================================
--- jakarta/jmeter/trunk/bin/jmeter.properties (original)
+++ jakarta/jmeter/trunk/bin/jmeter.properties Thu Nov  6 16:17:46 2008
@@ -634,6 +634,11 @@
 # Set to 0 to disable the size check
 #view.results.tree.max_size=0
 
+#JMS options
+# Enable the following property to stop JMS Point-to-Point Sampler from using
+# the properties java.naming.security.[principal|credentials] when creating the queue connection
+#JMSSampler.useSecurity.properties=false
+
 #---------------------------------------------------------------------------
 # Classpath configuration
 #---------------------------------------------------------------------------

Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java?rev=712018&r1=712017&r2=712018&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java (original)
+++ jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java Thu Nov  6 16:17:46 2008
@@ -46,6 +46,7 @@
 import org.apache.jmeter.testelement.ThreadListener;
 import org.apache.jmeter.testelement.property.BooleanProperty;
 import org.apache.jmeter.testelement.property.TestElementProperty;
+import org.apache.jmeter.util.JMeterUtils;
 import org.apache.jorphan.logging.LoggingManager;
 import org.apache.log.Logger;
 
@@ -88,6 +89,10 @@
 
     //--
 
+    // Should we use java.naming.security.[principal|credentials] to create the QueueConnection?
+    private static final boolean USE_SECURITY_PROPERTIES = 
+        JMeterUtils.getPropDefault("JMSSampler.useSecurity.properties", true); // $NON-NLS-1$
+    
     //
     // Member variables
     //
@@ -277,15 +282,6 @@
         return getQueueConnectionFactory() + ", queue: " + getSendQueue();
     }
 
-    public synchronized void testStarted() {
-        LOGGER.debug("testStarted, thread: " + Thread.currentThread().getName());
-
-    }
-
-    public synchronized void testEnded() {
-        LOGGER.debug("testEndded(), thread: " + Thread.currentThread().getName());
-    }
-
     public void testIterationStart(LoopIterationEvent event) {
         // LOGGER.debug("testIterationStart");
     }
@@ -309,10 +305,20 @@
             sendQueue = queue;
             if (!useTemporyQueue()) {
                 receiveQueue = (Queue) context.lookup(getReceiveQueue());
-                receiverThread = Receiver.createReceiver(factory, receiveQueue);
+                receiverThread = Receiver.createReceiver(factory, receiveQueue, getPrincipal(context), getCredentials(context));
             }
 
-            connection = factory.createQueueConnection();
+            String principal = null;
+            String credentials = null;
+            if (USE_SECURITY_PROPERTIES){
+                principal = getPrincipal(context);
+                credentials = getCredentials(context);                
+            }
+            if (principal != null && credentials != null) {
+                connection = factory.createQueueConnection(principal, credentials);
+            } else {
+                connection = factory.createQueueConnection();
+            }
 
             session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
 
@@ -485,4 +491,28 @@
 
     }
 
+    /**
+     * get the principal from the context property java.naming.security.principal
+     *
+     * @param context
+     * @return
+     * @throws NamingException
+     */
+    private String getPrincipal(Context context) throws NamingException{
+            Hashtable env = context.getEnvironment();
+            return (String) env.get("java.naming.security.principal"); // $NON-NLS-1$
+    }
+
+    /**
+     * get the credentials from the context property java.naming.security.credentials
+     *
+     * @param context
+     * @return
+     * @throws NamingException
+     */
+    private String getCredentials(Context context) throws NamingException{
+            Hashtable env = context.getEnvironment();
+            return (String) env.get("java.naming.security.credentials"); // $NON-NLS-1$
+    }
+
 }

Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/Receiver.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/Receiver.java?rev=712018&r1=712017&r2=712018&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/Receiver.java (original)
+++ jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/Receiver.java Thu Nov  6 16:17:46 2008
@@ -40,8 +40,14 @@
 
     // private static Receiver receiver;
 
-    private Receiver(QueueConnectionFactory factory, Queue receiveQueue) throws JMSException {
-        conn = factory.createQueueConnection();
+    private Receiver(QueueConnectionFactory factory, Queue receiveQueue, String principal, String credentials) throws JMSException {
+        if (null != principal && null != credentials) {
+            log.info("creating receiver WITH authorisation credentials");
+            conn = factory.createQueueConnection(principal, credentials);
+        }else{
+            log.info("creating receiver without authorisation credentials");
+            conn = factory.createQueueConnection(); 
+        }
         session = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
         consumer = session.createReceiver(receiveQueue);
         log.debug("Receiver - ctor. Starting connection now");
@@ -49,14 +55,12 @@
         log.info("Receiver - ctor. Connection to messaging system established");
     }
 
-    // TODO - does this need to be synchronized now that the variables are final?
-    public static synchronized Receiver createReceiver(QueueConnectionFactory factory, Queue receiveQueue)
+    public static Receiver createReceiver(QueueConnectionFactory factory, Queue receiveQueue,
+            String principal, String credentials)
             throws JMSException {
-        // if (receiver == null) {
-        Receiver receiver = new Receiver(factory, receiveQueue);
+        Receiver receiver = new Receiver(factory, receiveQueue, principal, credentials);
         Thread thread = new Thread(receiver);
         thread.start();
-        // }
         return receiver;
     }
 

Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=712018&r1=712017&r2=712018&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Thu Nov  6 16:17:46 2008
@@ -146,6 +146,7 @@
 <li>Bug 46142 - JMS Receiver now uses MessageID</li>
 <li>Bug 46148 - HTTP sampler fails on SSL requests when logging for jmeter.util is set to DEBUG</li>
 <li>TCP sampler now calls setupTest() and teardownTest() methods</li>
+<li>Bug 45458 - Point to Point JMS in combination with authentication</li>
 </ul>
 
 <h3>Improvements</h3>

Modified: jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=712018&r1=712017&r2=712018&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml Thu Nov  6 16:17:46 2008
@@ -1150,6 +1150,11 @@
 		This sampler sends and optionally receives JMS Messages through point-to-point connections (queues).
         It is different from pub/sub messages and is generally used for handling transactions.
 		</p>
+		<p>
+		Versions of JMeter after 2.3.2 use the properties java.naming.security.[principal|credentials] - if present -
+		when creating the Queue Connection. If this behaviour is not desired, set the JMeter property
+		<b>JMSSampler.useSecurity.properties=false</b>
+		</p>
 		<br></br>
 <note>JMeter does not include the JMS jar; this must be downloaded and put in the lib directory</note>
 	</description>



---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org