From 5616a9e7549c2efb75a6f4af8525c8304c7ce1a4 Mon Sep 17 00:00:00 2001 From: Pierre-Luc Paour Date: Thu, 12 Jun 2003 07:39:26 +0000 Subject: [PATCH] Added proxy support in the preferences. --- com/gallery/GalleryRemote/GalleryComm.java | 35 +++++++++++++++------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/com/gallery/GalleryRemote/GalleryComm.java b/com/gallery/GalleryRemote/GalleryComm.java index 7a7f3e5..5a504dd 100644 --- a/com/gallery/GalleryRemote/GalleryComm.java +++ b/com/gallery/GalleryRemote/GalleryComm.java @@ -25,17 +25,12 @@ import java.net.URL; import java.net.UnknownHostException; -import HTTPClient.Cookie; -import HTTPClient.CookieModule; -import HTTPClient.CookiePolicyHandler; -import HTTPClient.HTTPConnection; -import HTTPClient.HTTPResponse; -import HTTPClient.ModuleException; -import HTTPClient.RoRequest; -import HTTPClient.RoResponse; +import HTTPClient.*; import com.gallery.GalleryRemote.model.Album; import com.gallery.GalleryRemote.model.Gallery; +import com.gallery.GalleryRemote.prefs.GalleryProperties; +import com.gallery.GalleryRemote.prefs.PreferenceNames; /** * This interface is a temporary mechanism to let us use version @@ -46,7 +41,7 @@ * * @author Tim Miller */ -public abstract class GalleryComm { +public abstract class GalleryComm implements PreferenceNames { private static final String MODULE = "GalComm"; int[] capabilities = null; private static int lastRespCode = 0; @@ -142,7 +137,27 @@ public static boolean wasAuthFailure () { public static GalleryComm getCommInstance(StatusUpdate su, URL url, Gallery g) { try { - // create a connection + GalleryProperties p = GalleryRemote.getInstance().properties; + // set proxy info + if (p.getBooleanProperty(USE_PROXY)) { + String hostname = p.getProperty(PROXY_HOST); + int port = 80; + try { port = p.getIntProperty(PROXY_PORT); } catch (NumberFormatException e) {} + String username = p.getProperty(PROXY_USERNAME); + + Log.log(Log.TRACE, MODULE, "Setting proxy to " + hostname + ":" + port); + + HTTPConnection.setProxyServer(hostname, port); + + if (username != null && username.length() > 0) { + AuthorizationInfo.addBasicAuthorization(hostname, port, "", + username, p.getBase64Property(PROXY_PASSWORD)); + } + } else { + HTTPConnection.setProxyServer(null, 0); + } + + // create a connection HTTPConnection mConnection = new HTTPConnection( url ); if (g.getType() == Gallery.TYPE_STANDALONE) {