public class DslHttpDefaults extends BaseConfigElement
This is mainly a way to avoid duplication and an alternative to using java variables or builder method. When in doubt, prefer using java variables or custom defined builder methods since they are easier to write (in some cases), read and identify their scope.
DslHttpSampler
Modifier and Type | Class and Description |
---|---|
static class |
DslHttpDefaults.CodeBuilder |
Modifier and Type | Field and Description |
---|---|
protected DslHttpSampler.HttpClientImpl |
clientImpl |
protected Duration |
connectionTimeout |
protected boolean |
downloadEmbeddedResources |
protected String |
embeddedResourcesMatchRegex |
protected String |
embeddedResourcesNotMatchRegex |
protected Charset |
encoding |
protected Boolean |
followRedirects |
protected String |
host |
protected String |
path |
protected String |
port |
protected String |
protocol |
protected String |
proxyPassword |
protected String |
proxyUrl |
protected String |
proxyUser |
protected Duration |
responseTimeout |
guiClass, name
Constructor and Description |
---|
DslHttpDefaults() |
Modifier and Type | Method and Description |
---|---|
protected static void |
addPendingFollowRedirectsElement(org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy element,
BuildTreeContext context) |
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.
|
DslHttpDefaults |
clientImpl(DslHttpSampler.HttpClientImpl clientImpl)
Allows specifying which http client implementation to use by default for HTTP samplers.
|
DslHttpDefaults |
connectionsTtl(Duration ttl)
Allows specifying the connections ttl (time-to-live) used to determine how much time a
connection can be kept open.
|
DslHttpDefaults |
connectionTimeout(Duration timeout)
Allows to set the default maximum amount of time to wait for an HTTP connection to be
established.
|
DslHttpDefaults |
downloadEmbeddedResources()
Allows enabling automatic download of HTML embedded resources (images, iframes, etc) by
default.
|
DslHttpDefaults |
downloadEmbeddedResources(boolean enable)
Same as
downloadEmbeddedResources() but allowing to enable and disable the setting. |
DslHttpDefaults |
downloadEmbeddedResourcesMatching(String urlRegex)
Same as
downloadEmbeddedResources() but allowing to specify which embedded resources
to actually download. |
DslHttpDefaults |
downloadEmbeddedResourcesNotMatching(String urlRegex)
Same as
downloadEmbeddedResources() but allowing to ignore embedded resources with URL
matching a given regular expression. |
DslHttpDefaults |
encoding(Charset encoding)
Specifies the default charset to be used for encoding URLs and requests contents.
|
DslHttpDefaults |
followRedirects(boolean enable)
Specifies if by default HTTP redirects should be automatically followed (a new request
automatically created) when detected, or not.
|
DslHttpDefaults |
host(String host)
Specifies the default server host (domain) to be used in the HTTP samplers.
|
DslHttpDefaults |
path(String path)
Specifies the default URL path to be used in the HTTP samplers.
|
DslHttpDefaults |
port(int port)
Specifies the default port to be used in the HTTP samplers.
|
DslHttpDefaults |
protocol(String protocol)
Specifies the default protocol (eg: HTTP, HTTPS) to be used in the HTTP samplers.
|
DslHttpDefaults |
proxy(String url)
Allows specifying a proxy through which all http requests will be sent to their final
destination.
|
DslHttpDefaults |
proxy(String url,
String username,
String password)
Same as
proxy(String) but allowing also to specify proxy credentials. |
DslHttpDefaults |
resetConnectionsBetweenIterations()
Specifies to reset (drop and recreate) connections on each thread group iteration.
|
DslHttpDefaults |
resetConnectionsBetweenIterations(boolean enable)
Same as
resetConnectionsBetweenIterations() but allowing to enable or disable
setting. |
DslHttpDefaults |
responseTimeout(Duration timeout)
Allows to set the maximum amount of time to wait for a response to an HTTP request.
|
DslHttpDefaults |
url(String url)
Specifies the default URL for HTTP samplers.
|
buildConfiguredTestElement, buildTestElementGui, configureTestElement, durationToSeconds, loadBeanProperties, showAndWaitFrameWith, showFrameWith, showInGui, showTestElementGui
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
showInGui
protected String protocol
protected String host
protected String port
protected String path
protected Charset encoding
protected boolean downloadEmbeddedResources
protected String embeddedResourcesMatchRegex
protected String embeddedResourcesNotMatchRegex
protected Duration connectionTimeout
protected Duration responseTimeout
protected String proxyUrl
protected String proxyUser
protected String proxyPassword
protected DslHttpSampler.HttpClientImpl clientImpl
protected Boolean followRedirects
public DslHttpDefaults url(String url)
The DSL will parse the URL and properly set each of HTTP Request Defaults properties (protocol, host, port and path).
You can later on overwrite in a sampler the path (by specifying only the path as url), or the entire url (by specifying the full url as url).
url
- specifies the default URL to be used by HTTP samplers. It might contain the path or
not.public DslHttpDefaults protocol(String protocol)
You can specify entire url through url(String)
, but this method allows you to only
specify protocol when you need to override some other default, or just want that all samplers
use same default 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 DslHttpDefaults host(String host)
You can specify entire url through url(String)
, but this method allows you to only
specify host (and not protocol) when you need to override some other default, or just want that
all samplers use same default 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 DslHttpDefaults port(int port)
You can specify entire url through url(String)
, but this method allows you to only
specify port (and not protocol or host) when you need to override some other default, or just
want that all samplers use same default 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 DslHttpDefaults path(String path)
You can specify entire url through url(String)
, but this method allows you to only
specify path (and not protocol, host or port) when you need to override some other default, or
just want that all samplers use same path.
In general prefer using java variables and methods, to get shorter and more maintainable code, and use this method sparingly.
path
- contains URL path to be used by samplers.public DslHttpDefaults encoding(Charset encoding)
This can be overwritten by DslHttpSampler.encoding(Charset)
.
encoding
- specifies the charset to be used by default.DslHttpSampler.encoding(Charset)
public DslHttpDefaults followRedirects(boolean enable)
enable
- specifies whether to enable or disable automatic redirections by defaults. When
not set then the default is true.public DslHttpDefaults downloadEmbeddedResources()
DslHttpSampler.downloadEmbeddedResources()
public DslHttpDefaults downloadEmbeddedResources(boolean enable)
downloadEmbeddedResources()
but allowing to enable and disable the setting.
This is helpful when the resolution is taken at runtime.
enable
- specifies to enable or disable the setting. By default, it is set to false.downloadEmbeddedResources()
public DslHttpDefaults downloadEmbeddedResourcesMatching(String urlRegex)
downloadEmbeddedResources()
but allowing to specify which embedded resources
to actually download.
This is helpful when only some particular requests need to be downloaded and the rest should be ignored. Eg: to only make requests to the site under test, and no other external services.
An alternative is using downloadEmbeddedResourcesNotMatching(String)
. If a resources
matches this regex and also one specified in
downloadEmbeddedResourcesNotMatching(String)
, then it will be ignored.
urlRegex
- specifies the regular expression which will be used to ignore embedded
resources that have a URL matching with it.downloadEmbeddedResources()
,
downloadEmbeddedResourcesNotMatching(String)
public DslHttpDefaults downloadEmbeddedResourcesNotMatching(String urlRegex)
downloadEmbeddedResources()
but allowing to ignore embedded resources with URL
matching a given regular expression.
This is helpful when some particular requests (for example to other external services) don't want to be included in the test execution.
An alternative is using downloadEmbeddedResourcesMatching(String)
. If a resources
matches this regex and also one specified in
downloadEmbeddedResourcesMatching(String)
, then it will be ignored.
urlRegex
- specifies the regular expression which will be used to ignore embedded
resources that have a URL matching with it.downloadEmbeddedResources()
,
downloadEmbeddedResourcesMatching(String)
public DslHttpDefaults connectionTimeout(Duration timeout)
This can be overwritten by DslBaseHttpSampler.connectionTimeout(Duration)
.
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.DslBaseHttpSampler.connectionTimeout(Duration)
public DslHttpDefaults responseTimeout(Duration timeout)
This can be overwritten by DslBaseHttpSampler.responseTimeout(Duration)
.
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.DslBaseHttpSampler.responseTimeout(Duration)
public DslHttpDefaults 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 DslHttpDefaults 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)
public DslHttpDefaults clientImpl(DslHttpSampler.HttpClientImpl clientImpl)
This can be overwritten by DslHttpSampler.clientImpl(HttpClientImpl)
.
clientImpl
- the HTTP client implementation to use. If none is specified, then
DslHttpSampler.HttpClientImpl.HTTP_CLIENT
is used.DslHttpSampler.HttpClientImpl
,
DslHttpSampler.clientImpl(HttpClientImpl)
public DslHttpDefaults resetConnectionsBetweenIterations()
By default, connections will be reused to avoid common issues of port and file descriptors exhaustion requiring OS tuning, even though this means that generated load is not realistic enough for emulating as if each iteration were a different user. If you need to proper generation of connections and disconnections between iterations, then consider using this method.
When using reset connection for each thread consider tuning OS like explained in "Configure your environment" section of this article.
Warning: This setting is applied at JVM level, which means that it will affect the entire test plan and potentially other test plans running in the same JVM instance.
public DslHttpDefaults resetConnectionsBetweenIterations(boolean enable)
resetConnectionsBetweenIterations()
but allowing to enable or disable
setting.
This is helpful when the resolution is taken at runtime.
enable
- specifies to reset connections on each thread group iteration when true,
otherwise reuse connections. By default, connections are reused.public DslHttpDefaults connectionsTtl(Duration ttl)
This setting allows tuning connections handling avoiding unnecessary resources usage depending on the use case and server under test settings.
ttl
- specifies the duration for connections to keep open before they are closed. By
default, this is set to 1 minute.protected org.apache.jmeter.testelement.TestElement buildTestElement()
buildTestElement
in class BaseTestElement
public org.apache.jorphan.collections.HashTree buildTreeUnder(org.apache.jorphan.collections.HashTree parent, BuildTreeContext context)
DslTestElement
buildTreeUnder
in interface DslTestElement
buildTreeUnder
in class BaseTestElement
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).protected static void addPendingFollowRedirectsElement(org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy element, BuildTreeContext context)
Copyright © 2023. All rights reserved.