Search in sources :

Example 1 with ResteasyClientFactoryImpl

use of com.peterphi.std.guice.restclient.resteasy.impl.ResteasyClientFactoryImpl in project stdlib by petergeneric.

the class LogForwardDaemonPreGuice method start.

private void start() {
    final String instanceId = config.get(GuiceProperties.INSTANCE_ID);
    // TODO fix this!
    final String localEndpoint = config.get(GuiceProperties.LOCAL_REST_SERVICES_ENDPOINT, "http://unknown");
    final boolean useMoxy = config.getBoolean(GuiceProperties.MOXY_ENABLED, true);
    // Construct the necessary classes to create resteasy proxy clients.
    // We must do this independent of the guice creation path because we'll be running as Guice is starting up
    final JAXBContextResolver jaxb = new JAXBContextResolver(new JAXBSerialiserFactory(useMoxy));
    this.clientFactory = new ResteasyClientFactoryImpl(null, null, null, jaxb);
    ResteasyProxyClientFactoryImpl proxyFactory = new ResteasyProxyClientFactoryImpl(clientFactory, config);
    // Instantiate the services
    final ServiceManagerLoggingRestService logService = proxyFactory.getClient(ServiceManagerLoggingRestService.class);
    final ServiceManagerRegistryRestService registryService = proxyFactory.getClient(ServiceManagerRegistryRestService.class);
    this.daemon = new ServiceManagerLogForwardDaemon(instanceId, URI.create(localEndpoint), registryService, logService, this::guiceHasTakenOver);
    // Start the thread running
    this.daemon.startThread();
}
Also used : ServiceManagerLoggingRestService(com.peterphi.std.guice.common.logging.rest.iface.ServiceManagerLoggingRestService) ResteasyClientFactoryImpl(com.peterphi.std.guice.restclient.resteasy.impl.ResteasyClientFactoryImpl) ServiceManagerLogForwardDaemon(com.peterphi.std.guice.common.logging.appender.ServiceManagerLogForwardDaemon) JAXBSerialiserFactory(com.peterphi.std.util.jaxb.JAXBSerialiserFactory) ServiceManagerRegistryRestService(com.peterphi.std.guice.common.logging.rest.iface.ServiceManagerRegistryRestService) JAXBContextResolver(com.peterphi.std.guice.restclient.resteasy.impl.JAXBContextResolver) ResteasyProxyClientFactoryImpl(com.peterphi.std.guice.restclient.resteasy.impl.ResteasyProxyClientFactoryImpl)

Example 2 with ResteasyClientFactoryImpl

use of com.peterphi.std.guice.restclient.resteasy.impl.ResteasyClientFactoryImpl 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);
    }
}
Also used : ConfigRestService(com.peterphi.std.guice.config.rest.iface.ConfigRestService) ResteasyClientFactoryImpl(com.peterphi.std.guice.restclient.resteasy.impl.ResteasyClientFactoryImpl) JAXBSerialiserFactory(com.peterphi.std.util.jaxb.JAXBSerialiserFactory) ConfigPropertyData(com.peterphi.std.guice.config.rest.types.ConfigPropertyData) JAXBContextResolver(com.peterphi.std.guice.restclient.resteasy.impl.JAXBContextResolver) ConfigPropertyValue(com.peterphi.std.guice.config.rest.types.ConfigPropertyValue) ResteasyProxyClientFactoryImpl(com.peterphi.std.guice.restclient.resteasy.impl.ResteasyProxyClientFactoryImpl)

Aggregations

JAXBContextResolver (com.peterphi.std.guice.restclient.resteasy.impl.JAXBContextResolver)2 ResteasyClientFactoryImpl (com.peterphi.std.guice.restclient.resteasy.impl.ResteasyClientFactoryImpl)2 ResteasyProxyClientFactoryImpl (com.peterphi.std.guice.restclient.resteasy.impl.ResteasyProxyClientFactoryImpl)2 JAXBSerialiserFactory (com.peterphi.std.util.jaxb.JAXBSerialiserFactory)2 ServiceManagerLogForwardDaemon (com.peterphi.std.guice.common.logging.appender.ServiceManagerLogForwardDaemon)1 ServiceManagerLoggingRestService (com.peterphi.std.guice.common.logging.rest.iface.ServiceManagerLoggingRestService)1 ServiceManagerRegistryRestService (com.peterphi.std.guice.common.logging.rest.iface.ServiceManagerRegistryRestService)1 ConfigRestService (com.peterphi.std.guice.config.rest.iface.ConfigRestService)1 ConfigPropertyData (com.peterphi.std.guice.config.rest.types.ConfigPropertyData)1 ConfigPropertyValue (com.peterphi.std.guice.config.rest.types.ConfigPropertyValue)1