tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From SÅ‚awek Tuleja <tu...@tlen.pl>
Subject serialization (tomcat)
Date Sun, 18 Jan 2004 21:02:49 GMT
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 url = new java.net.URL(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@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message