📄 ldapextsampler.java
字号:
}
/***************************************************************************
* Gets the deref attribute of the LDAPSampler object
*
* @return if dereferencing is required
**************************************************************************/
public boolean isDeref() {
return getPropertyAsBoolean(DEREF);
}
/***************************************************************************
* Sets the deref attribute of the LDAPSampler object
*
* @param newDref
* The new deref value
**************************************************************************/
public void setDeref(String newDref) {
this.setProperty(DEREF, newDref);
}
/***************************************************************************
* Sets the Test attribute of the LdapConfig object
*
* @param newTest
* The new test value(Add,Modify,Delete and search)
**************************************************************************/
public void setTest(String newTest) {
this.setProperty(TEST, newTest);
}
/***************************************************************************
* Gets the test attribute of the LDAPSampler object
*
* @return The test value (Add,Modify,Delete and search)
**************************************************************************/
public String getTest() {
return getPropertyAsString(TEST);
}
/***************************************************************************
* Sets the attributes of the LdapConfig object
*
* @param newAttrs
* The new attributes value
**************************************************************************/
public void setAttrs(String newAttrs) {
this.setProperty(ATTRIBS, newAttrs);
}
/***************************************************************************
* Gets the attributes of the LDAPSampler object
*
* @return The attributes
**************************************************************************/
public String getAttrs() {
return getPropertyAsString(ATTRIBS);
}
/***************************************************************************
* Sets the Base Entry DN attribute of the LDAPSampler object
*
* @param newbaseentry
* The new Base entry DN value
**************************************************************************/
public void setBaseEntryDN(String newbaseentry) {
setProperty(new StringProperty(BASE_ENTRY_DN, newbaseentry));
}
/***************************************************************************
* Gets the BaseEntryDN attribute of the LDAPSampler object
*
* @return The Base entry DN value
**************************************************************************/
public String getBaseEntryDN() {
return getPropertyAsString(BASE_ENTRY_DN);
}
/***************************************************************************
* Sets the Arguments attribute of the LdapConfig object This will collect
* values from the table for user defined test case
*
* @param value
* The arguments
**************************************************************************/
public void setArguments(Arguments value) {
setProperty(new TestElementProperty(ARGUMENTS, value));
}
/***************************************************************************
* Gets the Arguments attribute of the LdapConfig object
*
* @return The arguments user defined test case
**************************************************************************/
public Arguments getArguments() {
return (Arguments) getProperty(ARGUMENTS).getObjectValue();
}
/***************************************************************************
* Sets the Arguments attribute of the LdapConfig object This will collect
* values from the table for user defined test case
*
* @param value
* The arguments
**************************************************************************/
public void setLDAPArguments(LDAPArguments value) {
setProperty(new TestElementProperty(LDAPARGUMENTS, value));
}
/***************************************************************************
* Gets the LDAPArguments attribute of the LdapConfig object
*
* @return The LDAParguments user defined modify test case
**************************************************************************/
public LDAPArguments getLDAPArguments() {
return (LDAPArguments) getProperty(LDAPARGUMENTS).getObjectValue();
}
/***************************************************************************
* Collect all the values from the table (Arguments), using this create the
* Attributes, this will create the Attributes for the User
* defined TestCase for Add Test
*
* @return The Attributes
**************************************************************************/
private Attributes getUserAttributes() {
Attributes attrs = new BasicAttributes(true);
Attribute attr;
PropertyIterator iter = getArguments().iterator();
while (iter.hasNext()) {
Argument item = (Argument) iter.next().getObjectValue();
attr = attrs.get(item.getName());
if (attr == null) {
attr = getBasicAttribute(item.getName(), item.getValue());
} else {
attr.add(item.getValue());
}
attrs.put(attr);
}
return attrs;
}
/***************************************************************************
* Collect all the value from the table (Arguments), using this create the
* basicAttributes This will create the Basic Attributes for the User
* defined TestCase for Modify test
*
* @return The BasicAttributes
**************************************************************************/
private ModificationItem[] getUserModAttributes() {
ModificationItem[] mods = new ModificationItem[getLDAPArguments().getArguments().size()];
BasicAttribute attr;
PropertyIterator iter = getLDAPArguments().iterator();
int count = 0;
while (iter.hasNext()) {
LDAPArgument item = (LDAPArgument) iter.next().getObjectValue();
if ((item.getValue()).length()==0) {
attr = new BasicAttribute(item.getName());
} else {
attr = getBasicAttribute(item.getName(), item.getValue());
}
final String opcode = item.getOpcode();
if ("add".equals(opcode)) { // $NON-NLS-1$
mods[count++] = new ModificationItem(DirContext.ADD_ATTRIBUTE, attr);
} else if ("delete".equals(opcode) // $NON-NLS-1$
|| "remove".equals(opcode)) { // $NON-NLS-1$
mods[count++] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, attr);
} else if("replace".equals(opcode)) { // $NON-NLS-1$
mods[count++] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, attr);
} else {
log.warn("Invalid opCode: "+opcode);
}
}
return mods;
}
/***************************************************************************
* Collect all the value from the table (Arguments), using this create the
* Attributes This will create the Basic Attributes for the User defined
* TestCase for search test
*
* @return The BasicAttributes
**************************************************************************/
private String[] getRequestAttributes(String reqAttr) {
int index;
String[] mods;
int count = 0;
if (reqAttr.length() == 0) {
return null;
}
if (!reqAttr.endsWith(SEMI_COLON)) {
reqAttr = reqAttr + SEMI_COLON;
}
String attr = reqAttr;
while (attr.length() > 0) {
index = attr.indexOf(SEMI_COLON);
count += 1;
attr = attr.substring(index + 1);
}
if (count > 0) {
mods = new String[count];
attr = reqAttr;
count = 0;
while (attr.length() > 0) {
index = attr.indexOf(SEMI_COLON);
mods[count] = attr.substring(0, index);
count += 1;
attr = attr.substring(index + 1);
}
} else {
mods = null;
}
return mods;
}
/***************************************************************************
* This will create the Basic Attribute for the give name value pair
*
* @return The BasicAttribute
**************************************************************************/
private BasicAttribute getBasicAttribute(String name, String value) {
BasicAttribute attr = new BasicAttribute(name, value);
return attr;
}
/**
* Returns a formatted string label describing this sampler Example output:
*
* @return a formatted string label describing this sampler
*/
public String getLabel() {
return ("ldap://" + this.getServername() //$NON-NLS-1$
+ ":" + getPort() //$NON-NLS-1$
+ "/" + this.getRootdn()); //$NON-NLS-1$
}
/***************************************************************************
* This will do the add test for the User defined TestCase
*
**************************************************************************/
private void addTest(LdapExtClient ldap, DirContext dirContext, SampleResult res) throws NamingException {
try {
res.sampleStart();
ldap.createTest(dirContext, getUserAttributes(), getBaseEntryDN());
} finally {
res.sampleEnd();
}
}
/***************************************************************************
* This will do the delete test for the User defined TestCase
*
**************************************************************************/
private void deleteTest(LdapExtClient ldap, DirContext dirContext, SampleResult res) throws NamingException {
try {
res.sampleStart();
ldap.deleteTest(dirContext, getPropertyAsString(DELETE));
} finally {
res.sampleEnd();
}
}
/***************************************************************************
* This will do the modify test for the User defined TestCase
*
**************************************************************************/
private void modifyTest(LdapExtClient ldap, DirContext dirContext, SampleResult res) throws NamingException {
try {
res.sampleStart();
ldap.modifyTest(dirContext, getUserModAttributes(), getBaseEntryDN());
} finally {
res.sampleEnd();
}
}
/***************************************************************************
* This will do the bind for the User defined Thread, this bind is used for
* the whole context
*
**************************************************************************/
private void bindOp(LdapExtClient ldap, DirContext dirContext, SampleResult res) throws NamingException {
DirContext ctx = (DirContext) ldapContexts.remove(getThreadName());
if (ctx != null) {
log.warn("Closing previous context for thread: " + getThreadName());
ctx.close();
}
try {
res.sampleStart();
ctx = ldap.connect(getServername(), getPort(), getRootdn(), getUserDN(), getUserPw(),getConnTimeOut(),isSecure());
} finally {
res.sampleEnd();
}
ldapContexts.put(getThreadName(), ctx);
}
/***************************************************************************
* This will do the bind and unbind for the User defined TestCase
*
**************************************************************************/
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);
} finally {
res.sampleEnd();
}
}
/***************************************************************************
* This will do a moddn Opp for the User new DN defined
*
**************************************************************************/
private void renameTest(LdapExtClient ldap, DirContext dirContext, SampleResult res) throws NamingException {
try {
res.sampleStart();
ldap.moddnOp(dirContext, getPropertyAsString(MODDDN), getPropertyAsString(NEWDN));
} finally {
res.sampleEnd();
}
}
/***************************************************************************
* This will do the unbind for the User defined TestCase as well as inbuilt
* test case
*
**************************************************************************/
private void unbindOp(LdapExtClient ldap, DirContext dirContext, SampleResult res) {
try {
res.sampleStart();
ldap.disconnect(dirContext);
} finally {
res.sampleEnd();
}
ldapConnections.remove(getThreadName());
ldapContexts.remove(getThreadName());
log.info("context and LdapExtClients removed");
}
/***************************************************************************
* !ToDo (Method description)
*
* @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());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -