1 18 19 package org.apache.jmeter.protocol.http.sampler; 20 21 import java.io.IOException ; 22 import java.net.HttpURLConnection ; 23 import java.net.URL ; 24 import org.apache.jmeter.samplers.Entry; 25 import org.apache.jmeter.protocol.http.util.accesslog.LogParser; 26 import org.apache.jmeter.protocol.http.util.accesslog.Generator; 27 import org.apache.jmeter.samplers.SampleResult; 29 30 68 public class AccessLogSampler extends HTTPSampler 69 { 70 public static final String DEFAULT_CLASS = 71 "org.apache.jmeter.protocol.http.util.accesslog.TCLogParser"; 72 73 public static final String LOG_FILE = 74 "AccessLogSampler.log_file"; 75 public static final String PARSER_CLASS_NAME = "AccessLogSampler.parser_class_name"; 76 public static final String GENERATOR_CLASS_NAME = "AccessLogSampler.generator_class_name"; 77 78 79 transient private Generator GENERATOR = null; 80 transient private LogParser PARSER = null; 81 private Class GENERATORCLASS = null; 83 private Class PARSERCLASS = null; 84 85 88 public void setLogFile(String path) 89 { 90 setProperty(LOG_FILE, path); 91 } 92 93 97 public String getLogFile() 98 { 99 return getPropertyAsString(LOG_FILE); 100 } 101 102 107 public void setParserClassName(String classname) 108 { 109 setProperty(PARSER_CLASS_NAME, classname); 110 } 111 112 116 public String getParserClassName() 117 { 118 return getPropertyAsString(PARSER_CLASS_NAME); 119 } 120 121 131 public void setGeneratorClassName(String classname){ 132 setProperty(GENERATOR_CLASS_NAME, classname); 133 } 134 135 139 public String getGeneratorClassName(){ 140 return getPropertyAsString(GENERATOR_CLASS_NAME); 141 } 142 143 147 public void setGenerator(Generator gen){ 148 if (gen == null){ 149 } else { 150 GENERATOR = gen; 151 } 152 } 153 154 158 public Generator getGenerator(){ 159 return GENERATOR; 160 } 161 162 166 public void setParser(LogParser parser){ 167 PARSER = parser; 168 } 169 170 174 public LogParser getParser(){ 175 return PARSER; 176 } 177 178 182 public SampleResult sampleWithGenerator() 183 { 184 checkParser(); 185 checkGenerator(); 186 this.instantiateParser(); 187 this.instantiateGenerator(); 188 HTTPSampler samp = null; 189 SampleResult res = null; 190 try 191 { 192 samp = (HTTPSampler) GENERATOR.generateRequest(); 193 194 197 PARSER.parse(1); 205 this.addTestElement(samp); 206 res = sample(); 207 res.setSampleLabel(toString()); 208 } 209 catch (Exception e) 210 { 211 } 213 return res; 214 } 215 216 221 public SampleResult sample(Entry e) 222 { 223 return sampleWithGenerator(); 224 } 225 226 231 public void instantiateGenerator(){ 232 if (this.getGeneratorClassName() != null 233 && this.getGeneratorClassName().length() > 0) 234 { 235 try 236 { 237 GENERATOR = (Generator) GENERATORCLASS.newInstance(); 238 if (GENERATOR != null) 239 { 240 if (this.getDomain() != null) 241 { 242 GENERATOR.setHost(this.getDomain()); 243 } 244 if (this.getPort() > 0) 245 { 246 GENERATOR.setPort(this.getPort()); 247 } 248 } 249 if (PARSER != null && GENERATOR != null) 250 { 251 PARSER.setGenerator(GENERATOR); 252 } 253 } 254 catch (InstantiationException e) 255 { 256 } 258 catch (IllegalAccessException e) 259 { 260 } 262 } 263 } 264 265 270 public boolean checkGenerator(){ 271 if (this.getGeneratorClassName() != null 272 && this.getGeneratorClassName().length() > 0) 273 { 274 try 275 { 276 if (GENERATORCLASS == null) 277 { 278 GENERATORCLASS = 279 Class.forName(this.getGeneratorClassName()); 280 } 281 return true; 282 } 283 catch (ClassNotFoundException e) 284 { 285 return false; 289 } 290 } 291 return false; 292 } 293 294 300 public void instantiateParser() 301 { 302 if (this.getParserClassName() != null && this.getParserClassName().length() > 0) 303 { 304 try 305 { 306 if (PARSER == null) 307 { 308 if (this.getLogFile() != null 309 && this.getLogFile().length() > 0) 310 { 311 PARSER = (LogParser) PARSERCLASS.newInstance(); 312 PARSER.setSourceFile(this.getLogFile()); 313 } 314 } 315 } 316 catch (InstantiationException e) 317 { 318 } 322 catch (IllegalAccessException e) 323 { 324 } 328 } 329 } 330 331 338 public boolean checkParser() 339 { 340 if (this.getParserClassName() != null && this.getParserClassName().length() > 0) 341 { 342 try 343 { 344 if (PARSERCLASS == null) 345 { 346 PARSERCLASS = Class.forName(this.getParserClassName()); 347 } 348 return true; 349 } 350 catch (ClassNotFoundException e) 351 { 352 return false; 356 } 357 } else { 358 return false; 359 } 360 } 361 362 367 public void addEncodedArgument(String name, String value, String metaData) 368 { 369 } 370 371 376 protected HttpURLConnection setupConnection(URL u, String method) 377 throws IOException 378 { 379 return null; 380 } 381 382 387 protected long connect() throws IOException 388 { 389 return -1; 390 } 391 } 392 | Popular Tags |