Class DslHttpDefaults
- java.lang.Object
-
- us.abstracta.jmeter.javadsl.core.testelements.BaseTestElement
-
- us.abstracta.jmeter.javadsl.core.configs.BaseConfigElement
-
- us.abstracta.jmeter.javadsl.http.DslHttpDefaults
-
- All Implemented Interfaces:
DslConfig,DslTestElement,DslTestPlan.TestPlanChild,BaseSampler.SamplerChild,MultiLevelTestElement,BaseThreadGroup.ThreadGroupChild
public class DslHttpDefaults extends BaseConfigElement
Allows configuring default values for common properties of HTTP samplers.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.
- Since:
- 0.39
- See Also:
DslHttpSampler
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDslHttpDefaults.CodeBuilder
-
Field Summary
Fields Modifier and Type Field Description protected DslHttpSampler.HttpClientImplclientImplprotected DurationconnectionTimeoutprotected booleandownloadEmbeddedResourcesprotected StringembeddedResourcesMatchRegexprotected StringembeddedResourcesNotMatchRegexprotected Charsetencodingprotected BooleanfollowRedirectsprotected Stringhostprotected Stringpathprotected Stringportprotected Stringprotocolprotected StringproxyPasswordprotected StringproxyUrlprotected StringproxyUserprotected DurationresponseTimeout-
Fields inherited from class us.abstracta.jmeter.javadsl.core.testelements.BaseTestElement
guiClass, name
-
-
Constructor Summary
Constructors Constructor Description DslHttpDefaults()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static voidaddPendingFollowRedirectsElement(org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy element, BuildTreeContext context)protected org.apache.jmeter.testelement.TestElementbuildTestElement()org.apache.jorphan.collections.HashTreebuildTreeUnder(org.apache.jorphan.collections.HashTree parent, BuildTreeContext context)Builds the JMeter HashTree for this TestElement under the provided tree node.DslHttpDefaultsclientImpl(DslHttpSampler.HttpClientImpl clientImpl)Allows specifying which http client implementation to use by default for HTTP samplers.DslHttpDefaultsconnectionsTtl(Duration ttl)Allows specifying the connections ttl (time-to-live) used to determine how much time a connection can be kept open.DslHttpDefaultsconnectionTimeout(Duration timeout)Allows to set the default maximum amount of time to wait for an HTTP connection to be established.DslHttpDefaultsdownloadEmbeddedResources()Allows enabling automatic download of HTML embedded resources (images, iframes, etc) by default.DslHttpDefaultsdownloadEmbeddedResources(boolean enable)Same asdownloadEmbeddedResources()but allowing to enable and disable the setting.DslHttpDefaultsdownloadEmbeddedResourcesMatching(String urlRegex)Same asdownloadEmbeddedResources()but allowing to specify which embedded resources to actually download.DslHttpDefaultsdownloadEmbeddedResourcesNotMatching(String urlRegex)Same asdownloadEmbeddedResources()but allowing to ignore embedded resources with URL matching a given regular expression.DslHttpDefaultsencoding(Charset encoding)Specifies the default charset to be used for encoding URLs and requests contents.DslHttpDefaultsfollowRedirects(boolean enable)Specifies if by default HTTP redirects should be automatically followed (a new request automatically created) when detected, or not.DslHttpDefaultshost(String host)Specifies the default server host (domain) to be used in the HTTP samplers.DslHttpDefaultspath(String path)Specifies the default URL path to be used in the HTTP samplers.DslHttpDefaultsport(int port)Specifies the default port to be used in the HTTP samplers.DslHttpDefaultsprotocol(String protocol)Specifies the default protocol (eg: HTTP, HTTPS) to be used in the HTTP samplers.DslHttpDefaultsproxy(String url)Allows specifying a proxy through which all http requests will be sent to their final destination.DslHttpDefaultsproxy(String url, String username, String password)Same asproxy(String)but allowing also to specify proxy credentials.DslHttpDefaultsresetConnectionsBetweenIterations()Specifies to reset (drop and recreate) connections on each thread group iteration.DslHttpDefaultsresetConnectionsBetweenIterations(boolean enable)Same asresetConnectionsBetweenIterations()but allowing to enable or disable setting.DslHttpDefaultsresponseTimeout(Duration timeout)Allows to set the maximum amount of time to wait for a response to an HTTP request.DslHttpDefaultsurl(String url)Specifies the default URL for HTTP samplers.-
Methods inherited from class us.abstracta.jmeter.javadsl.core.testelements.BaseTestElement
buildConfiguredTestElement, buildTestElementGui, configureTestElement, durationToSeconds, loadBeanProperties, showAndWaitFrameWith, showFrameWith, showInGui, showTestElementGui
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface us.abstracta.jmeter.javadsl.core.DslTestElement
showInGui
-
-
-
-
Field Detail
-
protocol
protected String protocol
-
host
protected String host
-
port
protected String port
-
path
protected String path
-
encoding
protected Charset encoding
-
downloadEmbeddedResources
protected boolean downloadEmbeddedResources
-
embeddedResourcesMatchRegex
protected String embeddedResourcesMatchRegex
-
embeddedResourcesNotMatchRegex
protected String embeddedResourcesNotMatchRegex
-
connectionTimeout
protected Duration connectionTimeout
-
responseTimeout
protected Duration responseTimeout
-
proxyUrl
protected String proxyUrl
-
proxyUser
protected String proxyUser
-
proxyPassword
protected String proxyPassword
-
clientImpl
protected DslHttpSampler.HttpClientImpl clientImpl
-
followRedirects
protected Boolean followRedirects
-
-
Method Detail
-
url
public DslHttpDefaults url(String url)
Specifies the default URL for HTTP samplers.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).
- Parameters:
url- specifies the default URL to be used by HTTP samplers. It might contain the path or not.- Returns:
- the config element for further configuration or usage.
-
protocol
public DslHttpDefaults protocol(String protocol)
Specifies the default protocol (eg: HTTP, HTTPS) to be used in the HTTP samplers.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.
- Parameters:
protocol- contains protocol value to be used (e.g.: http, https, etc).- Returns:
- the config element for further configuration or usage.
- Since:
- 0.49
-
host
public DslHttpDefaults host(String host)
Specifies the default server host (domain) to be used in the HTTP samplers.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.
- Parameters:
host- contains server name without protocol (no http/https) and path.- Returns:
- the config element for further configuration or usage.
- Since:
- 0.49
-
port
public DslHttpDefaults port(int port)
Specifies the default port to be used in the HTTP samplers.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.
- Parameters:
port- contains port value to be used.- Returns:
- the config element for further configuration or usage.
- Since:
- 0.49
-
path
public DslHttpDefaults path(String path)
Specifies the default URL path to be used in the HTTP samplers.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.
- Parameters:
path- contains URL path to be used by samplers.- Returns:
- the config element for further configuration or usage.
- Since:
- 0.49
-
encoding
public DslHttpDefaults encoding(Charset encoding)
Specifies the default charset to be used for encoding URLs and requests contents.This can be overwritten by
DslHttpSampler.encoding(Charset).- Parameters:
encoding- specifies the charset to be used by default.- Returns:
- the config element for further configuration or usage.
- See Also:
DslHttpSampler.encoding(Charset)
-
followRedirects
public DslHttpDefaults followRedirects(boolean enable)
Specifies if by default HTTP redirects should be automatically followed (a new request automatically created) when detected, or not.- Parameters:
enable- specifies whether to enable or disable automatic redirections by defaults. When not set then the default is true.- Returns:
- the config element for further configuration or usage.
- Since:
- 1.9
-
downloadEmbeddedResources
public DslHttpDefaults downloadEmbeddedResources()
Allows enabling automatic download of HTML embedded resources (images, iframes, etc) by default.- Returns:
- the config element for further configuration or usage.
- See Also:
DslHttpSampler.downloadEmbeddedResources()
-
downloadEmbeddedResources
public DslHttpDefaults downloadEmbeddedResources(boolean enable)
Same asdownloadEmbeddedResources()but allowing to enable and disable the setting.This is helpful when the resolution is taken at runtime.
- Parameters:
enable- specifies to enable or disable the setting. By default, it is set to false.- Returns:
- the config element for further configuration or usage.
- Since:
- 1.0
- See Also:
downloadEmbeddedResources()
-
downloadEmbeddedResourcesMatching
public DslHttpDefaults downloadEmbeddedResourcesMatching(String urlRegex)
Same asdownloadEmbeddedResources()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 indownloadEmbeddedResourcesNotMatching(String), then it will be ignored.- Parameters:
urlRegex- specifies the regular expression which will be used to ignore embedded resources that have a URL matching with it.- Returns:
- the sampler for further configuration or usage.
- Since:
- 1.3
- See Also:
downloadEmbeddedResources(),downloadEmbeddedResourcesNotMatching(String)
-
downloadEmbeddedResourcesNotMatching
public DslHttpDefaults downloadEmbeddedResourcesNotMatching(String urlRegex)
Same asdownloadEmbeddedResources()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 indownloadEmbeddedResourcesMatching(String), then it will be ignored.- Parameters:
urlRegex- specifies the regular expression which will be used to ignore embedded resources that have a URL matching with it.- Returns:
- the sampler for further configuration or usage.
- Since:
- 1.3
- See Also:
downloadEmbeddedResources(),downloadEmbeddedResourcesMatching(String)
-
connectionTimeout
public DslHttpDefaults connectionTimeout(Duration timeout)
Allows to set the default maximum amount of time to wait for an HTTP connection to be established.This can be overwritten by
DslBaseHttpSampler.connectionTimeout(Duration).- Parameters:
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.- Returns:
- the sampler for further configuration or usage.
- Since:
- 1.4
- See Also:
DslBaseHttpSampler.connectionTimeout(Duration)
-
responseTimeout
public DslHttpDefaults responseTimeout(Duration timeout)
Allows to set the maximum amount of time to wait for a response to an HTTP request.This can be overwritten by
DslBaseHttpSampler.responseTimeout(Duration).- Parameters:
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.- Returns:
- the sampler for further configuration or usage.
- Since:
- 1.4
- See Also:
DslBaseHttpSampler.responseTimeout(Duration)
-
proxy
public DslHttpDefaults proxy(String url)
Allows specifying a proxy through which all http requests will be sent to their final destination.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).- Parameters:
url- specifies the proxy url. For example http://myproxy:8181.- Returns:
- the config element for further configuration or usage.
-
proxy
public DslHttpDefaults proxy(String url, String username, String password)
Same asproxy(String)but allowing also to specify proxy credentials.- Parameters:
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.- Returns:
- the config element for further configuration or usage.
- See Also:
proxy(String)
-
clientImpl
public DslHttpDefaults clientImpl(DslHttpSampler.HttpClientImpl clientImpl)
Allows specifying which http client implementation to use by default for HTTP samplers.This can be overwritten by
DslHttpSampler.clientImpl(HttpClientImpl).- Parameters:
clientImpl- the HTTP client implementation to use. If none is specified, thenDslHttpSampler.HttpClientImpl.HTTP_CLIENTis used.- Returns:
- the config element for further configuration or usage.
- See Also:
DslHttpSampler.HttpClientImpl,DslHttpSampler.clientImpl(HttpClientImpl)
-
resetConnectionsBetweenIterations
public DslHttpDefaults resetConnectionsBetweenIterations()
Specifies to reset (drop and recreate) connections on each thread group iteration.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.
- Returns:
- the config element for further configuration or usage.
- Since:
- 1.0
-
resetConnectionsBetweenIterations
public DslHttpDefaults resetConnectionsBetweenIterations(boolean enable)
Same asresetConnectionsBetweenIterations()but allowing to enable or disable setting.This is helpful when the resolution is taken at runtime.
- Parameters:
enable- specifies to reset connections on each thread group iteration when true, otherwise reuse connections. By default, connections are reused.- Returns:
- the config element for further configuration or usage.
- Since:
- 0.65
-
connectionsTtl
public DslHttpDefaults connectionsTtl(Duration ttl)
Allows specifying the connections ttl (time-to-live) used to determine how much time a connection can be kept open.This setting allows tuning connections handling avoiding unnecessary resources usage depending on the use case and server under test settings.
- Parameters:
ttl- specifies the duration for connections to keep open before they are closed. By default, this is set to 1 minute.- Returns:
- the config element for further configuration or usage.
- Since:
- 0.65
-
buildTestElement
protected org.apache.jmeter.testelement.TestElement buildTestElement()
- Specified by:
buildTestElementin classBaseTestElement
-
buildTreeUnder
public org.apache.jorphan.collections.HashTree buildTreeUnder(org.apache.jorphan.collections.HashTree parent, BuildTreeContext context)Description copied from interface:DslTestElementBuilds the JMeter HashTree for this TestElement under the provided tree node.- Specified by:
buildTreeUnderin interfaceDslTestElement- Overrides:
buildTreeUnderin classBaseTestElement- Parameters:
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).- Returns:
- The tree created under the parent node.
-
addPendingFollowRedirectsElement
protected static void addPendingFollowRedirectsElement(org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy element, BuildTreeContext context)
-
-