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

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


        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>";
        HTTPSampleResult result = new HTTPSampleResult();
        result.setResponseData(responseText.getBytes());
        result.setSampleLabel(context.toString());
        result.setURL(context.getUrl());
        jmctx.setCurrentSampler(context);
        jmctx.setCurrentSampler(config);
        jmctx.setPreviousResult(result);
        parser.process();
        String newUrl = config.getUrl().toString();
View Full Code Here


        HTTPSampler context =
            makeContext("http://www.apache.org/subdir/one/previous.html");
        String responseText =
            "<html><head><title>Test page</title></head><body>"
                + "<a href=\"../index.html\">Goto index page</a></body></html>";
        HTTPSampleResult result = new HTTPSampleResult();
        result.setResponseData(responseText.getBytes());
        result.setSampleLabel(context.toString());
        result.setURL(context.getUrl());
        jmctx.setCurrentSampler(context);
        jmctx.setCurrentSampler(config);
        jmctx.setPreviousResult(result);
        parser.process();
        String newUrl = config.getUrl().toString();
View Full Code Here

            makeContext("http://www.apache.org/subdir/previous.html");
        String responseText =
            "<html><head><title>Test page</title></head><body>"
                + "<a href=\"/home/index.html?param1=value1\">"
                + "Goto index page</a></body></html>";
        HTTPSampleResult result = new HTTPSampleResult();
        String newUrl = config.getUrl().toString();
        result.setResponseData(responseText.getBytes());
        result.setSampleLabel(context.toString());
        result.setURL(context.getUrl());
        jmctx.setCurrentSampler(context);
        jmctx.setCurrentSampler(config);
        jmctx.setPreviousResult(result);
        parser.process();
        assertEquals(newUrl, config.getUrl().toString());
View Full Code Here

            makeContext("http://www.apache.org/subdir/previous.html");
        String responseText =
            "<html><head><title>Test page</title></head><body>"
                + "<a href=\"/home/index.html?param1=value1\">"
                + "Goto index page</a></body></html>";
        HTTPSampleResult result = new HTTPSampleResult();
        String newUrl = config.getUrl().toString();
        result.setResponseData(responseText.getBytes());
        result.setSampleLabel(context.toString());
        result.setURL(context.getUrl());
        jmctx.setCurrentSampler(context);
        jmctx.setCurrentSampler(config);
        jmctx.setPreviousResult(result);
        parser.process();
        assertEquals(newUrl + "?param1=value1", config.getUrl().toString());
View Full Code Here

            makeContext("http://www.apache.org/subdir/previous.html");
        String responseText =
            "<html><head><title>Test page</title></head><body>"
                + "<a href=\"/home/index.html?param1=value1\">"
                + "Goto index page</a></body></html>";
        HTTPSampleResult result = new HTTPSampleResult();
        result.setResponseData(responseText.getBytes());
        result.setSampleLabel(context.toString());
        result.setURL(context.getUrl());
        jmctx.setCurrentSampler(context);
        jmctx.setPreviousResult(result);
        parser.process();
        String newUrl = config.getUrl().toString();
        assertTrue(
View Full Code Here

        String responseText =
            "<html><head><title>Test page</title></head><body>"
                + "<form action=\"index.html\" method=\"POST\">"
                + "<input type=\"checkbox\" name=\"test\""
                + " value=\"goto\">Goto index page</form></body></html>";
        HTTPSampleResult result = new HTTPSampleResult();
        result.setResponseData(responseText.getBytes());
        result.setSampleLabel(context.toString());
        result.setURL(context.getUrl());
        jmctx.setCurrentSampler(context);
        jmctx.setCurrentSampler(config);
        jmctx.setPreviousResult(result);
        parser.process();
        assertEquals(
View Full Code Here

        String responseText =
            "<html><head><title>Test page</title></head><body>"
                + "<form action=\"index.html\" method=\"POST\">"
                + "<input type=\"checkbox\" name=\"te$st\""
                + " value=\"goto\">Goto index page</form></body></html>";
        HTTPSampleResult result = new HTTPSampleResult();
        result.setResponseData(responseText.getBytes());
        result.setSampleLabel(context.toString());
        result.setURL(context.getUrl());
        jmctx.setCurrentSampler(context);
        jmctx.setCurrentSampler(config);
        jmctx.setPreviousResult(result);
        parser.process();
        assertEquals(
View Full Code Here

    {
      JMeterContext context = getThreadContext();
        Sampler sam = context.getCurrentSampler();
        SampleResult res = context.getPreviousResult();
        HTTPSamplerBase sampler = null;
        HTTPSampleResult result = null;
        if (res == null
            || !(sam instanceof HTTPSamplerBase)
            || !(res instanceof HTTPSampleResult))
        {
            log.info("Can't apply HTML Link Parser when the previous"
                     +" sampler run is not an HTTP Request.");
            return;
        }
        else
        {
            sampler = (HTTPSamplerBase) sam;
            result = (HTTPSampleResult) res;
        }
        List potentialLinks = new ArrayList();
        String responseText = "";
        try
        {
            responseText = new String(result.getResponseData(), "8859_1");
        }
        catch (UnsupportedEncodingException e)
        {}
        Document html;
        try
View Full Code Here

                        new FileInputStream(
                            System.getProperty("user.dir")
                                + "/testfiles/load_bug_list.jmx"))
                    .getArray()[0];
            config.setRunningVersion(true);
            HTTPSampleResult result = new HTTPSampleResult();
            HTTPSamplerBase context =
                (HTTPSamplerBase) 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();
            assertEquals(
View Full Code Here

        log.debug("Start : sample " + urlStr);
        log.debug("method " + method);

        HttpMethodBase httpMethod = null;

        HTTPSampleResult res = new HTTPSampleResult();
        res.setMonitor(isMonitor());

        res.setSampleLabel(urlStr); // May be replaced later
        res.setHTTPMethod(method);
        res.setURL(url);
        res.sampleStart(); // Count the retries as well in the time
        HttpClient client = null;
        InputStream instream = null;
        try {
            httpMethod = createHttpMethod(method, urlStr);
            // Set any default request headers
            setDefaultRequestHeaders(httpMethod);
            // Setup connection
            client = setupConnection(url, httpMethod, res);
            // Handle the various methods
            if (httpMethod instanceof EntityEnclosingMethod) {
                String postBody = sendData((EntityEnclosingMethod) httpMethod);
                res.setResponseData(postBody.getBytes());
            }
            overrideHeaders(httpMethod);
            res.setRequestHeaders(getConnectionHeaders(httpMethod));

            int statusCode = -1;
            try {
                statusCode = client.executeMethod(httpMethod);
            } catch (RuntimeException e) {
                log.error("Exception when executing '" + httpMethod + "'", e);
                throw e;
            }

            // Request sent. Now get the response:
            instream = httpMethod.getResponseBodyAsStream();

            if (instream != null) {// will be null for HEAD

                Header responseHeader = httpMethod.getResponseHeader(HEADER_CONTENT_ENCODING);
                if (responseHeader != null && ENCODING_GZIP.equals(responseHeader.getValue())) {
                    instream = new GZIPInputStream(instream);
                }
                res.setResponseData(readResponse(res, instream, (int) httpMethod.getResponseContentLength()));
            }

            res.sampleEnd();
            // Done with the sampling proper.

            // Now collect the results into the HTTPSampleResult:

            res.setSampleLabel(httpMethod.getURI().toString());
            // Pick up Actual path (after redirects)

            res.setResponseCode(Integer.toString(statusCode));
            res.setSuccessful(isSuccessCode(statusCode));

            res.setResponseMessage(httpMethod.getStatusText());

            String ct = null;
            org.apache.commons.httpclient.Header h = httpMethod.getResponseHeader(HEADER_CONTENT_TYPE);
            if (h != null)// Can be missing, e.g. on redirect
            {
                ct = h.getValue();
                res.setContentType(ct);// e.g. text/html; charset=ISO-8859-1
                res.setEncodingAndType(ct);
            }

            String responseHeaders = getResponseHeaders(httpMethod);
            res.setResponseHeaders(responseHeaders);
            if (res.isRedirect()) {
                final Header headerLocation = httpMethod.getResponseHeader(HEADER_LOCATION);
                if (headerLocation == null) { // HTTP protocol violation, but
                    // avoids NPE
                    throw new IllegalArgumentException("Missing location header");
                }
                res.setRedirectLocation(headerLocation.getValue());
            }

            // If we redirected automatically, the URL may have changed
            if (getAutoRedirects()) {
                res.setURL(new URL(httpMethod.getURI().toString()));
            }

            // Store any cookies received in the cookie manager:
            saveConnectionCookies(httpMethod, res.getURL(), getCookieManager());

            // Save cache information
            final CacheManager cacheManager = getCacheManager();
            if (cacheManager != null) {
                cacheManager.saveDetails(httpMethod, res);
            }

            // Follow redirects and download page resources if appropriate:
            res = resultProcessing(areFollowingRedirect, frameDepth, res);

            log.debug("End : sample");
            httpMethod.releaseConnection();
            return res;
        } catch (IllegalArgumentException e)// e.g. some kinds of invalid URL
        {
            res.sampleEnd();
            HTTPSampleResult err = errorResult(e, res);
            err.setSampleLabel("Error: " + url.toString());
            return err;
        } catch (IOException e) {
            res.sampleEnd();
            HTTPSampleResult err = errorResult(e, res);
            err.setSampleLabel("Error: " + url.toString());
            return err;
        } finally {
            JOrphanUtils.closeQuietly(instream);
            if (httpMethod != null) {
                httpMethod.releaseConnection();
View Full Code Here

TOP

Related Classes of org.apache.jmeter.protocol.http.sampler.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.