* @param e
* !ToDo (Parameter description)
* @return !ToDo (Return description)
**************************************************************************/
public SampleResult sample(Entry e) {
XMLBuffer xmlBuffer = new XMLBuffer();
xmlBuffer.openTag("ldapanswer"); // $NON-NLS-1$
SampleResult res = new SampleResult();
res.setResponseData("successfull".getBytes());
res.setResponseMessage("Success"); // $NON-NLS-1$
res.setResponseCode("0"); // $NON-NLS-1$
boolean isSuccessful = true;
res.setSampleLabel(getName());
LdapExtClient temp_client = (LdapExtClient) ldapConnections.get(getThreadName());
DirContext 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$
final String testType = getTest();
xmlBuffer.tag("opertype", testType); // $NON-NLS-1$
log.debug("performing test: " + testType);
if (testType.equals(UNBIND)) {
res.setSamplerData("Unbind");
xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
xmlBuffer.tag("binddn",getUserDN()); // $NON-NLS-1$
unbindOp(temp_client, 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);
} else if (testType.equals(SBIND)) {
res.setSamplerData("SingleBind as "+getUserDN());
xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
xmlBuffer.tag("binddn",getUserDN()); // $NON-NLS-1$
xmlBuffer.tag("connectionTO",getConnTimeOut()); // $NON-NLS-1$
singleBindOp(res);
} else if (testType.equals(COMPARE)) {
res.setSamplerData("Compare "+getPropertyAsString(COMPAREFILT) + " "
+ getPropertyAsString(COMPAREDN));
xmlBuffer.tag("comparedn",getPropertyAsString(COMPAREDN)); // $NON-NLS-1$
xmlBuffer.tag("comparefilter",getPropertyAsString(COMPAREFILT)); // $NON-NLS-1$
NamingEnumeration cmp;
try {
res.sampleStart();
cmp = temp_client.compare(dirContext, getPropertyAsString(COMPAREFILT),
getPropertyAsString(COMPAREDN));
} finally {
res.sampleEnd();
}
if (cmp.hasMore()) {
} else {
res.setResponseCode("5"); // $NON-NLS-1$
res.setResponseMessage("compareFalse");
isSuccessful = false;
}
} else if (testType.equals(ADD)) {
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);
} else if (testType.equals(DELETE)) {
res.setSamplerData("Delete object " + getBaseEntryDN());
xmlBuffer.tag("dn",getBaseEntryDN()); // $NON-NLS-1$
deleteTest(temp_client, 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);
} 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);
} else if (testType.equals(SEARCH)) {
final String scopeStr = getScope();
final int scope = getScopeAsInt();
final String searchFilter = getPropertyAsString(SEARCHFILTER);
final String searchBase = getPropertyAsString(SEARCHBASE);
final String timeLimit = getTimelim();
final String countLimit = getCountlim();
res.setSamplerData("Search with filter " + searchFilter);
xmlBuffer.tag("searchfilter",searchFilter); // $NON-NLS-1$
xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
xmlBuffer.tag("searchbase",searchBase);// $NON-NLS-1$
xmlBuffer.tag("scope" , scopeStr); // $NON-NLS-1$
xmlBuffer.tag("countlimit",countLimit); // $NON-NLS-1$
xmlBuffer.tag("timelimit",timeLimit); // $NON-NLS-1$
NamingEnumeration srch;
try {
res.sampleStart();
srch = temp_client.searchTest(
dirContext, searchBase, searchFilter,
scope, getCountlimAsLong(),
getTimelimAsInt(),
getRequestAttributes(getAttrs()),
isRetobj(),
isDeref());
} finally {
res.sampleEnd();
}
if (isParseFlag()) {
try {
xmlBuffer.openTag("searchresults"); // $NON-NLS-1$
writeSearchResults(xmlBuffer, srch);
} finally {
xmlBuffer.closeTag("searchresults"); // $NON-NLS-1$
}
}
}
} catch (NamingException ex) {
//log.warn("DEBUG",ex);
// e.g. javax.naming.SizeLimitExceededException: [LDAP: error code 4 - Sizelimit Exceeded]; remaining name ''
// 123456789012345678901
// TODO: tidy this up
String returnData = ex.toString();
final int indexOfLDAPErrCode = returnData.indexOf("LDAP: error code");
if (indexOfLDAPErrCode >= 0) {
res.setResponseMessage(returnData.substring(indexOfLDAPErrCode + 21, returnData
.indexOf("]"))); // $NON-NLS-1$
res.setResponseCode(returnData.substring(indexOfLDAPErrCode + 17, indexOfLDAPErrCode + 19));
} else {
res.setResponseMessage(returnData);
res.setResponseCode("800"); // $NON-NLS-1$
}
isSuccessful = false;
} finally {
xmlBuffer.closeTag("operation"); // $NON-NLS-1$
xmlBuffer.tag("responsecode",res.getResponseCode()); // $NON-NLS-1$
xmlBuffer.tag("responsemessage",res.getResponseMessage()); // $NON-NLS-1$
res.setResponseData(xmlBuffer.toString().getBytes());
res.setDataType(SampleResult.TEXT);
res.setSuccessful(isSuccessful);
}
return res;
}