hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nick Coleman <nick.cole...@leanlogistics.com>
Subject RE: proxy and howto's and some questions.
Date Tue, 18 Feb 2003 15:13:59 GMT
Mike,

My company is currently using the HttpClient utility in an Applet
successfully through proxy servers detected by the browser.  Here is how the
proxy settings are configured:

HttpClient client = new HttpClient();
HostConfiguration hostConfig = client.getHostConfiguration();
hostConfig.setProxy(proxyHost, proxyPort);

We detect the browser proxy settings as follows:

// Retrieve Proxy Server Settings from System if specified
String proxyList = System.getProperty("javaplugin.proxy.config.list");
if (proxyList!=null && !"".equals(proxyList)){
   StringTokenizer tokenizer1 = new StringTokenizer(proxyList, ";,");
   if (tokenizer1.countTokens()>1){
      while (tokenizer1.hasMoreTokens()){
         String s = tokenizer1.nextToken();
         if (s.toLowerCase().startsWith("http")){
            StringTokenizer tokenizer2 = new StringTokenizer(s, "=:");
            tokenizer2.nextToken();
            proxyHost = tokenizer2.nextToken();
            proxyPort = Integer.parseInt(tokenizer2.nextToken());
         }
      }
   }
   else {
      StringTokenizer tokenizer = new StringTokenizer(proxyList, ":");
      proxyHost = tokenizer.nextToken();
      proxyPort = Integer.parseInt(tokenizer.nextToken());
   }
}

-Nick

> Hello,
>
> Are there any howto's about the usage of this package? I can only find
> the API, but some examples are always more clear.
>
> And why aren't the proxy settings not used by the package?
> I now made this method to create the HostConfiguration, but it would
> be nice if it's in the package automaticly.
>
> 	private static HostConfiguration getHostConfiguration(
> 			String host, String protocol) {
> 		String propNameHost = "proxyHost";
> 		String propNamePort = "proxyPort";
>
> 		String proxyHost =
> 			System.getProperty(protocol+"."+propNameHost);
> 		Integer proxyPortInt =
> 			Integer.getInteger(protocol+"."+propNameHost);
>
> 		if(proxyHost == null && proxyPortInt == null) {
> 			// Fall back if the properties do not exist.
> 			proxyHost = System.getProperty(propNameHost);
> 			proxyPortInt = Integer.getInteger(propNamePort);
> 		}
>
> 		HostConfiguration config = new HostConfiguration();
> 		config.setHost(host, -1, protocol); // Use default port.
>
> 		if (proxyHost != null && proxyPortInt != null) {
> 			int proxyPort = proxyPortInt.intValue();
> 			config.setProxy(proxyHost, proxyPort);
> 		}
>
> 		return config;
> 	}
>
> And is it needed to make a HostConfiguration by hand?
> Can't I just do:
> HttpClient hc = new HttpClient(); 
> hc.executeMethod("http://bla1.bla/bla/bla");
> hc.executeMethod("http://bla2.bla/bla/bla");
> hc.executeMethod("http://bla3.bla/bla/bla");
>
> And that the HostConfiguration is used internaly in HttpClient in
> stead of made by me.
> I now have to do the bookkeeping of all the hosts I connect with 
> myself and it would be nice if that is all handled automaticly by 
> httpClient.
> Just my to cents.
>
> I'm willing to write some code for this, but I don't wont to change
> the API, if other developers don't agree with it.
>
> Greetings,
>
> Ronald.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: 
> commons-httpclient-dev-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail:
commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail:
commons-httpclient-dev-help@jakarta.apache.org

Mime
View raw message