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

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


  /* (non-Javadoc)
   * @see org.apache.jmeter.protocol.http.util.accesslog.Generator#generateRequest()
   */
  public Object generateRequest() {
    try {
      SAMPLE = new HTTPSampler();
    } catch (NullPointerException e){
      e.printStackTrace();
    }
    return SAMPLE;
  }
View Full Code Here


    args.addArgument("password","pass");

    args.addArgument("action","login");

    config = new HTTPSampler();

    config.setName("Full Config");

    config.setProperty(HTTPSampler.DOMAIN,"www.lazer.com");

    config.setProperty(HTTPSampler.PATH,"login.jsp");

    config.setProperty(HTTPSampler.METHOD,HTTPSampler.POST);

    config.setProperty(HTTPSampler.ARGUMENTS,args);



    defaultConfig = new HTTPSampler();

    defaultConfig.setName("default");

    defaultConfig.setProperty(HTTPSampler.DOMAIN,"www.xerox.com");

    defaultConfig.setProperty(HTTPSampler.PATH,"default.html");



    partialConfig = new HTTPSampler();

    partialConfig.setProperty(HTTPSampler.PATH,"main.jsp");

    partialConfig.setProperty(HTTPSampler.METHOD,HTTPSampler.GET);
View Full Code Here

  {
    if (!(entry instanceof HTTPSampler))
    {
      return false;
    }
    HTTPSampler config = (HTTPSampler) entry;
    Map currentUser = allAvailableUsers.getNextUserMods();
    boolean changeValue = false;
    Iterator iter = config.getArguments().iterator();
    while (iter.hasNext())
    {
      Argument arg = (Argument) iter.next();
      // if parameter name exists in http request
      // then change its value
View Full Code Here

    public void testFiltering() throws Exception
    {
      ProxyControl control = new ProxyControl();
      control.addIncludedPattern(".*\\.jsp");
      control.addExcludedPattern(".*apache.org.*");
      HTTPSampler sampler = new HTTPSampler();
      sampler.setDomain("jakarta.org");
      sampler.setPath("index.jsp");
      assertTrue(control.filterUrl(sampler));
      sampler.setDomain("www.apache.org");
      assertTrue(!control.filterUrl(sampler));
      sampler.setPath("header.gif");
      sampler.setDomain("jakarta.org");
      assertTrue(!control.filterUrl(sampler));
    }
View Full Code Here

    boolean TakenFromCache = false;
    boolean isCachable = false;
    try {
      byte[] clientRequest = request.parse(new BufferedInputStream(
        ClientSocket.getInputStream()));
      HTTPSampler sampler = request.getSampler();
      HeaderManager headers = request.getHeaderManager();
      sampler.setHeaderManager(headers);
      byte[] serverResponse = sampler.sample().getResponseData();
      writeToClient(serverResponse,
        new BufferedOutputStream(ClientSocket.getOutputStream()));
      headers.removeHeaderNamed("cookie");
      target.deliverSampler(sampler,new TestElement[]{headers},serverResponse);
    } catch (UnknownHostException uhe) {
View Full Code Here

   *@return                           !ToDo (Return description)
   *@exception MalformedURLException  !ToDo (Exception description)
   ***************************************/
  public static HTTPSampler createUrlFromAnchor(String parsedUrlString, HTTPSampler context) throws MalformedURLException
  {
    HTTPSampler url = new HTTPSampler();
    url.setDomain(context.getDomain());
    url.setProtocol(context.getProtocol());
    url.setPort(context.getPort());

    // In JDK1.3, we can get the path using getPath(). However, in JDK1.2, we have to parse
    // the file to obtain the path. In the source for JDK1.3.1, they determine the path to
    // be from the start of the file up to the LAST question mark (if any).
    String contextPath = null;
    String contextFile = context.getPath();
    int indexContextQuery = contextFile.lastIndexOf('?');
    if(indexContextQuery != -1)
      contextPath = contextFile.substring(0, indexContextQuery);

    else
      contextPath = contextFile;

    int queryStarts = parsedUrlString.indexOf("?");

    if(queryStarts == -1)
      queryStarts = parsedUrlString.length();

    if(parsedUrlString.startsWith("/"))
      url.setPath(parsedUrlString.substring(0, queryStarts));

    else if(parsedUrlString.startsWith(".."))
      url.setPath(contextPath.substring(0, contextPath.substring(0,
          contextPath.lastIndexOf("/")).lastIndexOf("/")) +
          parsedUrlString.substring(2, queryStarts));

    else if(!parsedUrlString.toLowerCase().startsWith("http"))
      url.setPath(contextPath.substring(0, contextPath.lastIndexOf("/")) +
          "/" + parsedUrlString.substring(0, queryStarts));

    else
    {
      URL u = new URL(parsedUrlString);

      // Determine the path. (See JDK1.2/1.3 comment above.)
      String uPath = null;
      String uFile = u.getFile();
      int indexUQuery = uFile.lastIndexOf('?');
      if(indexUQuery != -1)
        uPath = uFile.substring(0, indexUQuery);

      else
        uPath = uFile;

      url.setPath(uPath);
      url.setDomain(u.getHost());
      url.setProtocol(u.getProtocol());
      url.setPort(u.getPort());
    }

    if(queryStarts < parsedUrlString.length())
      url.parseArguments(parsedUrlString.substring(queryStarts + 1));

    return url;
  }
View Full Code Here

    String tag = tempNode.getNodeName();
    try
    {
      if(inForm)
      {
        HTTPSampler url = (HTTPSampler)urlConfigs.getLast();
        if(tag.equalsIgnoreCase("form"))
        {
          try
          {
            urlConfigs.add(createFormUrlConfig(tempNode, context));
          }
          catch(MalformedURLException e)
          {
            inForm = false;
          }
        }
        else if(tag.equalsIgnoreCase("input"))
        {
          url.addArgument(getAttributeValue(nodeAtts, "name"),
              getAttributeValue(nodeAtts, "value"));
        }

        else if(tag.equalsIgnoreCase("textarea"))
          try
          {
            url.addArgument(getAttributeValue(nodeAtts, "name"),
                tempNode.getFirstChild().getNodeValue());
          }
          catch(NullPointerException e)
          {
            url.addArgument(getAttributeValue(nodeAtts, "name"), "");
          }

        else if(tag.equalsIgnoreCase("select"))
          selectName = getAttributeValue(nodeAtts, "name");

        else if(tag.equalsIgnoreCase("option"))
        {
          String value = getAttributeValue(nodeAtts, "value");
          if(value == null)
          {
            try
            {
              value = tempNode.getFirstChild().getNodeValue();
            }
            catch(NullPointerException e)
            {
              value = "";
            }
          }
          url.addArgument(selectName, value);
        }
      }
      else if(tag.equalsIgnoreCase("form"))
      {
        try
View Full Code Here

  {
    NamedNodeMap atts = tempNode.getAttributes();
    if(atts.getNamedItem("action") == null)
      throw new MalformedURLException();
    String action = atts.getNamedItem("action").getNodeValue();
    HTTPSampler url = createUrlFromAnchor(action, context);
    return url;
  }
View Full Code Here

   *
   *@return   !ToDo (Return description)
   ***************************************/
  public TestElement createTestElement()
  {
    HTTPSampler sampler;
    TestElement el = urlConfigGui.createTestElement();
    if(getImages.isSelected())
    {
      sampler = new HTTPSamplerFull();
    }
    else
    {
      sampler = new HTTPSampler();
    }
    sampler.addTestElement(el);
    this.configureTestElement(sampler);
    return sampler;
  }
View Full Code Here

   *
   *@exception  Exception  Description of Exception
   ***********************************************************/
  public void testSimpleParse() throws Exception
  {
    HTTPSampler config = makeUrlConfig(".*/index\\.html");
    HTTPSampler context = makeContext("http://www.apache.org/subdir/previous.html");
    String responseText = "<html><head><title>Test page</title></head><body>" +
        "<a href=\"index.html\">Goto index page</a></body></html>";
    SampleResult result = new SampleResult();
    result.setResponseData(responseText.getBytes());
    result.setSampleLabel(context.toString());
    result.setSamplerData(context);
    parser.modifyEntry(config, result);
    assertEquals("http://www.apache.org:80/subdir/index.html",
        config.getUrl().toString());
  }
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.