Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GZipInputStream problem

8 views
Skip to first unread message

Chris Bailey

unread,
Jul 30, 2002, 10:46:55 AM7/30/02
to
Here is the situation. A signed applet is uploading a file to a Servlet
which saves the file on the server. Code works fine. I added
GZipOutputStream to the applet side and GZipInputStream to the Servlet side
and this is where I get problems. The code works fine when running locally
using Internet Explorer or Netscape to run the applet, and Tomcat 4.03 (Java
1.4), no apache connector, to run the servlet, all on Windows 2000. It also
runs fine when the servlet is running on a test server box with Tomcat 3.3.1
(Java 1.4) w/Apache 1.3.22 on Redhat 7.3. However, it doesn't work when the
servlet is running on our production server which is Tomcat 4.0.3 (Java 1.4)
w/Apache on Redhat 7.2 (Ensim server). The problem happens in the server
code when trying to create the GZipInputStream, I get the following
exception:

java.io.IOException: Not in GZIP format
at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:127)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:55)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:65)

I know for a fact that it is in GZip format, and also that it works on every
server we try it on except on our production server.

Here is the code from the applet that is uploading the file:

URLConnection uc = url.openConnection();
uc.setUseCaches (false);
uc.setDefaultUseCaches(false);
uc.setDoOutput(true);
uc.setDoInput(true);
uc.setRequestProperty("Content-type", "multipart/form-data");
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new
GZIPOutputStream(uc.getOutputStream())));
...

and on the servlet:

// exception thrown on this line from GZIPInputStream constructor

BufferedInputStream bufIn= new BufferedInputStream(new
GZIPInputStream(request.getInputStream()));

What seems strange is that it all works on many different servers with
different versions of Tomcat and Java, but yet it refuses to work properly
on this one server. Does anyone have a clue what the problem may be?


Jon Skeet

unread,
Jul 30, 2002, 11:47:12 AM7/30/02
to
Chris Bailey <chrisba...@NOSPAMyahoo.ca> wrote:

> Here is the code from the applet that is uploading the file:
>
> URLConnection uc = url.openConnection();
> uc.setUseCaches (false);
> uc.setDefaultUseCaches(false);
> uc.setDoOutput(true);
> uc.setDoInput(true);
> uc.setRequestProperty("Content-type", "multipart/form-data");
> DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new
> GZIPOutputStream(uc.getOutputStream())));
> ...

And where's the code that writes to the stream and then closes it? That
could just as easily be at fault, I suspect.

If you could write a short but complete example of both halves, it would
help enormously.

--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

Chris Bailey

unread,
Jul 30, 2002, 4:33:23 PM7/30/02
to

The applet code I posted earlier is followed by

out.write(b,0,i);
out.flush();
out.close();

The HTTP Post is completed with the following code:

DataInputStream server;
server = new DataInputStream(uc.getInputStream());
String line = "";
while ((line = server.readLine())!= null) {
if (line.equals("limit")) done=true;
}
server.close();

Keep in mind as I mentioned, it isn't that the code doesn't work. It is
that it doesn't work on one particular machine. It works fine on the
following configs:

Windows 2000, Tomcat 4.0.3, JDK 1.4.0_1
Redhat 7.3, Tomcat 3.3.1, JDK 1.4.0
Redhat 7.2, Tomcat 4.0.3, JDK 1.3.1

The config of the server on which it doesn't work is:

Redhat 7.2, Tomcat 4.0.3, JDK 1.4.0_1.

The only difference other than that is that the non-working server is an
ensim WEBppliance v3.1. It works fine on this machine when I remove the
GZip portion. It also woks fine sending GZipped data down from the servlet
to the applet. It is only uploading that is a problem. One this
particular server we tried downgrading to JDK 1.3.1 and it didn't solve the
problem.

The problem disappears when I run the applet in the Java Plugin 1.3.1 or
higher. It only occurs when the applet is run in Microsoft's VM for Java,
Netscape 4.7, or Mac MRJ 3.1 (equivalent to java 1.3.1). Again keep in
mind, that all of these browser work fine when communicating with the
servlet on the other 3 servers.

Another important note, I can read the file on the servlet side without
uncmpressing it, and I write it to a file still in gzip form. I can then
successfully unzip it on the server and the file is not corrupted.

I guess the question should be... has anyone seen or experienced these kinds
of inconsistencies using GZip in Java? It seems it is just the one server
where it doesn't work, which leads me to believe it could be a server
problem.

"Jon Skeet" <sk...@pobox.com> wrote in message
news:MPG.17b0c55c5...@dnews.peramon.com...

Jon Skeet

unread,
Jul 30, 2002, 4:48:21 PM7/30/02
to
Chris Bailey <chrisba...@NOSPAMyahoo.ca> wrote:
> The HTTP Post is completed with the following code:
>
> DataInputStream server;
> server = new DataInputStream(uc.getInputStream());
> String line = "";
> while ((line = server.readLine())!= null) {
> if (line.equals("limit")) done=true;
> }
> server.close();

Aargh - that's probably what's wrong then. You're trying to read
*binary* data as if it were character data - unless I've misunderstood
something. I suspect one reason it may have worked on other platforms
would be due to character encoding differences.

As I said before: a short but complete example of both halves would
help.

Roedy Green

unread,
Jul 30, 2002, 4:46:26 PM7/30/02
to
On Tue, 30 Jul 2002 16:33:23 -0400, "Chris Bailey"
<chrisba...@NOSPAMyahoo.ca> wrote or quoted :

> out.flush();
> out.close();

is flush always redundant before a close is all circumstances in all
classes?

--
Available for tutoring, problem solving or contract
programming for $50 US per hour or fixed price.
The Java glossary is at
http://www.mindprod.com/jgloss.html
or http://64.251.89.39/jagg.html
-
canadian mind products, roedy green

0 new messages