use of org.infinispan.server.core.dataconversion.JsonTranscoder in project infinispan by infinispan.
the class CacheResourceTest method testServerDeserialization.
@Test
public void testServerDeserialization() throws Exception {
Object value = new Person();
byte[] jsonMarshalled = (byte[]) new JsonTranscoder().transcode(value, APPLICATION_OBJECT, APPLICATION_JSON);
byte[] xmlMarshalled = (byte[]) new XMLTranscoder().transcode(value, APPLICATION_OBJECT, APPLICATION_XML);
byte[] javaMarshalled = new JavaSerializationMarshaller().objectToByteBuffer(value);
String expectError = "Class '" + value.getClass().getName() + "' blocked by deserialization allow list";
RestEntity jsonEntity = RestEntity.create(APPLICATION_JSON, jsonMarshalled);
RestEntity xmlEntity = RestEntity.create(APPLICATION_XML, xmlMarshalled);
RestEntity javaEntity = RestEntity.create(APPLICATION_SERIALIZED_OBJECT, javaMarshalled);
CompletionStage<RestResponse> jsonResponse = client.cache("objectCache").put("addr2", jsonEntity);
assertThat(jsonResponse).isError();
assertThat(jsonResponse).containsReturnedText(expectError);
CompletionStage<RestResponse> xmlResponse = client.cache("objectCache").put("addr3", xmlEntity);
assertThat(xmlResponse).isError();
assertThat(xmlResponse).containsReturnedText(expectError);
CompletionStage<RestResponse> serializationResponse = client.cache("objectCache").put("addr4", javaEntity);
assertThat(serializationResponse).isError();
assertThat(serializationResponse).containsReturnedText(expectError);
}
use of org.infinispan.server.core.dataconversion.JsonTranscoder in project infinispan by infinispan.
the class LifecycleCallbacks method cacheManagerStarting.
@Override
public void cacheManagerStarting(GlobalComponentRegistry gcr, GlobalConfiguration globalConfiguration) {
SerializationContextRegistry ctxRegistry = gcr.getComponent(SerializationContextRegistry.class);
ctxRegistry.addContextInitializer(SerializationContextRegistry.MarshallerType.PERSISTENCE, new PersistenceContextInitializerImpl());
ClassAllowList classAllowList = gcr.getComponent(EmbeddedCacheManager.class).getClassAllowList();
ClassLoader classLoader = globalConfiguration.classLoader();
EncoderRegistry encoderRegistry = gcr.getComponent(EncoderRegistry.class);
JsonTranscoder jsonTranscoder = new JsonTranscoder(classLoader, classAllowList);
encoderRegistry.registerTranscoder(jsonTranscoder);
registerXmlTranscoder(encoderRegistry, classLoader, classAllowList);
// Allow transcoding between JBoss Marshalling and JSON
if (encoderRegistry.isConversionSupported(MediaType.APPLICATION_OBJECT, MediaType.APPLICATION_JBOSS_MARSHALLING)) {
Transcoder jbossMarshallingTranscoder = encoderRegistry.getTranscoder(MediaType.APPLICATION_OBJECT, MediaType.APPLICATION_JBOSS_MARSHALLING);
encoderRegistry.registerTranscoder(new TwoStepTranscoder(jbossMarshallingTranscoder, jsonTranscoder));
}
}
Aggregations