1 18 19 package org.apache.jmeter.protocol.http.modifier; 20 21 import java.io.Serializable ; 22 import java.util.LinkedList ; 23 import java.util.List ; 24 import java.util.Map ; 25 26 import org.apache.jmeter.config.Argument; 27 import org.apache.jmeter.config.ConfigTestElement; 28 import org.apache.jmeter.engine.event.LoopIterationEvent; 29 import org.apache.jmeter.processor.PreProcessor; 30 import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase; 31 import org.apache.jmeter.samplers.Sampler; 32 import org.apache.jmeter.testelement.TestListener; 33 import org.apache.jmeter.testelement.property.PropertyIterator; 34 import org.apache.jorphan.logging.LoggingManager; 35 import org.apache.log.Logger; 36 37 47 public class UserParameterModifier 48 extends ConfigTestElement 49 implements PreProcessor, Serializable , TestListener 50 { 51 transient private static Logger log = LoggingManager.getLoggerForClass(); 52 private static final String XMLURI = "UserParameterModifier.xmluri"; 53 54 private UserSequence allAvailableUsers; 55 56 59 public UserParameterModifier() 60 { 61 } 63 67 public void testStarted() 68 { 69 List allUsers = new LinkedList (); 71 try 72 { 73 UserParameterXMLParser readXMLParameters = 74 new UserParameterXMLParser(); 75 allUsers = readXMLParameters.getXMLParameters(getXmlUri()); 76 } 77 catch (Exception e) 78 { 79 log.error("Unable to read parameters from xml file " + getXmlUri()); 81 log.error( 82 "No unique values for http requests will be substituted for " + 83 "each thread", 84 e); 85 } 86 allAvailableUsers = new UserSequence(allUsers); 87 } 88 public void testEnded() 89 { 90 } 91 public void testStarted(String host) 92 { 93 testStarted(); 94 } 95 public void testEnded(String host) 96 { 97 } 98 99 104 105 110 public void process() 111 { 112 Sampler entry = getThreadContext().getCurrentSampler(); 113 if (!(entry instanceof HTTPSamplerBase)) 114 { 115 return; 116 } 117 HTTPSamplerBase config = (HTTPSamplerBase) entry; 118 Map currentUser = allAvailableUsers.getNextUserMods(); 119 PropertyIterator iter = config.getArguments().iterator(); 120 while (iter.hasNext()) 121 { 122 Argument arg = (Argument) iter.next().getObjectValue(); 123 if (currentUser.containsKey(arg.getName())) 127 { 128 arg.setValue((String ) currentUser.get(arg.getName())); 129 } 130 } 131 } 132 133 139 140 146 public String getXmlUri() 147 { 148 return this.getPropertyAsString(XMLURI); 149 } 150 151 157 public void setXmlUri(String xmlURI) 158 { 159 setProperty(XMLURI, xmlURI); 160 } 161 162 165 public void testIterationStart(LoopIterationEvent event) 166 { 167 } 168 169 172 public Object clone() 173 { 174 UserParameterModifier clone = (UserParameterModifier) super.clone(); 175 clone.allAvailableUsers = allAvailableUsers; 176 return clone; 177 } 178 } | Popular Tags |