T
- type of the sampler used to provide proper fluent API methods.public abstract class DslBaseHttpSampler<T extends DslBaseHttpSampler<T>> extends BaseSampler<T>
Modifier and Type | Class and Description |
---|---|
protected static class |
DslBaseHttpSampler.BaseHttpSamplerCodeBuilder |
BaseSampler.SamplerChild
Modifier and Type | Field and Description |
---|---|
protected Duration |
connectionTimeout |
protected HttpHeaders |
headers |
protected String |
host |
protected String |
path |
protected String |
port |
protected String |
protocol |
protected String |
proxyPassword |
protected String |
proxyUrl |
protected String |
proxyUser |
static String |
RESET_CONNECTIONS_BETWEEN_ITERATIONS_PROP |
protected Duration |
responseTimeout |
children
guiClass, name
Constructor and Description |
---|
DslBaseHttpSampler(String name,
String url,
Class<? extends org.apache.jmeter.gui.JMeterGUIComponent> guiClass) |
Modifier and Type | Method and Description |
---|---|
protected org.apache.jmeter.testelement.TestElement |
buildTestElement() |
org.apache.jorphan.collections.HashTree |
buildTreeUnder(org.apache.jorphan.collections.HashTree parent,
BuildTreeContext context)
Builds the JMeter HashTree for this TestElement under the provided tree node.
|
protected abstract org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy |
configureHttpTestElement(org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy elem) |
T |
connectionTimeout(Duration timeout)
Allows to set the maximum amount of time to wait for an HTTP connection to be established.
|
T |
contentType(org.apache.http.entity.ContentType contentType)
Allows to easily specify the Content-Type HTTP header to be used by the sampler.
|
T |
header(String name,
Class<? extends PropertyScriptBuilder.PropertyScript<String>> valueSupplierClass)
Same as
header(String, Function) but with support for running at scale in a remote
engine. |
T |
header(String name,
Function<DslJsr223PreProcessor.PreProcessorVars,String> valueSupplier)
Same as
header(String, String) but allows using dynamically calculated HTTP header
value. |
T |
header(String name,
String value)
Specifies an HTTP header to be sent by the sampler.
|
T |
host(String host)
Specifies the server host (domain) to be used in the HTTP request generated by the sampler.
|
T |
port(int port)
Specifies the HTTP Sampler port to be used in the HTTP request generated by the sampler.
|
T |
protocol(String protocol)
Specifies the HTTP Sampler protocol to be used in the HTTP request generated by the sampler.
|
T |
proxy(String url)
Allows specifying a proxy through which all http requests will be sent to their final
destination.
|
T |
proxy(String url,
String username,
String password)
Same as
proxy(String) but allowing also to specify proxy credentials. |
T |
responseTimeout(Duration timeout)
Allows to set the maximum amount of time to wait for a response to an HTTP request.
|
children
buildConfiguredTestElement, buildTestElementGui, configureTestElement, durationToSeconds, loadBeanProperties, showAndWaitFrameWith, showFrameWith, showInGui, showTestElementGui
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
showInGui
public static final String RESET_CONNECTIONS_BETWEEN_ITERATIONS_PROP
protected String path
protected final HttpHeaders headers
protected String protocol
protected String host
protected String port
protected String proxyUrl
protected String proxyUser
protected String proxyPassword
protected Duration connectionTimeout
protected Duration responseTimeout
public T protocol(String protocol)
You can specify entire url when creating a sampler, but this method allows you to override the protocol if needed. For example, if you have defaults element with url and just need in one sampler to have a different protocol.
In general prefer using java variables and methods, to get shorter and more maintainable code, and use this method sparingly.
protocol
- contains protocol value to be used (e.g.: http, https, etc).public T host(String host)
You can specify entire url when creating a sampler, but this method allows you to override the host if needed. For example, if you have defaults element with url and just need in one sampler to have a different host.
In general prefer using java variables and methods, to get shorter and more maintainable code, and use this method sparingly.
host
- contains server name without protocol (no http/https) and path.public T port(int port)
You can specify entire url when creating a sampler, but this method allows you to override the port if needed. For example, if you have defaults element with url and just need in one sampler to have a different port.
In general prefer using java variables and methods, to get shorter and more maintainable code, and use this method sparingly.
port
- contains port value to be used.public T header(String name, String value)
To specify multiple headers just invoke this method several times with the different header names and values.
name
- of the HTTP header.value
- of the HTTP header.public T header(String name, Function<DslJsr223PreProcessor.PreProcessorVars,String> valueSupplier)
header(String, String)
but allows using dynamically calculated HTTP header
value.
This method is just an abstraction that uses jexl2 function as HTTP header value.
WARNING: This only works when using embedded jmeter engine. Check the user guide for details on some alternative.
name
- of the HTTP header.valueSupplier
- builds the header value.public T header(String name, Class<? extends PropertyScriptBuilder.PropertyScript<String>> valueSupplierClass)
header(String, Function)
but with support for running at scale in a remote
engine.
Check the user guide for details on additional steps required to run them at scale in a remote engine.
DslJsr223PreProcessor.PreProcessorScript
,
header(String, Function)
public T contentType(org.apache.http.entity.ContentType contentType)
contentType
- value to send as Content-Type header.public T connectionTimeout(Duration timeout)
If the connection is not established within the specified timeout, then the request will fail and sample result will be marked as failed with proper response message.
timeout
- specifies the duration to be used as connection timeout. When set to 0 it
specifies to not timeout (wait indefinitely), which is not recommended. When set
to a negative number the operating system default is used. By default, is set to
-1.public T responseTimeout(Duration timeout)
If the response takes more than specified time, then the request will fail and sample result will be marked as failed with proper response message.
timeout
- specifies the duration to be used as response timeout. When set to 0 it
specifies to not timeout (wait indefinitely), which is not recommended. When set
to a negative number the operating system default is used. By default, is set to
-1.public T proxy(String url)
This is usually helpful when you need to use a proxy to access the internet when all access is behind and enterprise proxy (due to security measures) or when you want to intercept requests for further analysis or modification by other tools like fiddler or mitmproxy.
If your proxy requires authentication check proxy(String, String, String)
.
url
- specifies the proxy url. For example http://myproxy:8181.public T proxy(String url, String username, String password)
proxy(String)
but allowing also to specify proxy credentials.url
- specifies the proxy url. For example http://myproxy:8181.username
- specifies the username used to authenticate with the proxy.password
- specifies the password used to authenticate with the proxy.proxy(String)
protected org.apache.jmeter.testelement.TestElement buildTestElement()
buildTestElement
in class BaseTestElement
protected abstract org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy configureHttpTestElement(org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy elem)
public org.apache.jorphan.collections.HashTree buildTreeUnder(org.apache.jorphan.collections.HashTree parent, BuildTreeContext context)
DslTestElement
buildTreeUnder
in interface DslTestElement
buildTreeUnder
in class TestElementContainer<T extends DslBaseHttpSampler<T>,BaseSampler.SamplerChild>
parent
- the node which will be the parent for the created tree.context
- context information which contains information shared by elements while building
the test plan tree (eg: adding additional items to test plan when a particular protocol element
is added).Copyright © 2024. All rights reserved.