Class ConnectionFactory

java.lang.Object
net.adoptopenjdk.icedteaweb.http.ConnectionFactory

public class ConnectionFactory extends Object
Factory for opening connections to URLs.
  • Constructor Details

    • ConnectionFactory

      private ConnectionFactory()
  • Method Details

    • openConnection

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

      public static CloseableConnection openConnection(URL url, HttpMethod requestMethod, Map<String,String> requestProperties) throws 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:
      IOException - if an I/O exception occurs.
    • openConnection

      public static CloseableConnection openConnection(URL url, HttpMethod requestMethod, Map<String,String> requestProperties, int httpConnectTimeout, int httpReadTimeout) throws 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:
      IOException - if an I/O exception occurs.
    • openHttpConnection

      public static CloseableHttpConnection openHttpConnection(URL url, HttpMethod requestMethod, Map<String,String> requestProperties) throws 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:
      IOException - if an I/O exception occurs.
    • openHttpConnection

      public static CloseableHttpConnection openHttpConnection(URL url, HttpMethod requestMethod, Map<String,String> requestProperties, int httpConnectTimeout, int httpReadTimeout) throws 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:
      IOException - if an I/O exception occurs.
    • createHttpConnection

      private static CloseableHttpConnection createHttpConnection(HttpURLConnection httpConnection, HttpMethod requestMethod, Map<String,String> requestProperties) throws 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:
      IOException - if an I/O exception occurs.
    • createHttpConnection

      private static CloseableHttpConnection createHttpConnection(HttpURLConnection httpConnection, HttpMethod requestMethod, Map<String,String> requestProperties, int httpConnectTimeout, int httpReadTimeout) throws 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:
      IOException - if an I/O exception occurs.