Class BaseHttpRequest<T extends BaseHttpRequest>

java.lang.Object
sonia.scm.net.ahc.BaseHttpRequest<T>
Type Parameters:
T - request implementation
Direct Known Subclasses:
AdvancedHttpRequest, AdvancedHttpRequestWithBody

public abstract class BaseHttpRequest<T extends BaseHttpRequest> extends Object
Base class for http requests.
Since:
1.46
  • Field Details

  • Constructor Details

  • Method Details

    • request

      public AdvancedHttpResponse request() throws IOException
      Executes the request and returns the http response.
      Returns:
      http response
      Throws:
      IOException
    • self

      protected abstract T self()
      Implementing classes should return this.
      Returns:
      request instance
    • basicAuth

      public T basicAuth(String username, String password)
      Enabled http basic authentication.
      Parameters:
      username - username for http basic authentication
      password - password for http basic authentication
      Returns:
      http request instance
    • bearerAuth

      public T bearerAuth(String bearerToken)
      Enable authentication with a bearer token.
      Parameters:
      bearerToken - bearer token
      Returns:
      http request instance
      Since:
      2.28.0
    • decodeGZip

      public T decodeGZip(boolean decodeGZip)
      Enable or disabled gzip decoding. The default value is false.
      Parameters:
      decodeGZip - true to enable gzip decoding
      Returns:
      request instance
    • disableCertificateValidation

      public T disableCertificateValidation(boolean disableCertificateValidation)
      Enable or disable certificate validation of ssl certificates. The default value is false.
      Parameters:
      disableCertificateValidation - true to disable certificate validation
      Returns:
      request instance
    • disableHostnameValidation

      public T disableHostnameValidation(boolean disableHostnameValidation)
      Enable or disable the validation of ssl hostnames. The default value is false.
      Parameters:
      disableHostnameValidation - true to disable ssl hostname validation
      Returns:
      request instance
    • header

      public T header(String name, Object... values)
      Add http headers to request.
      Parameters:
      name - header name
      values - header values
      Returns:
      request instance
    • headers

      public T headers(String name, Iterable<? extends Object> values)
      Add http headers to request.
      Parameters:
      name - header name
      values - header values
      Returns:
      request instance
    • ignoreProxySettings

      public T ignoreProxySettings(boolean ignoreProxySettings)
      Ignore proxy settings. The default value is false.
      Parameters:
      ignoreProxySettings - true to ignore proxy settings.
      Returns:
      request instance
    • queryString

      public T queryString(String name, Object... values)
      Appends a query parameter to the request.
      Parameters:
      name - name of query parameter
      values - query parameter values
      Returns:
      request instance
    • queryStrings

      public T queryStrings(String name, Iterable<? extends Object> values)
      Appends a query parameter to the request.
      Parameters:
      name - name of query parameter
      values - query parameter values
      Returns:
      request instance
    • spanKind

      public T spanKind(String spanKind)
      Sets the kind of span for tracing api.
      Parameters:
      spanKind - kind of span
      Returns:
      request instance
      Since:
      2.9.0
    • acceptStatusCodes

      public T acceptStatusCodes(int... codes)
      Sets the response codes which should be traced as successful. Example: If 400 is set as acceptedStatusCodes then all requests which get a response with status code 400 will be traced as successful (not failed) request
      Parameters:
      codes - status codes which should be traced as successful
      Returns:
      request instance
      Since:
      2.10.0
    • disableTracing

      public T disableTracing()
      Disables tracing for the request. This should only be done for internal requests.
      Returns:
      request instance
    • getHeaders

      public com.google.common.collect.Multimap<String,String> getHeaders()
      Return a map with http headers used for the request.
    • getMethod

      public String getMethod()
      Returns the http method for the request.
    • getUrl

      public String getUrl()
      Returns the url for the request.
    • getSpanKind

      public String getSpanKind()
      Returns the kind of span which is used for the trace api.
      Since:
      2.9.0
    • getAcceptedStatus

      public int[] getAcceptedStatus()
      Returns the response codes which are accepted as successful by tracer.
      Returns:
      codes
      Since:
      2.10.0
    • isDecodeGZip

      public boolean isDecodeGZip()
      Returns true if the request decodes gzip compression.
    • isDisableCertificateValidation

      public boolean isDisableCertificateValidation()
      Returns true if the verification of ssl certificates is disabled.
    • isDisableHostnameValidation

      public boolean isDisableHostnameValidation()
      Returns true if the ssl hostname validation is disabled.
    • isIgnoreProxySettings

      public boolean isIgnoreProxySettings()
      Returns true if the proxy settings are ignored.
    • encoded

      protected String encoded(Object value)
      Returns the value url encoded.
      Parameters:
      value - value to encode
      Returns:
      encoded value
    • toString

      protected String toString(Object object)
      Returns string representation of the given object or null, if the object is null.