Add placeholder code for getting a URLConnection with a Proxy
If we implement Proxy support at top level this can form the basis for getting Proxy connections
@@ -9,9 +9,15 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.net.Authenticator;
+import java.net.HttpURLConnection;
+import java.net.InetSocketAddress;
import java.net.MalformedURLException;
+import java.net.PasswordAuthentication;
+import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
+import java.net.Proxy.Type;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
@@ -59,6 +65,31 @@ public class CheckForNewVersionAction extends Action {
return s.toString();
}
+ /**
+ * Get the connection through a Proxy
+ * Should we ever implement Proxy support in Archi this is the pattern to use
+ *
+ * coArchi sets Authenticator.setDefault(a) and resets it with Authenticator.setDefault(null)
+ * but this does not clear Java's cached authentication once Authenticator.setDefault(a) has been called
+ * so we need to explicitly set one on the connection here
+ */
+ @SuppressWarnings("unused")
+ private URLConnection getProxyConnection(URL url) throws IOException {
+ InetSocketAddress socketAddress = new InetSocketAddress("1.1.1.1", 1234); //$NON-NLS-1$
+ Proxy proxy = new Proxy(Type.HTTP, socketAddress);
+
+ HttpURLConnection connection = (HttpURLConnection)url.openConnection(proxy);
+
+ connection.setAuthenticator(new Authenticator() {
+ @Override
+ protected PasswordAuthentication getPasswordAuthentication() {
+ return new PasswordAuthentication("username", "password".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ });
+
+ return connection;
+ }
+
@Override
public void run() {
try {
