# Interface ConnectionFactory (2.1.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [2.1.0 (latest)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.javanet.ConnectionFactory)
- [2.0.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/2.0.3/com.google.api.client.http.javanet.ConnectionFactory)
- [1.47.1](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.47.1/com.google.api.client.http.javanet.ConnectionFactory)
- [1.46.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.46.3/com.google.api.client.http.javanet.ConnectionFactory)
- [1.45.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.45.3/com.google.api.client.http.javanet.ConnectionFactory)
- [1.44.2](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.44.2/com.google.api.client.http.javanet.ConnectionFactory)
- [1.43.2](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.43.2/com.google.api.client.http.javanet.ConnectionFactory)
- [1.42.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.42.3/com.google.api.client.http.javanet.ConnectionFactory)
- [1.41.8](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.41.8/com.google.api.client.http.javanet.ConnectionFactory)

    public interface ConnectionFactory

Given a [URL](https://docs.oracle.com/javase/8/docs/api/java/net/URL.html) instance, produces an [HttpURLConnection](https://docs.oracle.com/javase/8/docs/api/java/net/HttpURLConnection.html).

## Methods

### openConnection(URL url)

    public abstract HttpURLConnection openConnection(URL url)

Creates a new [HttpURLConnection](https://docs.oracle.com/javase/8/docs/api/java/net/HttpURLConnection.html) from the given `url`.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `url` | `https://docs.oracle.com/javase/8/docs/api/java/net/URL.html` the URL to which the connection will be made |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/net/HttpURLConnection.html` | the created connection object, which will still be in the pre-connected state |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` | if there was a problem producing the connection |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/ClassCastException.html` | if there was a problem producing the connection |