Class DslHttpSampler

    • Field Detail

      • method

        protected String method
      • arguments

        protected final List<org.apache.jmeter.protocol.http.util.HTTPArgument> arguments
      • 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
      • element

        protected org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy element
    • 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 as post(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)
      • 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 as body(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
      • 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
      • 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) or rawParam(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 as downloadEmbeddedResources() 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
      • buildTreeUnder

        public org.apache.jorphan.collections.HashTree buildTreeUnder​(org.apache.jorphan.collections.HashTree parent,
                                                                      BuildTreeContext context)
        Description copied from interface: DslTestElement
        Builds the JMeter HashTree for this TestElement under the provided tree node.
        Specified by:
        buildTreeUnder in interface DslTestElement
        Overrides:
        buildTreeUnder in class DslBaseHttpSampler<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.