1 18 19 package org.apache.jmeter.examples.sampler; 20 21 import org.apache.jmeter.samplers.AbstractSampler; 22 import org.apache.jmeter.samplers.Entry; 23 import org.apache.jmeter.samplers.SampleResult; 24 import org.apache.jorphan.logging.LoggingManager; 25 import org.apache.log.Logger; 26 27 41 public class ExampleSampler extends AbstractSampler 42 { 43 44 protected static Logger log = LoggingManager.getLoggerForClass(); 45 46 public final static String DATA = "ExampleSampler.data"; 49 private transient static int classCount=0; 52 public ExampleSampler() 53 { 54 classCount++; 55 trace("ExampleSampler()"); 56 } 57 58 63 public SampleResult sample(Entry e) 64 { 65 trace("sample()"); 66 SampleResult res = new SampleResult(); 67 boolean isOK = false; String data=getData(); String response=null; 70 71 res.setSampleLabel(getTitle()); 72 75 res.sampleStart(); try { 77 78 80 response=Thread.currentThread().getName(); 81 82 85 res.setSamplerData(data); 86 res.setResponseData(response.getBytes()); 87 res.setDataType(SampleResult.TEXT); 88 89 res.setResponseCode("200"); 90 res.setResponseMessage("OK"); 91 isOK = true; 92 } 93 catch (Exception ex){ 94 log.debug("",ex); 95 res.setResponseCode("500"); 96 res.setResponseMessage(ex.toString()); 97 } 98 res.sampleEnd(); 100 res.setSuccessful(isOK); 101 102 return res; 103 } 104 105 108 private String getTitle() 109 { 110 return this.getName(); 111 } 112 113 116 public String getData() 117 { 118 return getPropertyAsString(DATA); 119 } 120 121 124 private void trace(String s) 125 { 126 String tl = getTitle(); 127 String tn = Thread.currentThread().getName(); 128 String th = this.toString(); 129 log.debug(tn+" ("+classCount+") "+tl+" "+s+" "+th); 130 } 131 } | Popular Tags |