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. :)
> 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 --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]