Search in sources :

Example 1 with NotSerializableException

use of java.io.NotSerializableException in project tomcat by apache.

the class DeltaSession method doWriteObject.

private void doWriteObject(ObjectOutput stream) throws IOException {
    // Write the scalar instance variables (except Manager)
    stream.writeObject(Long.valueOf(creationTime));
    stream.writeObject(Long.valueOf(lastAccessedTime));
    stream.writeObject(Integer.valueOf(maxInactiveInterval));
    stream.writeObject(Boolean.valueOf(isNew));
    stream.writeObject(Boolean.valueOf(isValid));
    stream.writeObject(Long.valueOf(thisAccessedTime));
    stream.writeObject(Long.valueOf(version));
    stream.writeBoolean(getPrincipal() instanceof Serializable);
    if (getPrincipal() instanceof Serializable) {
        stream.writeObject(getPrincipal());
    }
    stream.writeObject(id);
    if (log.isDebugEnabled())
        log.debug(sm.getString("deltaSession.writeSession", id));
    // Accumulate the names of serializable and non-serializable attributes
    String[] keys = keys();
    ArrayList<String> saveNames = new ArrayList<>();
    ArrayList<Object> saveValues = new ArrayList<>();
    for (int i = 0; i < keys.length; i++) {
        Object value = null;
        value = attributes.get(keys[i]);
        if (value != null && !exclude(keys[i], value) && isAttributeDistributable(keys[i], value)) {
            saveNames.add(keys[i]);
            saveValues.add(value);
        }
    }
    // Serialize the attribute count and the Serializable attributes
    int n = saveNames.size();
    stream.writeObject(Integer.valueOf(n));
    for (int i = 0; i < n; i++) {
        stream.writeObject(saveNames.get(i));
        try {
            stream.writeObject(saveValues.get(i));
        } catch (NotSerializableException e) {
            log.error(sm.getString("standardSession.notSerializable", saveNames.get(i), id), e);
        }
    }
    // Serializable listeners
    ArrayList<SessionListener> saveListeners = new ArrayList<>();
    for (SessionListener listener : listeners) {
        if (listener instanceof ReplicatedSessionListener) {
            saveListeners.add(listener);
        }
    }
    stream.writeObject(Integer.valueOf(saveListeners.size()));
    for (SessionListener listener : saveListeners) {
        stream.writeObject(listener);
    }
}
Also used : Serializable(java.io.Serializable) NotSerializableException(java.io.NotSerializableException) ArrayList(java.util.ArrayList) SessionListener(org.apache.catalina.SessionListener)

Example 2 with NotSerializableException

use of java.io.NotSerializableException in project tomcat by apache.

the class DeltaSession method doReadObject.

private void doReadObject(ObjectInput stream) throws ClassNotFoundException, IOException {
    // Deserialize the scalar instance variables (except Manager)
    // Transient only
    authType = null;
    creationTime = ((Long) stream.readObject()).longValue();
    lastAccessedTime = ((Long) stream.readObject()).longValue();
    maxInactiveInterval = ((Integer) stream.readObject()).intValue();
    isNew = ((Boolean) stream.readObject()).booleanValue();
    isValid = ((Boolean) stream.readObject()).booleanValue();
    thisAccessedTime = ((Long) stream.readObject()).longValue();
    version = ((Long) stream.readObject()).longValue();
    boolean hasPrincipal = stream.readBoolean();
    principal = null;
    if (hasPrincipal) {
        principal = (Principal) stream.readObject();
    }
    //        setId((String) stream.readObject());
    id = (String) stream.readObject();
    if (log.isDebugEnabled())
        log.debug(sm.getString("deltaSession.readSession", id));
    // Deserialize the attribute count and attribute values
    if (attributes == null)
        attributes = new ConcurrentHashMap<>();
    int n = ((Integer) stream.readObject()).intValue();
    boolean isValidSave = isValid;
    isValid = true;
    for (int i = 0; i < n; i++) {
        String name = (String) stream.readObject();
        final Object value;
        try {
            value = stream.readObject();
        } catch (WriteAbortedException wae) {
            if (wae.getCause() instanceof NotSerializableException) {
                // Skip non serializable attributes
                continue;
            }
            throw wae;
        }
        // the web application was stopped.
        if (exclude(name, value)) {
            continue;
        }
        attributes.put(name, value);
    }
    isValid = isValidSave;
    // Session listeners
    n = ((Integer) stream.readObject()).intValue();
    if (listeners == null || n > 0) {
        listeners = new ArrayList<>();
    }
    for (int i = 0; i < n; i++) {
        SessionListener listener = (SessionListener) stream.readObject();
        listeners.add(listener);
    }
    if (notes == null) {
        notes = new Hashtable<>();
    }
    activate();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NotSerializableException(java.io.NotSerializableException) WriteAbortedException(java.io.WriteAbortedException) SessionListener(org.apache.catalina.SessionListener) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 3 with NotSerializableException

use of java.io.NotSerializableException in project dubbo by alibaba.

the class AbstractSerializationPersionFailTest method test_StringPersonListMap.

@Test
public void test_StringPersonListMap() throws Exception {
    Map<String, List<Person>> args = new HashMap<String, List<Person>>();
    List<Person> sublist = new ArrayList<Person>();
    sublist.add(new Person());
    args.put("1", sublist);
    try {
        ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
        objectOutput.writeObject(args);
        fail();
    } catch (NotSerializableException expected) {
    } catch (IllegalStateException expected) {
        assertThat(expected.getMessage(), containsString("Serialized class com.alibaba.dubbo.common.model.Person must implement java.io.Serializable"));
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) ObjectOutput(com.alibaba.dubbo.common.serialize.ObjectOutput) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) Person(com.alibaba.dubbo.common.model.Person) Test(org.junit.Test)

Example 4 with NotSerializableException

use of java.io.NotSerializableException in project dubbo by alibaba.

the class AbstractSerializationPersionFailTest method test_IntPersonMap.

@Test
public void test_IntPersonMap() throws Exception {
    Map<Integer, Person> args = new HashMap<Integer, Person>();
    args.put(1, new Person());
    try {
        ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
        objectOutput.writeObject(args);
        fail();
    } catch (NotSerializableException expected) {
    } catch (IllegalStateException expected) {
        assertThat(expected.getMessage(), containsString("Serialized class com.alibaba.dubbo.common.model.Person must implement java.io.Serializable"));
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) ObjectOutput(com.alibaba.dubbo.common.serialize.ObjectOutput) HashMap(java.util.HashMap) Person(com.alibaba.dubbo.common.model.Person) Test(org.junit.Test)

Example 5 with NotSerializableException

use of java.io.NotSerializableException in project dubbo by alibaba.

the class AbstractSerializationPersionFailTest method test_Person.

@Test
public void test_Person() throws Exception {
    try {
        ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
        objectOutput.writeObject(new Person());
        fail();
    } catch (NotSerializableException expected) {
    } catch (IllegalStateException expected) {
        assertThat(expected.getMessage(), containsString("Serialized class com.alibaba.dubbo.common.model.Person must implement java.io.Serializable"));
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) ObjectOutput(com.alibaba.dubbo.common.serialize.ObjectOutput) Person(com.alibaba.dubbo.common.model.Person) Test(org.junit.Test)

Aggregations

NotSerializableException (java.io.NotSerializableException)39 ObjectOutputStream (java.io.ObjectOutputStream)14 IOException (java.io.IOException)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 ObjectInputStream (java.io.ObjectInputStream)9 Test (org.junit.Test)9 Person (com.alibaba.dubbo.common.model.Person)7 ObjectOutput (com.alibaba.dubbo.common.serialize.ObjectOutput)7 ArrayList (java.util.ArrayList)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Serializable (java.io.Serializable)6 HashMap (java.util.HashMap)5 InvalidClassException (java.io.InvalidClassException)4 OptionalDataException (java.io.OptionalDataException)4 StreamCorruptedException (java.io.StreamCorruptedException)4 List (java.util.List)4 CancelException (org.apache.geode.CancelException)4 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)4 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)3 OMemoryInputStream (com.orientechnologies.orient.core.serialization.OMemoryInputStream)3