use of com.peterphi.std.guice.config.rest.iface.ConfigRestService in project stdlib by petergeneric.
the class GuiceFactory method applyNetworkConfiguration.
/**
* Add to the configuration any properties defined by the network configuration endpoint (if network config is enabled in a
* previous property)
*
* @param config
*/
private static void applyNetworkConfiguration(final GuiceConfig config) {
final String configEndpoint = config.get(GuiceProperties.CONFIG_ENDPOINT, null);
final Boolean configSkip = config.getBoolean(GuiceProperties.CONFIG_SKIP, false);
if (configEndpoint != null && !configSkip) {
final boolean useMoxy = config.getBoolean(GuiceProperties.MOXY_ENABLED, true);
final JAXBContextResolver jaxb = new JAXBContextResolver(new JAXBSerialiserFactory(useMoxy));
final ResteasyClientFactoryImpl clientFactory = new ResteasyClientFactoryImpl(null, null, null, jaxb);
try {
final ResteasyProxyClientFactoryImpl proxyFactory = new ResteasyProxyClientFactoryImpl(clientFactory, config);
final ConfigRestService client = proxyFactory.getClient(ConfigRestService.class);
// We set it in the config because otherwise the NetworkConfigReloadDaemon won't be able to load the config
if (config.get(GuiceProperties.CONFIG_PATH) == null) {
config.set(GuiceProperties.CONFIG_PATH, "services/" + config.get(GuiceProperties.SERVLET_CONTEXT_NAME, "unknown-service"));
}
// Get the config path to read
final String path = config.get(GuiceProperties.CONFIG_PATH);
final ConfigPropertyData data = client.read(path, config.get(GuiceProperties.INSTANCE_ID), null);
for (ConfigPropertyValue property : data.properties) {
config.set(property.name, property.value);
}
// Let others know that the configuration data is coming from a network source
config.set(GuiceProperties.CONFIG_SOURCE, GuiceConstants.CONFIG_SOURCE_NETWORK);
if (data.revision != null)
config.set(GuiceProperties.CONFIG_REVISION, data.revision);
} finally {
clientFactory.shutdown();
}
} else {
// Config is not coming from the network
config.set(GuiceProperties.CONFIG_SOURCE, GuiceConstants.CONFIG_SOURCE_LOCAL);
}
}
Aggregations