You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by jo...@serverkrash.nu on 2003/11/17 10:45:03 UTC

Extension of LDAP Request defaults.

Hi, first post to this list (forced to send this by colleagues as OpenSource
is about "take and give" and all that :-).
The stuff in the patch was a requirement for a project, where a product
"figured out" what groups a user belonged to by requesting the
groupofuniquenames for a uniquemember. In order to limit the response to
just what was needed, the attribute "1.1" was given, which will return no
attributes, only the groups.

Below is a patch which extends the ldap "task's" search feature by adding
the ability to define what attributes are to be returned.
Zero or more attributes can be specified. If zero attributes are given, the
task behaves like the original one distributed by apache. If more than one
attribute is given, they should be separated with a comma: ",".

I also changed the number of attributes which should be returned from just
one to all available, so that the task more properly simulates real-world
conditions.

PS. Please note that I downloaded jmeter for the first time Thursday
afternoon,learned to use it and patched it, all in a matter of hours, so
there might be some intricate details I am not aware of. Having said that,
the patch worked for our needs (using ethereal, sniffing the LDAP questions
and responses,  the queries looked correct and provide the assumed
response).

PPS. Wouldn't it be a good idea to use constants in the code instead of a
literal values as the former might better describe parameter values used for
method invocation etc. than just an integer for example?

== PATCH START ==
diff -r -u
src_orig\jakarta-jmeter-1.9.1\src\core\org\apache\jmeter\resources\messages.
properties
src_mod\jakarta-jmeter-1.9.1\src\core\org\apache\jmeter\resources\messages.p
roperties
--- 
src_orig\jakarta-jmeter-1.9.1\src\core\org\apache\jmeter\resources\messages.
properties Tue Jul 15 12:27:58 2003
+++
src_mod\jakarta-jmeter-1.9.1\src\core\org\apache\jmeter\resources\messages.p
roperties Wed Nov 12 16:16:18 2003
@@ -362,6 +362,7 @@
 ldap_sample_title=LDAP Request Defaults
 dn=DN
 search_filter=Search Filter
+attributes_to_return=Return Attributes
 search_base=Search base
 entry_dn=Entry DN
 test_configuration=Test Configuration
diff -r -u
src_orig\jakarta-jmeter-1.9.1\src\protocol\ldap\org\apache\jmeter\protocol\l
dap\config\gui\LdapConfigGui.java
src_mod\jakarta-jmeter-1.9.1\src\protocol\ldap\org\apache\jmeter\protocol\ld
ap\config\gui\LdapConfigGui.java
--- 
src_orig\jakarta-jmeter-1.9.1\src\protocol\ldap\org\apache\jmeter\protocol\l
dap\config\gui\LdapConfigGui.java Fri Jun 20 10:15:36 2003
+++
src_mod\jakarta-jmeter-1.9.1\src\protocol\ldap\org\apache\jmeter\protocol\ld
ap\config\gui\LdapConfigGui.java Mon Nov 17 09:19:31 2003
@@ -101,6 +101,7 @@
     private JTextField rootdn = new JTextField(20);
     private JTextField searchbase = new JTextField(20);
     private JTextField searchfilter = new JTextField(20);
+    private JTextField returnattributes = new JTextField(20);
     private JTextField delete = new JTextField(20);
     private JTextField add = new JTextField(20);
     private JTextField modify = new JTextField(20);
@@ -164,6 +165,7 @@
             searchTest.setSelected(true);

searchbase.setText(element.getPropertyAsString(LDAPSampler.SEARCHBASE));

searchfilter.setText(element.getPropertyAsString(LDAPSampler.SEARCHFILTER));
+
returnattributes.setText(element.getPropertyAsString(LDAPSampler.RETURNATTRI
BUTES));
             cl.show(cards,"Search");
         }
         if (element.getPropertyAsBoolean(LDAPSampler.USER_DEFINED)) {
@@ -212,6 +214,7 @@
             element.setProperty(new
StringProperty(LDAPSampler.TEST,LDAPSampler.SEARCHBASE));
             element.setProperty(new
StringProperty(LDAPSampler.SEARCHBASE,searchbase.getText()));
             element.setProperty(new
StringProperty(LDAPSampler.SEARCHFILTER,searchfilter.getText()));
+            element.setProperty(new
StringProperty(LDAPSampler.RETURNATTRIBUTES,returnattributes.getText()));
         }
 }

@@ -229,6 +232,7 @@
                 tableModifyPanel.clear();
                 searchbase.setText("");
                 searchfilter.setText("");
+                returnattributes.setText("");
                 delete.setText("");
             } else if(deleteTest.isSelected()){
                 cl.show(cards,"Delete");
@@ -236,6 +240,7 @@
                 tableAddPanel.clear();
                 searchbase.setText("");
                 searchfilter.setText("");
+                returnattributes.setText("");
             } else if(searchTest.isSelected()){
                 cl.show(cards,"Search");
                 delete.setText("");
@@ -246,6 +251,7 @@
                 tableAddPanel.clear();
                 searchbase.setText("");
                 searchfilter.setText("");
+                returnattributes.setText("");
                 delete.setText("");
             }else {
                 cl.show(cards,"");
@@ -253,6 +259,7 @@
                 tableModifyPanel.clear();
                 searchbase.setText("");
                 searchfilter.setText("");
+                returnattributes.setText("");
                 delete.setText("");
             }
         }else {
@@ -261,6 +268,7 @@
             tableModifyPanel.clear();
             searchbase.setText("");
             searchfilter.setText("");
+            returnattributes.setText("");
             delete.setText("");
         }
     }
@@ -322,18 +330,28 @@

     private JPanel createSearchPanel() {
         VerticalPanel searchPanel = new VerticalPanel();
+
         JPanel searchBPanel = new JPanel(new BorderLayout(5, 0));
         JLabel label = new JLabel(JMeterUtils.getResString("search_base"));
         label.setLabelFor(searchbase);
         searchBPanel.add(label, BorderLayout.WEST);
         searchBPanel.add(searchbase, BorderLayout.CENTER);
+
         JPanel searchFPanel  = new JPanel(new BorderLayout(5, 0));
         JLabel label2 = new
JLabel(JMeterUtils.getResString("search_filter"));
         label2.setLabelFor(searchfilter);
         searchFPanel.add(label2, BorderLayout.WEST);
         searchFPanel.add(searchfilter, BorderLayout.CENTER);
+
+        JPanel searchRPanel  = new JPanel(new BorderLayout(5, 0));
+        JLabel label3 = new
JLabel(JMeterUtils.getResString("attributes_to_return"));
+        label3.setLabelFor(returnattributes);
+        searchRPanel.add(label3, BorderLayout.WEST);
+        searchRPanel.add(returnattributes, BorderLayout.CENTER);
+
         searchPanel.add(searchBPanel);
         searchPanel.add(searchFPanel);
+        searchPanel.add(searchRPanel);
         return searchPanel;
     }

diff -r -u
src_orig\jakarta-jmeter-1.9.1\src\protocol\ldap\org\apache\jmeter\protocol\l
dap\sampler\LdapClient.java
src_mod\jakarta-jmeter-1.9.1\src\protocol\ldap\org\apache\jmeter\protocol\ld
ap\sampler\LdapClient.java
--- 
src_orig\jakarta-jmeter-1.9.1\src\protocol\ldap\org\apache\jmeter\protocol\l
dap\sampler\LdapClient.java Fri Jun 20 10:15:36 2003
+++
src_mod\jakarta-jmeter-1.9.1\src\protocol\ldap\org\apache\jmeter\protocol\ld
ap\sampler\LdapClient.java Wed Nov 12 16:31:00 2003
@@ -130,9 +130,13 @@
      *@param  search base  where the search should start
      *@param  search filter filter this value from the base
      ***********************************************************/
-    public void searchTest(String searchBase, String searchFilter)
+    public void searchTest(String searchBase, String searchFilter, String[]
attributesToReturn)
         throws NoPermissionException,NamingException {
-        SearchControls searchcontrols = new SearchControls(2, 1L, 0, null,
+        // Note,
+        SearchControls searchcontrols = new
SearchControls(SearchControls.SUBTREE_SCOPE,
+                                                           0L, /* FIXME:
Should probably be changed to 0L instead of 1L to represent real-world
situation */
+                                                           0,
+
attributesToReturn,
                                                            false, false);
         dirContext.search(searchBase, searchFilter, searchcontrols);
     }
diff -r -u
src_orig\jakarta-jmeter-1.9.1\src\protocol\ldap\org\apache\jmeter\protocol\l
dap\sampler\LDAPSampler.java
src_mod\jakarta-jmeter-1.9.1\src\protocol\ldap\org\apache\jmeter\protocol\ld
ap\sampler\LDAPSampler.java
--- 
src_orig\jakarta-jmeter-1.9.1\src\protocol\ldap\org\apache\jmeter\protocol\l
dap\sampler\LDAPSampler.java Fri Jun 20 10:15:36 2003
+++
src_mod\jakarta-jmeter-1.9.1\src\protocol\ldap\org\apache\jmeter\protocol\ld
ap\sampler\LDAPSampler.java Wed Nov 12 18:36:21 2003
@@ -54,6 +54,7 @@
  */
 package org.apache.jmeter.protocol.ldap.sampler;

+import java.util.StringTokenizer;
 import javax.naming.NamingException;
 import javax.naming.NoPermissionException;
 import javax.naming.directory.Attribute;
@@ -110,6 +111,7 @@
     public final static String USER_DEFINED = "user_defined";
     public final static String ARGUMENTS = "arguments";
     public final static String BASE_ENTRY_DN = "base_entry_dn";
+    public final static String RETURNATTRIBUTES = "returnattributes";

     //For In build test case using this counter
     //create the new entry in the server
@@ -471,9 +473,23 @@
             ldap.createTest(getBasicAttributes(),
getPropertyAsString(ADD));
             setProperty(new
StringProperty(SEARCHBASE,getPropertyAsString(ADD)));
             setProperty(new
StringProperty(SEARCHFILTER,getPropertyAsString(ADD)));
+            setProperty(new
StringProperty(RETURNATTRIBUTES,getPropertyAsString(ADD)));
         }
+
+        /* start change */
+        String[] returnAttributes = null;
+        StringTokenizer st = new
StringTokenizer(getPropertyAsString(RETURNATTRIBUTES).trim(),",");
+        int nrAtts = st.countTokens();
+        if (nrAtts > 0) {
+         returnAttributes = new String[nrAtts];
+         for (int i = 0; i < returnAttributes.length; i++) {
+    returnAttributes[i] = st.nextToken();
+   }
+        }
+        /* end change */
+
         start = System.currentTimeMillis();
-
ldap.searchTest(getPropertyAsString(SEARCHBASE),getPropertyAsString(SEARCHFI
LTER));
+
ldap.searchTest(getPropertyAsString(SEARCHBASE),getPropertyAsString(SEARCHFI
LTER), returnAttributes);
         end = System.currentTimeMillis();
         if (! getPropertyAsBoolean(USER_DEFINED)){
             ldap.deleteTest(getPropertyAsString(ADD));
@@ -529,6 +545,7 @@
             }else if (getPropertyAsString(TEST).equals("search")) {
                 time = searchTest(ldap);
             }
+
             res.setResponseData("success full".getBytes());
             isSuccessful = true;
             ldap.disconnect();



---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org