title: Jmeter sample code
body: <p>Need to test the application but I am getting below error:</p>
  
  <pre><code>ERROR - jmeter.samplers.SampleResult: setEndTime must be called after setStartTime java.lang.Throwable: Invalid call sequence
      at org.apache.jmeter.samplers.SampleResult.setEndTime(SampleResult.java:1023)
      at org.apache.jmeter.samplers.SampleResult.sampleEnd(SampleResult.java:1062)
      at infy.dop.rsi.jmeter.EmoDb.runTest(EmoDb.java:94)
      at org.apache.jmeter.protocol.java.sampler.JavaSampler.sample(JavaSampler.java:191)
      at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:434)
      at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:261)
      at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>He is my code:</p>
  
  <pre><code>public class EmoDb extends AbstractJavaSamplerClient {
      private static final Logger LOGGER = LoggerFactory.getLogger(EmoDb.class);
      private Properties prop = new Properties();
      public Arguments getDefaultParameters() {
          Arguments defaultParameters = new Arguments();
          return defaultParameters;
      }
      public void setupTest(JavaSamplerContext context) {
          for (Iterator&lt;String&gt; it = context.getParameterNamesIterator(); it.hasNext();) {
              String paramName = it.next();
              prop.put(paramName, context.getParameter(paramName));
          }
      }
      @Override
      public SampleResult runTest(JavaSamplerContext arg0) {
          SampleResult result = new SampleResult();
          try {
              URL url=new URL(" ");
              HttpURLConnection connection = (HttpURLConnection)url.openConnection();
              connection.setRequestMethod("GET");
              connection.connect();
              result.sampleStart();
              int code = connection.getResponseCode();
              if (code==200)
              {
                  System.out.println("OK");
                  result.sampleEnd();
              }
               else {
                  throw new Exception("status is not=200");
              }
  
          } catch (Exception e) {
              LOGGER.error(ExceptionUtils.getStackTrace(e));
              result.sampleEnd();
              result.setSuccessful(false);
              result.setResponseMessage("Exception: " + e);
              result.setSampleLabel(e.getMessage());
              return result;
          }
          result.setSuccessful(true);
          result.setResponseMessage("Successfully completed");
          result.setResponseOK();
          return result;
      }
  
  }
  </code></pre>