commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joel Palmius <>
Subject Re: [HttpClient] Using httpclient in applets (includes dirty fix)
Date Thu, 05 Dec 2002 14:50:21 GMT
Attached is a quick and dirty fix for making HttpClient work in applets. I
simply commented out the getProperties() calls and replaced them with
setting the appropriate string to what was earlier in the default value
part of the call. With the patch applied this code works in a JApplet:

  String docbase = this.getDocumentBase().toString();    
  URL url = new URL(docbase);
  String host = url.getHost();
  String path = url.getPath();
  System.out.println(docbase + " = " + host + " + " + path);
  HttpClient c = new HttpClient();
  GetMethod g = new GetMethod(path);
  String response = g.getResponseBodyAsString();

In Mozilla's Java Console, the address and the contents of the page that 
started the applet are printed. Without the patch, an exception is thrown 
when trying to construct a new HttpClient object. 

This is obviously not a long-term viable fix, but it works for me, so I
guess that it at least shows that it wouldn't be impossible to eventually
build a good solution working for applets.

I'll continue tinkering with it and get back if bother to write a 
better solution. :-) 

  // Joel

On Wed, 4 Dec 2002, Paul Libbrecht wrote:

> I think your best attempt is to remove System.getProperties in the 
> source-code and try to patch things appropriately later (recompiling 
> cleanly and working on errors and follow-up).
> The consideration about using jakarta-commons things for applet is, I 
> believe, important and I wonder wether some kind of flag as to wether a 
> library is or is not applet-compatible would make a lot of sense.
> (there used to be a time when this was in the faq and demos of most 
> projects).
> Paul

View raw message