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

The following examples show how to use org.apache.jmeter.protocol.http.sampler.HTTPSampleResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OAuthSamplerTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
/**
 * Test of sample method, of class OAuthSampler.
 */
@Test
public void testSample_4args() {
    System.out.println("sample");
    URL url = null;
    String method = "";
    boolean areFollowingRedirect = false;
    int frameDepth = 0;
    OAuthSampler instance = new OAuthSampler();
    HTTPSampleResult expResult = null;
    try {
        HTTPSampleResult result = instance.sample(url, method, areFollowingRedirect, frameDepth);
        fail();
    } catch (UnsupportedOperationException e) {
    }
}
 
Example #2
Source File: DummySamplerTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void testSample_http() {
    DummySampler instance = new DummySampler();
    instance.getDummy().setSimulateWaiting(true);
    instance.getDummy().setResultClass(HTTPSampleResult.class.getCanonicalName());
    SampleResult result = instance.sample(null);
    Assert.assertTrue(result instanceof HTTPSampleResult);
}
 
Example #3
Source File: ParallelHTTPSampler.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
@Override
protected HTTPSampleResult sample(java.net.URL u, String method, boolean areFollowingRedirect, int depth) {
    if (depth < 1) {
        JMeterProperty data = getData();
        StringBuilder body = new StringBuilder();
        StringBuilder req = new StringBuilder();
        if (!(data instanceof NullProperty)) {
            CollectionProperty rows = (CollectionProperty) data;

            for (JMeterProperty row : rows) {
                ArrayList<Object> curProp = (ArrayList<Object>) row.getObjectValue();
                req.append(curProp.get(0)).append("\n");
                body.append("<iframe src='").append(curProp.get(0)).append("'></iframe>\n");
            }
        }

        HTTPSampleResult res = new HTTPSampleResult();
        res.setSamplerData(req.toString());
        res.setRequestHeaders("\n");
        res.setHTTPMethod("GET");
        try {
            res.setURL(new URL("http://parallel-urls-list"));
        } catch (MalformedURLException e) {
            log.warn("Failed to set empty url", e);
        }

        res.setSuccessful(true);
        res.setResponseData(body.toString(), res.getDataEncodingWithDefault());
        res.setContentType("text/html");
        res.sampleStart();
        downloadPageResources(res, res, depth);
        if (res.getEndTime() == 0L) {
            res.sampleEnd();
        }
        return res;
    } else {
        if (impl == null) {
            impl = HCAccessor.getInstance(this);
        }

        return HCAccessor.sample(impl, u, method, areFollowingRedirect, depth);
    }
}
 
Example #4
Source File: ParallelHTTPSamplerMock.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
@Override
protected HTTPSampleResult sample(URL url, String s, boolean b, int i) {
    HTTPSampleResult res = new HTTPSampleResult();
    res.setSuccessful(true);
    return res;
}
 
Example #5
Source File: JMeterProxyControl.java    From jsflight with Apache License 2.0 4 votes vote down vote up
/**
 * Receives the recorded sampler from the proxy server for placing in the
 * test tree; this is skipped if the sampler is null (e.g. for recording SSL errors)
 * Always sends the result to any registered sample listeners.
 *
 * @param sampler    the sampler, may be null
 * @param subConfigs the configuration elements to be added (e.g. header namager)
 * @param result     the sample result, not null
 *                   TODO param serverResponse to be added to allow saving of the
 *                   server's response while recording.
 */
public synchronized void deliverSampler(final HTTPSamplerBase sampler, final TestElement[] subConfigs,
        final SampleResult result)
{
    if (sampler != null)
    {
        if (ATTEMPT_REDIRECT_DISABLING && (samplerRedirectAutomatically || samplerFollowRedirects))
        {
            if (result instanceof HTTPSampleResult)
            {
                final HTTPSampleResult httpSampleResult = (HTTPSampleResult)result;
                final String urlAsString = httpSampleResult.getUrlAsString();
                if (urlAsString.equals(LAST_REDIRECT))
                { // the url matches the last redirect
                    sampler.setEnabled(false);
                    sampler.setComment("Detected a redirect from the previous sample");
                }
                else
                { // this is not the result of a redirect
                    LAST_REDIRECT = null; // so break the chain
                }
                if (httpSampleResult.isRedirect())
                { // Save Location so resulting sample can be disabled
                    if (LAST_REDIRECT == null)
                    {
                        sampler.setComment("Detected the start of a redirect chain");
                    }
                    LAST_REDIRECT = httpSampleResult.getRedirectLocation();
                }
                else
                {
                    LAST_REDIRECT = null;
                }
            }
        }
        if (filterContentType(result) && filterUrl(sampler))
        {
            if (currentSamplerIndex >= maxSamplersPerJmx)
            {
                recorder.splitScenario();
                currentSamplerIndex = 0;
            }
            TestElement myTarget = target;
            sampler.setAutoRedirects(samplerRedirectAutomatically);
            sampler.setFollowRedirects(samplerFollowRedirects);
            sampler.setUseKeepAlive(useKeepAlive);
            sampler.setImageParser(samplerDownloadImages);

            Authorization authorization = createAuthorization(subConfigs, sampler);

            placeSampler(sampler, subConfigs, myTarget);
            currentSamplerIndex++;
        }
        else
        {
            if (LOG.isDebugEnabled())
            {
                LOG.debug("Sample excluded based on url or content-type: " + result.getUrlAsString() + " - "
                        + result.getContentType());
            }
            result.setSampleLabel("[" + result.getSampleLabel() + "]");
        }
    }
}
 
Example #6
Source File: OAuthSampler.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
protected HttpClient setupConnection(URL u, HttpMethodBase httpMethod)
        throws IOException {
    HTTPSampleResult temp = new HTTPSampleResult();
    return super.setupConnection(u, httpMethod, temp);
}
 
Example #7
Source File: OAuthSampler.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
protected HTTPSampleResult sample(URL url, String method,
                                  boolean areFollowingRedirect, int frameDepth) {
    throw new UnsupportedOperationException("Should never be called");
}