You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2014/03/01 00:06:53 UTC
svn commit: r1573108 - in /jmeter/trunk:
src/protocol/jms/org/apache/jmeter/protocol/jms/Utils.java
src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java
xdocs/changes.xml
Author: pmouawad
Date: Fri Feb 28 23:06:52 2014
New Revision: 1573108
URL: http://svn.apache.org/r1573108
Log:
Bug 56198 - JMSSampler : NullPointerException is thrown when JNDI underlying implementation of JMS provider does not comply with Context.getEnvironment contract
Apply check on every call of Context.getEnvironment
Bugzilla Id: 56198
Modified:
jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/Utils.java
jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java
jmeter/trunk/xdocs/changes.xml
Modified: jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/Utils.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/Utils.java?rev=1573108&r1=1573107&r2=1573108&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/Utils.java (original)
+++ jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/Utils.java Fri Feb 28 23:06:52 2014
@@ -19,6 +19,7 @@
package org.apache.jmeter.protocol.jms;
import java.util.Enumeration;
+import java.util.Hashtable;
import java.util.Map;
import javax.jms.Connection;
@@ -137,6 +138,29 @@ public final class Utils {
}
/**
+ * Get value from Context environment taking into account non fully compliant
+ * JNDI implementations
+ * @param context
+ * @param key
+ * @return String or null if context.getEnvironment() is not compliant
+ * @throws NamingException
+ */
+ public static final String getFromEnvironment(Context context, String key) throws NamingException {
+ try {
+ Hashtable<?,?> env = context.getEnvironment();
+ if(env != null) {
+ return (String) env.get(key);
+ } else {
+ log.warn("context.getEnvironment() returned null (should not happen according to javadoc but non compliant implementation can return this)");
+ return null;
+ }
+ } catch (javax.naming.OperationNotSupportedException ex) {
+ // Some JNDI implementation can return this
+ log.warn("context.getEnvironment() not supported by implementation ");
+ return null;
+ }
+ }
+ /**
* Obtain the queue connection from the context and factory name.
*
* @param ctx
@@ -153,11 +177,9 @@ public final class Utils {
throw new NamingException("Lookup failed: "+e.toString());
}
if (objfac instanceof javax.jms.ConnectionFactory) {
- @SuppressWarnings("unchecked") // The environment is supposed to use String keys only
- Map<String, Object> env = (Map<String, Object>)ctx.getEnvironment();
- if(env.containsKey(Context.SECURITY_PRINCIPAL)) {
- String username = (String)env.get(Context.SECURITY_PRINCIPAL);
- String password = (String)env.get(Context.SECURITY_CREDENTIALS);
+ String username = getFromEnvironment(ctx, Context.SECURITY_PRINCIPAL);
+ if(username != null) {
+ String password = getFromEnvironment(ctx, Context.SECURITY_CREDENTIALS);
return ((javax.jms.ConnectionFactory) objfac).createConnection(username, password);
}
else {
Modified: jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java?rev=1573108&r1=1573107&r2=1573108&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java (original)
+++ jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java Fri Feb 28 23:06:52 2014
@@ -19,7 +19,6 @@
package org.apache.jmeter.protocol.jms.sampler;
import java.util.Date;
-import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Map;
@@ -329,15 +328,16 @@ public class JMSSampler extends Abstract
if (!useTemporyQueue()) {
receiveQueue = (Queue) context.lookup(getReceiveQueue());
- receiverThread = Receiver.createReceiver(factory, receiveQueue, getPrincipal(context), getCredentials(context)
+ receiverThread = Receiver.createReceiver(factory, receiveQueue, Utils.getFromEnvironment(context, Context.SECURITY_PRINCIPAL),
+ Utils.getFromEnvironment(context, Context.SECURITY_CREDENTIALS)
, isUseResMsgIdAsCorrelId(), getJMSSelector());
}
String principal = null;
String credentials = null;
if (USE_SECURITY_PROPERTIES){
- principal = getPrincipal(context);
- credentials = getCredentials(context);
+ principal = Utils.getFromEnvironment(context, Context.SECURITY_PRINCIPAL);
+ credentials = Utils.getFromEnvironment(context, Context.SECURITY_CREDENTIALS);
}
if (principal != null && credentials != null) {
connection = factory.createQueueConnection(principal, credentials);
@@ -527,28 +527,4 @@ public class JMSSampler extends Abstract
setProperty(JNDI_CONTEXT_PROVIDER_URL, string);
}
-
- /**
- * get the principal from the context property java.naming.security.principal
- *
- * @param context
- * @return the principal
- * @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 the credentials
- * @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: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1573108&r1=1573107&r2=1573108&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Fri Feb 28 23:06:52 2014
@@ -130,7 +130,7 @@ A workaround is to use a Java 7 update 4
<ul>
<li><bugzilla>55977</bugzilla> - JDBC pook keepalive flooding</li>
<li><bugzilla>55999</bugzilla> - Scroll bar on jms point-to-point sampler does not work when content exceeds display</li>
-<li><bugzilla>56198</bugzilla> - JMSSampler : NullPointerException is thrown when log level is DEBUG and JNDI underlying implementation of JMS provider does not comply with Context.getEnvironment contract</li>
+<li><bugzilla>56198</bugzilla> - JMSSampler : NullPointerException is thrown when JNDI underlying implementation of JMS provider does not comply with Context.getEnvironment contract</li>
</ul>
<h3>Controllers</h3>