Search in sources :

Example 1 with MediaTypeUtils.negotiateMediaType

use of org.infinispan.rest.resources.MediaTypeUtils.negotiateMediaType in project infinispan by infinispan.

the class ContainerResource method getConfig.

private CompletionStage<RestResponse> getConfig(RestRequest request) {
    NettyRestResponse.Builder responseBuilder = checkCacheManager(request);
    if (responseBuilder.getHttpStatus() == NOT_FOUND)
        return completedFuture(responseBuilder.build());
    EmbeddedCacheManager embeddedCacheManager = invocationHelper.getRestCacheManager().getInstance().withSubject(request.getSubject());
    GlobalConfiguration globalConfiguration = SecurityActions.getCacheManagerConfiguration(embeddedCacheManager);
    MediaType format = MediaTypeUtils.negotiateMediaType(request, APPLICATION_JSON, APPLICATION_XML);
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try (ConfigurationWriter writer = ConfigurationWriter.to(baos).withType(format).build()) {
            parserRegistry.serialize(writer, globalConfiguration, emptyMap());
        }
        responseBuilder.contentType(format);
        responseBuilder.entity(baos.toByteArray());
    } catch (Exception e) {
        responseBuilder.status(HttpResponseStatus.INTERNAL_SERVER_ERROR);
    }
    return completedFuture(responseBuilder.build());
}
Also used : GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) ConfigurationWriter(org.infinispan.commons.configuration.io.ConfigurationWriter) MediaType(org.infinispan.commons.dataconversion.MediaType) MediaTypeUtils.negotiateMediaType(org.infinispan.rest.resources.MediaTypeUtils.negotiateMediaType) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) NettyRestResponse(org.infinispan.rest.NettyRestResponse)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ConfigurationWriter (org.infinispan.commons.configuration.io.ConfigurationWriter)1 MediaType (org.infinispan.commons.dataconversion.MediaType)1 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)1 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)1 NettyRestResponse (org.infinispan.rest.NettyRestResponse)1 MediaTypeUtils.negotiateMediaType (org.infinispan.rest.resources.MediaTypeUtils.negotiateMediaType)1