• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I meet a problem. It is very interesting!!!!!!!!!!!!!!!!

 
Geoffrey Ren
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my applet interact with the webserver by HTTP protocol. I need to get a object from server.
But when I used the ObjectInputStream object readObject method. It throw a exception:
Server code:
ObjectOutputStream objout = new ObjectOutputStream(response.getOutputStream());
response.setContentType("application/octet-stream");

if (result.size() > 0)
{
for (int i = 0; i < result.size(); i++)
{
objout.reset();
objout.writeObject(result.get(i));
objout.flush();
}
}
else
{
Lesson lesson = new Lesson();
objout.writeObject(lesson);
objout.flush();
}
It is right.
Client code:
ObjectInputStream read = new ObjectInputStream(socket.getInputStream());

System.out.println("Get the outputing object2");

Vector result = new Vector();
Lesson lesson = null;
while ((lesson = (Lesson)read.readObject()) != null)
{
result.add(lesson);
}
writer.close();
socket.close ();
It meet problem:
The exception:
java.io.StreamCorruptedException: InputStream does not contain a serialized object
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:849)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:168)
at test.TestGet.main(TestGet.java:56)
HTTP/1.0 200 OK
Date: Wed, 05 Mar 2003 13:57:00 GMT
Server: WebLogic WebLogic Server 7.0 Thu Apr 25 17:16:22 PDT 2002 180709
Content-Type: application/octet-stream
Connection: Close
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is in result.get(i)? Is it a serializable object?
[ March 05, 2003: Message edited by: Paul Stevens ]
 
Geoffrey Ren
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is class which implements the Serializable interface.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's so Interesting!!! about that?
 
Geoffrey Ren
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this problem is very monstrosity. I resarched all of material. I can't find any key.
I wanted superior can help me settle the problem. Our project will be end. I will very malformation if this problem can't be settled.
Thanks!!
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to show more code in the handling of your socket variable... You might be trying to deserialize the response itself, rather than the octet stream in the response body...

Of course, you may get more help on this topic by posting it to the Servlets forum instead of the Swing/JFC/AWT forum... Don't worry... I'll move it for you...
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Just for fun - try setting the content type and all other headers before getting the OuputStream and lets see if that makes a difference. Also, where does "socket" in the following come from?

You should be using a URLConnection on the applet side and getting the input stream from that.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic