I'm not sure I agree with the conclusion, but I have inserted some code to do
what you want. There is no problem storing the handle in an HTTPSession.

There is one neat trick that you can do by storing a Stateful Session Bean
handle in a cookie. When the user comes back to a web farm, any webserver may
handle the request, because the SFSB handle is accessible to all of them. This
allows any webserver to access the user's state if it is all stored in a SFSB.

jim

================== Code begins
    /**
     *   Encode the object as a string. Useful for persisting into a
     *   relational database which supports strings but not raw Java objects
     *   The encoding is done using the BASE64-algorithm.
     *
     *   @param      object     the object to encode. Object must implement
     *                          java.io.Serializable
     *   @return     the object converted to a Base64 string
     */
    public static String toString(Serializable object) {
        sun.misc.BASE64Encoder enc = new sun.misc.BASE64Encoder();

        try {
            ByteArrayOutputStream buf = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream(buf);
            out.writeObject(object);
            return new String(enc.encodeBuffer(buf.toByteArray()));
        } catch (IOException e) {
            return null;
        }
    }

    /**
     *  Convert a string to an object
     *
     *  @param      str     the string-encoded object
     *  @return     the object
     */
    public static Serializable toObject(String str) {
        sun.misc.BASE64Decoder dec = new sun.misc.BASE64Decoder();

        try {
            ByteArrayInputStream buf = new
ByteArrayInputStream(dec.decodeBuffer(str));
            ObjectInputStream in = new ObjectInputStream(buf);
            return (Serializable)in.readObject();
        } catch (IOException e) {
            throw new IllegalArgumentException("Not serializable: " +
e.getMessage());
        } catch (ClassNotFoundException e) {
            throw new IllegalArgumentException("Not serializable: " +
e.getMessage());
        }
    }
================== Code ends

----- Original Message -----
From: "Dave Ford" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, August 31, 2000 8:47 AM
Subject: Encoding javax.ejb.Handle as String


> There was some discussion earlier about the best way for a web app to store
> a handle to a stateful session bean. One of the suggestions was to NOT use
> the HttpSession object at all, but rather encode the serialized handle as a
> string and then pass it as a cookie.
>
> My question is, where can I find the algorithm for converting a serialized
> handle to a string?
>
> Thanks,
>
> Dave Ford
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff EJB-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to