- From: Ronen Lazar <RonenL@gilian.com>
- Date: Tue, 13 Mar 2001 11:53:25 -0500 (EST)
- To: "'www-jigsaw@w3.org'" <www-jigsaw@w3.org>
Hi all, I'm trying to use the HttpURLConnection in order issue "GET" HTTP requests. So I created a derived class of it (only set the constructor to be public), and set the stream handler factory to generate an instance of it each time an "http" call is being made, with calling url.openConnection(...). This works just fine when working with existing urls. The problem is that when requesting non-existing urls, the connection with the web-server doesn't seem to close correctly, and it gets stuck after calling getInputStream() (in the 6th "GET" request). I.e. after 5 GET requests to non-existing file, the 6th will stuck after the call to getInputStream. When checking what's going on with "netstat", I see 5 sockets to the server in "CLOSE_WAIT" status. I thought maybe it has something to do with the max concurrent users allowed, so I tried to call HttpManager.getManager().setMaxConnections(...) with number bigger than 5 (after calling openConnection()), but it didn't help. Can you help on this urgent one, please? Thanks a lot, Ronen ******** my code: ******** public class MyHttpURLConnection extends org.w3c.www.protocol.http.HttpURLConnection { public CGJHttpURLConnection(URL u) throws IOException { super(u); } public void setMaxConn (int connections) { HttpManager.getManager().setMaxConnections(connections); } } public class MyURLStreamHandlerFactory extends Object implements URLStreamHandlerFactory { public URLStreamHandler createURLStreamHandler(String protocol) { if (protocol.equalsIgnoreCase("http")){ return new URLStreamHandler(){ protected URLConnection openConnection(URL u) throws IOException { try{ return new MyHttpURLConnection (u); } catch (IOException e){ throw e; } } }; } } } // the executing class: public class GetTest { private static URL url_obj = null; public static void main (String args[]) { try { url_obj = new URL ("http", "www.somesite.com", 80, "/non-existing.url"); URL.setURLStreamHandlerFactory(new MyURLStreamHandlerFactory()); for (int i = 0; i < 6; i++){ // on the last iteration, it will stuck get(); } } catch( Exception e ) { e.printStackTrace(System.err); } } private static void get () { try{ org.w3c.www.protocol.http.HttpURLConnection con = (org.w3c.www.protocol.http.HttpURLConnection)url_obj.openConnection (); con.setRequestMethod("GET"); con.setDoInput(true); con.setDoOutput(true); OutputStream out = con.getOutputStream(); InputStream in = con.getInputStream(); System.out.println ("code = "+con.getResponseCode()); } catch (java.net.MalformedURLException e){ } catch (java.net.ProtocolException e){ } catch (java.io.IOException e){ } } }
Received on Tuesday, 13 March 2001 12:02:33 UTC