org.apache.jmeter.protocol.http.sampler

## Class HTTPHC4Impl

- java.lang.Object
- - org.apache.jmeter.protocol.http.sampler.HTTPAbstractImpl
  - - org.apache.jmeter.protocol.http.sampler.HTTPHCAbstractImpl
    - - org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl

- All Implemented Interfaces:
    HTTPConstantsInterface, Interruptible

      public class HTTPHC4Impl
      extends HTTPHCAbstractImpl

  HTTP Sampler using Apache HttpClient 4.x.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `HTTPHC4Impl.HttpDelete`
    `static class` | `HTTPHC4Impl.HttpGetWithEntity` Implementation that allows GET method to have a body

  - ### Field Summary

    - ### Fields inherited from class org.apache.jmeter.protocol.http.sampler.HTTPHCAbstractImpl

      `CPS_HTTP, CPS_HTTPS, HTTP_VERSION, localAddress, LOCALHOST, NON_PROXY_HOST_SUFFIX_SIZE, NONPROXY_HOSTS, nonProxyHostFull, nonProxyHostSuffix, PROXY_DEFINED, PROXY_DOMAIN, PROXY_HOST, PROXY_PASS, PROXY_PORT, PROXY_SCHEME, PROXY_USER, RESET_STATE_ON_THREAD_GROUP_ITERATION, resetStateOnThreadGroupIteration, SO_TIMEOUT, USE_CACHED_SSL_CONTEXT, USE_LOOPBACK`

    - ### Fields inherited from class org.apache.jmeter.protocol.http.sampler.HTTPAbstractImpl

      `ADD_CONTENT_TYPE_TO_POST_IF_MISSING, ALL_EXCEPT_COOKIE, ONLY_COOKIE, testElement`

    - ### Fields inherited from interface org.apache.jmeter.protocol.http.util.HTTPConstantsInterface

      `APPLICATION_X_WWW_FORM_URLENCODED, CACHE_CONTROL, CONNECT, CONNECTION_CLOSE, COPY, DATE, DEFAULT_HTTP_PORT, DEFAULT_HTTP_PORT_STRING, DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_PORT_STRING, DELETE, ENCODING_BROTLI, ENCODING_DEFLATE, ENCODING_GZIP, ETAG, EXPIRES, GET, HEAD, HEADER_AUTHORIZATION, HEADER_CONNECTION, HEADER_CONTENT_DISPOSITION, HEADER_CONTENT_ENCODING, HEADER_CONTENT_LENGTH, HEADER_CONTENT_TYPE, HEADER_COOKIE, HEADER_COOKIE_IN_REQUEST, HEADER_HOST, HEADER_LOCAL_ADDRESS, HEADER_LOCATION, HEADER_SET_COOKIE, HTTP_1_1, IF_MODIFIED_SINCE, IF_NONE_MATCH, KEEP_ALIVE, LAST_MODIFIED, LOCK, MKCALENDAR, MKCOL, MOVE, MULTIPART_FORM_DATA, OPTIONS, PATCH, POST, PROPFIND, PROPPATCH, PROTOCOL_HTTP, PROTOCOL_HTTPS, PUT, REPORT, SC_MOVED_PERMANENTLY, SC_MOVED_TEMPORARILY, SC_PERMANENT_REDIRECT, SC_SEE_OTHER, SC_TEMPORARY_REDIRECT, SEARCH, TRACE, TRANSFER_ENCODING, UNLOCK, VARY`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `HTTPHC4Impl(HTTPSamplerBase testElement)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected HTTPSampleResult` | `createSampleResult(URL url, String method)` Create HTTPSampleResult filling url, method and SampleLabel.
    `protected org.apache.http.client.AuthenticationStrategy` | `getProxyAuthStrategy()`
    `protected void` | `handleMethod(String method, HTTPSampleResult result, org.apache.http.client.methods.HttpRequestBase httpRequest, org.apache.http.protocol.HttpContext localContext)` Setup Body of request if different from GET.
    `boolean` | `interrupt()` Interrupt the current operation if possible.
    `protected void` | `notifyFirstSampleAfterLoopRestart()`
    `protected HTTPSampleResult` | `sample(URL url, String method, boolean areFollowingRedirect, int frameDepth)`
    `protected String` | `sendEntityData(org.apache.http.client.methods.HttpEntityEnclosingRequestBase entity)` Creates the entity data to be sent.
    `protected String` | `setConnectionCookie(org.apache.http.HttpRequest request, URL url, CookieManager cookieManager)` Extracts all the required cookies for that particular URL request and sets them in the `HttpMethod` passed in.
    `protected void` | `setConnectionHeaders(org.apache.http.client.methods.HttpRequestBase request, URL url, HeaderManager headerManager, CacheManager cacheManager)` Extracts all the required non-cookie headers for that particular URL request and sets them in the `HttpMethod` passed in
    `protected void` | `setDefaultRequestHeaders(org.apache.http.HttpRequest request)` Set any default request headers to include
    `protected String` | `setupHttpEntityEnclosingRequestData(org.apache.http.client.methods.HttpEntityEnclosingRequestBase entityEnclosingRequest)`
    `protected void` | `setupRequest(URL url, org.apache.http.client.methods.HttpRequestBase httpRequest, HTTPSampleResult res)` Setup following elements on httpRequest: ConnRoutePNames.LOCAL_ADDRESS enabling IP-SPOOFING Socket and connection timeout Redirect handling Keep Alive header or Connection Close Calls setConnectionHeaders to setup headers Calls setConnectionCookie to setup Cookie
    `protected void` | `threadFinished()`

    - ### Methods inherited from class org.apache.jmeter.protocol.http.sampler.HTTPHCAbstractImpl

      `isDynamicProxy, isNonProxy, isNullOrEmptyTrimmed, isPartialMatch, isStaticProxy`

    - ### Methods inherited from class org.apache.jmeter.protocol.http.sampler.HTTPAbstractImpl

      `configureSampleLabel, errorResult, getArguments, getAuthManager, getAutoRedirects, getCacheManager, getConnectTimeout, getContentEncoding, getCookieManager, getDoBrowserCompatibleMultipart, getHeaderManager, getHTTPFiles, getIpSource, getIpSourceAddress, getProxyHost, getProxyPass, getProxyPortInt, getProxyScheme, getProxyUser, getResponseTimeout, getSendFileAsPostBody, getSendParameterValuesAsPostBody, getUseKeepAlive, getUseMultipart, getUseMultipartForPost, hasArguments, isMonitor, isSuccessCode, notifySSLContextWasReset, readResponse, readResponse, readResponse, readResponse, resultProcessing, setUseKeepAlive, updateSampleResultForResourceInCache`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### HTTPHC4Impl

          protected HTTPHC4Impl(HTTPSamplerBase testElement)

  - ### Method Detail

    - #### sample

          protected HTTPSampleResult sample(URL url,
                                            String method,
                                            boolean areFollowingRedirect,
                                            int frameDepth)

      Specified by:
        `sample` in class `HTTPAbstractImpl`

    - #### handleMethod

          protected void handleMethod(String method,
                                      HTTPSampleResult result,
                                      org.apache.http.client.methods.HttpRequestBase httpRequest,
                                      org.apache.http.protocol.HttpContext localContext)
                               throws IOException

      Setup Body of request if different from GET. Field HTTPSampleResult#queryString of result is modified in the 2 cases
      Parameters:
        `method` - String HTTP method
        `result` - `HTTPSampleResult`
        `httpRequest` - `HttpRequestBase`
        `localContext` - `HttpContext`
      Throws:
        `IOException` - when posting data fails due to I/O

    - #### createSampleResult

          protected HTTPSampleResult createSampleResult(URL url,
                                                        String method)

      Create HTTPSampleResult filling url, method and SampleLabel. Monitor field is computed calling isMonitor()
      Parameters:
        `url` - URL
        `method` - HTTP Method
      Returns:
        `HTTPSampleResult`

    - #### getProxyAuthStrategy

          protected org.apache.http.client.AuthenticationStrategy getProxyAuthStrategy()

    - #### setupRequest

          protected void setupRequest(URL url,
                                      org.apache.http.client.methods.HttpRequestBase httpRequest,
                                      HTTPSampleResult res)
                               throws IOException

      Setup following elements on httpRequest:
      - ConnRoutePNames.LOCAL_ADDRESS enabling IP-SPOOFING
      - Socket and connection timeout
      - Redirect handling
      - Keep Alive header or Connection Close
      - Calls setConnectionHeaders to setup headers
      - Calls setConnectionCookie to setup Cookie
      Parameters:
        `url` - `URL` of the request
        `httpRequest` - http request for the request
        `res` - sample result to set cookies on
      Throws:
        `IOException` - if hostname/ip to use could not be figured out

    - #### setDefaultRequestHeaders

          protected void setDefaultRequestHeaders(org.apache.http.HttpRequest request)

      Set any default request headers to include
      Parameters:
        `request` - the HttpRequest to be used

    - #### setConnectionCookie

          protected String setConnectionCookie(org.apache.http.HttpRequest request,
                                               URL url,
                                               CookieManager cookieManager)

      Extracts all the required cookies for that particular URL request and sets them in the `HttpMethod` passed in.
      Parameters:
        `request` - `HttpRequest` for the request
        `url` - `URL` of the request
        `cookieManager` - the `CookieManager` containing all the cookies
      Returns:
        a String containing the cookie details (for the response) May be null

    - #### setConnectionHeaders

          protected void setConnectionHeaders(org.apache.http.client.methods.HttpRequestBase request,
                                              URL url,
                                              HeaderManager headerManager,
                                              CacheManager cacheManager)

      Extracts all the required non-cookie headers for that particular URL request and sets them in the `HttpMethod` passed in
      Parameters:
        `request` - `HttpRequest` which represents the request
        `url` - `URL` of the URL request
        `headerManager` - the `HeaderManager` containing all the cookies for this `UrlConfig`
        `cacheManager` - the CacheManager (may be null)

    - #### setupHttpEntityEnclosingRequestData

          protected String setupHttpEntityEnclosingRequestData(org.apache.http.client.methods.HttpEntityEnclosingRequestBase entityEnclosingRequest)
                                                        throws IOException

      Parameters:
        `entityEnclosingRequest` - `HttpEntityEnclosingRequestBase`
      Returns:
        String body sent if computable
      Throws:
        `IOException` - if sending the data fails due to I/O

    - #### sendEntityData

          protected String sendEntityData(org.apache.http.client.methods.HttpEntityEnclosingRequestBase entity)
                                   throws IOException

      Creates the entity data to be sent.

      If there is a file entry with a non-empty MIME type we use that to set the request Content-Type header, otherwise we default to whatever header is present from a Header Manager.

      If the content charset `HTTPAbstractImpl.getContentEncoding()` is null or empty we use the HC4 default provided by `HTTP.DEF_CONTENT_CHARSET` which is ISO-8859-1.

      Parameters:
        `entity` - to be processed, e.g. PUT or PATCH
      Returns:
        the entity content, may be empty
      Throws:
        `UnsupportedEncodingException` - for invalid charset name
        `IOException` - cannot really occur for ByteArrayOutputStream methods

    - #### notifyFirstSampleAfterLoopRestart

          protected void notifyFirstSampleAfterLoopRestart()

      Overrides:
        `notifyFirstSampleAfterLoopRestart` in class `HTTPAbstractImpl`

    - #### threadFinished

          protected void threadFinished()

      Overrides:
        `threadFinished` in class `HTTPAbstractImpl`

    - #### interrupt

          public boolean interrupt()

      Description copied from interface: `Interruptible`
      Interrupt the current operation if possible.
      Returns:
        `true` if there was an operation to interrupt.

Copyright © 1998-2022 Apache Software Foundation. All Rights Reserved.