Search in sources :

Example 1 with Transcoder

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

the class ScriptConversions method convertToRequestType.

public Object convertToRequestType(Object obj, MediaType objType, MediaType requestType) {
    if (obj == null)
        return null;
    if (requestType.equals(MediaType.MATCH_ALL))
        return obj;
    // Older HR clients do not send request type and assume the script metadata type is the output type
    MediaType outputFormat = requestType.match(MediaType.APPLICATION_UNKNOWN) ? objType : requestType;
    OutputFormatter outputFormatter = formatterByMediaType.get(outputFormat.getTypeSubtype());
    if (obj instanceof Collection) {
        if (outputFormatter != null) {
            return outputFormatter.formatCollection((Collection<?>) obj, objType, requestType);
        }
    }
    Transcoder transcoder = encoderRegistry.getTranscoder(objType, requestType);
    return transcoder.transcode(obj, objType, requestType);
}
Also used : MediaType(org.infinispan.commons.dataconversion.MediaType) Collection(java.util.Collection) Transcoder(org.infinispan.commons.dataconversion.Transcoder)

Example 2 with Transcoder

use of org.infinispan.commons.dataconversion.Transcoder 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));
    }
}
Also used : SerializationContextRegistry(org.infinispan.marshall.protostream.impl.SerializationContextRegistry) TwoStepTranscoder(org.infinispan.encoding.impl.TwoStepTranscoder) ClassAllowList(org.infinispan.commons.configuration.ClassAllowList) EncoderRegistry(org.infinispan.marshall.core.EncoderRegistry) Transcoder(org.infinispan.commons.dataconversion.Transcoder) TwoStepTranscoder(org.infinispan.encoding.impl.TwoStepTranscoder) JsonTranscoder(org.infinispan.server.core.dataconversion.JsonTranscoder) XMLTranscoder(org.infinispan.server.core.dataconversion.XMLTranscoder) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) JsonTranscoder(org.infinispan.server.core.dataconversion.JsonTranscoder)

Example 3 with Transcoder

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

the class LifecycleManager method buildQuerySerializers.

private QuerySerializers buildQuerySerializers(ComponentRegistry cr, MediaType storageMediaType) {
    EncoderRegistry encoderRegistry = cr.getGlobalComponentRegistry().getComponent(EncoderRegistry.class);
    QuerySerializers querySerializers = new QuerySerializers();
    DefaultQuerySerializer defaultQuerySerializer = new DefaultQuerySerializer(encoderRegistry);
    querySerializers.addSerializer(MediaType.MATCH_ALL, defaultQuerySerializer);
    if (encoderRegistry.isConversionSupported(storageMediaType, APPLICATION_JSON)) {
        Transcoder jsonStorage = encoderRegistry.getTranscoder(APPLICATION_JSON, storageMediaType);
        querySerializers.addSerializer(APPLICATION_JSON, new JsonQuerySerializer(storageMediaType, jsonStorage));
    }
    return querySerializers;
}
Also used : EncoderRegistry(org.infinispan.marshall.core.EncoderRegistry) Transcoder(org.infinispan.commons.dataconversion.Transcoder)

Example 4 with Transcoder

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

the class DefaultQuerySerializer method encodeQueryResponse.

public byte[] encodeQueryResponse(Object queryResponse, MediaType destinationType) {
    MediaType destination = destinationType;
    // QueryResponses are sent in 'unwrapped' protobuf format
    if (destinationType.match(APPLICATION_PROTOSTREAM))
        destination = PROTOSTREAM_UNWRAPPED;
    Transcoder transcoder = encoderRegistry.getTranscoder(APPLICATION_OBJECT, destinationType);
    return (byte[]) transcoder.transcode(queryResponse, APPLICATION_OBJECT, destination);
}
Also used : MediaType(org.infinispan.commons.dataconversion.MediaType) Transcoder(org.infinispan.commons.dataconversion.Transcoder)

Aggregations

Transcoder (org.infinispan.commons.dataconversion.Transcoder)4 MediaType (org.infinispan.commons.dataconversion.MediaType)2 EncoderRegistry (org.infinispan.marshall.core.EncoderRegistry)2 Collection (java.util.Collection)1 ClassAllowList (org.infinispan.commons.configuration.ClassAllowList)1 TwoStepTranscoder (org.infinispan.encoding.impl.TwoStepTranscoder)1 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)1 SerializationContextRegistry (org.infinispan.marshall.protostream.impl.SerializationContextRegistry)1 JsonTranscoder (org.infinispan.server.core.dataconversion.JsonTranscoder)1 XMLTranscoder (org.infinispan.server.core.dataconversion.XMLTranscoder)1