• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

EOF error

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello guys, i am writing applet-servlet communication application, i am getting this error, which i am unable to resolve after digging into google also, hope someone here could help me get rid of the error. thanks in advance

code at applet

....
URL url = new URL(getCodeBase(), "NewServlet");
URLConnection con = url.openConnection();

con.setUseCaches(false);
con.setDoOutput(true);
con.setDoInput(false);


ByteArrayOutputStream stream = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(stream);
oos.writeObject(obj);
oos.flush();
oos.close();

byte[] buf = stream.toByteArray();
// con.setRequestProperty ("Content-Type", "application/x-java-serialized-object");
con.setRequestProperty("CONTENT-LENGTH",Integer.toString(buf.length));


DataOutputStream dataout = new DataOutputStream(con.getOutputStream());
dataout.write(buf);
dataout.flush();
dataout.close();
....

code at servlet

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
doPost(request, response);
....
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
InputStream in = request.getInputStream();
try
{
ObjectInputStream ois = new ObjectInputStream(in);
}
catch(EOFException e1)
{
System.out.println(" EXCEPTION ");
e1.printStackTrace();
}
....
}




java.io.EOFException
at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2279)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2748)
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:780)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:280)
at NewServlet.doPost(NewServlet.java:112)
at NewServlet.doGet(NewServlet.java:69)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:619)


also another thing :
when i do System.out.println(" Content Length = " + request.getContentLength()); it shows -1

and at applet side when i write
JOptionPane.showMessageDialog(this,"Priting buf length \n" + buf.length,"Testing!!" , JOptionPane.WARNING_MESSAGE); it shows 501
while
JOptionPane.showMessageDialog(this,"Priting con length \n" + con.getContentLength(),"testing!!" , JOptionPane.WARNING_MESSAGE); shows 234
 
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are attempting to connect to a servlet without using HTTP. Instead of URLConnection use HttpUrlConnection.
 
Gurbhej Singh Dhillon
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i changed it to
HttpURLConnection con = (HttpURLConnection)url.openConnection();
but still the error persists
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Same error?
 
Gurbhej Singh Dhillon
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, same error !!
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure, but why are you writing the object to a ByteArrayOutputStream before streaming it across thew wire?

Just get a handle to the stream from the HttpUrlConnection and create your object stream with this. Then write your object to this stream.

I thin this is the nature of your problem.
 
Gurbhej Singh Dhillon
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes i was using that before only, but was getting same here, untill someone suggested to use ByteArrayOutputStream + DataOutputStream to set the content length, which might be the reason for EOF Exception. both ways none is working
 
Gurbhej Singh Dhillon
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
does any1 has an answer to my question ??.. thought newbies questions would be answered over here, alas
 
Sheriff
Posts: 67694
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gurbhej Singh Dhillon:
thought newbies questions would be answered over here, alas

Perhaps you should ask for a refund?
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you are coding is not a daily thing for most people, unlike most questions/problems that are posted.
In order to help you a person would either have to receate your problem and debug or search the net for an example that works and compare it to your problem.
This is a lot of work to ask other people to do on your behalf...
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is an example I found on the net for sending an object across the wire. Please compare it to your code.




and the code the de-serialize the object on the server side

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Michael Ku:
Here is an example I found on the net for sending an object across the wire. Please compare it to your code.



Excellent!
Not that I want to be picky, but you should have pointed out from where you have got this code..
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Michael,

Don't jump to the conclusion . Gurbhej will probabily use your example and if it's what he needs, he will thank you if you want it... but "picky" was Val�ry Urbain who might be (or not) the author of your found source code.

Thank you
[ October 22, 2007: Message edited by: Laurentiu Bold ]
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Laurentiu, thank you for pointing out my mistake. I have deleted my post.

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic