private byte[] encodeStateRepoSync(EhcacheStateRepoSyncMessage syncMessage) { StructEncoder<Void> encoder = STATE_REPO_SYNC_STRUCT.encoder(); encoder.enm(SYNC_MESSAGE_TYPE_FIELD_NAME, STATE_REPO) .string(SERVER_STORE_NAME_FIELD, syncMessage.getCacheId()) .string(STATE_REPO_MAP_NAME_FIELD, syncMessage.getMapId()); encoder.structs(STATE_REPO_ENTRIES_SUB_STRUCT, syncMessage.getMappings().entrySet(), (entryEncoder, entry) -> entryEncoder.byteBuffer(KEY_FIELD, wrap(marshall(entry.getKey()))) .byteBuffer(STATE_REPO_VALUE_FIELD, wrap(marshall(entry.getValue())))); return encoder.encode().array(); }
private byte[] encodePutIfAbsentMessage(StateRepositoryOpMessage.PutIfAbsentMessage message) { StructEncoder<Void> encoder = PUT_IF_ABSENT_MESSAGE_STRUCT.encoder(); messageCodecUtils.encodeMandatoryFields(encoder, message); encoder.string(SERVER_STORE_NAME_FIELD, message.getCacheId()); encoder.string(MAP_ID_FIELD, message.getCacheId()); // TODO this needs to change - serialization needs to happen in the StateRepo not here, though we need the hashcode for server side comparison. encoder.byteBuffer(KEY_FIELD, wrap(Util.marshall(message.getKey()))); encoder.byteBuffer(VALUE_FIELD, wrap(Util.marshall(message.getValue()))); return encoder.encode().array(); }
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 byte[] encodeGetMessage(StateRepositoryOpMessage.GetMessage message) { StructEncoder<Void> encoder = GET_MESSAGE_STRUCT.encoder(); messageCodecUtils.encodeMandatoryFields(encoder, message); encoder.string(SERVER_STORE_NAME_FIELD, message.getCacheId()); encoder.string(MAP_ID_FIELD, message.getCacheId()); // TODO this needs to change - serialization needs to happen in the StateRepo not here, though we need the hashcode for server side comparison. encoder.byteBuffer(KEY_FIELD, wrap(Util.marshall(message.getKey()))); return encoder.encode().array(); }
@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.")); } }
byte[] encodedMapValue = Util.marshall(mapValue.getValue()); return MAP_VALUE_RESPONSE_STRUCT.encoder() .enm(RESPONSE_TYPE_FIELD_NAME, mapValue.getResponseType())
private byte[] encodePutIfAbsentMessage(StateRepositoryOpMessage.PutIfAbsentMessage message) { StructEncoder<Void> encoder = PUT_IF_ABSENT_MESSAGE_STRUCT.encoder(); messageCodecUtils.encodeMandatoryFields(encoder, message); encoder.string(SERVER_STORE_NAME_FIELD, message.getCacheId()); encoder.string(MAP_ID_FIELD, message.getCacheId()); // TODO this needs to change - serialization needs to happen in the StateRepo not here, though we need the hashcode for server side comparison. encoder.byteBuffer(KEY_FIELD, wrap(Util.marshall(message.getKey()))); encoder.byteBuffer(VALUE_FIELD, wrap(Util.marshall(message.getValue()))); return encoder.encode().array(); }
private byte[] encodeGetMessage(StateRepositoryOpMessage.GetMessage message) { StructEncoder<Void> encoder = GET_MESSAGE_STRUCT.encoder(); messageCodecUtils.encodeMandatoryFields(encoder, message); encoder.string(SERVER_STORE_NAME_FIELD, message.getCacheId()); encoder.string(MAP_ID_FIELD, message.getCacheId()); // TODO this needs to change - serialization needs to happen in the StateRepo not here, though we need the hashcode for server side comparison. encoder.byteBuffer(KEY_FIELD, wrap(Util.marshall(message.getKey()))); return encoder.encode().array(); }
byte[] encodedMapValue = Util.marshall(mapValue.getValue()); return MAP_VALUE_RESPONSE_STRUCT.encoder() .enm(RESPONSE_TYPE_FIELD_NAME, mapValue.getResponseType())