struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael McGrady <m...@michaelmcgrady.com>
Subject Re: [OT] Serializing HttpSession Object
Date Fri, 16 Apr 2004 06:34:58 GMT
I don't know you and there is not enough code here to tell how much you 
know, but do you know that you have to get the output stream to write to 
from wherever you are sending it to?  Thus, you might have something like:


       URL url = new URL(/* some destination */);
       HttpURLConnection connection = (HttpURLConnection)url.openConnection();
       connection.setDoInput(true);
       connection.setDoOutput(true);
       connection.setUseCaches(false);
       connection.setRequestProperty("Content-Type", 
"application/x-java-serialized-object");
       ObjectOutputStream out = new 
ObjectOutputStream(connection.getOutputStream());
       out.writeObject(message);
       out.flush();
       out.close();
       BufferedInputStream bis = new 
BufferedInputStream(connection.getInputStream());
       Reader reader = new InputStreamReader(bis);
       StringBuffer sb = new StringBuffer("");

       int read;
       byte [] buffer = new byte[1024];
       while ((read = bis.read(buffer)) != -1) {
         sb.append(new String(buffer));
       }

Is this helpful?  Why not use your logger to find out what is up?




At 11:27 PM 4/15/2004, Johan Wasserman - CPX Mngd Services wrote:
>I need to serialize the session and save it to a blob in MySql (i use
>Hibernate).
>
>I have tried, for example;
>...
>ByteArrayOutputSream baos = new ByteArrayOutputstream();
>ObjectOutputStream oos = new ObjectOutputStream(boas);
>oos.writeObject(session);  //<-- it fails here, nothing in the logs
>byte[] sessionAsBytes = baos.toByteArray();
>...
>
>I need this to give the user the option to restore a previous session
>(where they where before they last logged out, with all the session
>variables required to restore to that point).
>
>  Thanks, Johan.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message