aspose file tools*
The moose likes Applets and the fly likes applet-servlet communication: Error writing to server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "applet-servlet communication: Error writing to server" Watch "applet-servlet communication: Error writing to server" New topic
Author

applet-servlet communication: Error writing to server

Lukas Benberg
Ranch Hand

Joined: Jan 03, 2007
Posts: 45
Hi all,
I have trouble with my applet-servet communication. I send a file from an applet to a servlet. The servlet then sends a response "Thank you" (or an error message).

Generally this works, however it does not at one of the users. The user gets this error sending the file to the servlet:

java.io.IOException: Error writing to server
at sun.net.www.protocol.http.HttpURLConnection.writeRequests(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.writeRequests(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at AppletGUI.sendToServlet(AppletGUI.java:354)

I cannot reproduce the error, so I assume this is maybe due to a firewall. Which ports does my HTTP connection require except of 80?

This is the relevant code:




Thanks for help!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
Which ports does my HTTP connection require except of 80?

None.

catch (Exception e) {}

This is almost always a bad idea, and defintely when doing any kind of I/O. How are you going to know if there are problems?


Ping & DNS - my free Android networking tools app
Lukas Benberg
Ranch Hand

Joined: Jan 03, 2007
Posts: 45
Thanks Ulf,
Sorry, I did not post the catch block, because it didn't seem relevant to me concerning my question. Of course I catch Exceptions in the servlet. However, no exception is thrown in the Servlet, because the doPost function is not invoked by the *one* user who has the problem.

I am really helpless with this problem. The user uses the latest JRE, WinXP and tested IE6 and Firefox. On my computers all this works fine (and also on the ones of other users). I think I can also exlude firewall problems, since port 80 is definitely open. Strange.

If you have any ideas where the problem could be, I am grateful!

Thanks, L
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
OK. You could check whether the client request ever got to your server (by checking the access log of the server), if you know when exactly this happened.

The client could also try to access other parts of your server, maybe by using a test applet that tries to connect to various URLs.
chen bing
Greenhorn

Joined: Mar 03, 2008
Posts: 1
//write to servlet
ObjectOutputStream outputToHost = new
ObjectOutputStream(servletConnection.getOutputStream());
outputToHost.writeObject(tf);
outputToHost.flush();

String header = urlcon.getHeaderField(0);//this magic string works
lincy lau
Greenhorn

Joined: Aug 12, 2009
Posts: 1
the same problem i met.
If you have any ideas ,please email me.
Thanks very much!
Jasper Vandaele
Greenhorn

Joined: Sep 28, 2009
Posts: 2
I'm facing almost exactly the same problem, only in my case the response is also a Java Object containing a pdf as byte[] or an Exception Object in case of a server side Exception.

Some users have the same IOException as in your post, no matter when and how many times they try.
At the server side, I have a ProtocolException that I do not understand:

java.net.ProtocolException: EOF after reading only: '98304' of: '197686' promised bytes, out of which at least: '512' were already buffered
at weblogic.servlet.internal.PostInputStream.complain(PostInputStream.java:91)
at weblogic.servlet.internal.PostInputStream.read(PostInputStream.java:172)
at weblogic.servlet.internal.ServletInputStreamImpl.read(ServletInputStreamImpl.java:180)
at java.io.ObjectInputStream$PeekInputStream.read(ObjectInputStream.java:2140)
at java.io.ObjectInputStream$BlockDataInputStream.read(ObjectInputStream.java:2539)
at java.io.ObjectInputStream$BlockDataInputStream.readFully(ObjectInputStream.java:2569)
at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1584)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1271)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1835)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1759)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:322)
at my.own.package.SendAction.execute(SendAction.java:123)

The number of bytes in the error message are always the same if the user tries multiple times. Has any one seen this Exception before? Can anyone explain me what it means? I guess that a TCP packet is lost and that server gives up trying to read the incomming request, but I'm not sure at all. Especially not as this happens for a minority of users every time again, and always at the same byte.

A custom Exception indicating a transfer error is stored in a JavaObject which is returned to my applet.
From the applet logging, I can see that the user has been sending for 4 minutes and 36 seconds. I have the exact same stacktrace in my applet (on the HttpURLConnection.getInputStream()). The timeout on the servers is 5 minutes;

Until now, I have never succeeded to reproduce the problem, even if I send the same data the user send.
Did any one find an explanation and/or a solution for this problem?
This is a real killer.
 
wood burning stoves
 
subject: applet-servlet communication: Error writing to server