0

I have a signed file uploader applet that works in Chrome but seems to hang when run in IE. In IE, I can successfully upload a file (or set of files) one time but the next time I try to upload another file, the browser freezes and I have to close the browser. It seems to be happening when I attempt to retrieve the outputstream of the HttpUrlConnection object. Here is my code:

public void upload(URL url, URL returnUrl, List<FileIconPanel> files) {
    HttpURLConnection conn = null;

    try {
        conn = (HttpURLConnection) url.openConnection();
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.setUseCaches(false);
        conn.setChunkedStreamingMode(1024);
        HttpURLConnection.setFollowRedirects(false);
        conn.setRequestProperty("content-type", "application/zip");
        conn.setRequestMethod("POST");

        //This zip output stream will server as our stream to the server and will zip each file while 
        // it sends it to the server.
        ZipOutputStream out = new ZipOutputStream(conn.getOutputStream());
        for (int i = 0; i < files.size(); i++) {
            //For each file we will create a new entry in the ZIP archive and stream the file into that entry.

            File f = (File) files.get(i).getFile();
            ZipEntry entry = new ZipEntry(f.getName());
            out.putNextEntry(entry);
            InputStream in = new FileInputStream(f);
            int read;
            byte[] buf = new byte[1024];

            while ((read = in.read(buf)) > 0) {
                out.write(buf, 0, read);
            }

            out.closeEntry();
        }

        //Once we are done writing out our stream we will finish building the archive and close the stream.
        out.finish();
        out.close();

        // Now that we have set all the connection parameters and prepared all
        //  the data we are ready to connect to the server.
        conn.connect();

        // read & parse the response
        InputStream is = conn.getInputStream();
        StringBuilder response = new StringBuilder();
        byte[] respBuffer = new byte[4096];
        while (is.read(respBuffer) >= 0) {
            response.append(new String(respBuffer).trim());
        }
        is.close();
    } catch (IOException ioE) {
        ioE.printStackTrace();
        logger.info("An unexpected exception has occurred. Contact your system administrator");
    } catch (Exception e) {
        e.printStackTrace();
        logger.info("An unexpected exception has occurred. Contact your system administrator");
    } finally {
        //Once we are done we want to make sure to disconnect from the server.
        if (conn != null) conn.disconnect();
    }
}

I can see in the log files that it is freezing a this line:

ZipOutputStream out = new ZipOutputStream(conn.getOutputStream());

the second time I try to upload a file. This code also does work in IE under java 6. It has had this problem since I updated to the latest.

Is there something I'm leaving open that I need to make sure to close out before using the applet again? Been beating my head against this for the last two days. Sure hope someone can help...

2
  • No stack trace? What does the console show when set to maximum output? Commented Dec 15, 2012 at 6:30
  • There's no exception thrown. The browser freezes and therefore the console is frozen too...the last line in the console is always "network: Connecting localhost:8080 with proxy=DIRECT".
    – malificent
    Commented Dec 24, 2012 at 17:57

1 Answer 1

0

I have an idea of what's going on but I don't know exactly the details of the what's causing the problem. I at least figured it out a workaround...I was using a jquery dialog box to display the applet. I was doing this on the fly so every time I open the dialog box, it was building the applet again. It's strange because I was in fact removing the div element that contained the applet every time the dialog box was closed so I would have thought that would ensure the old applet instance was destroyed as well. Chrome seems to be smart enough to destroy it and create a new one (or something to that effect) but IE has problems.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.