Second POST fails using Macintosh Netscape 4.75 and Apple MRJ 2.2.4

    This Netscape bug appears to be an instance of a known bug in the MRJPlugin.  This page demonstrates this POST bug using the EMBED tag to get the applet to use the MRJPlugin.  The version with regular applet tags that uses the native Netscape Java Virtual Machine and fails in a different way is at this link.   

    Using Macintosh Netscape 4.75 and Apple MRJ 2.2.4 under Macintosh OS 9 no POSTs succeed from this applet at all and the applet does not hang the browser.  Internet Explorer 5.0 fails in different ways as described at this link.   POSTing using this applet works properly with Netscape 6.01 and MRJ 2.2.4, using either this page or the version with applet tags, though tests were done with the updated MRJPlugin from http://homepage.mac.com/mrjplugin/.  

    You can reproduce the problem as follows:

  1. Type some String into the TextField below to identify your test.
  2. Press the button to POST.  It will do nothing.  Although there are println methods to follow the progress of the applet I don't see any output in the regular Netscape Java Console or in the Java Message Log file for this or other applets, presumably due to some other issue with the MRJPlugin. 

    A partial workaround for this problem using Sun's HttpURLConnection class is described at: http://developer.apple.com/qa/java/java26.html but this requires the applet to be digitally signed and it does not appear to work if the user is behind a proxy server. 

 

    If you have any insights, workarounds or comments about this test page please contact Mickey Segal.  A listing of  many Macintosh Java bugs with demonstration applets is at this link, including information on how to add any necessary Java plugins.

    Please vote for this bug on the Mozilla bug list; you will need to sign up with Mozilla's Bugzilla bug reporting system if you have not already done so. 

    The code for this applet is available from this link and displayed below, including all the println statements used for debugging:

import java.applet.*;
import java.awt.*;
import java.net.*;
import java.io.*;

public class PostNoThread extends Applet {

Button postButton;
TextField tf;

public void init()
{
    tf = new TextField(10);
    add(tf);
    postButton = new Button ("Type a String and then press this button");
    add (postButton);
    URLPoster.refreshStatics();
}

public boolean action(Event evt, Object obj) 

    if (evt.target == postButton)
    {
        try
        {
            URLPoster.numberStarted++;
            new URLPoster(URLPoster.numberStarted, "TestExported", "test.txt", 
                tf.getText() + ": data from run " + String.valueOf(URLPoster.numberStarted));
            System.out.println(URLPoster.numberStarted + " POST is done"); 
        }
        catch (Exception e)
        {
            System.out.println("send failed");
            return true;
        }
    }
    return true;
}
} // END OF Class PostNoThread



class URLPoster {

URL urlCGI;
String query, file, ext;
int numberOfThis;
static int numberStarted;

URLPoster(int numberOfThis, String folder, String fileWithExt, String data)
{
    this.numberOfThis = numberOfThis;
    urlCGI = null;
    try
    {
        urlCGI = new URL("https://segal.org/cgi-bin/form2mail");
    }
    catch (Exception e)
    {
        urlCGI = null;
        System.out.println("url could not be formed" + e);
    }
    int dotPosition = fileWithExt.indexOf('.');
    file = fileWithExt.substring(0, dotPosition);
    ext = fileWithExt.substring(dotPosition + 1);
    query = URLEncoder.encode("config") + "=" + URLEncoder.encode("/templates/" + folder + 
    "Append.txt");
    addToQuery("file", file);
    addToQuery("ext", ext);
    addToQuery("data", data);
    System.out.println(numberOfThis + " POST starting");
    post();
}

static final void refreshStatics()
{
    numberStarted = 0;
}

final void addToQuery (String name, String value)
{
    query += ("&" + URLEncoder.encode(name) + "=" + URLEncoder.encode(value));
}

final void post()
{
    try
    {
    URLConnection uc = urlCGI.openConnection();
    System.out.println(numberOfThis + " uc = " + uc);
    uc.setUseCaches(false);
    System.out.println(numberOfThis + " point A");
    uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    System.out.println(numberOfThis + " point B");
    // setRequestProperty needed since some Netscape versions don't give this out properly
    uc.setAllowUserInteraction(false);
    System.out.println(numberOfThis + " point C");
    uc.setDoInput(true);
    System.out.println(numberOfThis + " point D");
    uc.setDoOutput(true); // after setRequestProperty which can reset doOutput to false
    System.out.println(numberOfThis + " point E");
    DataOutputStream udos = new DataOutputStream(uc.getOutputStream ());
    System.out.println(numberOfThis + " point F");
    udos.writeBytes(query);
    System.out.println(numberOfThis + " point G");
    udos.flush(); // sends
    System.out.println(numberOfThis + " point H");
    udos.close(); // cgi program won't return response until this is closed
    System.out.println(numberOfThis + " point I");
    DataInputStream udis = new DataInputStream(uc.getInputStream ());
    System.out.println(numberOfThis + " point J");
    // NN won't post data unless inputStream is opened, but reading input is not necessary 
    udis.close(); // always close after opening
    System.out.println(numberOfThis + " point K");
    }
    catch (Exception e)
    {
    System.out.println("Error in posting");
    }
}
} // END OF Class URLPoster