Lines 17-25
Link Here
|
17 |
|
17 |
|
18 |
package org.apache.jmeter.protocol.ldap.sampler; |
18 |
package org.apache.jmeter.protocol.ldap.sampler; |
19 |
|
19 |
|
20 |
import java.util.Hashtable; |
20 |
import java.util.*; |
21 |
import java.util.Iterator; |
|
|
22 |
import java.util.Map; |
23 |
|
21 |
|
24 |
import javax.naming.NamingEnumeration; |
22 |
import javax.naming.NamingEnumeration; |
25 |
import javax.naming.NamingException; |
23 |
import javax.naming.NamingException; |
Lines 44-49
Link Here
|
44 |
import org.apache.jmeter.testelement.property.PropertyIterator; |
42 |
import org.apache.jmeter.testelement.property.PropertyIterator; |
45 |
import org.apache.jmeter.testelement.property.StringProperty; |
43 |
import org.apache.jmeter.testelement.property.StringProperty; |
46 |
import org.apache.jmeter.testelement.property.TestElementProperty; |
44 |
import org.apache.jmeter.testelement.property.TestElementProperty; |
|
|
45 |
import org.apache.jmeter.util.JMeterUtils; |
47 |
import org.apache.jorphan.logging.LoggingManager; |
46 |
import org.apache.jorphan.logging.LoggingManager; |
48 |
import org.apache.log.Logger; |
47 |
import org.apache.log.Logger; |
49 |
|
48 |
|
Lines 56-61
Link Here
|
56 |
|
55 |
|
57 |
private static final Logger log = LoggingManager.getLoggerForClass(); |
56 |
private static final Logger log = LoggingManager.getLoggerForClass(); |
58 |
|
57 |
|
|
|
58 |
/** Signature start of response data generated by this sample. */ |
59 |
public static final String LDAPANSWER = "<ldapanswer>"; |
60 |
|
59 |
public final static String SERVERNAME = "servername"; // $NON-NLS-1$ |
61 |
public final static String SERVERNAME = "servername"; // $NON-NLS-1$ |
60 |
|
62 |
|
61 |
public final static String PORT = "port"; // $NON-NLS-1$ |
63 |
public final static String PORT = "port"; // $NON-NLS-1$ |
Lines 125-139
Link Here
|
125 |
// TODO replace these with ThreadLocal |
127 |
// TODO replace these with ThreadLocal |
126 |
private static Hashtable ldapConnections = new Hashtable(); |
128 |
private static Hashtable ldapConnections = new Hashtable(); |
127 |
|
129 |
|
128 |
private static Hashtable ldapContexts = new Hashtable(); |
130 |
private static Hashtable ldapContexts = new Hashtable(); |
|
|
131 |
protected static final int MAX_SORTED_RESULTS = JMeterUtils.getPropDefault("ldapsampler.max_sorted_results", 1000); |
129 |
|
132 |
|
130 |
/*************************************************************************** |
|
|
131 |
* !ToDo (Constructor description) |
132 |
**************************************************************************/ |
133 |
public LDAPExtSampler() { |
134 |
} |
135 |
|
133 |
|
136 |
/*************************************************************************** |
134 |
/*************************************************************************** |
|
|
135 |
* !ToDo (Constructor description) |
136 |
**************************************************************************/ |
137 |
public LDAPExtSampler() { |
138 |
} |
139 |
|
140 |
/*************************************************************************** |
137 |
* Gets the username attribute of the LDAP object |
141 |
* Gets the username attribute of the LDAP object |
138 |
* |
142 |
* |
139 |
* @return The username |
143 |
* @return The username |
Lines 681-687
Link Here
|
681 |
* @return !ToDo (Return description) |
685 |
* @return !ToDo (Return description) |
682 |
**************************************************************************/ |
686 |
**************************************************************************/ |
683 |
public SampleResult sample(Entry e) { |
687 |
public SampleResult sample(Entry e) { |
684 |
String responseData = "<ldapanswer>"; |
688 |
String responseData = LDAPANSWER; |
685 |
SampleResult res = new SampleResult(); |
689 |
SampleResult res = new SampleResult(); |
686 |
res.setResponseData("successfull".getBytes()); |
690 |
res.setResponseData("successfull".getBytes()); |
687 |
res.setResponseMessage("Success"); |
691 |
res.setResponseMessage("Success"); |
Lines 761-799
Link Here
|
761 |
responseData = responseData + "<newdn>" + getPropertyAsString(NEWDN) + "</newdn></operation>"; |
765 |
responseData = responseData + "<newdn>" + getPropertyAsString(NEWDN) + "</newdn></operation>"; |
762 |
renameTest(temp_client, dirContext, res); |
766 |
renameTest(temp_client, dirContext, res); |
763 |
} else if (getPropertyAsString(TEST).equals(SEARCHBASE)) { |
767 |
} else if (getPropertyAsString(TEST).equals(SEARCHBASE)) { |
764 |
res.setSamplerData("Search with filter " + getPropertyAsString(SEARCHFILTER)); |
768 |
final StringBuffer sb = new StringBuffer(2 * 1024); |
765 |
responseData = responseData + "<operation><opertype>search</opertype>"; |
769 |
|
766 |
responseData = responseData + "<searchfilter>" + getPropertyAsString(SEARCHFILTER) + "</searchfilter>"; |
770 |
res.setSamplerData("Search with filter " + getPropertyAsString(SEARCHFILTER)); |
767 |
responseData = responseData + "<searchbase>" + getPropertyAsString(SEARCHBASE) + "," |
771 |
sb.append(responseData); |
768 |
+ getPropertyAsString(ROOTDN) + "</searchbase>"; |
772 |
writeSearchResponseHeader(sb); |
769 |
responseData = responseData + "<scope>" + getPropertyAsString(SCOPE) + "</scope>"; |
|
|
770 |
responseData = responseData + "<countlimit>" + getPropertyAsString(COUNTLIM) + "</countlimit>"; |
771 |
responseData = responseData + "<timelimit>" + getPropertyAsString(TIMELIM) + "</timelimit>"; |
772 |
responseData = responseData + "</operation><searchresult>"; |
773 |
res.sampleStart(); |
773 |
res.sampleStart(); |
774 |
NamingEnumeration srch = temp_client.searchTest(dirContext, getPropertyAsString(SEARCHBASE), getPropertyAsString(SEARCHFILTER), |
774 |
NamingEnumeration srch = temp_client.searchTest(dirContext, getPropertyAsString(SEARCHBASE), getPropertyAsString(SEARCHFILTER), |
775 |
getPropertyAsInt(SCOPE), getPropertyAsLong(COUNTLIM), getPropertyAsInt(TIMELIM), |
775 |
getPropertyAsInt(SCOPE), getPropertyAsLong(COUNTLIM), getPropertyAsInt(TIMELIM), |
776 |
getRequestAttributes(getPropertyAsString(ATTRIBS)), getPropertyAsBoolean(RETOBJ), |
776 |
getRequestAttributes(getPropertyAsString(ATTRIBS)), getPropertyAsBoolean(RETOBJ), |
777 |
getPropertyAsBoolean(DEREF)); |
777 |
getPropertyAsBoolean(DEREF)); |
778 |
res.sampleEnd(); |
778 |
res.sampleEnd(); |
779 |
while (srch.hasMore()) { |
779 |
writeSearchResults(sb, srch); |
780 |
SearchResult sr = (SearchResult) srch.next(); |
780 |
responseData = sb.toString(); |
781 |
responseData = responseData + "<dn>" + sr.getName() + "," + getPropertyAsString(SEARCHBASE) + "," |
781 |
} |
782 |
+ getRootdn() + "</dn>"; |
|
|
783 |
responseData = responseData + "<returnedattr>" + sr.getAttributes().size() + "</returnedattr>"; |
784 |
NamingEnumeration attrlist = sr.getAttributes().getIDs(); |
785 |
while (attrlist.hasMore()) { |
786 |
String iets = (String) attrlist.next(); |
787 |
responseData = responseData + "<attribute><attributename>" + iets |
788 |
+ "</attributename>"; |
789 |
responseData = responseData |
790 |
+ "<attributevalue>" |
791 |
+ sr.getAttributes().get(iets).toString().substring( |
792 |
iets.length() + 2) + "</attributevalue></attribute>"; |
793 |
} |
794 |
} |
795 |
responseData = responseData + "</searchresult></operation>"; |
796 |
} |
797 |
|
782 |
|
798 |
} catch (NamingException ex) { |
783 |
} catch (NamingException ex) { |
799 |
String returnData = ex.toString(); |
784 |
String returnData = ex.toString(); |
Lines 818-827
Link Here
|
818 |
return res; |
803 |
return res; |
819 |
} |
804 |
} |
820 |
|
805 |
|
821 |
public void testStarted() { |
806 |
public void writeSearchResponseHeader(final StringBuffer sb) |
822 |
testStarted(""); |
807 |
{ |
823 |
} |
808 |
sb.append("<operation><opertype>search</opertype>"); |
|
|
809 |
sb.append("<searchfilter>").append(getPropertyAsString(SEARCHFILTER)).append("</searchfilter>"); |
810 |
sb.append("<searchbase>").append(getPropertyAsString(SEARCHBASE)).append(",") |
811 |
.append(getPropertyAsString(ROOTDN)).append("</searchbase>"); |
812 |
sb.append("<scope>").append(getPropertyAsString(SCOPE)).append("</scope>"); |
813 |
sb.append("<countlimit>").append(getPropertyAsString(COUNTLIM)).append("</countlimit>"); |
814 |
sb.append("<timelimit>").append(getPropertyAsString(TIMELIM)).append("</timelimit>"); |
815 |
sb.append("</operation>"); |
816 |
} |
824 |
|
817 |
|
|
|
818 |
/** |
819 |
* Write out search results in a stable order (including order of all subelements which might |
820 |
* be reordered like attributes and their values) so that simple textual comparison can be done, |
821 |
* unless the number of results exceeds {@link #MAX_SORTED_RESULTS} in which case just stream |
822 |
* the results out without sorting. |
823 |
*/ |
824 |
public void writeSearchResults(final StringBuffer sb, final NamingEnumeration srch) |
825 |
throws NamingException |
826 |
{ |
827 |
final ArrayList sortedResults = new ArrayList(MAX_SORTED_RESULTS); |
828 |
boolean abandonedSort; |
829 |
|
830 |
sb.append("<searchresults>"); |
831 |
// read all sortedResults into memory so we can guarantee ordering |
832 |
while (srch.hasMore() && (sortedResults.size() < MAX_SORTED_RESULTS)) { |
833 |
final SearchResult sr = (SearchResult) srch.next(); |
834 |
|
835 |
sortedResults.add(sr); |
836 |
} |
837 |
|
838 |
abandonedSort = (sortedResults.size() >= MAX_SORTED_RESULTS); |
839 |
if (!abandonedSort) |
840 |
{ |
841 |
Collections.sort(sortedResults, new Comparator() |
842 |
{ |
843 |
public int compare(Object o1, Object o2) |
844 |
{ |
845 |
String nm1 = ((SearchResult) o1).getName(); |
846 |
String nm2 = ((SearchResult) o2).getName(); |
847 |
|
848 |
if (nm1 == null) |
849 |
nm1 = ""; |
850 |
if (nm2 == null) |
851 |
nm2 = ""; |
852 |
return nm1.compareTo(nm2); |
853 |
} |
854 |
}); |
855 |
} |
856 |
|
857 |
for (Iterator it = sortedResults.iterator(); it.hasNext();) |
858 |
{ |
859 |
final SearchResult sr = (SearchResult) it.next(); |
860 |
writeSearchResult(sr, sb); |
861 |
} |
862 |
|
863 |
if (abandonedSort) |
864 |
{ |
865 |
// if abonded sort because there were too many items, then read the |
866 |
// rest of the results now... |
867 |
while (srch.hasMore()) { |
868 |
final SearchResult sr = (SearchResult) srch.next(); |
869 |
|
870 |
writeSearchResult(sr, sb); |
871 |
} |
872 |
} |
873 |
sb.append("</searchresults>"); |
874 |
} |
875 |
|
876 |
private void writeSearchResult(final SearchResult sr, final StringBuffer responseData) |
877 |
throws NamingException |
878 |
{ |
879 |
final String srName = sr.getName(); |
880 |
final Attributes attrs = sr.getAttributes(); |
881 |
final ArrayList sortedAttrs; |
882 |
|
883 |
responseData.append("<searchresult>"); |
884 |
responseData.append("<dn>"); |
885 |
if (srName.length() > 0) |
886 |
responseData.append(srName).append(","); |
887 |
responseData.append(getPropertyAsString(SEARCHBASE)); |
888 |
if (getRootdn().length() > 0) |
889 |
responseData.append(",").append(getRootdn()); |
890 |
responseData.append("</dn>"); |
891 |
responseData.append("<returnedattr>").append(attrs.size()).append("</returnedattr>"); |
892 |
sortedAttrs = new ArrayList(attrs.size()); |
893 |
for (NamingEnumeration en = attrs.getAll(); en.hasMore(); ) |
894 |
{ |
895 |
final Attribute attr = (Attribute) en.next(); |
896 |
|
897 |
sortedAttrs.add(attr); |
898 |
} |
899 |
Collections.sort(sortedAttrs, new Comparator() |
900 |
{ |
901 |
public int compare(Object o1, Object o2) |
902 |
{ |
903 |
String nm1 = ((Attribute) o1).getID(); |
904 |
String nm2 = ((Attribute) o2).getID(); |
905 |
|
906 |
return nm1.compareTo(nm2); |
907 |
} |
908 |
}); |
909 |
for (Iterator ait = sortedAttrs.iterator(); ait.hasNext();) |
910 |
{ |
911 |
final Attribute attr = (Attribute) ait.next(); |
912 |
|
913 |
responseData.append("<attribute><attributename>").append(attr.getID()).append("</attributename>"); |
914 |
responseData.append("<attributevalue>"); |
915 |
if (attr.size() == 1) |
916 |
responseData.append(attr.get()); |
917 |
else |
918 |
{ |
919 |
final ArrayList sortedVals = new ArrayList(attr.size()); |
920 |
boolean first = true; |
921 |
|
922 |
for (NamingEnumeration ven = attr.getAll(); ven.hasMore(); ) |
923 |
{ |
924 |
final Object value = ven.next(); |
925 |
|
926 |
sortedVals.add(value.toString()); |
927 |
} |
928 |
|
929 |
Collections.sort(sortedVals); |
930 |
|
931 |
for (Iterator vit = sortedVals.iterator(); vit.hasNext();) |
932 |
{ |
933 |
final String value = (String) vit.next(); |
934 |
|
935 |
if (first) |
936 |
first = false; |
937 |
else |
938 |
responseData.append(", "); |
939 |
responseData.append(value); |
940 |
} |
941 |
} |
942 |
responseData.append("</attributevalue></attribute>"); |
943 |
} |
944 |
responseData.append("</searchresult>"); |
945 |
} |
946 |
|
947 |
public void testStarted() { |
948 |
testStarted(""); |
949 |
} |
950 |
|
825 |
public void testEnded() { |
951 |
public void testEnded() { |
826 |
testEnded(""); |
952 |
testEnded(""); |
827 |
} |
953 |
} |