Class DslHttpDefaults

    • Field Detail

      • protocol

        protected String protocol
      • 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
      • followRedirects

        protected Boolean followRedirects
    • Constructor Detail

      • DslHttpDefaults

        public DslHttpDefaults()
    • 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
      • 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 as downloadEmbeddedResources() 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()
      • 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 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 config element for further configuration or usage.
        See Also:
        proxy(String)
      • 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 as resetConnectionsBetweenIterations() 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
      • 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 BaseTestElement
        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)