Search in sources :

Example 1 with SerializationException

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);
    }
}
Also used : SerializationException(org.apache.geode.SerializationException) DataTypeNotSupportedException(org.apache.geode.rest.internal.web.exception.DataTypeNotSupportedException) JSONObject(org.json.JSONObject)

Example 2 with SerializationException

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);
}
Also used : SerializationException(org.apache.geode.SerializationException) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) ArrayList(java.util.ArrayList) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) ServerOperationException(org.apache.geode.cache.client.ServerOperationException)

Example 3 with SerializationException

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) {
    }
}
Also used : SerializationException(org.apache.geode.SerializationException) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) SerializationException(org.apache.geode.SerializationException) MalformedURLException(java.net.MalformedURLException) Test(org.junit.Test) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 4 with SerializationException

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);
    }
}
Also used : SerializationException(org.apache.geode.SerializationException) CacheClosedException(org.apache.geode.cache.CacheClosedException) DataSerializable(org.apache.geode.DataSerializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) NonPortableClassException(org.apache.geode.pdx.NonPortableClassException) IOException(java.io.IOException) CancelException(org.apache.geode.CancelException) EOFException(java.io.EOFException) UTFDataFormatException(java.io.UTFDataFormatException) GemFireIOException(org.apache.geode.GemFireIOException) SerializationException(org.apache.geode.SerializationException) CacheClosedException(org.apache.geode.cache.CacheClosedException) NotSerializableException(java.io.NotSerializableException) ToDataException(org.apache.geode.ToDataException) DataInput(java.io.DataInput) EOFException(java.io.EOFException) ObjectStreamClass(java.io.ObjectStreamClass)

Example 5 with SerializationException

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);
    }
}
Also used : SerializationException(org.apache.geode.SerializationException) Constructor(java.lang.reflect.Constructor) ObjectStreamClass(java.io.ObjectStreamClass) InvocationTargetException(java.lang.reflect.InvocationTargetException) NonPortableClassException(org.apache.geode.pdx.NonPortableClassException) IOException(java.io.IOException) CancelException(org.apache.geode.CancelException) EOFException(java.io.EOFException) UTFDataFormatException(java.io.UTFDataFormatException) GemFireIOException(org.apache.geode.GemFireIOException) SerializationException(org.apache.geode.SerializationException) CacheClosedException(org.apache.geode.cache.CacheClosedException) NotSerializableException(java.io.NotSerializableException) ToDataException(org.apache.geode.ToDataException)

Aggregations

SerializationException (org.apache.geode.SerializationException)11 IOException (java.io.IOException)7 EOFException (java.io.EOFException)5 NotSerializableException (java.io.NotSerializableException)4 UTFDataFormatException (java.io.UTFDataFormatException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 CancelException (org.apache.geode.CancelException)4 GemFireIOException (org.apache.geode.GemFireIOException)4 ToDataException (org.apache.geode.ToDataException)4 CacheClosedException (org.apache.geode.cache.CacheClosedException)4 NonPortableClassException (org.apache.geode.pdx.NonPortableClassException)4 ObjectStreamClass (java.io.ObjectStreamClass)3 DataSerializable (org.apache.geode.DataSerializable)3 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)3 Constructor (java.lang.reflect.Constructor)2 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)2 Region (org.apache.geode.cache.Region)2 Version (org.apache.geode.internal.Version)2 DataTypeNotSupportedException (org.apache.geode.rest.internal.web.exception.DataTypeNotSupportedException)2 JSONObject (org.json.JSONObject)2