Search in sources :

Example 1 with DefaultTranscoder

use of org.infinispan.commons.dataconversion.DefaultTranscoder in project infinispan by infinispan.

the class TextBinaryTranscoderTest method setUp.

@BeforeClass(alwaysRun = true)
public void setUp() {
    dataSrc = " !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
    transcoder = new DefaultTranscoder(new ProtoStreamMarshaller());
    supportedMediaTypes = transcoder.getSupportedMediaTypes();
}
Also used : DefaultTranscoder(org.infinispan.commons.dataconversion.DefaultTranscoder) ProtoStreamMarshaller(org.infinispan.commons.marshall.ProtoStreamMarshaller) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with DefaultTranscoder

use of org.infinispan.commons.dataconversion.DefaultTranscoder in project infinispan by infinispan.

the class TextObjectTranscoderTest method setUp.

@BeforeClass(alwaysRun = true)
public void setUp() {
    dataSrc = new Person("Joe");
    Address address = new Address();
    address.setCity("London");
    dataSrc.setAddress(address);
    transcoder = new DefaultTranscoder(TestingUtil.createProtoStreamMarshaller(RestTestSCI.INSTANCE));
    supportedMediaTypes = transcoder.getSupportedMediaTypes();
}
Also used : DefaultTranscoder(org.infinispan.commons.dataconversion.DefaultTranscoder) Address(org.infinispan.test.data.Address) Person(org.infinispan.test.data.Person) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with DefaultTranscoder

use of org.infinispan.commons.dataconversion.DefaultTranscoder in project infinispan by infinispan.

the class EncoderRegistryFactory method construct.

@Override
public Object construct(String componentName) {
    ClassLoader classLoader = globalConfiguration.classLoader();
    EncoderRegistryImpl encoderRegistry = new EncoderRegistryImpl();
    ClassAllowList classAllowList = embeddedCacheManager.getClassAllowList();
    encoderRegistry.registerEncoder(IdentityEncoder.INSTANCE);
    encoderRegistry.registerEncoder(UTF8Encoder.INSTANCE);
    encoderRegistry.registerEncoder(new JavaSerializationEncoder(classAllowList));
    encoderRegistry.registerEncoder(new GlobalMarshallerEncoder(globalMarshaller.wired()));
    // Default and binary transcoder use the user marshaller to convert data to/from a byte array
    encoderRegistry.registerTranscoder(new DefaultTranscoder(userMarshaller));
    encoderRegistry.registerTranscoder(new BinaryTranscoder(userMarshaller));
    // Core transcoders are always available
    encoderRegistry.registerTranscoder(new ProtostreamTranscoder(ctxRegistry, classLoader));
    encoderRegistry.registerTranscoder(new JavaSerializationTranscoder(classAllowList));
    // Wraps the GlobalMarshaller so that it can be used as a transcoder
    // Keeps application/x-infinispan-marshalling available for backwards compatibility
    encoderRegistry.registerTranscoder(new TranscoderMarshallerAdapter(globalMarshaller.wired()));
    // Make the user marshaller's media type available as well
    // As custom marshaller modules like Kryo and Protostuff do not define their own transcoder
    encoderRegistry.registerTranscoder(new TranscoderMarshallerAdapter(userMarshaller));
    encoderRegistry.registerWrapper(ByteArrayWrapper.INSTANCE);
    encoderRegistry.registerWrapper(IdentityWrapper.INSTANCE);
    return encoderRegistry;
}
Also used : EncoderRegistryImpl(org.infinispan.marshall.core.EncoderRegistryImpl) DefaultTranscoder(org.infinispan.commons.dataconversion.DefaultTranscoder) TranscoderMarshallerAdapter(org.infinispan.commons.dataconversion.TranscoderMarshallerAdapter) ClassAllowList(org.infinispan.commons.configuration.ClassAllowList) BinaryTranscoder(org.infinispan.commons.dataconversion.BinaryTranscoder) JavaSerializationTranscoder(org.infinispan.encoding.impl.JavaSerializationTranscoder) ProtostreamTranscoder(org.infinispan.encoding.ProtostreamTranscoder) GlobalMarshallerEncoder(org.infinispan.commons.dataconversion.GlobalMarshallerEncoder) JavaSerializationEncoder(org.infinispan.commons.dataconversion.JavaSerializationEncoder)

Example 4 with DefaultTranscoder

use of org.infinispan.commons.dataconversion.DefaultTranscoder in project infinispan by infinispan.

the class TranscoderRegistrationTest method testTranscoderLookup.

public void testTranscoderLookup() {
    EncoderRegistry encoderRegistry = new EncoderRegistryImpl();
    TestTranscoder t1 = new TestTranscoder(MediaType.APPLICATION_JSON, MediaType.APPLICATION_OBJECT);
    TestTranscoder t2 = new TestTranscoder(MediaType.APPLICATION_XML, MediaType.APPLICATION_OBJECT);
    DefaultTranscoder t3 = new DefaultTranscoder(new JavaSerializationMarshaller());
    encoderRegistry.registerTranscoder(t3);
    encoderRegistry.registerTranscoder(t2);
    encoderRegistry.registerTranscoder(t1);
    assertEquals(encoderRegistry.getTranscoder(MediaType.TEXT_PLAIN, MediaType.APPLICATION_OBJECT), t3);
    assertEquals(encoderRegistry.getTranscoder(MediaType.TEXT_PLAIN, MediaType.TEXT_PLAIN), t3);
    assertEquals(encoderRegistry.getTranscoder(MediaType.TEXT_PLAIN, MediaType.APPLICATION_OBJECT), t3);
    assertEquals(encoderRegistry.getTranscoder(MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_OCTET_STREAM), t3);
    assertEquals(encoderRegistry.getTranscoder(MediaType.APPLICATION_OBJECT, MediaType.APPLICATION_OBJECT), t3);
    assertEquals(encoderRegistry.getTranscoder(MediaType.TEXT_PLAIN, MediaType.APPLICATION_OCTET_STREAM), t3);
    assertNotFound(encoderRegistry, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML);
    assertNotFound(encoderRegistry, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON);
    assertEquals(encoderRegistry.getTranscoder(MediaType.APPLICATION_JSON, MediaType.APPLICATION_OBJECT), t1);
    assertEquals(encoderRegistry.getTranscoder(MediaType.APPLICATION_OBJECT, MediaType.APPLICATION_JSON), t1);
    assertEquals(encoderRegistry.getTranscoder(MediaType.APPLICATION_XML, MediaType.APPLICATION_OBJECT), t2);
    assertEquals(encoderRegistry.getTranscoder(MediaType.APPLICATION_OBJECT, MediaType.APPLICATION_XML), t2);
    assertEquals(encoderRegistry.getTranscoder(MediaType.APPLICATION_WWW_FORM_URLENCODED, MediaType.APPLICATION_WWW_FORM_URLENCODED), t3);
}
Also used : EncoderRegistryImpl(org.infinispan.marshall.core.EncoderRegistryImpl) DefaultTranscoder(org.infinispan.commons.dataconversion.DefaultTranscoder) EncoderRegistry(org.infinispan.marshall.core.EncoderRegistry) JavaSerializationMarshaller(org.infinispan.commons.marshall.JavaSerializationMarshaller)

Aggregations

DefaultTranscoder (org.infinispan.commons.dataconversion.DefaultTranscoder)4 EncoderRegistryImpl (org.infinispan.marshall.core.EncoderRegistryImpl)2 BeforeClass (org.testng.annotations.BeforeClass)2 ClassAllowList (org.infinispan.commons.configuration.ClassAllowList)1 BinaryTranscoder (org.infinispan.commons.dataconversion.BinaryTranscoder)1 GlobalMarshallerEncoder (org.infinispan.commons.dataconversion.GlobalMarshallerEncoder)1 JavaSerializationEncoder (org.infinispan.commons.dataconversion.JavaSerializationEncoder)1 TranscoderMarshallerAdapter (org.infinispan.commons.dataconversion.TranscoderMarshallerAdapter)1 JavaSerializationMarshaller (org.infinispan.commons.marshall.JavaSerializationMarshaller)1 ProtoStreamMarshaller (org.infinispan.commons.marshall.ProtoStreamMarshaller)1 ProtostreamTranscoder (org.infinispan.encoding.ProtostreamTranscoder)1 JavaSerializationTranscoder (org.infinispan.encoding.impl.JavaSerializationTranscoder)1 EncoderRegistry (org.infinispan.marshall.core.EncoderRegistry)1 Address (org.infinispan.test.data.Address)1 Person (org.infinispan.test.data.Person)1