use of org.apache.jorphan.util.XMLBuffer in project jmeter by apache.
the class TestXMLBuffer method test3.
@Test
public void test3() throws Exception {
XMLBuffer xb = new XMLBuffer();
xb.openTag("abc");
xb.closeTag("abc");
assertEquals("<abc></abc>\n", xb.toString());
}
use of org.apache.jorphan.util.XMLBuffer in project jmeter by apache.
the class TestXMLBuffer method test1.
@Test
public void test1() throws Exception {
XMLBuffer xb = new XMLBuffer();
xb.openTag("start");
assertEquals("<start></start>\n", xb.toString());
}
use of org.apache.jorphan.util.XMLBuffer in project jmeter by apache.
the class TestXMLBuffer method test4.
@Test
public void test4() throws Exception {
XMLBuffer xb = new XMLBuffer();
xb.openTag("abc");
try {
xb.closeTag("abcd");
fail("Should have caused IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
}
use of org.apache.jorphan.util.XMLBuffer in project jmeter by apache.
the class TestXMLBuffer method test2.
@Test
public void test2() throws Exception {
XMLBuffer xb = new XMLBuffer();
xb.tag("start", "now");
assertEquals("<start>now</start>\n", xb.toString());
}
use of org.apache.jorphan.util.XMLBuffer in project jmeter by apache.
the class LDAPExtSampler method sample.
@Override
public SampleResult sample(Entry e) {
XMLBuffer xmlBuffer = new XMLBuffer();
// $NON-NLS-1$
xmlBuffer.openTag("ldapanswer");
SampleResult res = new SampleResult();
res.setResponseData("successfull", null);
// $NON-NLS-1$
res.setResponseMessage("Success");
// $NON-NLS-1$
res.setResponseCode("0");
// $NON-NLS-1$
res.setContentType("text/xml");
boolean isSuccessful = true;
res.setSampleLabel(getName());
DirContext dirContext = ldapContexts.get(getThreadName());
try {
// $NON-NLS-1$
xmlBuffer.openTag("operation");
final String testType = getTest();
// $NON-NLS-1$
xmlBuffer.tag("opertype", testType);
log.debug("performing test: " + testType);
if (testType.equals(UNBIND)) {
res.setSamplerData("Unbind");
// $NON-NLS-1$
xmlBuffer.tag("baseobj", getRootdn());
// $NON-NLS-1$
xmlBuffer.tag("binddn", getUserDN());
unbindOp(dirContext, res);
} else if (testType.equals(BIND)) {
res.setSamplerData("Bind as " + getUserDN());
// $NON-NLS-1$
xmlBuffer.tag("baseobj", getRootdn());
// $NON-NLS-1$
xmlBuffer.tag("binddn", getUserDN());
// $NON-NLS-1$
xmlBuffer.tag("connectionTO", getConnTimeOut());
bindOp(res);
} else if (testType.equals(SBIND)) {
res.setSamplerData("SingleBind as " + getUserDN());
// $NON-NLS-1$
xmlBuffer.tag("baseobj", getRootdn());
// $NON-NLS-1$
xmlBuffer.tag("binddn", getUserDN());
// $NON-NLS-1$
xmlBuffer.tag("connectionTO", getConnTimeOut());
singleBindOp(res);
} else if (testType.equals(COMPARE)) {
res.setSamplerData("Compare " + getPropertyAsString(COMPAREFILT) + " " + getPropertyAsString(COMPAREDN));
// $NON-NLS-1$
xmlBuffer.tag("comparedn", getPropertyAsString(COMPAREDN));
// $NON-NLS-1$
xmlBuffer.tag("comparefilter", getPropertyAsString(COMPAREFILT));
NamingEnumeration<SearchResult> cmp = null;
try {
res.sampleStart();
cmp = LdapExtClient.compare(dirContext, getPropertyAsString(COMPAREFILT), getPropertyAsString(COMPAREDN));
if (!cmp.hasMore()) {
// $NON-NLS-1$
res.setResponseCode("5");
res.setResponseMessage("compareFalse");
isSuccessful = false;
}
} finally {
res.sampleEnd();
if (cmp != null) {
cmp.close();
}
}
} else if (testType.equals(ADD)) {
res.setSamplerData("Add object " + getBaseEntryDN());
// $NON-NLS-1$
xmlBuffer.tag("attributes", getArguments().toString());
// $NON-NLS-1$
xmlBuffer.tag("dn", getBaseEntryDN());
addTest(dirContext, res);
} else if (testType.equals(DELETE)) {
res.setSamplerData("Delete object " + getBaseEntryDN());
// $NON-NLS-1$
xmlBuffer.tag("dn", getBaseEntryDN());
deleteTest(dirContext, res);
} else if (testType.equals(MODIFY)) {
res.setSamplerData("Modify object " + getBaseEntryDN());
// $NON-NLS-1$
xmlBuffer.tag("dn", getBaseEntryDN());
// $NON-NLS-1$
xmlBuffer.tag("attributes", getLDAPArguments().toString());
modifyTest(dirContext, res);
} else if (testType.equals(RENAME)) {
res.setSamplerData("ModDN object " + getPropertyAsString(MODDDN) + " to " + getPropertyAsString(NEWDN));
// $NON-NLS-1$
xmlBuffer.tag("dn", getPropertyAsString(MODDDN));
// $NON-NLS-1$
xmlBuffer.tag("newdn", getPropertyAsString(NEWDN));
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);
// $NON-NLS-1$
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);
NamingEnumeration<SearchResult> srch = null;
try {
res.sampleStart();
srch = LdapExtClient.searchTest(dirContext, searchBase, searchFilter, scope, getCountlimAsLong(), getTimelimAsInt(), getRequestAttributes(getAttrs()), isRetobj(), isDeref());
if (isParseFlag()) {
try {
// $NON-NLS-1$
xmlBuffer.openTag("searchresults");
writeSearchResults(xmlBuffer, srch);
} finally {
// $NON-NLS-1$
xmlBuffer.closeTag("searchresults");
}
} else {
// $NON-NLS-1$
xmlBuffer.tag(// $NON-NLS-1$
"searchresults", // $NON-NLS-1$
"hasElements=" + srch.hasMoreElements());
}
} finally {
if (srch != null) {
srch.close();
}
res.sampleEnd();
}
}
} catch (NamingException ex) {
// 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);
// $NON-NLS-1$
res.setResponseCode("800");
}
isSuccessful = false;
} finally {
// $NON-NLS-1$
xmlBuffer.closeTag("operation");
// $NON-NLS-1$
xmlBuffer.tag("responsecode", res.getResponseCode());
// $NON-NLS-1$
xmlBuffer.tag("responsemessage", res.getResponseMessage());
res.setResponseData(xmlBuffer.toString(), null);
res.setDataType(SampleResult.TEXT);
res.setSuccessful(isSuccessful);
}
return res;
}
Aggregations