private StateRepositoryOpMessage.PutIfAbsentMessage decodePutIfAbsentMessage(ByteBuffer messageBuffer) { StructDecoder<Void> decoder = PUT_IF_ABSENT_MESSAGE_STRUCT.decoder(messageBuffer); String storeName = decoder.string(SERVER_STORE_NAME_FIELD); String mapId = decoder.string(MAP_ID_FIELD); ByteBuffer keyBuffer = decoder.byteBuffer(KEY_FIELD); Object key = Util.unmarshall(keyBuffer, WHITELIST_PREDICATE); ByteBuffer valueBuffer = decoder.byteBuffer(VALUE_FIELD); Object value = Util.unmarshall(valueBuffer, WHITELIST_PREDICATE); return new StateRepositoryOpMessage.PutIfAbsentMessage(storeName, mapId, key, value); }
private EhcacheSyncMessage decodeStateRepoSync(ByteBuffer message) { StructDecoder<Void> decoder = STATE_REPO_SYNC_STRUCT.decoder(message); String storeId = decoder.string(SERVER_STORE_NAME_FIELD); String mapId = decoder.string(STATE_REPO_MAP_NAME_FIELD); ConcurrentMap<Object, Object> mappings = new ConcurrentHashMap<>(); StructArrayDecoder<StructDecoder<Void>> structsDecoder = decoder.structs(STATE_REPO_ENTRIES_SUB_STRUCT); if (structsDecoder != null) { while (structsDecoder.hasNext()) { StructDecoder<StructArrayDecoder<StructDecoder<Void>>> structDecoder = structsDecoder.next(); Object key = unmarshall(structDecoder.byteBuffer(KEY_FIELD), WHITELIST_PREDICATE); Object value = unmarshall(structDecoder.byteBuffer(STATE_REPO_VALUE_FIELD), WHITELIST_PREDICATE); mappings.put(key, value); } } return new EhcacheStateRepoSyncMessage(storeId, mapId, mappings); }
private <T> void unmarshallingCheck(T t, Predicate<Class<?>> isClassPermitted) { @SuppressWarnings("unchecked") T unmarshalled = (T) Util.unmarshall(ByteBuffer.wrap(Util.marshall(t)), isClassPermitted); Assert.assertThat(unmarshalled, Matchers.is(t)); }
private StateRepositoryOpMessage.GetMessage decodeGetMessage(ByteBuffer messageBuffer) { StructDecoder<Void> decoder = GET_MESSAGE_STRUCT.decoder(messageBuffer); String storeName = decoder.string(SERVER_STORE_NAME_FIELD); String mapId = decoder.string(MAP_ID_FIELD); ByteBuffer keyBuffer = decoder.byteBuffer(KEY_FIELD); Object key = Util.unmarshall(keyBuffer, WHITELIST_PREDICATE); return new StateRepositoryOpMessage.GetMessage(storeName, mapId, key); }
@Test public void unmarshallingNonWhitelistedClassTest() { String className = ObjectStreamClass.lookup(Date.class).getName(); Date date = new Date(); byte[] marshalledDate = Util.marshall(date); try { Object object = Util.unmarshall(ByteBuffer.wrap(marshalledDate), Arrays.asList(Integer.class, Long.class)::contains); fail("Exception was expected to be thrown here"); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().equals("java.io.InvalidClassException: Class deserialization of " + className + " blocked.")); } }
decoder = MAP_VALUE_RESPONSE_STRUCT.decoder(buffer); return EhcacheEntityResponse.mapValue( Util.unmarshall(decoder.byteBuffer(MAP_VALUE_FIELD), WHITELIST_PREDICATE));
private StateRepositoryOpMessage.PutIfAbsentMessage decodePutIfAbsentMessage(ByteBuffer messageBuffer) { StructDecoder<Void> decoder = PUT_IF_ABSENT_MESSAGE_STRUCT.decoder(messageBuffer); String storeName = decoder.string(SERVER_STORE_NAME_FIELD); String mapId = decoder.string(MAP_ID_FIELD); ByteBuffer keyBuffer = decoder.byteBuffer(KEY_FIELD); Object key = Util.unmarshall(keyBuffer, WHITELIST_PREDICATE); ByteBuffer valueBuffer = decoder.byteBuffer(VALUE_FIELD); Object value = Util.unmarshall(valueBuffer, WHITELIST_PREDICATE); return new StateRepositoryOpMessage.PutIfAbsentMessage(storeName, mapId, key, value); }
private StateRepositoryOpMessage.GetMessage decodeGetMessage(ByteBuffer messageBuffer) { StructDecoder<Void> decoder = GET_MESSAGE_STRUCT.decoder(messageBuffer); String storeName = decoder.string(SERVER_STORE_NAME_FIELD); String mapId = decoder.string(MAP_ID_FIELD); ByteBuffer keyBuffer = decoder.byteBuffer(KEY_FIELD); Object key = Util.unmarshall(keyBuffer, WHITELIST_PREDICATE); return new StateRepositoryOpMessage.GetMessage(storeName, mapId, key); }
decoder = MAP_VALUE_RESPONSE_STRUCT.decoder(buffer); return EhcacheEntityResponse.mapValue( Util.unmarshall(decoder.byteBuffer(MAP_VALUE_FIELD), WHITELIST_PREDICATE));