use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.
the class HTTPFileArgsPanel method modifyTestElement.
/**
* Save the GUI data in the HTTPSamplerBase element.
*
* @param testElement {@link TestElement} to modify
*/
public void modifyTestElement(TestElement testElement) {
GuiUtils.stopTableEditing(table);
if (testElement instanceof HTTPSamplerBase) {
HTTPSamplerBase base = (HTTPSamplerBase) testElement;
int rows = tableModel.getRowCount();
// we only put HTTPFileArgs in it
@SuppressWarnings("unchecked") Iterator<HTTPFileArg> modelData = (Iterator<HTTPFileArg>) tableModel.iterator();
HTTPFileArg[] files = new HTTPFileArg[rows];
int row = 0;
while (modelData.hasNext()) {
HTTPFileArg file = modelData.next();
files[row++] = file;
}
base.setHTTPFiles(files);
}
}
use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.
the class HtmlParsingUtils method recurseForm.
// N.B. Since the tags are extracted from an HTML Form, any values must already have been encoded
@SuppressWarnings("JdkObsolete")
private static boolean recurseForm(Node tempNode, LinkedList<HTTPSamplerBase> urlConfigs, URL context, String selectName, boolean inForm) {
NamedNodeMap nodeAtts = tempNode.getAttributes();
String tag = tempNode.getNodeName();
try {
if (inForm) {
HTTPSamplerBase url = urlConfigs.getLast();
if (tag.equalsIgnoreCase("form")) {
// $NON-NLS-1$
try {
urlConfigs.add(createFormUrlConfig(tempNode, context));
} catch (MalformedURLException e) {
inForm = false;
}
} else if (tag.equalsIgnoreCase("input")) {
// $NON-NLS-1$
// $NON-NLS-1$
url.addEncodedArgument(// $NON-NLS-1$
getAttributeValue(nodeAtts, "name"), // $NON-NLS-1$
getAttributeValue(nodeAtts, "value"));
} else if (tag.equalsIgnoreCase("textarea")) {
// $NON-NLS-1$
try {
// $NON-NLS-1$
url.addEncodedArgument(// $NON-NLS-1$
getAttributeValue(nodeAtts, "name"), tempNode.getFirstChild().getNodeValue());
} catch (NullPointerException e) {
// $NON-NLS-1$
url.addArgument(getAttributeValue(nodeAtts, "name"), "");
}
} else if (tag.equalsIgnoreCase("select")) {
// $NON-NLS-1$
// $NON-NLS-1$
selectName = getAttributeValue(nodeAtts, "name");
} else if (tag.equalsIgnoreCase("option")) {
// $NON-NLS-1$
// $NON-NLS-1$
String value = getAttributeValue(nodeAtts, "value");
if (value == null) {
try {
value = tempNode.getFirstChild().getNodeValue();
} catch (NullPointerException e) {
// $NON-NLS-1$
value = "";
}
}
url.addEncodedArgument(selectName, value);
}
} else if (tag.equalsIgnoreCase("form")) {
// $NON-NLS-1$
try {
urlConfigs.add(createFormUrlConfig(tempNode, context));
inForm = true;
} catch (MalformedURLException e) {
inForm = false;
}
}
} catch (Exception ex) {
log.warn("Some bad HTML {}", printNode(tempNode), ex);
}
NodeList childNodes = tempNode.getChildNodes();
for (int x = 0; x < childNodes.getLength(); x++) {
inForm = recurseForm(childNodes.item(x), urlConfigs, context, selectName, inForm);
}
return inForm;
}
use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.
the class TestCookieManagerThreadIteration method testJmeterVariableCookieWhenThreadIterationIsANewUser.
@Test
public void testJmeterVariableCookieWhenThreadIterationIsANewUser() {
jmvars.putObject(SAME_USER, true);
jmctx.setVariables(jmvars);
HTTPSamplerBase sampler = (HTTPSamplerBase) new HttpTestSampleGui().createTestElement();
CookieManager cookieManager = new CookieManager();
cookieManager.setControlledByThread(true);
sampler.setCookieManager(cookieManager);
sampler.setThreadContext(jmctx);
boolean res = (boolean) cookieManager.getThreadContext().getVariables().getObject(SAME_USER);
assertTrue("When test different users on the different iternations, the cookie should be cleared", res);
}
use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.
the class TestCookieManagerThreadIteration method testJmeterVariableCookieWhenThreadIterationIsSameUser.
@Test
public void testJmeterVariableCookieWhenThreadIterationIsSameUser() {
jmvars.putObject(SAME_USER, false);
jmctx.setVariables(jmvars);
HTTPSamplerBase sampler = (HTTPSamplerBase) new HttpTestSampleGui().createTestElement();
CookieManager cookieManager = new CookieManager();
cookieManager.setControlledByThread(true);
sampler.setCookieManager(cookieManager);
sampler.setThreadContext(jmctx);
boolean res = (boolean) cookieManager.getThreadContext().getVariables().getObject(SAME_USER);
assertFalse("When test same user on the different iternations, the cookie shouldn't be cleared", res);
}
use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.
the class DnsManagerTest method badDnsInCustomResolverShouldFailHttpSampler.
@ParameterizedTest
@MethodSource("org.apache.jmeter.protocol.http.sampler.HTTPSamplerFactory#getImplementations")
void badDnsInCustomResolverShouldFailHttpSampler(String httpImplementation, WireMockServer server) {
Assumptions.assumeTrue(!HTTPSamplerFactory.IMPL_JAVA.equals(httpImplementation), "Java implementation does not support custom DNS resolver yet");
DNSCacheManager dns = new DNSCacheManager();
dns.setCustomResolver(true);
dns.addServer("20.0.118.11");
// By default it uses 3 retries (see org.xbill.DNS.ExtendedResolver#setRetries)
dns.setTimeoutMs(2000);
HTTPSamplerBase http = HTTPSamplerFactory.newInstance(httpImplementation);
http.setDNSResolver(dns);
http.setMethod(HTTPSampler.GET);
http.setPort(server.port());
http.setDomain("localhost");
http.setPath("/index.html");
http.setRunningVersion(true);
SampleResult result = http.sample();
Assertions.assertEquals("Non HTTP response message: Failed to resolve host name: localhost", result.getResponseMessage(), () -> "HTTP is using a custom DNS resolver, so it must fail resolving localhost \n" + ResultAsString.toString(result));
}
Aggregations