Package org.apache.jmeter.samplers

Examples of org.apache.jmeter.samplers.HttpSampleResult


   */
  private SampleResult sample(Entry e, boolean redirected)
  {
    catClass.debug("Start : sample2");
    long time;
    SampleResult res = new HttpSampleResult();
    UrlConfig url = getUrlConfig(e);
    if(redirected)
    {
      url.removeArguments();
    }
    URL u = null;
    try
    {
      u = url.getUrl();
      res.putValue(SampleResult.SAMPLE_LABEL, u.toString());
      res.putValue(SampleResult.DISPLAY_NAME, u.toString());
      res.putValue(HTTPSampler.URL,u);
      // specify the data to the result.
      res.putValue(HttpSampleResult.DATA, url);
      System.out.println("Sampling url: " + u);
      if(catClass.isDebugEnabled())
      {
        catClass.debug("sample2 : sampling url - " + u);
      }
      HttpURLConnection conn = setupConnection(u, url, e);
      writeToStream(redirected, url, conn);
      time = System.currentTimeMillis();
      conn.connect();
      saveConnectionCookies(conn, u, (CookieManager) e.getConfigElement(CookieManager.class));

      int errorLevel = getErrorLevel(conn, res, time);
      if (errorLevel == 2)
      {
        byte[] ret = readResponse(conn);
        time = System.currentTimeMillis() - time;
        res.putValue(SampleResult.TEXT_RESPONSE, ret);
        res.putValue(SampleResult.SUCCESS, new Boolean(true));
        getResponseHeaders(conn, res);
      }
      else if (errorLevel == 3)
      {
        redirectUrl(conn, u, url);

        time = System.currentTimeMillis() - time;
        res = sample(e, true);
        time += res.getTime();
      }
      else
      {
        // Could not sample the URL
        System.out.println("URL = " + u);
        throw new IOException();
      }
      res.setTime(time);
      catClass.debug("End : sample2");
      return res;
    }
    catch (IOException ex)
    {
      ex.printStackTrace();
      res.setTime((long) 0);
      res.putValue(this.RESPONSE_CODE,
        NON_HTTP_RESPONSE_CODE);
      res.putValue(this.RESPONSE_MESSAGE,
        NON_HTTP_RESPONSE_MESSAGE);
      res.putValue(SampleResult.TEXT_RESPONSE, ex.toString().getBytes());
      res.putValue(SampleResult.SUCCESS, new Boolean(false));
    }
    catClass.debug("End : sample2");
    return res;
  }
View Full Code Here

TOP

Related Classes of org.apache.jmeter.samplers.HttpSampleResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.