use of org.apache.geode.SerializationException in project geode by apache.
the class AbstractBaseController method getValues.
protected <T> Map<Object, T> getValues(final String regionNamePath, Object... keys) {
try {
final Region<Object, T> region = getRegion(regionNamePath);
final Map<Object, T> entries = region.getAll(Arrays.asList(getKeys(regionNamePath, keys)));
for (Object key : entries.keySet()) {
entries.put(key, (T) securityService.postProcess(regionNamePath, key, entries.get(key), false));
}
return entries;
} catch (SerializationException se) {
throw new DataTypeNotSupportedException("The resource identified could not convert into the supported content characteristics (JSON)!", se);
}
}
use of org.apache.geode.SerializationException in project geode by apache.
the class ClassNotFoundExceptionDUnitTest method doTest.
public void doTest(final ObjectFactory objectFactory) throws InterruptedException {
IgnoredException.addIgnoredException("SerializationException");
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
VM vm3 = host.getVM(3);
int port1 = createServerRegion(vm0);
int port2 = createServerRegion(vm1);
createClientRegion(vm2, port1);
createClientRegion(vm3, port2);
SerializableRunnable putKey = new SerializableRunnable() {
public void run() {
Region region = getCache().getRegion("testSimplePdx");
region.put("a", "b");
region.put("b", "b");
for (int i = 0; i < 10; i++) {
region.put(i, i);
}
if (!region.containsKey("test")) {
region.put("test", objectFactory.get());
}
try {
region.put(objectFactory.get(), objectFactory.get());
fail("Should have received an exception");
} catch (SerializationException expected) {
// ok
} catch (ServerOperationException expected) {
if (!(expected.getCause() instanceof SerializationException) && !(expected.getCause() instanceof ClassNotFoundException)) {
throw expected;
}
}
// try {
// region.replace("test", objectFactory.get(), objectFactory.get());
// fail("Should have received an exception");
// } catch(SerializationException expected) {
// //ok
// } catch(ServerOperationException expected) {
// if(!(expected.getCause() instanceof SerializationException) && !(expected.getCause()
// instanceof ClassNotFoundException)) {
// throw expected;
// }
// }
}
};
SerializableRunnable getValue = new SerializableRunnable() {
public void run() {
Region region = getCache().getRegion("testSimplePdx");
try {
assertNotNull(region.get("test"));
fail("Should have received an exception");
} catch (SerializationException expected) {
// ok
} catch (ServerOperationException expected) {
if (!(expected.getCause() instanceof SerializationException) && !(expected.getCause() instanceof ClassNotFoundException)) {
throw expected;
}
}
}
};
SerializableRunnable registerInterest = new SerializableRunnable() {
public void run() {
Region region = getCache().getRegion("testSimplePdx");
try {
ArrayList keys = new ArrayList();
for (int i = 0; i < 1000; i++) {
keys.add(i);
}
keys.add("test");
region.getAll(keys);
fail("Should have received an exception");
} catch (SerializationException expected) {
System.out.println("hi");
// ok
} catch (ServerOperationException expected) {
if (!(expected.getCause() instanceof SerializationException) && !(expected.getCause() instanceof ClassNotFoundException)) {
throw expected;
}
}
}
};
vm2.invoke(putKey);
vm1.invoke(getValue);
vm3.invoke(getValue);
vm3.invoke(registerInterest);
vm1.invoke(putKey);
}
use of org.apache.geode.SerializationException in project geode by apache.
the class AutoSerializableJUnitTest method testException.
/*
* Check that an exception is appropriately thrown for a 'bad' object. In this case the bad class
* masks a field from a superclass and defines it as a different type.
*/
@Test
public void testException() throws Exception {
setupSerializer(stdSerializableClasses);
DomainObject objOut = new DomainObjectBad();
HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
try {
DataSerializer.writeObject(objOut, out);
} catch (SerializationException ex) {
// Pass
} catch (Exception ex) {
}
}
use of org.apache.geode.SerializationException in project geode by apache.
the class InternalDataSerializer method invokeFromData.
/**
* For backward compatibility this method should be used to invoke fromData on a DSFID or
* DataSerializable. It will invoke the correct fromData method based on the class's version
* information. This method does not read information about the class of the object. When
* serializing use the method invokeToData to write the contents of the object.
*
* @param ds the object to write
* @param in the input stream.
*/
public static void invokeFromData(Object ds, DataInput in) throws IOException, ClassNotFoundException {
try {
boolean invoked = false;
Version v = InternalDataSerializer.getVersionForDataStreamOrNull(in);
if (v != null && v != Version.CURRENT) {
// get versions where DataOutput was upgraded
Version[] versions = null;
if (ds instanceof SerializationVersions) {
SerializationVersions vds = (SerializationVersions) ds;
versions = vds.getSerializationVersions();
}
// there has been a change in the message
if (versions != null && versions.length > 0) {
for (Version version : versions) {
// if peer version is less than the greatest upgraded version
if (v.compareTo(version) < 0) {
ds.getClass().getMethod("fromDataPre" + '_' + version.getMethodSuffix(), new Class[] { DataInput.class }).invoke(ds, in);
invoked = true;
break;
}
}
}
}
if (!invoked) {
if (ds instanceof DataSerializableFixedID) {
((DataSerializableFixedID) ds).fromData(in);
} else {
((DataSerializable) ds).fromData(in);
}
}
} catch (EOFException | ClassNotFoundException | CacheClosedException ex) {
// client went away - ignore
throw ex;
} catch (Exception ex) {
throw new SerializationException(LocalizedStrings.DataSerializer_COULD_NOT_CREATE_AN_INSTANCE_OF_0.toLocalizedString(ds.getClass().getName()), ex);
}
}
use of org.apache.geode.SerializationException in project geode by apache.
the class InternalDataSerializer method readDataSerializableFixedID.
private static Object readDataSerializableFixedID(final DataInput in) throws IOException, ClassNotFoundException {
Class c = readClass(in);
try {
Constructor init = c.getConstructor(new Class[0]);
init.setAccessible(true);
Object o = init.newInstance(new Object[0]);
invokeFromData(o, in);
if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
logger.trace(LogMarker.SERIALIZER, "Read DataSerializableFixedID {}", o);
}
return o;
} catch (Exception ex) {
throw new SerializationException(LocalizedStrings.DataSerializer_COULD_NOT_CREATE_AN_INSTANCE_OF_0.toLocalizedString(c.getName()), ex);
}
}
Aggregations