1 18 19 package org.apache.jmeter.protocol.http.modifier; 20 21 import java.io.Serializable ; 22 23 import org.apache.jmeter.config.Argument; 24 import org.apache.jmeter.engine.event.LoopIterationEvent; 25 import org.apache.jmeter.processor.PreProcessor; 26 import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase; 27 import org.apache.jmeter.samplers.Sampler; 28 import org.apache.jmeter.testelement.AbstractTestElement; 29 import org.apache.jmeter.testelement.TestListener; 30 import org.apache.jmeter.testelement.property.PropertyIterator; 31 import org.apache.jmeter.testelement.property.TestElementProperty; 32 33 53 public class ParamModifier 54 extends AbstractTestElement 55 implements TestListener, PreProcessor, Serializable 56 { 57 58 63 64 67 private final static String MASK = "ParamModifier.mask"; 68 69 74 75 78 public ParamModifier() 79 { 80 setProperty(new TestElementProperty(MASK, new ParamMask())); 81 } 82 83 public ParamMask getMask() 84 { 85 return (ParamMask) getProperty(MASK).getObjectValue(); 86 } 87 88 public void testStarted() 89 { 90 getMask().resetValue(); 91 } 92 93 public void testStarted(String host) 94 { 95 getMask().resetValue(); 96 } 97 98 public void testEnded() 99 { 100 } 101 102 public void testEnded(String host) 103 { 104 } 105 106 111 112 117 public void process() 118 { 119 Sampler sam = getThreadContext().getCurrentSampler(); 120 HTTPSamplerBase sampler = null; 121 if (!(sam instanceof HTTPSamplerBase)) 122 { 123 return; 124 } 125 else 126 { 127 sampler = (HTTPSamplerBase) sam; 128 } 129 boolean modified = false; 130 PropertyIterator iter = sampler.getArguments().iterator(); 131 while (iter.hasNext()) 132 { 133 Argument arg = (Argument) iter.next().getObjectValue(); 134 modified = modifyArgument(arg); 135 if (modified) 136 { 137 break; 138 } 139 } 140 } 141 142 147 148 155 private boolean modifyArgument(Argument arg) 156 { 157 if (arg.getName().equals(getMask().getFieldName())) 159 { 160 if ("*".equals(arg.getValue())) 162 { 163 arg.setValue(getMask().getNextValue()); 164 return true; 165 } 166 } 167 return false; 168 } 169 170 173 public void testIterationStart(LoopIterationEvent event) 174 { 175 } 176 } 177 | Popular Tags |