hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ronald Klop <ronald-mailingl...@base.nl>
Subject Re: proxy and howto's and some questions.
Date Tue, 18 Feb 2003 23:17:48 GMT
Thank for the explanation. It makes it more clear what the purpose of
some things are. Now I now you don't need an HttpClient per host my code
can be cleaned up some. Just create one HttpClient. Config it with
HostConfiguration with proxy settings and feed it methods using complete
urls.

Greetings,

Ronald.

On Wed, 19 Feb 2003 08:52:18 +1000
Adrian Sutton <adrian.sutton@ephox.com> wrote:

> Disclaimer: It's 10:30pm, I've been writing documentation for the
> various authentication schemes and I normally reply to email in the
> morning - I hope this makes sense. :)
> 
> Second disclaimer: I don't think this message has made it though - I
> had many problems with the nightly backup starting and killing my mail
> server last night. :)  Some of the stuff mentioned in this has been
> mentioned by others but the detection method for proxies is important
> and I haven't noticed anyone else point out that it's highly JVM
> specific.
> 
> > 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.
> 
> There are examples in CVS and in the source distribution.  You can
> view them online at:
> http://cvs.apache.org/viewcvs/jakarta-commons/httpclient/src/examples/
> 
> > 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.
> 
> The method you provide with fail on various OS's and JVMs.  There is
> no requirement that the proxy information be provided in the System
> Properties at all let alone what the properties should be called.  The
> code I'm currently using which works on the Sun JVM for Windows and
> Solaris as well as working on OS X is:
> 
> try {
>           String noProxy = "";
>           if
> (System.getProperty("java.vm.vendor").toLowerCase().indexOf("apple")
> >= 0) {
>               proxyHost = System.getProperty("http.proxyHost");
>               noProxy = System.getProperty("http.nonProxyHosts", "");
>               proxyPort =
> Integer.parseInt(System.getProperty("http.proxyPort", "-1"));
>               _client.setProxyHost(proxyHost);
>               _client.setProxyPort(proxyPort);
>           } else {
>               String proxy =
> System.getProperty("javaplugin.proxy.config.list", "");
>               noProxy =
>               System.getProperty("javaplugin.proxy.config.bypass",
> "");
>               if (proxy.toLowerCase().indexOf("http=") >= 0) {
>                   proxy =
> proxy.substring(proxy.toLowerCase().indexOf("http=") +
> "http=".length());
>                   if (proxy.indexOf(",") >= 0) {
>                       proxy = proxy.substring(0, proxy.indexOf(","));
>                   }
>                   proxyHost = proxy;
>                   proxyPort = 8080;
>                   if (proxy.indexOf(":") >= 0) {
>                       proxyHost = proxy.substring(0,
>                       proxy.indexOf(":")); proxyPort =
> Integer.parseInt(proxy.substring(proxy.indexOf(":") + 1));
>                   }
>                   _client.setProxyHost(proxyHost);
>                   _client.setProxyPort(proxyPort);
>               }
>           }
>           StringTokenizer st = new StringTokenizer(noProxy, ",");
>           noProxyHosts = new String[st.countTokens()];
>           for (int i = 0; i < noProxyHosts.length; i++) {
>               noProxyHosts[i] = st.nextToken();
>           }
>           _client.setNoProxyHosts(noProxyHosts);
>       } catch (Exception e) {
>           log.error("Failed to detect proxy settings.");
>           e.printStackTrace();
>       }
> 
> Note that I'm using quite an old version of HttpClient
> (HttpMultiClient actually) so the actual means of setting the proxy
> host in HttpClient probably needs to change now but the basic idea is
> the same.  I think I also added support for NoProxyHosts to HttpClient
> as well, not sure if that's been added to the main source or not (I
> can provide the logic I use if someone has time to update it for the
> lastest API).
> 
> > 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");
> 
> You can do something similar:
> 
> HttpClient hc = new HttpClient();
> GetMethod get = new GetMethod(http://bla1.bla/bla/bla);
> get.getHostConfiguration().setProxy("proxy", 8080);
> hc.executeMethod(get);
> 
> The reason for the extra complexity is that HttpClient has to know
> what method you want to execute (GET, POST, PUT, HEAD or perhaps even
> your own custom DOOHICKY method).  I would like to see a more central
> management of proxy settings but that could be handled client side
> quite easily anyway.
> 
> > 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.
> 
> The above code should do pretty much what you want, you still have to
> manage the selection of proxy hosts by yourself but generally there
> will only be one anyway so it's not that tough.
> 
> > Ronald.
> 
> Guess we need a tutorial on using HttpClient.  Maybe tomorrow night.
> :)
> 
> Hope that helps, I'll be awake again in another 10 hours or so to
> answer any other questions you have.
> 
> Adrian Sutton
> Software Engineer
> Ephox Corporation
> 
> ---------------------------------------------------------------------
> 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