Class DslBaseHttpSampler<T extends DslBaseHttpSampler<T>>
- java.lang.Object
-
- us.abstracta.jmeter.javadsl.core.testelements.BaseTestElement
-
- us.abstracta.jmeter.javadsl.core.testelements.TestElementContainer<T,BaseSampler.SamplerChild>
-
- us.abstracta.jmeter.javadsl.core.samplers.BaseSampler<T>
-
- us.abstracta.jmeter.javadsl.http.DslBaseHttpSampler<T>
-
- Type Parameters:
T- type of the sampler used to provide proper fluent API methods.
- All Implemented Interfaces:
DslTestElement,DslSampler,BaseThreadGroup.ThreadGroupChild
- Direct Known Subclasses:
DslHttpSampler
public abstract class DslBaseHttpSampler<T extends DslBaseHttpSampler<T>> extends BaseSampler<T>
Abstracts common logic used by HTTP based samplers.- Since:
- 0.52
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classDslBaseHttpSampler.BaseHttpSamplerCodeBuilder-
Nested classes/interfaces inherited from class us.abstracta.jmeter.javadsl.core.samplers.BaseSampler
BaseSampler.SamplerChild
-
-
Field Summary
Fields Modifier and Type Field Description protected DurationconnectionTimeoutprotected HttpHeadersheadersprotected Stringhostprotected Stringpathprotected Stringportprotected Stringprotocolprotected StringproxyPasswordprotected StringproxyUrlprotected StringproxyUserstatic StringRESET_CONNECTIONS_BETWEEN_ITERATIONS_PROPprotected DurationresponseTimeout-
Fields inherited from class us.abstracta.jmeter.javadsl.core.testelements.TestElementContainer
children
-
Fields inherited from class us.abstracta.jmeter.javadsl.core.testelements.BaseTestElement
guiClass, name
-
-
Constructor Summary
Constructors Constructor Description DslBaseHttpSampler(String name, String url, Class<? extends org.apache.jmeter.gui.JMeterGUIComponent> guiClass)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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.protected abstract org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxyconfigureHttpTestElement(org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy elem)TconnectionTimeout(Duration timeout)Allows to set the maximum amount of time to wait for an HTTP connection to be established.TcontentType(org.apache.http.entity.ContentType contentType)Allows to easily specify the Content-Type HTTP header to be used by the sampler.Theader(String name, Class<? extends PropertyScriptBuilder.PropertyScript<String>> valueSupplierClass)Same asheader(String, Function)but with support for running at scale in a remote engine.Theader(String name, String value)Specifies an HTTP header to be sent by the sampler.Theader(String name, Function<DslJsr223PreProcessor.PreProcessorVars,String> valueSupplier)Same asheader(String, String)but allows using dynamically calculated HTTP header value.Thost(String host)Specifies the server host (domain) to be used in the HTTP request generated by the sampler.Tport(int port)Specifies the HTTP Sampler port to be used in the HTTP request generated by the sampler.Tprotocol(String protocol)Specifies the HTTP Sampler protocol to be used in the HTTP request generated by the sampler.Tproxy(String url)Allows specifying a proxy through which all http requests will be sent to their final destination.Tproxy(String url, String username, String password)Same asproxy(String)but allowing also to specify proxy credentials.TresponseTimeout(Duration timeout)Allows to set the maximum amount of time to wait for a response to an HTTP request.-
Methods inherited from class us.abstracta.jmeter.javadsl.core.samplers.BaseSampler
children
-
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
-
RESET_CONNECTIONS_BETWEEN_ITERATIONS_PROP
public static final String RESET_CONNECTIONS_BETWEEN_ITERATIONS_PROP
- See Also:
- Constant Field Values
-
path
protected String path
-
headers
protected final HttpHeaders headers
-
protocol
protected String protocol
-
host
protected String host
-
port
protected String port
-
proxyUrl
protected String proxyUrl
-
proxyUser
protected String proxyUser
-
proxyPassword
protected String proxyPassword
-
connectionTimeout
protected Duration connectionTimeout
-
responseTimeout
protected Duration responseTimeout
-
-
Method Detail
-
protocol
public T protocol(String protocol)
Specifies the HTTP Sampler protocol to be used in the HTTP request generated by the sampler.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.
- Parameters:
protocol- contains protocol value to be used (e.g.: http, https, etc).- Returns:
- the sampler for further configuration or usage.
-
host
public T host(String host)
Specifies the server host (domain) to be used in the HTTP request generated by the sampler.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.
- Parameters:
host- contains server name without protocol (no http/https) and path.- Returns:
- the sampler for further configuration or usage.
-
port
public T port(int port)
Specifies the HTTP Sampler port to be used in the HTTP request generated by the sampler.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.
- Parameters:
port- contains port value to be used.- Returns:
- the sampler for further configuration or usage.
-
header
public T header(String name, String value)
Specifies an HTTP header to be sent by the sampler.To specify multiple headers just invoke this method several times with the different header names and values.
- Parameters:
name- of the HTTP header.value- of the HTTP header.- Returns:
- the sampler for further configuration or usage.
-
header
public T header(String name, Function<DslJsr223PreProcessor.PreProcessorVars,String> valueSupplier)
Same asheader(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.
- Parameters:
name- of the HTTP header.valueSupplier- builds the header value.- Returns:
- the altered sampler to allow for fluent API usage.
-
header
public T header(String name, Class<? extends PropertyScriptBuilder.PropertyScript<String>> valueSupplierClass)
Same asheader(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.
- Since:
- 1.14
- See Also:
DslJsr223PreProcessor.PreProcessorScript,header(String, Function)
-
contentType
public T contentType(org.apache.http.entity.ContentType contentType)
Allows to easily specify the Content-Type HTTP header to be used by the sampler.- Parameters:
contentType- value to send as Content-Type header.- Returns:
- the sampler for further configuration or usage.
-
connectionTimeout
public T connectionTimeout(Duration timeout)
Allows to set the maximum amount of time to wait for an HTTP connection to be established.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.
- 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. By default, is set to -1.- Returns:
- the sampler for further configuration or usage.
- Since:
- 1.4
-
responseTimeout
public T responseTimeout(Duration timeout)
Allows to set the maximum amount of time to wait for a response to an HTTP request.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.
- 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. By default, is set to -1.- Returns:
- the sampler for further configuration or usage.
- Since:
- 1.4
-
proxy
public T 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 sampler for further configuration or usage.
-
proxy
public T 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 sampler for further configuration or usage.
- See Also:
proxy(String)
-
buildTestElement
protected org.apache.jmeter.testelement.TestElement buildTestElement()
- Specified by:
buildTestElementin classBaseTestElement
-
configureHttpTestElement
protected abstract org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy configureHttpTestElement(org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy elem)
-
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 classTestElementContainer<T extends DslBaseHttpSampler<T>,BaseSampler.SamplerChild>- 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.
-
-