Search in sources :

Example 51 with HTTPSamplerBase

use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.

the class TestAnchorModifier method makeUrlConfig.

private HTTPSamplerBase makeUrlConfig(String path) {
    HTTPSamplerBase config = new HTTPNullSampler();
    config.setDomain("www.apache.org");
    config.setMethod(HTTPConstants.GET);
    config.setPath(path);
    config.setPort(HTTPConstants.DEFAULT_HTTP_PORT);
    config.setProtocol(HTTPConstants.PROTOCOL_HTTP);
    return config;
}
Also used : HTTPNullSampler(org.apache.jmeter.protocol.http.sampler.HTTPNullSampler) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)

Example 52 with HTTPSamplerBase

use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.

the class TestAnchorModifier method testSimpleParse.

@Test
public void testSimpleParse() throws Exception {
    HTTPSamplerBase config = makeUrlConfig(".*/index\\.html");
    HTTPSamplerBase 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();
    jmctx.setCurrentSampler(context);
    jmctx.setCurrentSampler(config);
    result.setResponseData(responseText, null);
    result.setSampleLabel(context.toString());
    result.setSamplerData(context.toString());
    result.setURL(context.getUrl());
    jmctx.setPreviousResult(result);
    parser.process();
    assertEquals("http://www.apache.org/subdir/index.html", config.getUrl().toString());
}
Also used : HTTPSampleResult(org.apache.jmeter.protocol.http.sampler.HTTPSampleResult) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase) Test(org.junit.jupiter.api.Test)

Example 53 with HTTPSamplerBase

use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.

the class TestHttpRequestHdr method testRepeatedArguments.

@Test
public void testRepeatedArguments() throws Exception {
    String url = "http://localhost/matrix.html";
    // A HTTP GET request
    String contentEncoding = "UTF-8";
    String testGetRequest = "GET " + url + "?update=yes&d=1&d=2&d=&d=&d=&d=&d=&d=1&d=2&d=1&d=&d= " + "HTTP/1.0\r\n\r\n";
    HTTPSamplerBase s = getSamplerForRequest(url, testGetRequest, contentEncoding);
    assertEquals(HTTPConstants.GET, s.getMethod());
    assertEquals(contentEncoding, s.getContentEncoding());
    // Check arguments
    Arguments arguments = s.getArguments();
    assertEquals(13, arguments.getArgumentCount());
    checkArgument((HTTPArgument) arguments.getArgument(0), "update", "yes", "yes", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(1), "d", "1", "1", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(2), "d", "2", "2", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(3), "d", "", "", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(4), "d", "", "", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(5), "d", "", "", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(6), "d", "", "", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(7), "d", "", "", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(8), "d", "1", "1", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(9), "d", "2", "2", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(10), "d", "1", "1", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(11), "d", "", "", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(12), "d", "", "", contentEncoding, false);
    // A HTTP POST request
    contentEncoding = "UTF-8";
    String postBody = "update=yes&d=1&d=2&d=&d=&d=&d=&d=&d=1&d=2&d=1&d=&d=";
    String testPostRequest = "POST " + url + " HTTP/1.0\n" + "Content-type: " + HTTPConstants.APPLICATION_X_WWW_FORM_URLENCODED + "\r\n" + "Content-length: " + getBodyLength(postBody, contentEncoding) + "\r\n" + "\r\n" + postBody;
    s = getSamplerForRequest(url, testPostRequest, contentEncoding);
    assertEquals(HTTPConstants.POST, s.getMethod());
    assertFalse(s.getDoMultipart());
    assertEquals(contentEncoding, s.getContentEncoding());
    // Check arguments
    arguments = s.getArguments();
    assertEquals(13, arguments.getArgumentCount());
    checkArgument((HTTPArgument) arguments.getArgument(0), "update", "yes", "yes", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(1), "d", "1", "1", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(2), "d", "2", "2", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(3), "d", "", "", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(4), "d", "", "", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(5), "d", "", "", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(6), "d", "", "", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(7), "d", "", "", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(8), "d", "1", "1", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(9), "d", "2", "2", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(10), "d", "1", "1", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(11), "d", "", "", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(12), "d", "", "", contentEncoding, false);
    // A HTTP POST request, with content-type text/plain
    contentEncoding = "UTF-8";
    postBody = "update=yes&d=1&d=2&d=&d=&d=&d=&d=&d=1&d=2&d=1&d=\uc385&d=";
    testPostRequest = "POST " + url + " HTTP/1.1\r\n" + "Content-type: text/plain\r\n" + "Content-length: " + getBodyLength(postBody, contentEncoding) + "\r\n" + "\r\n" + postBody;
    s = getSamplerForRequest(url, testPostRequest, contentEncoding);
    assertEquals(HTTPConstants.POST, s.getMethod());
    assertFalse(s.getDoMultipart());
    assertEquals(contentEncoding, s.getContentEncoding());
    // Check arguments
    // We should have one argument, with the value equal to the post body
    arguments = s.getArguments();
    assertEquals(1, arguments.getArgumentCount());
    checkArgument((HTTPArgument) arguments.getArgument(0), "", postBody, postBody, contentEncoding, false);
    // A HTTP POST request, with content-type text/plain; charset=UTF-8
    // The encoding should be picked up from the header we send with the request
    contentEncoding = "UTF-8";
    postBody = "update=yes&d=1&d=2&d=&d=&d=&d=&d=&d=1&d=2&d=1&d=\uc385&d=";
    testPostRequest = "POST " + url + " HTTP/1.1\r\n" + "Content-type: text/plain; charset=" + contentEncoding + "\r\n" + "Content-length: " + getBodyLength(postBody, contentEncoding) + "\r\n" + "\r\n" + postBody;
    // Use null for url to simulate that HttpRequestHdr do not
    // know the encoding for the page. Specify contentEncoding, so the
    // request is "sent" using that encoding
    s = getSamplerForRequest(null, testPostRequest, contentEncoding);
    assertEquals(HTTPConstants.POST, s.getMethod());
    assertFalse(s.getDoMultipart());
    assertEquals(contentEncoding, s.getContentEncoding());
    // Check arguments
    // We should have one argument, with the value equal to the post body
    arguments = s.getArguments();
    assertEquals(1, arguments.getArgumentCount());
    checkArgument((HTTPArgument) arguments.getArgument(0), "", postBody, postBody, contentEncoding, false);
    // A HTTP POST request, with content-type text/plain; charset=UTF-8
    // The encoding should be picked up from the header we send with the request
    contentEncoding = "UTF-8";
    url = "http://vmdal-hqqa9/retalixhq/GG_Implementation/ScreenEntity/ScreenEntityHTTP.aspx?Action=Save&ET=Vendor&TT=Single&Sid=1347280336092";
    postBody = "<Action UIStatus=\"2\"><Vendor Id=\"9292\" HOST_ID=\"0\" VENDOR=\"9292\" TERMS_TYPE=\"No Terms\" TERMS=\"0 %\"" + " AUTO_PRICE=\"Use System Default\" VM_VENDOR_TYPE=\"DSD Vendor\" ITEM_FORMAT=\"PLU\" COST_ENTRY_SORT=\"UPC/EAN\"" + " VM_REPORT_SORT=\"UPC/EAN\" VM_ORDER_SORT=\"UPC/EAN\" VM_RECEIVING_SORT=\"UPC/EAN\" VM_MAX_BACK_ORDERS=\"99\"" + " MAX_OPEN_DAYS=\"99\" PAY_BASED_ON=\"System Cost\" ORDER_COST_DATE=\"Use System Rule\" VM_CONSIDER_FREE=\"False\"" + " VM_SHOW_DETAIL=\"False\" VM_UPDATE_COST=\"No\" RD_USE_VENDOR_CC=\"False\" BLIND_RECEIVING=\"Default\"" + " EXCLUDE_RECEIVED_COST=\"False\" PRINT_ITEM_ADJ=\"False\" PRINT_OVERALL_ADJ=\"False\" PRINT_TAX_DETAIL=\"False\"" + " BLOCK_PRICE_VIEW=\"False\" DELIVERY_STATUS=\"No Delivery\" AUTO_RECEIVE=\"False\" TARGET_GM_FLAG=\"%\"" + " MINIMUM_GM_FLAG=\"%\" MARGIN_TYPE=\"Gross Margin\" HOLD_REGULAR=\"Default\" HOLD_SPECIALS=\"Default\"" + " TRUSTING_VENDOR=\"False\" AUTO_ACCEPT=\"All\" EARLY_RCPT_AFFECTS=\"All Costs\" SBT_ELIGIBLE=\"Not eligible\"" + " SBT_REPORTING_DAY=\"Monday\" AUTO_BALANCE_FLAG=\"$\" DAX_MANAGED=\"False\" CHANGE_ID=\"QA\" CHANGE_SOURCE=\"Manual Change\"" + " ORIGINAL_SOURCE=\"Manual Change\" RECORD_STATUS=\"Add\" RECORD_STATUS_DATE=\"9/7/2012 8:34:58 AM\" VENDOR_NAME=\"test\"" + " UIStatus=\"2\"/></Action>";
    testPostRequest = "POST " + url + " HTTP/1.1\r\n" + "x-requested-with: XMLHttpRequest" + "\r\n" + "Accept-Language: en-us" + "\r\n" + "Referer: http://vmdal-hqqa9/retalixhq/GG_Implementation/ScreenEntity/ScreenEntityPage.aspx?ET=Vendor&TT=Single&" + "WM=2&UID=9292&Sid=1347280331908&UITH=Blue&MUID=window_0" + "\r\n" + "Accept: */*" + "\r\n" + "Content-Type: application/x-www-form-urlencoded" + "\r\n" + "Accept-Encoding: gzip, deflate" + "\r\n" + "User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729;" + " .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; Tablet PC 2.0)" + "\r\n" + "Host: vmdal-hqqa9" + "\r\n" + "Content-Length: " + getBodyLength(postBody, contentEncoding) + "\r\n" + "Proxy-Connection: Keep-Alive" + "\r\n" + "Pragma: no-cache" + "\r\n" + "Cookie: RHQ=sid=5aaeb66c-e174-4f4c-9928-83cffcc62150" + "\r\n" + "\r\n" + postBody;
    // Use null for url to simulate that HttpRequestHdr do not
    // know the encoding for the page. Specify contentEncoding, so the
    // request is "sent" using that encoding
    s = getSamplerForRequest(null, testPostRequest, contentEncoding);
    assertEquals(HTTPConstants.POST, s.getMethod());
    assertFalse(s.getDoMultipart());
    // TODO Should this be OK ?
    // assertEquals(contentEncoding, s.getContentEncoding());
    // Check arguments
    // We should have one argument, with the value equal to the post body
    arguments = s.getArguments();
    assertEquals(1, arguments.getArgumentCount());
    checkArgument((HTTPArgument) arguments.getArgument(0), "", postBody, postBody, contentEncoding, false);
}
Also used : Arguments(org.apache.jmeter.config.Arguments) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase) Test(org.junit.jupiter.api.Test)

Example 54 with HTTPSamplerBase

use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.

the class TestHttpRequestHdr method getSamplerForRequest.

private HTTPSamplerBase getSamplerForRequest(String url, String request, String contentEncoding) throws Exception {
    HttpRequestHdr req = new HttpRequestHdr();
    ByteArrayInputStream bis = null;
    if (contentEncoding != null) {
        bis = new ByteArrayInputStream(request.getBytes(contentEncoding));
    } else {
        // Most browsers use ISO-8859-1 as default encoding, even if spec says UTF-8
        bis = new ByteArrayInputStream(request.getBytes("ISO-8859-1"));
    }
    req.parse(bis);
    bis.close();
    Map<String, String> pageEncodings = Collections.synchronizedMap(new HashMap<String, String>());
    Map<String, String> formEncodings = Collections.synchronizedMap(new HashMap<String, String>());
    if (url != null && contentEncoding != null) {
        pageEncodings.put(url, contentEncoding);
    }
    SamplerCreatorFactory creatorFactory = new SamplerCreatorFactory();
    SamplerCreator creator = creatorFactory.getSamplerCreator(req, pageEncodings, formEncodings);
    HTTPSamplerBase sampler = creator.createSampler(req, pageEncodings, formEncodings);
    creator.populateSampler(sampler, req, pageEncodings, formEncodings);
    return sampler;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)

Example 55 with HTTPSamplerBase

use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.

the class TestHttpRequestHdr method testGetRequestEncodings.

private void testGetRequestEncodings(String url) throws Exception {
    // A HTTP GET request, with encoding not known
    String contentEncoding = "";
    String param1Value = "yes";
    String param2Value = "0+5 -\u00c5\uc385%C3%85";
    String param2ValueEncoded = URLEncoder.encode(param2Value, "UTF-8");
    String testGetRequest = "GET " + url + "?param1=" + param1Value + "&param2=" + param2ValueEncoded + " " + "HTTP/1.1\r\n\r\n";
    // Use null for url and contentEncoding, to simulate that HttpRequestHdr do not
    // know the encoding for the page
    HTTPSamplerBase s = getSamplerForRequest(null, testGetRequest, null);
    assertEquals(HTTPConstants.GET, s.getMethod());
    assertEquals(contentEncoding, s.getContentEncoding());
    // Check arguments
    Arguments arguments = s.getArguments();
    assertEquals(2, arguments.getArgumentCount());
    checkArgument((HTTPArgument) arguments.getArgument(0), "param1", param1Value, param1Value, contentEncoding, false);
    // When the encoding is not known, the argument will get the encoded value, and the "encode?" set to false
    checkArgument((HTTPArgument) arguments.getArgument(1), "param2", param2ValueEncoded, param2ValueEncoded, contentEncoding, false);
    // A HTTP GET request, with UTF-8 encoding
    contentEncoding = "UTF-8";
    param1Value = "yes";
    param2Value = "0+5 -\u007c\u2aa1\u266a\u0153\u20a1\u0115\u0364\u00c5\u2052\uc385%C3%85";
    param2ValueEncoded = URLEncoder.encode(param2Value, contentEncoding);
    testGetRequest = "GET " + url + "?param1=" + param1Value + "&param2=" + param2ValueEncoded + " " + "HTTP/1.1\r\n\r\n";
    s = getSamplerForRequest(url, testGetRequest, contentEncoding);
    assertEquals(HTTPConstants.GET, s.getMethod());
    assertEquals(contentEncoding, s.getContentEncoding());
    // Check arguments
    arguments = s.getArguments();
    assertEquals(2, arguments.getArgumentCount());
    checkArgument((HTTPArgument) arguments.getArgument(0), "param1", param1Value, param1Value, contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(1), "param2", param2Value, param2ValueEncoded, contentEncoding, true);
    // A HTTP GET request, with ISO-8859-1 encoding
    contentEncoding = "ISO-8859-1";
    param1Value = "yes";
    param2Value = "0+5 -\u00c5%C3%85";
    param2ValueEncoded = URLEncoder.encode(param2Value, contentEncoding);
    testGetRequest = "GET " + url + "?param1=" + param1Value + "&param2=" + param2ValueEncoded + " " + "HTTP/1.1\r\n\r\n";
    s = getSamplerForRequest(url, testGetRequest, contentEncoding);
    assertEquals(HTTPConstants.GET, s.getMethod());
    assertEquals(contentEncoding, s.getContentEncoding());
    // Check arguments
    arguments = s.getArguments();
    assertEquals(2, arguments.getArgumentCount());
    checkArgument((HTTPArgument) arguments.getArgument(0), "param1", param1Value, param1Value, contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(1), "param2", param2Value, param2ValueEncoded, contentEncoding, true);
}
Also used : Arguments(org.apache.jmeter.config.Arguments) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)

Aggregations

HTTPSamplerBase (org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)65 Test (org.junit.jupiter.api.Test)40 SampleResult (org.apache.jmeter.samplers.SampleResult)20 Arguments (org.apache.jmeter.config.Arguments)18 HTTPSampleResult (org.apache.jmeter.protocol.http.sampler.HTTPSampleResult)14 HTTPNullSampler (org.apache.jmeter.protocol.http.sampler.HTTPNullSampler)6 HttpTestSampleGui (org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui)5 NodeList (org.w3c.dom.NodeList)4 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 HTTPFileArg (org.apache.jmeter.protocol.http.util.HTTPFileArg)3 Sampler (org.apache.jmeter.samplers.Sampler)3 NamedNodeMap (org.w3c.dom.NamedNodeMap)3 ClientCookie (org.apache.http.cookie.ClientCookie)2 BasicClientCookie (org.apache.http.impl.cookie.BasicClientCookie)2 Argument (org.apache.jmeter.config.Argument)2 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)2 JMeterContext (org.apache.jmeter.threads.JMeterContext)2 Node (org.w3c.dom.Node)2