Class ConnectionFactory


  • public class ConnectionFactory
    extends java.lang.Object
    Factory for opening connections to URLs.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ConnectionFactory()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static CloseableHttpConnection createHttpConnection​(java.net.HttpURLConnection httpConnection, HttpMethod requestMethod, java.util.Map<java.lang.String,​java.lang.String> requestProperties)
      Create a HTTP or HTTPS connection The requestMethod and requestProperties are set onto the connection.
      private static CloseableHttpConnection createHttpConnection​(java.net.HttpURLConnection httpConnection, HttpMethod requestMethod, java.util.Map<java.lang.String,​java.lang.String> requestProperties, int httpConnectTimeout, int httpReadTimeout)
      Create a HTTP or HTTPS connection The requestMethod and requestProperties are set onto the connection.
      static CloseableConnection openConnection​(java.net.URL url)
      Opens a connection to an URL.
      static CloseableConnection openConnection​(java.net.URL url, HttpMethod requestMethod, java.util.Map<java.lang.String,​java.lang.String> requestProperties)
      Opens a connection to a URL.
      static CloseableConnection openConnection​(java.net.URL url, HttpMethod requestMethod, java.util.Map<java.lang.String,​java.lang.String> requestProperties, int httpConnectTimeout, int httpReadTimeout)
      Opens a connection to a URL.
      static CloseableHttpConnection openHttpConnection​(java.net.URL url, HttpMethod requestMethod, java.util.Map<java.lang.String,​java.lang.String> requestProperties)
      Opens a connection to a URL.
      static CloseableHttpConnection openHttpConnection​(java.net.URL url, HttpMethod requestMethod, java.util.Map<java.lang.String,​java.lang.String> requestProperties, int httpConnectTimeout, int httpReadTimeout)
      Opens a connection to a URL.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ConnectionFactory

        private ConnectionFactory()
    • Method Detail

      • openConnection

        public static CloseableConnection openConnection​(java.net.URL url)
                                                  throws java.io.IOException
        Opens a connection to an URL.
        Parameters:
        url - the url to which to open a connection.
        Returns:
        the established connection.
        Throws:
        java.io.IOException - if an I/O exception occurs.
      • openConnection

        public static CloseableConnection openConnection​(java.net.URL url,
                                                         HttpMethod requestMethod,
                                                         java.util.Map<java.lang.String,​java.lang.String> requestProperties)
                                                  throws java.io.IOException
        Opens a connection to a URL.

        If the URL has HTTP or HTTPS as its protocol than HttpURLConnection is opened and the requestMethod and requestProperties are set onto the connection. Otherwise the requestMethod and requestProperties are ignored.

        Parameters:
        url - the url to which to open a connection. Must have protocol HTTP or HTTPS
        requestMethod - the HTTP method to use for the connection.
        requestProperties - properties to set on the connection.
        Returns:
        the established connection.
        Throws:
        java.io.IOException - if an I/O exception occurs.
      • openConnection

        public static CloseableConnection openConnection​(java.net.URL url,
                                                         HttpMethod requestMethod,
                                                         java.util.Map<java.lang.String,​java.lang.String> requestProperties,
                                                         int httpConnectTimeout,
                                                         int httpReadTimeout)
                                                  throws java.io.IOException
        Opens a connection to a URL.

        If the URL has HTTP or HTTPS as its protocol than HttpURLConnection is opened and the requestMethod and requestProperties are set onto the connection. Otherwise the requestMethod and requestProperties are ignored.

        Parameters:
        url - the url to which to open a connection. Must have protocol HTTP or HTTPS
        requestMethod - the HTTP method to use for the connection.
        requestProperties - properties to set on the connection.
        httpConnectTimeout -
        httpReadTimeout -
        Returns:
        the established connection.
        Throws:
        java.io.IOException - if an I/O exception occurs.
      • openHttpConnection

        public static CloseableHttpConnection openHttpConnection​(java.net.URL url,
                                                                 HttpMethod requestMethod,
                                                                 java.util.Map<java.lang.String,​java.lang.String> requestProperties)
                                                          throws java.io.IOException
        Opens a connection to a URL.

        If the URL has not HTTP or HTTPS as its protocol a IllegalArgumentException is thrown. Otherwise the requestMethod and requestProperties are set onto the connection.

        Parameters:
        url - the url to which to open a connection. Must have protocol HTTP or HTTPS
        requestMethod - the HTTP method to use for the connection.
        requestProperties - properties to set on the connection.
        Returns:
        the established connection.
        Throws:
        java.io.IOException - if an I/O exception occurs.
      • openHttpConnection

        public static CloseableHttpConnection openHttpConnection​(java.net.URL url,
                                                                 HttpMethod requestMethod,
                                                                 java.util.Map<java.lang.String,​java.lang.String> requestProperties,
                                                                 int httpConnectTimeout,
                                                                 int httpReadTimeout)
                                                          throws java.io.IOException
        Opens a connection to a URL.

        If the URL has not HTTP or HTTPS as its protocol a IllegalArgumentException is thrown. Otherwise the requestMethod and requestProperties are set onto the connection.

        Parameters:
        url - the url to which to open a connection. Must have protocol HTTP or HTTPS
        requestMethod - the HTTP method to use for the connection.
        requestProperties - properties to set on the connection.
        httpConnectTimeout -
        httpReadTimeout -
        Returns:
        the established connection.
        Throws:
        java.io.IOException - if an I/O exception occurs.
      • createHttpConnection

        private static CloseableHttpConnection createHttpConnection​(java.net.HttpURLConnection httpConnection,
                                                                    HttpMethod requestMethod,
                                                                    java.util.Map<java.lang.String,​java.lang.String> requestProperties)
                                                             throws java.io.IOException
        Create a HTTP or HTTPS connection The requestMethod and requestProperties are set onto the connection.
        Parameters:
        httpConnection - the connection to wrap.
        requestMethod - the HTTP method to use for the connection.
        requestProperties - properties to set on the connection.
        Returns:
        the established connection.
        Throws:
        java.io.IOException - if an I/O exception occurs.
      • createHttpConnection

        private static CloseableHttpConnection createHttpConnection​(java.net.HttpURLConnection httpConnection,
                                                                    HttpMethod requestMethod,
                                                                    java.util.Map<java.lang.String,​java.lang.String> requestProperties,
                                                                    int httpConnectTimeout,
                                                                    int httpReadTimeout)
                                                             throws java.io.IOException
        Create a HTTP or HTTPS connection The requestMethod and requestProperties are set onto the connection.
        Parameters:
        httpConnection - the connection to wrap.
        requestMethod - the HTTP method to use for the connection.
        requestProperties - properties to set on the connection.
        httpConnectTimeout -
        httpReadTimeout -
        Returns:
        the established connection.
        Throws:
        java.io.IOException - if an I/O exception occurs.