use of org.infinispan.commons.io.StringBuilderWriter in project infinispan by infinispan.
the class Server method parseConfiguration.
private void parseConfiguration(List<Path> configurationFiles) {
ParserRegistry parser = new ParserRegistry(classLoader, false, properties);
try {
// load the defaults first
URL defaults = this.getClass().getClassLoader().getResource(SERVER_DEFAULTS);
defaultsHolder = parser.parse(defaults);
// Set a default audit logger
defaultsHolder.getGlobalConfigurationBuilder().security().authorization().auditLogger(new LoggingAuditLogger());
// base the global configuration to the default
configurationBuilderHolder = new ConfigurationBuilderHolder(classLoader);
GlobalConfigurationBuilder global = configurationBuilderHolder.getGlobalConfigurationBuilder();
global.read(defaultsHolder.getGlobalConfigurationBuilder().build());
// Copy all default templates
for (Map.Entry<String, ConfigurationBuilder> entry : defaultsHolder.getNamedConfigurationBuilders().entrySet()) {
configurationBuilderHolder.newConfigurationBuilder(entry.getKey()).read(entry.getValue().build());
}
// then load the user configurations
for (Path configurationFile : configurationFiles) {
if (!configurationFile.isAbsolute()) {
configurationFile = serverConf.toPath().resolve(configurationFile);
}
parser.parse(configurationFile.toUri().toURL(), configurationBuilderHolder);
}
if (log.isDebugEnabled()) {
StringBuilderWriter sw = new StringBuilderWriter();
try (ConfigurationWriter w = ConfigurationWriter.to(sw).build()) {
Map<String, Configuration> configs = configurationBuilderHolder.getNamedConfigurationBuilders().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().build()));
parser.serialize(w, global.build(), configs);
}
log.debugf("Actual configuration: %s", sw);
}
// Amend the named caches configurations with the defaults
for (Map.Entry<String, ConfigurationBuilder> entry : configurationBuilderHolder.getNamedConfigurationBuilders().entrySet()) {
Configuration cfg = entry.getValue().build();
ConfigurationBuilder defaultCfg = defaultsHolder.getNamedConfigurationBuilders().get("org.infinispan." + cfg.clustering().cacheMode().name());
ConfigurationBuilder rebased = new ConfigurationBuilder().read(defaultCfg.build());
rebased.read(cfg);
entry.setValue(rebased);
}
// Process the server configuration
ServerConfigurationBuilder serverBuilder = global.module(ServerConfigurationBuilder.class);
// Set up transport security
TransportSecurityConfiguration transportSecurityConfiguration = serverBuilder.security().transport().create();
if (transportSecurityConfiguration.securityRealm() != null) {
String securityRealm = transportSecurityConfiguration.securityRealm();
Supplier<SSLContext> serverSSLContextSupplier = serverBuilder.serverSSLContextSupplier(securityRealm);
Supplier<SSLContext> clientSSLContextSupplier = serverBuilder.clientSSLContextSupplier(securityRealm);
NamedSocketFactory namedSocketFactory = new NamedSocketFactory(() -> clientSSLContextSupplier.get().getSocketFactory(), () -> serverSSLContextSupplier.get().getServerSocketFactory());
global.transport().addProperty(JGroupsTransport.SOCKET_FACTORY, namedSocketFactory);
Server.log.sslTransport(securityRealm);
}
// Set the operation handler on all endpoints
ServerAdminOperationsHandler adminOperationsHandler = new ServerAdminOperationsHandler(defaultsHolder);
ServerConfigurationBuilder serverConfigurationBuilder = global.module(ServerConfigurationBuilder.class);
for (EndpointConfigurationBuilder endpoint : serverConfigurationBuilder.endpoints().endpoints().values()) {
for (ProtocolServerConfigurationBuilder<?, ?> connector : endpoint.connectors()) {
connector.adminOperationsHandler(adminOperationsHandler);
}
}
configurationBuilderHolder.validate();
} catch (IOException e) {
throw new CacheConfigurationException(e);
}
}
use of org.infinispan.commons.io.StringBuilderWriter in project infinispan by infinispan.
the class CacheResourceV2 method convert.
private CompletionStage<RestResponse> convert(RestRequest request, MediaType toType) {
NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder();
String contents = request.contents().asString();
if (contents == null || contents.isEmpty()) {
responseBuilder.status(HttpResponseStatus.BAD_REQUEST);
return CompletableFuture.completedFuture(responseBuilder.build());
}
return CompletableFuture.supplyAsync(() -> {
ParserRegistry parserRegistry = invocationHelper.getParserRegistry();
ConfigurationBuilderHolder builderHolder = parserRegistry.parse(contents, request.contentType());
Map.Entry<String, ConfigurationBuilder> entry = builderHolder.getNamedConfigurationBuilders().entrySet().iterator().next();
Configuration configuration = entry.getValue().build();
StringBuilderWriter out = new StringBuilderWriter();
try (ConfigurationWriter writer = ConfigurationWriter.to(out).withType(toType).clearTextSecrets(true).prettyPrint(true).build()) {
parserRegistry.serialize(writer, entry.getKey(), configuration);
}
return responseBuilder.contentType(toType).entity(out.toString()).build();
}, invocationHelper.getExecutor());
}
use of org.infinispan.commons.io.StringBuilderWriter in project infinispan by infinispan.
the class ContainerResource method convertToJson.
private CompletionStage<RestResponse> convertToJson(RestRequest restRequest) {
NettyRestResponse.Builder responseBuilder = checkCacheManager(restRequest);
if (responseBuilder.getHttpStatus() == NOT_FOUND)
return completedFuture(responseBuilder.build());
ContentSource contents = restRequest.contents();
ConfigurationBuilderHolder builderHolder = parserRegistry.parse(new String(contents.rawContent(), UTF_8));
Map.Entry<String, ConfigurationBuilder> entry = builderHolder.getNamedConfigurationBuilders().entrySet().iterator().next();
StringBuilderWriter sw = new StringBuilderWriter();
try (ConfigurationWriter w = ConfigurationWriter.to(sw).withType(APPLICATION_JSON).build()) {
invocationHelper.getParserRegistry().serialize(w, entry.getKey(), entry.getValue().build());
}
responseBuilder.contentType(APPLICATION_JSON).entity(sw.toString());
return completedFuture(responseBuilder.build());
}
use of org.infinispan.commons.io.StringBuilderWriter in project infinispan by infinispan.
the class SerializationUtils method toJson.
public static String toJson(RemoteStoreConfiguration configuration) {
ConfigurationBuilder builder = new ConfigurationBuilder();
RemoteStoreConfigurationBuilder storeBuilder = builder.persistence().addStore(RemoteStoreConfigurationBuilder.class);
storeBuilder.read(configuration);
StringBuilderWriter sw = new StringBuilderWriter();
try (ConfigurationWriter w = ConfigurationWriter.to(sw).withType(APPLICATION_JSON).build()) {
parserRegistry.serialize(w, null, builder.build());
}
return Json.read(sw.toString()).at("local-cache").at("persistence").toString();
}
use of org.infinispan.commons.io.StringBuilderWriter in project infinispan by infinispan.
the class ContainerResourceTest method testGetGlobalConfig.
@Test
public void testGetGlobalConfig() {
RestResponse response = join(adminCacheManagerClient.globalConfiguration());
ResponseAssertion.assertThat(response).isOk();
String json = response.getBody();
EmbeddedCacheManager embeddedCacheManager = cacheManagers.get(0);
GlobalConfiguration globalConfiguration = embeddedCacheManager.withSubject(ADMIN).getCacheManagerConfiguration();
StringBuilderWriter sw = new StringBuilderWriter();
try (ConfigurationWriter w = ConfigurationWriter.to(sw).withType(APPLICATION_JSON).build()) {
new ParserRegistry().serialize(w, globalConfiguration, Collections.emptyMap());
}
assertEquals(sw.toString(), json);
}
Aggregations