  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Struts - A MVC web framework | | Tomcat - JSP/Servlet container | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | | JSP - A mailing list about Java Server Pages specification and reference | |
Struts & Hibernate
|
|
|
  | | | serialization (tomcat) | serialization (tomcat) 2004-01-19 - By SBawek Tuleja
Back Hi
A have problem with serialization of objects in tomcat. I wrote something like this:
servlet:
__ ____ ____ ____ ____ ____ _____package tunelowanie_http;
import javax.servlet.*; import javax.servlet.http.*; import java.io.*;
public class DataStreamEcho extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, java.io.IOException  {
String text = "Hi"; resp.setContentType("application/x-java-serialized-object"); //resp.setContentType("application/octet-stream");
ObjectOutputStream out = new ObjectOutputStream(resp.getOutputStream()); out.writeObject(text); out.flush();
}
} __ ____ ____ ____ ____ ____ ____ _____
APPLICATION:
__ ____ ____ ____ ____ ____ ____ _____
package tunelowanie_http;
import java.io.*;
public class TestDataStream {
public static void main(String args[]) {
if (args.length == 0) { System.out.println("\nServlet URL must be specified"); return; }
try { System.out.println("Attempting to connect to " + args[0]); java.net.URL .html>java.net.URL java.net.URL .java.html> ' border=0> url = new java.net.URL .html>java.net.URL java.net.URL .java.html> ' border=0>(args[0]); java.net.URLConnection con = url.openConnection(); con.setRequestProperty("Content-type","application/x-java- serialized-object"); //con.setRequestProperty("Content-type","application/octet-stream"); con.setUseCaches(false);
System.out.println("Reading response");
ObjectInputStream in = new ObjectInputStream(con.getInputStream()); String returned = (String)in.readObject(); in.close();
System.out.println("Data read: " + returned ); } catch (Exception ex) { ex.printStackTrace(); }
}
} __ ____ ____ ____ ____ ____ ____ ____ ____ _____
When i'm using "application/x-java-serialized-object" it seems tomcat does not recognize this type when i'm using "application/octet-stream" its connecting but it returns objectinputstream Exception: wrong header or sth.
this same happens when i want to send single number using: writeInt readInt writeBoolean readBoolean [i dont have code with me right now so i dont remember exactly] but when i sent e.g. int 5, i recive int 26487485 it seems tomcat write some prefixes in both examples
im sure that it is problem of tomcat because i can serialize objets to file and read them back.
-- Pozdrowienia
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected) For additional commands, e-mail: tomcat-user-help@(protected)
|
|
 |