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);
}
}
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();
}
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"));
}
}
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"));
}
}
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"));
}
}
Aggregations