Class DslHttpSampler
- 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<DslHttpSampler>
-
- us.abstracta.jmeter.javadsl.http.DslHttpSampler
-
- All Implemented Interfaces:
DslTestElement,DslSampler,BaseThreadGroup.ThreadGroupChild
public class DslHttpSampler extends DslBaseHttpSampler<DslHttpSampler>
Allows to configure a JMeter HTTP sampler to make HTTP requests in a test plan.- Since:
- 0.1
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDslHttpSampler.CodeBuilderstatic classDslHttpSampler.HttpClientImplSpecifies an HTTP client implementation to be used by HTTP samplers.-
Nested classes/interfaces inherited from class us.abstracta.jmeter.javadsl.http.DslBaseHttpSampler
DslBaseHttpSampler.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 List<org.apache.jmeter.protocol.http.util.HTTPArgument>argumentsprotected Objectbodyprotected DslHttpSampler.HttpClientImplclientImplprotected booleandownloadEmbeddedResourcesprotected org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxyelementprotected StringembeddedResourcesMatchRegexprotected StringembeddedResourcesNotMatchRegexprotected Charsetencodingprotected List<org.apache.jmeter.protocol.http.util.HTTPFileArg>filesprotected BooleanfollowRedirectsprotected Stringmethodprotected booleanmultiPartprotected PropertyScriptBuilder<String>urlBuilder-
Fields inherited from class us.abstracta.jmeter.javadsl.http.DslBaseHttpSampler
connectionTimeout, headers, host, path, port, protocol, proxyPassword, proxyUrl, proxyUser, RESET_CONNECTIONS_BETWEEN_ITERATIONS_PROP, responseTimeout
-
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 DslHttpSampler(String name, Class<? extends PropertyScriptBuilder.PropertyScript<String>> urlSolverClass)DslHttpSampler(String name, String url)DslHttpSampler(String name, Function<DslJsr223PreProcessor.PreProcessorVars,String> urlSupplier)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DslHttpSamplerbody(Class<? extends PropertyScriptBuilder.PropertyScript<String>> bodySolverClass)Same asbody(Function)but with support for running at scale in a remote engine.DslHttpSamplerbody(String body)Specifies the body to be sent in the HTTP request generated by the sampler.DslHttpSamplerbody(Function<DslJsr223PreProcessor.PreProcessorVars,String> bodySupplier)Same asbody(String)but allows using dynamically calculated HTTP request body.DslHttpSamplerbodyFile(String filePath)Specifies a file to be sent as body of the request.DslHttpSamplerbodyFilePart(String name, String filePath, org.apache.http.entity.ContentType contentType)Specifies a file to be sent in a multipart form body.DslHttpSamplerbodyPart(String name, String value, org.apache.http.entity.ContentType contentType)Specifies a part of a multipart form body.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.DslHttpSamplerclientImpl(DslHttpSampler.HttpClientImpl clientImpl)Allows specifying the HTTP client implementation to use for this particular sampler.org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxyconfigureHttpTestElement(org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy elem)DslHttpSamplerdownloadEmbeddedResources()Allows enabling automatic download of HTML embedded resources (images, iframes, etc).DslHttpSamplerdownloadEmbeddedResources(boolean enable)Same asdownloadEmbeddedResources()but allowing to enable or disable the setting.DslHttpSamplerdownloadEmbeddedResourcesMatching(String urlRegex)Same asdownloadEmbeddedResources()but allowing to specify which embedded resources to actually download.DslHttpSamplerdownloadEmbeddedResourcesNotMatching(String urlRegex)Same asdownloadEmbeddedResources()but allowing to ignore embedded resources with URL matching a given regular expression.DslHttpSamplerencoding(Charset encoding)Specifies the charset to be used to encode URLs and request contents.DslHttpSamplerfollowRedirects(boolean followRedirects)Allows enabling/disabling automatic request for redirects.DslHttpSamplermethod(String method)Specifies the HTTP method to be used in the HTTP request generated by the sampler.DslHttpSamplerparam(String name, String value)Allows specifying a query parameter or url encoded form body parameter.DslHttpSamplerpost(Class<? extends PropertyScriptBuilder.PropertyScript<String>> bodySolverClass, org.apache.http.entity.ContentType contentType)Same aspost(Function, ContentType)but with support for running at scale in a remote engine.DslHttpSamplerpost(String body, org.apache.http.entity.ContentType contentType)Specifies that the sampler should send an HTTP POST to defined URL.DslHttpSamplerpost(Function<DslJsr223PreProcessor.PreProcessorVars,String> bodySupplier, org.apache.http.entity.ContentType contentType)Same aspost(String, ContentType)but allowing to use a dynamically calculated body.DslHttpSamplerrawParam(String name, String value)Same asparam(String, String)but param name and value will be sent with no additional encoding.-
Methods inherited from class us.abstracta.jmeter.javadsl.http.DslBaseHttpSampler
buildTestElement, connectionTimeout, contentType, header, header, header, host, port, protocol, proxy, proxy, responseTimeout
-
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
-
urlBuilder
protected final PropertyScriptBuilder<String> urlBuilder
-
method
protected String method
-
arguments
protected final List<org.apache.jmeter.protocol.http.util.HTTPArgument> arguments
-
body
protected Object body
-
multiPart
protected boolean multiPart
-
files
protected final List<org.apache.jmeter.protocol.http.util.HTTPFileArg> files
-
encoding
protected Charset encoding
-
followRedirects
protected Boolean followRedirects
-
downloadEmbeddedResources
protected boolean downloadEmbeddedResources
-
embeddedResourcesMatchRegex
protected String embeddedResourcesMatchRegex
-
embeddedResourcesNotMatchRegex
protected String embeddedResourcesNotMatchRegex
-
clientImpl
protected DslHttpSampler.HttpClientImpl clientImpl
-
element
protected org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy element
-
-
Constructor Detail
-
DslHttpSampler
public DslHttpSampler(String name, Function<DslJsr223PreProcessor.PreProcessorVars,String> urlSupplier)
-
DslHttpSampler
public DslHttpSampler(String name, Class<? extends PropertyScriptBuilder.PropertyScript<String>> urlSolverClass)
-
-
Method Detail
-
post
public DslHttpSampler post(String body, org.apache.http.entity.ContentType contentType)
Specifies that the sampler should send an HTTP POST to defined URL.- Parameters:
body- to include in HTTP POST request body.contentType- to be sent as Content-Type header in HTTP POST request.- Returns:
- the sampler for further configuration or usage.
- Since:
- 0.42
-
post
public DslHttpSampler post(Function<DslJsr223PreProcessor.PreProcessorVars,String> bodySupplier, org.apache.http.entity.ContentType contentType)
Same aspost(String, ContentType)but allowing to use a dynamically calculated body.This method is just an abstraction that uses jexl2 function as HTTP request body.
WARNING: This only works when using embedded jmeter engine. Check the user guide for details on some alternative.
- Parameters:
bodySupplier- function to calculate the body on each request.contentType- to be sent as Content-Type header in HTTP POST request.- Returns:
- the sampler for further configuration or usage.
- Since:
- 0.42
- See Also:
body(Function)
-
post
public DslHttpSampler post(Class<? extends PropertyScriptBuilder.PropertyScript<String>> bodySolverClass, org.apache.http.entity.ContentType contentType)
Same aspost(Function, ContentType)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:
post(Function, ContentType)
-
method
public DslHttpSampler method(String method)
Specifies the HTTP method to be used in the HTTP request generated by the sampler.- Parameters:
method- is the HTTP method to be used by the sampler.- Returns:
- the sampler for further configuration or usage.
- Since:
- 0.42
-
body
public DslHttpSampler body(String body)
Specifies the body to be sent in the HTTP request generated by the sampler.- Parameters:
body- to be used as in the body of the HTTP request.- Returns:
- the sampler for further configuration or usage.
-
body
public DslHttpSampler body(Function<DslJsr223PreProcessor.PreProcessorVars,String> bodySupplier)
Same asbody(String)but allows using dynamically calculated HTTP request body.This method is just an abstraction that uses jexl2 function as HTTP request body.
WARNING: This only works when using embedded jmeter engine. Check the user guide for details on some alternative.
- Parameters:
bodySupplier- function to calculate the body on each request.- Returns:
- the sampler for further configuration or usage.
- Since:
- 0.10
-
body
public DslHttpSampler body(Class<? extends PropertyScriptBuilder.PropertyScript<String>> bodySolverClass)
Same asbody(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:
body(Function)
-
bodyFile
public DslHttpSampler bodyFile(String filePath)
Specifies a file to be sent as body of the request.This method is useful to send binary data in request (eg: uploading an image to a server).
- Parameters:
filePath- is path to the file to be sent as request body.- Returns:
- the sampler for further configuration or usage.
- Since:
- 0.44
-
param
public DslHttpSampler param(String name, String value)
Allows specifying a query parameter or url encoded form body parameter.JMeter will automatically URL encode provided parameters names and values. Use
rawParam(String, String)to send parameters values which are already encoded and should be sent as is by JMeter.JMeter will use provided parameter in query string if method is GET, DELETE or OPTIONS, otherwise it will use them in url encoded form body.
If you set a parameter with empty string name, it results in same behavior as using
body(String)method. In general, you either use body function or parameters functions, but don't use both of them in same sampler.- Parameters:
name- specifies the name of the parameter.value- specifies the value of the parameter to be URL encoded to include in URL- Returns:
- the sampler for further configuration or usage.
- Since:
- 0.42
-
rawParam
public DslHttpSampler rawParam(String name, String value)
Same asparam(String, String)but param name and value will be sent with no additional encoding.- Since:
- 0.54
- See Also:
param(String, String)
-
bodyPart
public DslHttpSampler bodyPart(String name, String value, org.apache.http.entity.ContentType contentType)
Specifies a part of a multipart form body.In general, samplers should not use this method in combination with
param(String, String)orrawParam(String, String).- Parameters:
name- specifies the name of the part.value- specifies the string to be sent in the part.contentType- specifies the content-type associated to the part.- Returns:
- the sampler for further configuration or usage.
- Since:
- 0.42
-
bodyFilePart
public DslHttpSampler bodyFilePart(String name, String filePath, org.apache.http.entity.ContentType contentType)
Specifies a file to be sent in a multipart form body.- Parameters:
name- is the name to be assigned to the file part.filePath- is path to the file to be sent in the multipart form body.contentType- the content type associated to the part.- Returns:
- the sampler for further configuration or usage.
- Since:
- 0.42
-
encoding
public DslHttpSampler encoding(Charset encoding)
Specifies the charset to be used to encode URLs and request contents.- Parameters:
encoding- contains the charset to be used.- Returns:
- the sampler for further configuration or usage.
- Since:
- 0.39
-
followRedirects
public DslHttpSampler followRedirects(boolean followRedirects)
Allows enabling/disabling automatic request for redirects.When a response is a redirection response (3xx status code with a Location header), JMeter automatically generates a new request to the redirected destination registering the redirect request as a sub sample. This method allows enabling/disabling such behavior.
- Parameters:
followRedirects- sets either to enable or disable automatic redirects. By default, redirects are automatically followed.- Returns:
- the sampler for further configuration or usage.
- Since:
- 0.21
-
downloadEmbeddedResources
public DslHttpSampler downloadEmbeddedResources()
Allows enabling automatic download of HTML embedded resources (images, iframes, etc).When enabled JMeter will automatically parse HTMLs and download any found embedded resources adding their information as sub samples of the original request.
Additionally, and in contrast to JMeter, this will download embedded resources in parallel by default (with up to 6 parallel downloads). The DSL enables this behavior by default since it is the most common way to use it to properly emulate browsers behavior.
Check JMeter HTTP Request documentation for additional details on embedded resources download.
- Returns:
- the sampler for further configuration or usage.
- Since:
- 0.24
-
downloadEmbeddedResources
public DslHttpSampler downloadEmbeddedResources(boolean enable)
Same asdownloadEmbeddedResources()but allowing to enable or 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 sampler for further configuration or usage.
- Since:
- 1.0
-
downloadEmbeddedResourcesMatching
public DslHttpSampler 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.2
- See Also:
downloadEmbeddedResources(),downloadEmbeddedResourcesNotMatching(String)
-
downloadEmbeddedResourcesNotMatching
public DslHttpSampler 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.2
- See Also:
downloadEmbeddedResources(),downloadEmbeddedResourcesMatching(String)
-
clientImpl
public DslHttpSampler clientImpl(DslHttpSampler.HttpClientImpl clientImpl)
Allows specifying the HTTP client implementation to use for this particular sampler.Changing the default implementation (
DslHttpSampler.HttpClientImpl.HTTP_CLIENT) toDslHttpSampler.HttpClientImpl.JAVAmay improve performance in some scenarios (connection time, memory, cpu usage). But, Java implementation has its own limitations, check JMeter documentation for more details.- Parameters:
clientImpl- the HTTP client implementation to use. If none is specified, thenDslHttpSampler.HttpClientImpl.HTTP_CLIENTis used.- Returns:
- the sampler for further configuration or usage.
- Since:
- 0.39
-
configureHttpTestElement
public org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy configureHttpTestElement(org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy elem)
- Specified by:
configureHttpTestElementin classDslBaseHttpSampler<DslHttpSampler>
-
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 classDslBaseHttpSampler<DslHttpSampler>- 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.
-
-