es.gob.fnmt.net

## Class DroidHttpClient

- java.lang.Object
- - es.gob.fnmt.net.DroidHttpClient

-     public final class DroidHttpClient
      extends java.lang.Object

  Manage secure HTTPS client connection with both client and server certificate authentication.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `DroidHttpClient.Builder` Java builder pattern class used to set DroidHttpClient parameters.
    `static class` | `DroidHttpClient.CookiePolicy`
    `static class` | `DroidHttpClient.MultipartData` Class that manage multipart data for 'post' method.
    `static class` | `DroidHttpClient.Parse` Class to manipulate the HTML content recovered.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `DEFAULT_HEADER_USER_AGENT`
    `static java.lang.String` | `DEFAULT_HTML_CONTENT_CHAR_SET`
    `static java.lang.String` | `DEFAULT_SSL_PROTOCOL`
    `static java.lang.String` | `DEFAULT_TRUSTED_KEYSTORE_TYPE`
    `static java.lang.String` | `DEFAUTL_TRUSTED_KEYSTORE_PROVIDER`
    `static int` | `HTTP_DEFAULT_TIMEOUT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DroidHttpClient()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addRequestHeader(java.lang.String key, java.lang.String value)` Add specific header fields following RFC 7230.
    `void` | `clearRequestHeaders()` Remove all the header fields.
    `void` | `connect(java.lang.String URL)` Connect to the URL connection.
    `void` | `connect(java.lang.String URL, java.lang.String method)` Connect to the URL connection.
    `void` | `connect(java.lang.String URL, java.lang.String method, java.lang.String[] params, boolean fixedURL)` Connect to the URL connection.
    `void` | `deleteRequestHeader(java.lang.String key)` Delete the header field.
    `static DroidHttpClient.Builder` | `getBuilder()` Returns an object builder instance.
    `byte[]` | `getByteArrayContent(java.lang.String URL)` Get the content from the URL connection.
    `byte[]` | `getByteArrayContent(java.lang.String URL, DroidHttpClient.MultipartData multipartData)` Get the content from the URL connection.
    `byte[]` | `getByteArrayContent(java.lang.String URL, java.lang.String method)` Get the content from the URL connection.
    `HttpEntity` | `getContent(java.lang.String URL)` Get the content from the URL connection.
    `HttpEntity` | `getContent(java.lang.String url, DroidHttpClient.MultipartData multipartData)` Get the content from the URL connection.
    `HttpEntity` | `getContent(java.lang.String URL, java.lang.String method)` Get the content from the URL connection.
    `HttpEntity` | `getContent(java.lang.String url, java.lang.String method, java.lang.String[] params, boolean fixedURL)` Get the content from the URL connection.
    `java.lang.String` | `getHTMLContent(java.lang.String URL)` Get the HTML content response from the URL connection.
    `java.lang.String` | `getHTMLContent(java.lang.String URL, DroidHttpClient.MultipartData multipartData)` Get the HTML content response from the URL connection.
    `java.lang.String` | `getHTMLContent(java.lang.String URL, java.lang.String method)` Get the HTML content response from the URL connection.
    `java.lang.String` | `getHTMLContent(java.lang.String URL, java.lang.String charSet, DroidHttpClient.MultipartData multipartData)` Get the HTML content response from the URL connection.
    `java.lang.String` | `getHTMLContent(java.lang.String URL, java.lang.String method, java.lang.String[] params, boolean fixedURL)` Get the HTML content response from the URL connection.
    `java.lang.String` | `getHTMLContent(java.lang.String URL, java.lang.String charSet, java.lang.String method, java.lang.String[] params, boolean fixedURL)` Get the HTML content response from the URL connection.
    `static java.security.KeyStore` | `getKeyStoreFromResource(int trustKeyStoreResource)` Build KeyStore object from resource.
    `static java.security.KeyStore` | `getKeyStoreFromResource(int trustKeyStoreResource, java.lang.String keyStorePassword)` Build KeyStore object from resource.
    `static java.security.KeyStore` | `getKeyStoreFromResource(int trustKeyStoreResource, java.lang.String keyStorePassword, java.lang.String keyStoreType, java.lang.String provider)` Build KeyStore object from resource.
    `int` | `getLastStatusError()` Get the HTTP last status recovered.
    `java.util.List<java.util.Map.Entry<java.lang.String,java.lang.String>>` | `getRequestHeaders()` Return request headers set.
    `javax.net.ssl.SSLSocketFactory` | `getSocketFactory()` Return a javax.net.ssl.SSLSocketFactory object instance.
    `java.io.InputStream` | `getStreamContent(java.lang.String URL)` Get the content from the URL connection.
    `java.io.InputStream` | `getStreamContent(java.lang.String URL, DroidHttpClient.MultipartData multipartData)` Get the content from the URL connection.
    `java.io.InputStream` | `getStreamContent(java.lang.String URL, java.lang.String method)` Get the content from the URL connection.
    `java.io.InputStream` | `getStreamContent(java.lang.String URL, java.lang.String method, java.lang.String[] params, boolean fixedURL)` Get the content from the URL connection.
    `boolean` | `isInitialized()` Return if HttpClient is initialized.
    `void` | `reset()` Reset HttpClient.

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

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

- - ### Field Detail

    - #### DEFAULT_HEADER_USER_AGENT

          public static final java.lang.String DEFAULT_HEADER_USER_AGENT

      See Also:
        Constant Field Values

    - #### DEFAULT_HTML_CONTENT_CHAR_SET

          public static final java.lang.String DEFAULT_HTML_CONTENT_CHAR_SET

      See Also:
        Constant Field Values

    - #### DEFAULT_SSL_PROTOCOL

          public static final java.lang.String DEFAULT_SSL_PROTOCOL

      See Also:
        Constant Field Values

    - #### DEFAULT_TRUSTED_KEYSTORE_TYPE

          public static final java.lang.String DEFAULT_TRUSTED_KEYSTORE_TYPE

      See Also:
        Constant Field Values

    - #### DEFAUTL_TRUSTED_KEYSTORE_PROVIDER

          public static final java.lang.String DEFAUTL_TRUSTED_KEYSTORE_PROVIDER

      See Also:
        Constant Field Values

    - #### HTTP_DEFAULT_TIMEOUT

          public static final int HTTP_DEFAULT_TIMEOUT

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### DroidHttpClient

          public DroidHttpClient()

  - ### Method Detail

    - #### addRequestHeader

          public void addRequestHeader(java.lang.String key,
                                       java.lang.String value)

      Add specific header fields following RFC 7230. If the key exists, value will be overwritten.
      Parameters:
        `key` - name of the header field.
        `value` - value of the header field.

    - #### clearRequestHeaders

          public void clearRequestHeaders()

      Remove all the header fields.

    - #### connect

          public void connect(java.lang.String URL)
                       throws java.io.IOException

      Connect to the URL connection.
      Parameters:
        `URL` - the web site to connect.
      Throws:
        `java.io.IOException`

    - #### connect

          public void connect(java.lang.String URL,
                              java.lang.String method)
                       throws java.io.IOException

      Connect to the URL connection.
      Parameters:
        `URL` - the web site to connect.
        `method` - force GET or POST method.
      Throws:
        `java.io.IOException`

    - #### connect

          public void connect(java.lang.String URL,
                              java.lang.String method,
                              java.lang.String[] params,
                              boolean fixedURL)
                       throws java.io.IOException

      Connect to the URL connection.
      Parameters:
        `URL` - the web site to connect.
        `method` - force GET or POST method.
        `params` - array of request parameters in the string format 'name=value'.
        `fixedURL` - if the URL must not be parameterized (only for POST method).
      Throws:
        `java.io.IOException`

    - #### deleteRequestHeader

          public void deleteRequestHeader(java.lang.String key)

      Delete the header field.
      Parameters:
        `key` - name of the header field.

    - #### getBuilder

          public static final DroidHttpClient.Builder getBuilder()

      Returns an object builder instance.
      Returns:
        builder instance.

    - #### getByteArrayContent

          public final byte[] getByteArrayContent(java.lang.String URL)
                                           throws java.io.IOException

      Get the content from the URL connection.
      Parameters:
        `URL` - the web site to connect.
      Returns:
        byte array of content recovered.
      Throws:
        `java.io.IOException`

    - #### getByteArrayContent

          public final byte[] getByteArrayContent(java.lang.String URL,
                                                  DroidHttpClient.MultipartData multipartData)
                                           throws java.io.IOException

      Get the content from the URL connection.
      Parameters:
        `URL` - the web site to connect.
        `multipartData` - request parameters.
      Returns:
        byte array of content recovered.
      Throws:
        `java.io.IOException`

    - #### getByteArrayContent

          public final byte[] getByteArrayContent(java.lang.String URL,
                                                  java.lang.String method)
                                           throws java.io.IOException

      Get the content from the URL connection.
      Parameters:
        `URL` - the web site to connect.
        `method` - GET, POST or default request method.
      Returns:
        byte array of content recovered.
      Throws:
        `java.io.IOException`

    - #### getContent

          public final HttpEntity getContent(java.lang.String URL)
                                      throws java.io.IOException

      Get the content from the URL connection.
      Parameters:
        `URL` - the web site to connect.
      Returns:
        HTTPEntity recovered.
      Throws:
        `java.io.IOException`

    - #### getContent

          public final HttpEntity getContent(java.lang.String url,
                                             DroidHttpClient.MultipartData multipartData)
                                      throws java.io.IOException

      Get the content from the URL connection.
      Parameters:
        `url` - the web site to connect.
        `multipartData` - request parameters.
      Returns:
        HTTPEntity recovered.
      Throws:
        `java.io.IOException`

    - #### getContent

          public final HttpEntity getContent(java.lang.String URL,
                                             java.lang.String method)
                                      throws java.io.IOException

      Get the content from the URL connection.
      Parameters:
        `URL` - the web site to connect.
        `method` - force GET or POST method.
      Returns:
        HTTPEntity recovered.
      Throws:
        `java.io.IOException`

    - #### getContent

          public final HttpEntity getContent(java.lang.String url,
                                             java.lang.String method,
                                             java.lang.String[] params,
                                             boolean fixedURL)
                                      throws java.io.IOException

      Get the content from the URL connection.
      Parameters:
        `url` - the web site to connect.
        `method` - force GET or POST method.
        `params` - array of request parameters in the string format 'name=value'.
        `fixedURL` - if the URL must not be parameterized (only for POST method).
      Returns:
        HTTPEntity recovered.
      Throws:
        `java.io.IOException`

    - #### getHTMLContent

          public final java.lang.String getHTMLContent(java.lang.String URL)
                                                throws java.io.IOException

      Get the HTML content response from the URL connection.
      Parameters:
        `URL` - the web site to connect.
      Returns:
        the web page as a string.
      Throws:
        `java.io.IOException`

    - #### getHTMLContent

          public final java.lang.String getHTMLContent(java.lang.String URL,
                                                       DroidHttpClient.MultipartData multipartData)
                                                throws java.io.IOException

      Get the HTML content response from the URL connection.
      Parameters:
        `URL` - the web site to connect.
        `multipartData` - request parameters.
      Returns:
        the web page as a string.
      Throws:
        `java.io.IOException`

    - #### getHTMLContent

          public final java.lang.String getHTMLContent(java.lang.String URL,
                                                       java.lang.String method)
                                                throws java.io.IOException

      Get the HTML content response from the URL connection.
      Parameters:
        `URL` - the web site to connect.
        `method` - GET, POST or default request method.
      Returns:
        the web page as a string.
      Throws:
        `java.io.IOException`

    - #### getHTMLContent

          public final java.lang.String getHTMLContent(java.lang.String URL,
                                                       java.lang.String charSet,
                                                       DroidHttpClient.MultipartData multipartData)
                                                throws java.io.IOException

      Get the HTML content response from the URL connection.
      Parameters:
        `URL` - the web site to connect.
        `charSet` - the character codification.
        `multipartData` - request parameters.
      Returns:
        the web page as a string.
      Throws:
        `java.io.IOException`

    - #### getHTMLContent

          public final java.lang.String getHTMLContent(java.lang.String URL,
                                                       java.lang.String method,
                                                       java.lang.String[] params,
                                                       boolean fixedURL)
                                                throws java.io.IOException

      Get the HTML content response from the URL connection.
      Parameters:
        `URL` - the web site to connect.
        `method` - GET, POST or default request method.
        `params` - array of request parameters in the string format 'name=value'.
        `fixedURL` - if the URL must not be parameterized (only for POST method).
      Returns:
        the web page as a string.
      Throws:
        `java.io.IOException`

    - #### getHTMLContent

          public final java.lang.String getHTMLContent(java.lang.String URL,
                                                       java.lang.String charSet,
                                                       java.lang.String method,
                                                       java.lang.String[] params,
                                                       boolean fixedURL)
                                                throws java.io.IOException

      Get the HTML content response from the URL connection.
      Parameters:
        `URL` - the web site to connect.
        `charSet` - the character codification.
        `method` - GET, POST or default request method.
        `params` - array of request parameters in the string format 'name=value'.
        `fixedURL` - if the URL must not be parameterized (only for POST method).
      Returns:
        the web page as a string.
      Throws:
        `java.io.IOException`

    - #### getKeyStoreFromResource

          public static java.security.KeyStore getKeyStoreFromResource(int trustKeyStoreResource)
                                                                throws java.security.NoSuchProviderException,
                                                                       java.security.KeyStoreException,
                                                                       java.security.cert.CertificateException,
                                                                       java.security.NoSuchAlgorithmException,
                                                                       java.io.IOException

      Build KeyStore object from resource.
      Parameters:
        `trustKeyStoreResource` - identification of the resource to load.
      Returns:
        KeyStore
      Throws:
        `java.security.NoSuchProviderException`
        `java.security.KeyStoreException`
        `java.security.cert.CertificateException`
        `java.security.NoSuchAlgorithmException`
        `java.io.IOException`

    - #### getKeyStoreFromResource

          public static java.security.KeyStore getKeyStoreFromResource(int trustKeyStoreResource,
                                                                       java.lang.String keyStorePassword)
                                                                throws java.security.NoSuchProviderException,
                                                                       java.security.KeyStoreException,
                                                                       java.security.cert.CertificateException,
                                                                       java.security.NoSuchAlgorithmException,
                                                                       java.io.IOException

      Build KeyStore object from resource.
      Parameters:
        `trustKeyStoreResource` - identification of the resource to load.
        `keyStorePassword` - password that protects the keystore.
      Returns:
        KeyStore
      Throws:
        `java.security.NoSuchProviderException`
        `java.security.KeyStoreException`
        `java.security.cert.CertificateException`
        `java.security.NoSuchAlgorithmException`
        `java.io.IOException`

    - #### getKeyStoreFromResource

          public static java.security.KeyStore getKeyStoreFromResource(int trustKeyStoreResource,
                                                                       java.lang.String keyStorePassword,
                                                                       java.lang.String keyStoreType,
                                                                       java.lang.String provider)
                                                                throws java.security.NoSuchProviderException,
                                                                       java.security.KeyStoreException,
                                                                       java.security.cert.CertificateException,
                                                                       java.security.NoSuchAlgorithmException,
                                                                       java.io.IOException

      Build KeyStore object from resource.
      Parameters:
        `trustKeyStoreResource` - identification of the resource to load.
        `keyStorePassword` - password that protects the keystore.
        `keyStoreType` - type of the keystore to load ("JKS", "JCEKS", "BKS", "PKCS12", etc. More info at https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#KeyStore).
        `provider` - provider use to load the keystore. Set null if default JCA Provider must be used.
      Returns:
        KeyStore
      Throws:
        `java.security.NoSuchProviderException`
        `java.security.KeyStoreException`
        `java.security.cert.CertificateException`
        `java.security.NoSuchAlgorithmException`
        `java.io.IOException`

    - #### getLastStatusError

          public int getLastStatusError()

      Get the HTTP last status recovered.
      Returns:
        the HTTP status.

    - #### getRequestHeaders

          public java.util.List<java.util.Map.Entry<java.lang.String,java.lang.String>> getRequestHeaders()

      Return request headers set.

    - #### getSocketFactory

          public javax.net.ssl.SSLSocketFactory getSocketFactory()
                                                          throws java.security.UnrecoverableKeyException,
                                                                 java.security.NoSuchAlgorithmException,
                                                                 java.security.KeyStoreException,
                                                                 java.security.NoSuchProviderException,
                                                                 java.security.KeyManagementException

      Return a javax.net.ssl.SSLSocketFactory object instance.
      Returns:
        javax.net.ssl.SSLSocketFactory object instance.
      Throws:
        `java.security.UnrecoverableKeyException`
        `java.security.NoSuchAlgorithmException`
        `java.security.KeyStoreException`
        `java.security.NoSuchProviderException`
        `java.security.KeyManagementException`

    - #### getStreamContent

          public final java.io.InputStream getStreamContent(java.lang.String URL)
                                                     throws java.io.IOException

      Get the content from the URL connection.
      Parameters:
        `URL` - the web site to connect.
      Returns:
        stream of content recovered.
      Throws:
        `java.io.IOException`

    - #### getStreamContent

          public final java.io.InputStream getStreamContent(java.lang.String URL,
                                                            DroidHttpClient.MultipartData multipartData)
                                                     throws java.io.IOException

      Get the content from the URL connection.
      Parameters:
        `URL` - the web site to connect.
        `multipartData` - request parameters.
      Returns:
        stream of content recovered.
      Throws:
        `java.io.IOException`

    - #### getStreamContent

          public final java.io.InputStream getStreamContent(java.lang.String URL,
                                                            java.lang.String method)
                                                     throws java.io.IOException

      Get the content from the URL connection.
      Parameters:
        `URL` - the web site to connect.
        `method` - GET, POST or default request method.
      Returns:
        stream of content recovered.
      Throws:
        `java.io.IOException`

    - #### getStreamContent

          public final java.io.InputStream getStreamContent(java.lang.String URL,
                                                            java.lang.String method,
                                                            java.lang.String[] params,
                                                            boolean fixedURL)
                                                     throws java.io.IOException

      Get the content from the URL connection.
      Parameters:
        `URL` - the web site to connect.
        `method` - GET, POST or default request method.
        `params` - array of request parameters in the string format 'name=value'.
        `fixedURL` - if the URL must not be parameterized (only for POST method).
      Returns:
        stream of content recovered.
      Throws:
        `java.io.IOException`

    - #### isInitialized

          public boolean isInitialized()

      Return if HttpClient is initialized.
      Returns:
        boolean.

    - #### reset

          public void reset()

      Reset HttpClient.