W3C home > Mailing lists > Public > www-jigsaw@w3.org > March to April 2001

Re: HttpURLConnection and GET requests - please help

From: John Philip Anderson <jpanderson_215@hotmail.com>
Date: Tue, 13 Mar 2001 22:06:30 -0000
To: RonenL@gilian.com
Cc: www-jigsaw@w3.org
Message-ID: <F195qHhLL3J8r8HhS7P00006a50@hotmail.com>
Dear Mr. Lazar,

I do not have any decent answers to help you, but here are some thoughts:

1.) I believe that MyHttpURL.setMaxConn() is operating on an instance of 
HttpManager that is not "connected" to the rest of your software. Consider 
calling HttpManager.getManager() and setMaxConnections() in your executing 
class, "GetTest."

2.) At the end of GetTest.get() trying doing something to destroy "con."  
Maybe you can write something like:

con.finalize();
gc.run();

In any case, find some method that cues the garbage collector to eat the 
open sockets before they pile up and cause your "sticking" problem.


Good luck!
John Philip Anderson
jpanderson_215@hotmail.com


>From: Ronen Lazar <RonenL@gilian.com>
>To: "'www-jigsaw@w3.org'" <www-jigsaw@w3.org>
>Subject: HttpURLConnection and GET requests - please help
>Date: Tue, 13 Mar 2001 11:53:25 -0500 (EST)
>
>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){
>		}
>	}
>}
>
>

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com
Received on Tuesday, 13 March 2001 17:07:02 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 9 April 2012 12:13:35 GMT