in src/protocol/ldap/src/main/java/org/apache/jmeter/protocol/ldap/sampler/LDAPExtSampler.java [730:875]
public SampleResult sample(Entry e) {
XMLBuffer xmlBuffer = new XMLBuffer();
xmlBuffer.openTag("ldapanswer"); // $NON-NLS-1$
SampleResult res = new SampleResult();
res.setResponseData("successfull", null);
res.setResponseMessage("Success"); // $NON-NLS-1$
res.setResponseCode("0"); // $NON-NLS-1$
res.setContentType("text/xml");// $NON-NLS-1$
boolean isSuccessful = true;
res.setSampleLabel(getName());
DirContext dirContext = ldapContexts.get(getThreadName());
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(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(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<SearchResult> cmp=null;
try {
res.sampleStart();
cmp = LdapExtClient.compare(dirContext, getPropertyAsString(COMPAREFILT),
getPropertyAsString(COMPAREDN));
if (!cmp.hasMore()) {
res.setResponseCode("5"); // $NON-NLS-1$
res.setResponseMessage("compareFalse");
isSuccessful = false;
}
} finally {
res.sampleEnd();
if (cmp != null) {
cmp.close();
}
}
} 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(dirContext, res);
} else if (testType.equals(DELETE)) {
res.setSamplerData("Delete object " + getBaseEntryDN());
xmlBuffer.tag("dn",getBaseEntryDN()); // $NON-NLS-1$
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(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(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", StringEscapeUtils.escapeXml10(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<SearchResult> srch=null;
try {
res.sampleStart();
srch = LdapExtClient.searchTest(
dirContext, searchBase, searchFilter,
scope, getCountlimAsLong(),
getTimelimAsInt(),
getRequestAttributes(getAttrs()),
isRetobj(),
isDeref());
if (isParseFlag()) {
try {
xmlBuffer.openTag("searchresults"); // $NON-NLS-1$
writeSearchResults(xmlBuffer, srch);
} finally {
xmlBuffer.closeTag("searchresults"); // $NON-NLS-1$
}
} else {
xmlBuffer.tag("searchresults", // $NON-NLS-1$
"hasElements="+srch.hasMoreElements()); // $NON-NLS-1$
}
} finally {
if (srch != null){
srch.close();
}
res.sampleEnd();
}
}
} catch (NamingException ex) {
String returnData = ex.toString();
final int indexOfLDAPErrCode = returnData.indexOf(RETURN_CODE_PREFIX);
if (indexOfLDAPErrCode >= 0) {
res.setResponseCode(returnData.substring(indexOfLDAPErrCode + RETURN_CODE_PREFIX.length(), indexOfLDAPErrCode + 19));
res.setResponseMessage(returnData.substring(indexOfLDAPErrCode + ERROR_MSG_START_INDEX, returnData.indexOf(']'))); // $NON-NLS-1$
} else {
res.setResponseMessage(returnData);
res.setResponseCode("800"); // $NON-NLS-1$
}
isSuccessful = false;
} catch (Exception ex) { // NOSONAR Exception is reported
String returnData = ex.toString();
res.setResponseCode("500");
res.setResponseMessage(returnData); // $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(), null);
res.setDataType(SampleResult.TEXT);
res.setSuccessful(isSuccessful);
}
return res;
}