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());
}
Aggregations