Changes to accomodate setting local outgoing address explicitly on Azure connections

New Classes

The internal mechanics of the URLStreamHandler for http and https connections were mirrored up to the point where the socket is created by effectively duplicating the functionality of the internal implementations of HttpURLConnection and HttpsURLConnection within OpenJDK Java 7.

AzureStreamHandlerFactory

Holds a cache of URLStreamHandler instances based on the combination of protocol and local address to be used.

AzureHttpHandler

Extends the internal implementation class sun.net.www.protocol.http.handler.

The modified behavior is to override the openConnection method to return an AzureHttpURLConnection instance.

AzureHttpsHandler

Extends the internal implementation class sun.net.www.protocol.https.handler.

The modified behavior is to override the openConnection method. It delegates to the super class, and then explicitly sets the SSLSocketFactory on the returned connection object before handing it back to the caller. The internal HttpsURLConnection implementation always invokes its SSLSocketFactory to create sockets, so replacing that with a factory that always binds the socket to the correct local address is sufficient to handle HTTPS connections.

AzureHttpURLConnection

Extends the internal implementation class sun.net.www.protocol.http.HttpURLConnection.

Overrides all methods which produce HttpClient instances to produce AzureHttpClient instances instead.

AzureHttpClient

Extends the internal implementation class sun.net.www.http.HttpClient.

Constructor logic was copied from the super class because the constructor calls openServer (which creates a socket), and the local address needs to be set first. Mirrors the functionality of the super class's New methods, except they produce AzureHttpClient instances. Overrides the keep alive cache mechanisms because the variable that drives it is private and cannot be accessed in the subclass. Overrides the createSocket method to look at the local address and bind it to the socket before returning.

Modified Classes

The following describes the changes to existing Azure SDK classes.

RequestOptions

Adds a new option to set the local IP address to be used for client connections. Follows the existing pattern the class uses.

BaseRequest

Modifies the createURLConnection method. When a local address has been set, instead of using the URI.toURL() method, the URL is formed by using the constructor that accepts a URLStreamHandler parameter and invoking the AzureStreamHandlerFactory to produce a handler instance.