public HttpURLConnection getHttpURLConnection(URL url) throws IOException {
final Domain domain = habitat.getComponent(Domain.class);
SecureAdmin secureAdmin = domain.getSecureAdmin();
final String certAlias = SecureAdmin.Util.isUsingUsernamePasswordAuth(secureAdmin) ? null : SecureAdmin.Util.DASAlias(secureAdmin);
HttpConnectorAddress httpConnectorAddress = new HttpConnectorAddress(habitat.getComponent(SSLUtils.class).getAdminSocketFactory(certAlias, "TLS"));
AuthenticationInfo authenticationInfo = authenticationInfo(habitat, secureAdmin);
if (authenticationInfo != null) {
httpConnectorAddress.setAuthenticationInfo(authenticationInfo);
}
HttpURLConnection httpURLConnection = (HttpURLConnection) httpConnectorAddress.openConnection(url); // The URL constructed for REST will always be Http(s) so, it is ok to cast here.
//Hack - httpConnectorAddress calls httpURLConnection.setRequestProperty("Content-type", "application/octet-stream"); before returning connection above