Class DslBaseHttpSampler<T extends DslBaseHttpSampler<T>>

    • Field Detail

      • RESET_CONNECTIONS_BETWEEN_ITERATIONS_PROP

        public static final String RESET_CONNECTIONS_BETWEEN_ITERATIONS_PROP
        See Also:
        Constant Field Values
      • protocol

        protected String protocol
      • proxyUrl

        protected String proxyUrl
      • proxyUser

        protected String proxyUser
      • proxyPassword

        protected String proxyPassword
      • connectionTimeout

        protected Duration connectionTimeout
      • responseTimeout

        protected Duration responseTimeout
    • Constructor Detail

      • DslBaseHttpSampler

        public DslBaseHttpSampler​(String name,
                                  String url,
                                  Class<? extends org.apache.jmeter.gui.JMeterGUIComponent> guiClass)
    • 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 as header(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.
      • 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 as proxy(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)
      • 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: DslTestElement
        Builds the JMeter HashTree for this TestElement under the provided tree node.
        Specified by:
        buildTreeUnder in interface DslTestElement
        Overrides:
        buildTreeUnder in class TestElementContainer<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.