/** * @param urlString This string should include the ApiKey but not any auth data. * @return * @throws IOException */ private HttpURLConnection createRealHttpURLConnection(final String urlString) throws IOException { URL url; try { url = AccessController.doPrivileged( new PrivilegedExceptionAction<URL>() { @Override public URL run() throws MalformedURLException { return new URL(urlString); } }); } catch (PrivilegedActionException e) { throw (MalformedURLException) e.getCause(); } // If an HTTP proxy is defined, open the connection with a java.net.Proxy HttpURLConnection connection = null; if (loginInfo.getProxy() != null && loginInfo.getProxy().isHTTP()) { LoginInfoClientProxy loginProxy = loginInfo.getProxy(); Proxy javaNetProxy = new Proxy( Proxy.Type.HTTP, new InetSocketAddress( loginProxy.getProxyURL().getHost(), loginProxy.getProxyURL().getPort())); connection = (HttpURLConnection) url.openConnection(javaNetProxy); } else { connection = (HttpURLConnection) url.openConnection(); } addAuthToConnection(connection); String userAgent = loginInfo.getUserAgent(); if (userAgent != null && !userAgent.isEmpty()) { connection.setRequestProperty("User-Agent", userAgent); } return connection; }