Search in sources :

Example 1 with SerializationException

use of org.apache.commons.lang.SerializationException in project geode by apache.

the class IntegratedSecurityService method postProcess.

public Object postProcess(Object principal, String regionPath, Object key, Object value, boolean valueIsSerialized) {
    if (!needPostProcess())
        return value;
    if (principal == null) {
        Subject subject = getSubject();
        if (subject == null)
            return value;
        principal = (Serializable) subject.getPrincipal();
    }
    String regionName = StringUtils.stripStart(regionPath, "/");
    Object newValue = null;
    // it to the callback.
    if (valueIsSerialized && value instanceof byte[]) {
        try {
            Object oldObj = EntryEventImpl.deserialize((byte[]) value);
            Object newObj = postProcessor.processRegionValue(principal, regionName, key, oldObj);
            newValue = BlobHelper.serializeToBlob(newObj);
        } catch (IOException | SerializationException e) {
            throw new GemFireIOException("Exception de/serializing entry value", e);
        }
    } else {
        newValue = postProcessor.processRegionValue(principal, regionName, key, value);
    }
    return newValue;
}
Also used : SerializationException(org.apache.commons.lang.SerializationException) GemFireIOException(org.apache.geode.GemFireIOException) GemFireIOException(org.apache.geode.GemFireIOException) IOException(java.io.IOException) Subject(org.apache.shiro.subject.Subject)

Example 2 with SerializationException

use of org.apache.commons.lang.SerializationException in project geode by apache.

the class JGroupsMessengerJUnitTest method testSerializationError.

@Test
public void testSerializationError() throws Exception {
    for (int i = 0; i < 2; i++) {
        boolean enableMcast = (i == 1);
        initMocks(enableMcast);
        InternalDistributedMember mbr = createAddress(8888);
        DistributedCacheOperation.CacheOperationMessage msg = mock(DistributedCacheOperation.CacheOperationMessage.class);
        when(msg.getRecipients()).thenReturn(new InternalDistributedMember[] { mbr });
        when(msg.getMulticast()).thenReturn(enableMcast);
        if (!enableMcast) {
            // for non-mcast we send a message with a reply-processor
            when(msg.getProcessorId()).thenReturn(1234);
        } else {
            // for mcast we send a direct-ack message and expect the messenger
            // to register it
            stub(msg.isDirectAck()).toReturn(true);
        }
        when(msg.getDSFID()).thenReturn((int) DataSerializableFixedID.PUT_ALL_MESSAGE);
        // for code coverage we need to test with both a SerializationException and
        // an IOException. The former is wrapped in a GemfireIOException while the
        // latter is not
        doThrow(new SerializationException()).when(msg).toData(any(DataOutput.class));
        try {
            messenger.send(msg);
            fail("expected a failure");
        } catch (GemFireIOException e) {
        // success
        }
        if (enableMcast) {
            verify(msg, atLeastOnce()).registerProcessor();
        }
        doThrow(new IOException()).when(msg).toData(any(DataOutput.class));
        try {
            messenger.send(msg);
            fail("expected a failure");
        } catch (GemFireIOException e) {
        // success
        }
    }
}
Also used : DataOutput(java.io.DataOutput) DistributedCacheOperation(org.apache.geode.internal.cache.DistributedCacheOperation) SerializationException(org.apache.commons.lang.SerializationException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) GemFireIOException(org.apache.geode.GemFireIOException) GemFireIOException(org.apache.geode.GemFireIOException) IOException(java.io.IOException) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

IOException (java.io.IOException)2 SerializationException (org.apache.commons.lang.SerializationException)2 GemFireIOException (org.apache.geode.GemFireIOException)2 DataOutput (java.io.DataOutput)1 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1 DistributedCacheOperation (org.apache.geode.internal.cache.DistributedCacheOperation)1 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)1 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)1 Subject (org.apache.shiro.subject.Subject)1 Test (org.junit.Test)1