use of org.infinispan.commons.dataconversion.MediaType in project infinispan by infinispan.
the class ObjectRemoteQueryManager method createEntityNamesResolver.
private EntityNameResolver<Class<?>> createEntityNamesResolver(MediaType mediaType) {
if (mediaType.match(APPLICATION_PROTOSTREAM)) {
return new ProtobufEntityNameResolver(serCtx);
} else {
ClassLoader classLoader = cr.getGlobalComponentRegistry().getComponent(ClassLoader.class);
ReflectionEntityNamesResolver reflectionEntityNamesResolver = new ReflectionEntityNamesResolver(classLoader);
if (searchMapping != null) {
// If indexing is enabled then use the declared set of indexed classes for lookup but fallback to global classloader.
QueryInterceptor queryInterceptor = cr.getComponent(QueryInterceptor.class);
Map<String, Class<?>> indexedEntities = queryInterceptor.indexedEntities();
return name -> {
Class<?> c = indexedEntities.get(name);
if (c == null) {
c = reflectionEntityNamesResolver.resolve(name);
}
return c;
};
}
return reflectionEntityNamesResolver;
}
}
use of org.infinispan.commons.dataconversion.MediaType in project infinispan by infinispan.
the class LifecycleManager method buildQueryManager.
private RemoteQueryManager buildQueryManager(Configuration cfg, SerializationContext ctx, ComponentRegistry cr) {
ContentTypeConfiguration valueEncoding = cfg.encoding().valueDataType();
MediaType valueStorageMediaType = valueEncoding.mediaType();
AdvancedCache<?, ?> cache = cr.getComponent(Cache.class).getAdvancedCache();
MediaType storageMediaType = cache.getValueDataConversion().getStorageMediaType();
QuerySerializers querySerializers = buildQuerySerializers(cr, storageMediaType);
boolean isObjectStorage = valueStorageMediaType != null && valueStorageMediaType.match(APPLICATION_OBJECT);
if (isObjectStorage)
return new ObjectRemoteQueryManager(cache, cr, querySerializers);
return new ProtobufRemoteQueryManager(cache, cr, ctx, querySerializers);
}
use of org.infinispan.commons.dataconversion.MediaType in project infinispan by infinispan.
the class CacheResourceV2 method getCacheConfig.
private CompletionStage<RestResponse> getCacheConfig(RestRequest request) {
NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder();
String cacheName = request.variables().get("cacheName");
MediaType accept = negotiateMediaType(request, APPLICATION_JSON, APPLICATION_XML, APPLICATION_YAML);
responseBuilder.contentType(accept);
if (!invocationHelper.getRestCacheManager().getInstance().getCacheConfigurationNames().contains(cacheName)) {
responseBuilder.status(NOT_FOUND).build();
}
Cache<?, ?> cache = invocationHelper.getRestCacheManager().getCache(cacheName, request);
if (cache == null)
return notFoundResponseFuture();
Configuration cacheConfiguration = SecurityActions.getCacheConfiguration(cache.getAdvancedCache());
ByteArrayOutputStream entity = new ByteArrayOutputStream();
try (ConfigurationWriter writer = ConfigurationWriter.to(entity).withType(accept).prettyPrint(false).build()) {
parserRegistry.serialize(writer, cacheName, cacheConfiguration);
} catch (Exception e) {
return CompletableFuture.completedFuture(responseBuilder.status(INTERNAL_SERVER_ERROR).entity(Util.getRootCause(e)).build());
}
responseBuilder.entity(entity);
return CompletableFuture.completedFuture(responseBuilder.status(OK).build());
}
use of org.infinispan.commons.dataconversion.MediaType in project infinispan by infinispan.
the class CacheResourceV2 method cacheListen.
private CompletionStage<RestResponse> cacheListen(RestRequest request) {
MediaType accept = negotiateMediaType(request, APPLICATION_JSON, TEXT_PLAIN);
String cacheName = request.variables().get("cacheName");
boolean includeCurrentState = Boolean.parseBoolean(request.getParameter("includeCurrentState"));
RestCacheManager<Object> restCacheManager = invocationHelper.getRestCacheManager();
if (!restCacheManager.cacheExists(cacheName))
return notFoundResponseFuture();
Cache<?, ?> cache = restCacheManager.getCache(cacheName, accept, accept, request);
BaseCacheListener listener = includeCurrentState ? new StatefulCacheListener(cache) : new StatelessCacheListener(cache);
NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder();
responseBuilder.contentType(TEXT_EVENT_STREAM).entity(listener.getEventStream());
return cache.addListenerAsync(listener).thenApply(v -> responseBuilder.build());
}
use of org.infinispan.commons.dataconversion.MediaType in project infinispan by infinispan.
the class ContainerResource method listenConfig.
private CompletionStage<RestResponse> listenConfig(RestRequest request) {
MediaType mediaType = negotiateMediaType(request, APPLICATION_YAML, APPLICATION_JSON, APPLICATION_XML);
boolean includeCurrentState = Boolean.parseBoolean(request.getParameter("includeCurrentState"));
EmbeddedCacheManager cacheManager = invocationHelper.getRestCacheManager().getInstance();
NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder();
ConfigurationListener listener = new ConfigurationListener(cacheManager, mediaType, includeCurrentState);
responseBuilder.contentType(TEXT_EVENT_STREAM).entity(listener.getEventStream());
return cacheManager.addListenerAsync(listener).thenApply(v -> responseBuilder.build());
}
Aggregations