This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Different results from servlet

 
seema mani
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
I'm opening a URLConnection and writing a simple string to a servlet.In the servlet when I try to read it using readObject, I get
java.io.StreamCorruptedException
Version Mismatch,
Expected 5 and got 2
This happens only when I run the program from my machine in office. When I try the same thing from my home pc, it works fine. In both cases the servlet was running on the same remote server. Could someone think of any reason for this difference in behaviour ?
Thanx in advance
seema
 
chanoch wiggers
Author
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why dont you add it as a parameter? if you send it using the object serialization you will get version mismatch if the JDK has been tweaked ( I think). Basically the class version will cause a deserialization failure http://stein.cshl.org/jade/distrib/docs/java.io.ObjectInputStream.html
if there is a version mismatch and because String is treated as an object if you get object, this will be checked for. I guess its sort of a bug since a version mismatch in a string should cause any deserialization problems and so the handlers should account for that.
Since it's just a string, is there not a better way to do it?
 
seema mani
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi thanks a lot for the reply. Actually the object written to the servlet may not always be a String. It could be a Vector or a Hashtable depending on some conditions. Thats why I used readObject and writeObject thinking that this would work in all cases. If it was a String, I would have passed it as parameter itself as you suggested. Is there any other way to get around this problem ? My whole project depends on this.
Thanks again
Seema
 
chanoch wiggers
Author
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you could get around it by subclassing the classes you will need to pass and in each case implementing a readObject that doesnt check the version information.
the only problem is... string is final so I am not sure how you would get around that - I am finding it hard to believe that this is the problem because surely they wouldnt have done this to themselves? Anyway, a string is internally stored as an array of characters so you could implement a class that does that for serialization and deserialization.
Can I ask what the jdk versions on the two machines are?
 
seema mani
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi thanks. I'll try this way. About the JDK versions, the server is on JDK1.3.1 and the client on JDK1.2.2

Thank you
Seema
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't forget that there are other ways to serialize objects, even complex ones. Serialization/desierialization is such a common issue that lots of clever people have solutions for it. Look at "hessian" and "burlap" from http://www.caucho.com/ , for example.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic