Name: gm110360			Date: 02/07/2003
FULL PRODUCT VERSION :
JDK: 1.4.0_01-b03 or 1.4.1_01
JRE: 1.4.1_01
FULL OPERATING SYSTEM VERSION :
Win XP SP1
ADDITIONAL OPERATING SYSTEMS :
Win 2000 SP3
Linux
EXTRA RELEVANT SYSTEM CONFIGURATION :
Internet Explorer 5.5
Internet Explorer 6.0
Linux Mozilla
A DESCRIPTION OF THE PROBLEM :
My applet sends many POST requests (10-20 per second) one
by one (not concurrently) to an IIS server application,
using HttpUrlConnection with Keep-Alive option. When I run
it with AppletViewer, I see (with netstat) a single HTTP
connection which is re-used for each new POST.
However, when I run it under IE with Plugin 1.4.0 or 1.4.1,
netstat shows that each POST creates a new connection.
After the response arrives, this connection goes to
TIME_WAIT state for several minutes and the next POST opens
a brand new connection. After some time I see hundreds of
TIME_WAIT connections.
I got an advice (from experts-exchange) to force using
sun.net rather than sun.plugin, thus avoiding the apparent
plugin bug. I do it as follows:
URL.setURLStreamHandlerFactory(null);
sysProperties.setProperty
("java.protocol.handler.pkgs", "sun.net.www.protocol");
Now a single connection is opened and re-used for all
POSTs, but the applet is not aware that it runs under a
plugin or browser, e.g., it doesn't recognize the IE proxy
settings.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the sample applet given in Source Code below.
The corresponding sample server ISAPI application can be
seen at http://212.29.222.92/Applets/ServerCode.html.
EXPECTED VERSUS ACTUAL BEHAVIOR :
Use netstat to see the connections accumulate.
Run the same with AppletViewer - only 1 connection is
opened.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
============= Applet code ===============
import java.io.*;
import java.net.*;
public class Isapi_Applet extends java.applet.Applet {
URL  m_url;
HttpURLConnection  m_conn;
String result;
public void init() {
   try {
       m_url = new URL("http://212.29.222.92/TestOut/IsapiTest.dll");
       for (int i=1; i<=10; i++) {
           String resp = doPost("REQUEST=DUMMY");
           if (resp.equals("RESPONSE=OK"))
               result = i + ") response OK";
           else
               result = i + ") Unexpected response: " + resp;
           showStatus(result);
           System.out.println(result);
       }
       showStatus("Applet completed");
       Thread.sleep(1000); // Allow time to see last message
   }
   catch (Exception exception) {
           exception.printStackTrace();
   }
}
public String doPost(String postData) throws IOException {
   try {
       m_conn = (HttpURLConnection)m_url.openConnection();
       m_conn.setDoOutput(true);
       m_conn.setRequestProperty("Connection", "Keep-Alive");
       m_conn.setUseCaches(false);
       /* Send request */
       PrintWriter outSock = new PrintWriter(m_conn.getOutputStream());
       outSock.print(postData);
       outSock.close();
       /* Read response and return it */
       BufferedReader inSock = new BufferedReader(new InputStreamReader
(m_conn.getInputStream()));
       String response = inSock.readLine();
       inSock.close();
       return response;
   }
   catch (IOException exception) {
           exception.printStackTrace();
           return null;
   }
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
Force using sun.net rather than sun.plugin:
URL.setURLStreamHandlerFactory(null);
sysProperties.setProperty
("java.protocol.handler.pkgs", "sun.net.www.protocol");
However, the applet does not recognize browser settings,
e.g., proxy.
(Review ID: 180924) 
======================================================================