Author: sebb
Date: Wed Jan 20 23:49:12 2010
New Revision: 901444
URL: http://svn.apache.org/viewvc?rev=901444&view=rev
Log:
Bug 48573 - LDAPExtSampler directory context handling
Modified:
jakarta/jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/LDAPExtSampler.java
jakarta/jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/LdapExtClient.java
jakarta/jmeter/trunk/xdocs/changes.xml
Modified:
jakarta/jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/LDAPExtSampler.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/LDAPExtSampler.java?rev=901444&r1=901443&r2=901444&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/LDAPExtSampler.java
(original)
+++
jakarta/jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/LDAPExtSampler.java
Wed Jan 20 23:49:12 2010
@@ -33,7 +33,6 @@
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
-import javax.naming.directory.InitialDirContext;
import javax.naming.directory.ModificationItem;
import javax.naming.directory.SearchResult;
@@ -139,9 +138,6 @@
private static final String SEMI_COLON = ";"; // $NON-NLS-1$
- private static final Hashtable<String, LdapExtClient> ldapConnections =
- new Hashtable<String, LdapExtClient>();
-
private static final Hashtable<String, DirContext> ldapContexts =
new Hashtable<String, DirContext>();
@@ -603,10 +599,10 @@
* This will do the add test for the User defined TestCase
*
**************************************************************************/
- private void addTest(LdapExtClient ldap, DirContext dirContext,
SampleResult res) throws NamingException {
+ private void addTest(DirContext dirContext, SampleResult res) throws
NamingException {
try {
res.sampleStart();
- DirContext ctx = ldap.createTest(dirContext, getUserAttributes(),
getBaseEntryDN());
+ DirContext ctx = LdapExtClient.createTest(dirContext,
getUserAttributes(), getBaseEntryDN());
ctx.close(); // the createTest() method creates an extra context
which needs to be closed
} finally {
res.sampleEnd();
@@ -617,10 +613,10 @@
* This will do the delete test for the User defined TestCase
*
**************************************************************************/
- private void deleteTest(LdapExtClient ldap, DirContext dirContext,
SampleResult res) throws NamingException {
+ private void deleteTest(DirContext dirContext, SampleResult res) throws
NamingException {
try {
res.sampleStart();
- ldap.deleteTest(dirContext, getPropertyAsString(DELETE));
+ LdapExtClient.deleteTest(dirContext, getPropertyAsString(DELETE));
} finally {
res.sampleEnd();
}
@@ -630,10 +626,10 @@
* This will do the modify test for the User defined TestCase
*
**************************************************************************/
- private void modifyTest(LdapExtClient ldap, DirContext dirContext,
SampleResult res) throws NamingException {
+ private void modifyTest(DirContext dirContext, SampleResult res) throws
NamingException {
try {
res.sampleStart();
- ldap.modifyTest(dirContext, getUserModAttributes(),
getBaseEntryDN());
+ LdapExtClient.modifyTest(dirContext, getUserModAttributes(),
getBaseEntryDN());
} finally {
res.sampleEnd();
}
@@ -644,7 +640,7 @@
* the whole context
*
**************************************************************************/
- private void bindOp(LdapExtClient ldap, DirContext dirContext,
SampleResult res) throws NamingException {
+ private void bindOp(DirContext dirContext, SampleResult res) throws
NamingException {
DirContext ctx = ldapContexts.remove(getThreadName());
if (ctx != null) {
log.warn("Closing previous context for thread: " +
getThreadName());
@@ -652,7 +648,7 @@
}
try {
res.sampleStart();
- ctx = ldap.connect(getServername(), getPort(), getRootdn(),
getUserDN(), getUserPw(),getConnTimeOut(),isSecure());
+ ctx = LdapExtClient.connect(getServername(), getPort(),
getRootdn(), getUserDN(), getUserPw(),getConnTimeOut(),isSecure());
} finally {
res.sampleEnd();
}
@@ -664,12 +660,10 @@
*
**************************************************************************/
private void singleBindOp(SampleResult res) throws NamingException {
- LdapExtClient ldap_temp;
- ldap_temp = new LdapExtClient();
try {
res.sampleStart();
- DirContext ctx = ldap_temp.connect(getServername(), getPort(),
getRootdn(), getUserDN(), getUserPw(),getConnTimeOut(),isSecure());
- ldap_temp.disconnect(ctx);
+ DirContext ctx = LdapExtClient.connect(getServername(), getPort(),
getRootdn(), getUserDN(), getUserPw(),getConnTimeOut(),isSecure());
+ LdapExtClient.disconnect(ctx);
} finally {
res.sampleEnd();
}
@@ -679,10 +673,10 @@
* This will do a moddn Opp for the User new DN defined
*
**************************************************************************/
- private void renameTest(LdapExtClient ldap, DirContext dirContext,
SampleResult res) throws NamingException {
+ private void renameTest(DirContext dirContext, SampleResult res) throws
NamingException {
try {
res.sampleStart();
- ldap.moddnOp(dirContext, getPropertyAsString(MODDDN),
getPropertyAsString(NEWDN));
+ LdapExtClient.moddnOp(dirContext, getPropertyAsString(MODDDN),
getPropertyAsString(NEWDN));
} finally {
res.sampleEnd();
}
@@ -693,14 +687,13 @@
* test case
*
**************************************************************************/
- private void unbindOp(LdapExtClient ldap, DirContext dirContext,
SampleResult res) {
+ private void unbindOp(DirContext dirContext, SampleResult res) {
try {
res.sampleStart();
- ldap.disconnect(dirContext);
+ LdapExtClient.disconnect(dirContext);
} finally {
res.sampleEnd();
}
- ldapConnections.remove(getThreadName());
ldapContexts.remove(getThreadName());
log.info("context and LdapExtClients removed");
}
@@ -722,17 +715,7 @@
res.setContentType("text/xml");// $NON-NLS-1$
boolean isSuccessful = true;
res.setSampleLabel(getName());
- LdapExtClient temp_client = ldapConnections.get(getThreadName());
DirContext dirContext = ldapContexts.get(getThreadName());
- if (temp_client == null) {
- temp_client = new LdapExtClient();
- try {
- dirContext = new InitialDirContext();
- } catch (NamingException err) {
- log.error("Ldap client context creation - ", err);
- }
- ldapConnections.put(getThreadName(), temp_client);
- }
try {
xmlBuffer.openTag("operation"); // $NON-NLS-1$
@@ -743,13 +726,13 @@
res.setSamplerData("Unbind");
xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
xmlBuffer.tag("binddn",getUserDN()); // $NON-NLS-1$
- unbindOp(temp_client, dirContext, res);
+ unbindOp(dirContext, res);
} else if (testType.equals(BIND)) {
res.setSamplerData("Bind as "+getUserDN());
xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
xmlBuffer.tag("binddn",getUserDN()); // $NON-NLS-1$
xmlBuffer.tag("connectionTO",getConnTimeOut()); // $NON-NLS-1$
- bindOp(temp_client, dirContext, res);
+ bindOp(dirContext, res);
} else if (testType.equals(SBIND)) {
res.setSamplerData("SingleBind as "+getUserDN());
xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
@@ -764,7 +747,7 @@
NamingEnumeration<SearchResult> cmp=null;
try {
res.sampleStart();
- cmp = temp_client.compare(dirContext,
getPropertyAsString(COMPAREFILT),
+ cmp = LdapExtClient.compare(dirContext,
getPropertyAsString(COMPAREFILT),
getPropertyAsString(COMPAREDN));
if (!cmp.hasMore()) {
res.setResponseCode("5"); // $NON-NLS-1$
@@ -781,21 +764,21 @@
res.setSamplerData("Add object " + getBaseEntryDN());
xmlBuffer.tag("attributes",getArguments().toString()); //
$NON-NLS-1$
xmlBuffer.tag("dn",getBaseEntryDN()); // $NON-NLS-1$
- addTest(temp_client, dirContext, res);
+ addTest(dirContext, res);
} else if (testType.equals(DELETE)) {
res.setSamplerData("Delete object " + getBaseEntryDN());
xmlBuffer.tag("dn",getBaseEntryDN()); // $NON-NLS-1$
- deleteTest(temp_client, dirContext, res);
+ deleteTest(dirContext, res);
} else if (testType.equals(MODIFY)) {
res.setSamplerData("Modify object " + getBaseEntryDN());
xmlBuffer.tag("dn",getBaseEntryDN()); // $NON-NLS-1$
xmlBuffer.tag("attributes",getLDAPArguments().toString()); //
$NON-NLS-1$
- modifyTest(temp_client, dirContext, res);
+ modifyTest(dirContext, res);
} else if (testType.equals(RENAME)) {
res.setSamplerData("ModDN object " +
getPropertyAsString(MODDDN) + " to " + getPropertyAsString(NEWDN));
xmlBuffer.tag("dn",getPropertyAsString(MODDDN)); // $NON-NLS-1$
xmlBuffer.tag("newdn",getPropertyAsString(NEWDN)); //
$NON-NLS-1$
- renameTest(temp_client, dirContext, res);
+ renameTest(dirContext, res);
} else if (testType.equals(SEARCH)) {
final String scopeStr = getScope();
final int scope = getScopeAsInt();
@@ -815,7 +798,7 @@
NamingEnumeration<SearchResult> srch=null;
try {
res.sampleStart();
- srch = temp_client.searchTest(
+ srch = LdapExtClient.searchTest(
dirContext, searchBase, searchFilter,
scope, getCountlimAsLong(),
getTimelimAsInt(),
Modified:
jakarta/jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/LdapExtClient.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/LdapExtClient.java?rev=901444&r1=901443&r2=901444&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/LdapExtClient.java
(original)
+++
jakarta/jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/LdapExtClient.java
Wed Jan 20 23:49:12 2010
@@ -71,7 +71,7 @@
* @exception NamingException
* Description of Exception
*/
- public DirContext connect(String host, String port, String rootdn, String
username, String password, String connTimeOut, boolean secure)
+ public static DirContext connect(String host, String port, String rootdn,
String username, String password, String connTimeOut, boolean secure)
throws NamingException {
DirContext dirContext;
Hashtable<String, String> env = new Hashtable<String, String>();
@@ -105,7 +105,7 @@
/**
* disconnect from the server
*/
- public void disconnect(DirContext dirContext) {
+ public static void disconnect(DirContext dirContext) {
if (dirContext == null) {
log.info("Cannot disconnect null context");
return;
@@ -126,7 +126,7 @@
* @param searchFilter
* filter filter this value from the base
**************************************************************************/
- public NamingEnumeration<SearchResult> searchTest(DirContext dirContext,
String searchBase, String searchFilter, int scope, long countlim,
+ public static NamingEnumeration<SearchResult> searchTest(DirContext
dirContext, String searchBase, String searchFilter, int scope, long countlim,
int timelim, String[] attrs, boolean retobj, boolean deref) throws
NamingException {
if (dirContext == null) {
throw new NamingException(CONTEXT_IS_NULL);
@@ -154,7 +154,7 @@
* @param filter
* filter this value from the base
**************************************************************************/
- public NamingEnumeration<SearchResult> compare(DirContext dirContext,
String filter, String entrydn) throws NamingException {
+ public static NamingEnumeration<SearchResult> compare(DirContext
dirContext, String filter, String entrydn) throws NamingException {
if (dirContext == null) {
throw new NamingException(CONTEXT_IS_NULL);
}
@@ -166,7 +166,7 @@
* ModDN the data in the ldap directory for the given search base
*
**************************************************************************/
- public void moddnOp(DirContext dirContext, String ddn, String newdn)
throws NamingException {
+ public static void moddnOp(DirContext dirContext, String ddn, String
newdn) throws NamingException {
log.debug("ddn and newDn= " + ddn + "@@@@" + newdn);
if (dirContext == null) {
throw new NamingException(CONTEXT_IS_NULL);
@@ -182,7 +182,7 @@
* @param string
* The string (dn) value
**************************************************************************/
- public void modifyTest(DirContext dirContext, ModificationItem[] mods,
String string) throws NamingException {
+ public static void modifyTest(DirContext dirContext, ModificationItem[]
mods, String string) throws NamingException {
if (dirContext == null) {
throw new NamingException(CONTEXT_IS_NULL);
}
@@ -198,7 +198,7 @@
* @param string
* The string (dn) value
**************************************************************************/
- public DirContext createTest(DirContext dirContext, Attributes attributes,
String string)
+ public static DirContext createTest(DirContext dirContext, Attributes
attributes, String string)
throws NamingException {
if (dirContext == null) {
throw new NamingException(CONTEXT_IS_NULL);
@@ -212,10 +212,10 @@
* @param string
* The string (dn) value
**************************************************************************/
- public void deleteTest(DirContext dirContext, String string) throws
NamingException {
+ public static void deleteTest(DirContext dirContext, String string) throws
NamingException {
if (dirContext == null) {
throw new NamingException(CONTEXT_IS_NULL);
}
dirContext.destroySubcontext(string);
}
-}
\ No newline at end of file
+}
Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=901444&r1=901443&r2=901444&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Wed Jan 20 23:49:12 2010
@@ -85,6 +85,7 @@
<li>Bug 47899 - NullPointerExceptions in ReceiveSubscriber constructor</li>
<li>Bug 48144 - NPE in OnMessageSubscriber</li>
<li>Bug 47992 - JMS Point-to-Point Request - Response option doesn't work</li>
+<li>Bug 48573 - LDAPExtSampler directory context handling</li>
</ul>
<h3>Controllers</h3>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]