Les the following test is failing for me (java 1.6 on os x):

package semantica.enterprise.service;

import static org.junit.Assert.*;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Date;

import org.apache.shiro.cache.CacheException;
import org.apache.shiro.session.mgt.SimpleSession;
import org.junit.Test;


public class SessionTest {
        
        private byte[] toBytes(Object value) {
                try {
                        ByteArrayOutputStream baos = new 
ByteArrayOutputStream() ;
                        ObjectOutputStream oos = new ObjectOutputStream(baos);
                    oos.writeObject(value);
                   //
oos.writeObject("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbffffffffffffffffffffffffffffffffffffffffjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj");
                    oos.flush();
                    oos.close();
                    // Get the bytes of the serialized object
                    byte[] buf  = baos.toByteArray();
                    return buf;
                } catch (IOException io) {
                        throw new CacheException(io);
                }
        }
        
        //@SuppressWarnings("unchecked")
        private Object fromBytes(byte[] bytes) {
                try {
                        ObjectInputStream ois = new ObjectInputStream(new
ByteArrayInputStream(bytes));
                        Object value =  ois.readObject();
                    ois.close();
                    return value;
                } catch (ClassNotFoundException e) {
                        throw new CacheException(e);
                } catch (IOException e) {
                        throw new CacheException(e);
                } catch (ClassCastException e) {
                        throw new CacheException(e);
                }
        }
        
        
        @Test
    public void testDefaultSerialization() throws Exception {
        SimpleSession session = new SimpleSession();
        long timeout = session.getTimeout();
        Date start = session.getStartTimestamp();
        Date lastAccess = session.getLastAccessTime();

        byte[] serialized = toBytes(session);
        SimpleSession deserialized = (SimpleSession)fromBytes(serialized);

        assertEquals(timeout, deserialized.getTimeout());
        assertEquals(start, deserialized.getStartTimestamp());
        assertEquals(lastAccess, deserialized.getLastAccessTime());
    } 

}




-- 
View this message in context: 
http://shiro-user.582556.n2.nabble.com/serialization-problem-with-SimpleSession-tp5537015p5537266.html
Sent from the Shiro User mailing list archive at Nabble.com.

Reply via email to