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

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


        {
            String html = "href='index.html?session_id=jfdkjdkfjddkfdfjkdjfdf\t";
            response = new SampleResult();
            response.setResponseData(html.getBytes());
            mod.setArgumentName("session_id");
            HTTPSampler sampler = createSampler();
            context.setCurrentSampler(sampler);
            context.setPreviousResult(response);
            mod.process();
            Arguments args = sampler.getArguments();
            assertEquals(
                "jfdkjdkfjddkfdfjkdjfdf",
                ((Argument) args.getArguments().get(0).getObjectValue())
                    .getValue());
        }
View Full Code Here


            response = new SampleResult();
            response.setResponseData(html.getBytes());
            mod.setArgumentName("%24sid%24");
            mod.setPathExtension(true);
            mod.setPathExtensionNoEquals(true);
            HTTPSampler sampler = createSampler();
            context.setCurrentSampler(sampler);
            context.setPreviousResult(response);
            mod.process();
            //Arguments args = sampler.getArguments();
            assertEquals(
                "index.html;%24sid%24KQNq3AAADQZoEQAxlkX8uQV5bjqVBPbT",
                sampler.getPath());
        }
View Full Code Here

                response.setResponseData(html[i].getBytes());
                URLRewritingModifier mod = new URLRewritingModifier();
                mod.setThreadContext(context);
                mod.setArgumentName("sid");
                mod.setPathExtension(false);
                HTTPSampler sampler = createSampler();
                context.setCurrentSampler(sampler);
                context.setPreviousResult(response);
                mod.process();
                Arguments args = sampler.getArguments();
                assertEquals(
                    "For case i="+i,
                    "myId",
                    ((Argument) args.getArguments().get(0).getObjectValue())
                        .getValue());
View Full Code Here

    public void process()
    {
      JMeterContext context = getThreadContext();
        Sampler sam = context.getCurrentSampler();
        SampleResult res = context.getPreviousResult();
        HTTPSampler sampler = null;
        HTTPSampleResult result = null;
        if (res == null
            || !(sam instanceof HTTPSampler)
            || !(res instanceof HTTPSampleResult))
        {
            log.info("Can't apply HTML Link Parser when the previous"
                     +" sampler run is not an HTTP Request.");
            return;
        }
        else
        {
            sampler = (HTTPSampler) sam;
            result = (HTTPSampleResult) res;
        }
        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) HtmlParsingUtils.getDOM(responseText.substring(index));
        }
        catch (SAXException e)
        {
            return;
        }
        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))
            {
                PropertyIterator iter = sampler.getArguments().iterator();
                while (iter.hasNext())
                {
                    Argument arg = (Argument) iter.next().getObjectValue();
                    modifyArgument(arg, url.getArguments());
                }
            }
            else
            {
                sampler.setArguments(url.getArguments());
                //config.parseArguments(url.getQueryString());
            }
            sampler.setProtocol(url.getProtocol());
            return;
        }
        return;
    }
View Full Code Here

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

        {
            log.debug("Creating URL from Anchor: "+parsedUrlString
                +", base: "+context);
        }
        URL url= new URL(context, parsedUrlString);
        HTTPSampler sampler = new HTTPSampler();
        sampler.setDomain(url.getHost());
        sampler.setProtocol(url.getProtocol());
        sampler.setPort(url.getPort());
        sampler.setPath(url.getPath());
        sampler.parseArguments(url.getQuery());

        return sampler;
    }
View Full Code Here

                continue;
            }
            String hrefStr = namedItem.getNodeValue();
            try
            {
                HTTPSampler newUrl =
                    HtmlParsingUtils.createUrlFromAnchor(
                        hrefStr, result.getURL());
                newUrl.setMethod(HTTPSampler.GET);
                log.debug("possible match: " + newUrl);
                if (HtmlParsingUtils.isAnchorMatched(newUrl, config))
                {
                    log.debug("Is a match! " + newUrl);
                    potentialLinks.add(newUrl);
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

        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

          jmctx = JMeterContextService.getContext();
        }

        public void testProcessingHTMLFile(String HTMLFileName) throws Exception
        {
            HTTPSampler config =
                (HTTPSampler) SaveService
                    .loadSubTree(
                        new FileInputStream(
                            System.getProperty("user.dir")
                                + "/testfiles/load_bug_list.jmx"))
                    .getArray()[0];
            config.setRunningVersion(true);
            HTTPSampleResult result = new HTTPSampleResult();
            HTTPSampler context =
                (HTTPSampler) SaveService
                    .loadSubTree(
                        new FileInputStream(
                            System.getProperty("user.dir")
                                + "/testfiles/Load_JMeter_Page.jmx"))
                    .getArray()[0];
            jmctx.setCurrentSampler(context);
            jmctx.setCurrentSampler(config);
            result.setResponseData(
                new TextFile(
                    System.getProperty("user.dir")
                        + HTMLFileName)
                    .getText()
                    .getBytes());
            result.setSampleLabel(context.toString());
            result.setSamplerData(context.toString());
            result.setURL(new URL("http://nagoya.apache.org/fakepage.html"));
            jmctx.setPreviousResult(result);
            AnchorModifier modifier = new AnchorModifier();
            modifier.setThreadContext(jmctx);
            modifier.process();
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.