Package org.apache.jmeter.protocol.http.sampler

Examples of org.apache.jmeter.protocol.http.sampler.HTTPSampler


    return context;
  }

  private HTTPSampler makeUrlConfig(String path)
  {
    HTTPSampler config = new HTTPSampler();
    config.setDomain("www.apache.org");
    config.setMethod(config.GET);
    config.setPath(path);
    config.setPort(80);
    config.setProtocol("http");
    return config;
  }
View Full Code Here


   *@param  entry  Entry object containing information about the current test
   *@return        <code>True</code> if modified, else <code>false</code>
   */
  public boolean modifyEntry(Sampler sam)
  {
    HTTPSampler sampler = null;
    if(!(sam instanceof HTTPSampler))
    {
      return false;
    }
    else
    {
      sampler = (HTTPSampler)sam;
    }
    boolean modified = false;
    Iterator iter = sampler.getArguments().iterator();
    while (iter.hasNext())
    {
      Argument arg = (Argument) iter.next();
      modified = modifyArgument(arg);
      if (modified)
View Full Code Here

        "location: http://server.com/index.html?session_id=jfdkjdkf%jddkfdfjkdjfdf";
      response = new SampleResult();
      response.setResponseData(html.getBytes());
      URLRewritingModifier mod = new URLRewritingModifier();
      mod.setArgumentName("session_id");
      HTTPSampler sampler = new HTTPSampler();
      sampler.setDomain("server.com");
      sampler.setPath("index.html");
      sampler.setMethod(HTTPSampler.GET);
      sampler.setProtocol("http");
      sampler.addArgument("session_id", "adfasdfdsafasdfasd");
      mod.modifyEntry(sampler, response);
      Arguments args = sampler.getArguments();
      assertEquals(
        "jfdkjdkf%jddkfdfjkdjfdf",
        ((Argument) args.getArguments().get(0)).getValue());
      assertEquals(
        "http://server.com:80/index.html?session_id=jfdkjdkf%jddkfdfjkdjfdf",
        sampler.toString());
    }
View Full Code Here

        "<a href=\"http://server.com/index.html?session_id=jfdkjdkfjddkfdfjkdjfdf\">";
      response = new SampleResult();
      response.setResponseData(html.getBytes());
      URLRewritingModifier mod = new URLRewritingModifier();
      mod.setArgumentName("session_id");
      HTTPSampler sampler = new HTTPSampler();
      sampler.setDomain("server.com");
      sampler.setPath("index.html");
      sampler.setMethod(HTTPSampler.GET);
      sampler.setProtocol("http");
      mod.modifyEntry(sampler, response);
      Arguments args = sampler.getArguments();
      assertEquals(
        "jfdkjdkfjddkfdfjkdjfdf",
        ((Argument) args.getArguments().get(0)).getValue());
    }
View Full Code Here

        "href='index.html?session_id=jfdkjdkfjddkfdfjkdjfdf'";
      response = new SampleResult();
      response.setResponseData(html.getBytes());
      URLRewritingModifier mod = new URLRewritingModifier();
      mod.setArgumentName("session_id");
      HTTPSampler sampler = new HTTPSampler();
      sampler.setDomain("server.com");
      sampler.setPath("index.html");
      sampler.setMethod(HTTPSampler.GET);
      sampler.setProtocol("http");
      mod.modifyEntry(sampler, response);
      Arguments args = sampler.getArguments();
      assertEquals(
        "jfdkjdkfjddkfdfjkdjfdf",
        ((Argument) args.getArguments().get(0)).getValue());
    }
View Full Code Here

  public HTTPSampler getSampler()
    throws MalformedURLException, IOException, ProtocolException
  {
    HttpTestSampleGui tempGui = new HttpTestSampleGui();
    tempGui.configure(createSampler());
    HTTPSampler result = (HTTPSampler) tempGui.createTestElement();
    result.setFollowRedirects(false);
    result.setUseKeepAlive(true);
    return result;
  }
View Full Code Here

    }
  }
  private HTTPSampler createSampler()
  {
    MultipartUrlConfig urlConfig = null;
    HTTPSampler sampler = new HTTPSampler();
    sampler.setDomain(serverName());
    log.debug("Proxy: setting server: "+sampler.getDomain());
    sampler.setMethod(method);
    log.debug("Proxy: method server: "+sampler.getMethod());
    sampler.setPath(serverUrl());
    log.debug("Proxy: setting path: "+sampler.getPath());
    sampler.setName(sampler.getPath());
    sampler.setPort(serverPort());
    log.debug("Proxy: setting port: "+sampler.getPort());
    if (url.indexOf("//") > -1)
    {
      String protocol = url.substring(0, url.indexOf(":"));
      log.debug("Proxy: setting protocol to : "+protocol);
      sampler.setProtocol(protocol);
    }
    else if(sampler.getPort() == 443)
    {
      sampler.setProtocol("https");
      log.debug("Proxy: setting protocol to https");
    }
    else
    {
      log.debug("Proxy setting default protocol to: http");
      sampler.setProtocol("http");
    }
    if ((urlConfig = isMultipart(getContentType())) != null)
    {
      urlConfig.parseArguments(postData);
      sampler.setArguments(urlConfig.getArguments());
      sampler.setFileField(urlConfig.getFileFieldName());
      sampler.setFilename(urlConfig.getFilename());
      sampler.setMimetype(urlConfig.getMimeType());
    }
    else
    {
      sampler.parseArguments(postData);
    }
    return sampler;
  }
View Full Code Here

                    String TEST_REQ=
                        "GET http://localhost/matrix.html?update=yes&d=1&d=2&d=&d=&d=&d=&d=&d=1&d=2&d=1&d=&d= HTTP/1.0\n\n";
                    HttpRequestHdr req= new HttpRequestHdr();
                    req.parse(new java.io.ByteArrayInputStream(
                            TEST_REQ.getBytes()));
                    HTTPSampler s= req.getSampler();
                    assertEquals(s.getArguments().getArguments().size(), 13);
                }
View Full Code Here

   *@param  result  !ToDo (Parameter description)
   *@return         !ToDo (Return description)
   ***********************************************************/
  public boolean modifyEntry(Sampler sam, SampleResult result)
  {
    HTTPSampler sampler = null;
    if(result == null || !(sam instanceof HTTPSampler))
    {
      return false;
    }
    else
    {
      sampler = (HTTPSampler)sam;
    }
    List potentialLinks = new ArrayList();
    String responseText = "";
    try {
      responseText = new String(result.getResponseData(),"8859_1");
    } catch(UnsupportedEncodingException e) {
    }
    Document html;
    try
    {
      int index = responseText.indexOf("<");
      if(index == -1)
      {
        index = 0;
      }
      html = (Document)HtmlParser.getDOM(responseText.substring(index));
    }
    catch (SAXException e)
    {
      return false;
    }
    addAnchorUrls(html, result, sampler, potentialLinks);
    addFormUrls(html,result,sampler,potentialLinks);
    if (potentialLinks.size() > 0)
    {
      HTTPSampler url = (HTTPSampler)potentialLinks.get(rand.nextInt(potentialLinks.size()));
      sampler.setDomain(url.getDomain());
      sampler.setPath(url.getPath());
      if(url.getMethod().equals(HTTPSampler.POST))
      {
        Iterator iter = sampler.getArguments().iterator();
        while(iter.hasNext())
        {
          Argument arg = (Argument)iter.next();
          modifyArgument(arg,url.getArguments());
        }
      }
      else
      {
        sampler.setArguments(url.getArguments());
        //config.parseArguments(url.getQueryString());
      }
      sampler.setProtocol(url.getProtocol());
      return true;
    }
    return false;
  }
View Full Code Here

          (HTTPSampler)result.getSamplerData()));
    }
    Iterator iter = urls.iterator();
    while (iter.hasNext())
    {
      HTTPSampler newUrl = (HTTPSampler)iter.next();
      try
      {
        newUrl.setMethod(HTTPSampler.POST);
        if(HtmlParser.isAnchorMatched(newUrl,config))
        {
          potentialLinks.add(newUrl);
        }
      }
View Full Code Here

TOP

Related Classes of org.apache.jmeter.protocol.http.sampler.HTTPSampler

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.