Search in sources :

Example 1 with HttpStrategy

use of org.platformlayer.http.HttpStrategy in project platformlayer by platformlayer.

the class GuiceXaasConfig method configure.

@Override
protected void configure() {
    bind(EncryptionStore.class).toProvider(EncryptionStoreProvider.class);
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    FreemarkerTemplateEngine freemarker = new FreemarkerTemplateEngine(classLoader);
    bind(TemplateEngine.class).toInstance(freemarker);
    bind(ItemService.class).to(ItemServiceImpl.class);
    bind(ISshContext.class).to(MinaSshContext.class);
    bind(OpsSystem.class);
    bind(OpsContext.class).toProvider(OpsContextProvider.class);
    bind(JobRegistry.class).to(PersistentJobRegistry.class).asEagerSingleton();
    File jobLogStoreBaseDir = new File("jobs");
    jobLogStoreBaseDir.mkdirs();
    bind(JobLogStore.class).toInstance(new FilesystemJobLogStore(jobLogStoreBaseDir));
    // TODO: Split off scheduler
    bind(ResultSetMappersProvider.class).asEagerSingleton();
    bind(ResultSetMappers.class).toProvider(ResultSetMappersProvider.class).in(Scopes.SINGLETON);
    bind(DataSource.class).toProvider(GuiceDataSourceProvider.bind("platformlayer.jdbc.")).asEagerSingleton();
    URLClassLoader urlClassLoader = (URLClassLoader) Thread.currentThread().getContextClassLoader();
    JerseyAnnotationDiscovery discovery = new JerseyAnnotationDiscovery();
    discovery.scan(urlClassLoader);
    bind(AnnotationDiscovery.class).toInstance(discovery);
    for (AnnotatedClass annotatedClass : discovery.findAnnotatedClasses(org.platformlayer.xaas.Module.class)) {
        Class<?> moduleClass = annotatedClass.getSubjectClass();
        log.info("Installing extension module: " + moduleClass);
        com.google.inject.Module module;
        try {
            module = (com.google.inject.Module) moduleClass.newInstance();
        } catch (InstantiationException e) {
            throw new IllegalStateException("Error creating class: " + moduleClass, e);
        } catch (IllegalAccessException e) {
            throw new IllegalStateException("Error creating class: " + moduleClass, e);
        }
        this.install(module);
    }
    HttpStrategy httpStrategy = new InstrumentedApacheHttpStrategy();
    bind(HttpStrategy.class).toInstance(httpStrategy);
    bind(AuthenticationTokenValidator.class).toProvider(PlatformLayerAuthAdminClient.Provider.class).in(Scopes.SINGLETON);
    // boolean isMultitenant = !Strings.isNullOrEmpty(configuration.lookup("multitenant.keys", null));
    if (true) {
        // isMultitenant) {
        bind(PlatformLayerAuthenticationClient.class).toProvider(PlatformLayerAuthenticationClientProvider.class).asEagerSingleton();
        bind(AuthenticationService.class).to(PlatformlayerAuthenticationService.class).asEagerSingleton();
    }
    bind(BackupContextFactory.class).to(StubBackupContextFactory.class);
    bind(ExecutorService.class).toInstance(Executors.newCachedThreadPool());
    bind(ServiceProviderDictionary.class).to(AnnotationServiceProviderDictionary.class).in(Scopes.SINGLETON);
    bind(JaxbContextHelper.class).asEagerSingleton();
    bind(JAXBContext.class).toProvider(JaxbContextHelper.class);
    bind(OperationQueue.class).to(SimpleOperationQueue.class).asEagerSingleton();
    bind(ObjectInjector.class).to(GuiceObjectInjector.class);
    bind(OpsKeyStore.class).to(SimpleOpsKeyStore.class).in(Scopes.SINGLETON);
    bind(JobRepository.class).to(JdbcJobRepository.class);
    bind(ManagedItemRepository.class).to(JdbcManagedItemRepository.class);
    bind(ServiceAuthorizationRepository.class).to(JdbcServiceAuthorizationRepository.class);
    bind(ChangeQueue.class).to(InProcessChangeQueue.class);
    bind(PlatformLayerClient.class).toProvider(PlatformLayerClientProvider.class);
}
Also used : JaxbContextHelper(org.platformlayer.xaas.web.jaxrs.JaxbContextHelper) HttpStrategy(org.platformlayer.http.HttpStrategy) InstrumentedApacheHttpStrategy(org.platformlayer.http.apache.InstrumentedApacheHttpStrategy) PlatformlayerAuthenticationService(org.platformlayer.auth.system.PlatformlayerAuthenticationService) JAXBContext(javax.xml.bind.JAXBContext) ManagedItemRepository(org.platformlayer.xaas.repository.ManagedItemRepository) JdbcManagedItemRepository(org.platformlayer.guice.xaas.JdbcManagedItemRepository) OpsContext(org.platformlayer.ops.OpsContext) AnnotationServiceProviderDictionary(org.platformlayer.xaas.services.AnnotationServiceProviderDictionary) JobRepository(org.platformlayer.xaas.repository.JobRepository) JdbcJobRepository(org.platformlayer.ops.jobstore.jdbc.JdbcJobRepository) PlatformLayerClient(org.platformlayer.PlatformLayerClient) FreemarkerTemplateEngine(org.platformlayer.ops.templates.FreemarkerTemplateEngine) TemplateEngine(org.platformlayer.ops.templates.TemplateEngine) ResultSetMappersProvider(com.fathomdb.jpa.impl.ResultSetMappersProvider) PlatformLayerAuthenticationClientProvider(org.platformlayer.auth.client.PlatformLayerAuthenticationClientProvider) AnnotatedClass(org.platformlayer.xaas.discovery.AnnotatedClass) ItemService(org.platformlayer.ops.ItemService) SimpleOpsKeyStore(org.platformlayer.ops.crypto.SimpleOpsKeyStore) URLClassLoader(java.net.URLClassLoader) ISshContext(org.platformlayer.ops.ssh.ISshContext) EncryptionStore(com.fathomdb.crypto.EncryptionStore) JobLogStore(org.platformlayer.ops.jobstore.JobLogStore) FilesystemJobLogStore(org.platformlayer.ops.jobstore.FilesystemJobLogStore) ChangeQueue(org.platformlayer.xaas.services.ChangeQueue) InProcessChangeQueue(org.platformlayer.xaas.ops.InProcessChangeQueue) SimpleOperationQueue(org.platformlayer.ops.jobstore.SimpleOperationQueue) FilesystemJobLogStore(org.platformlayer.ops.jobstore.FilesystemJobLogStore) EncryptionStoreProvider(org.platformlayer.crypto.EncryptionStoreProvider) OpsContextProvider(org.platformlayer.ops.guice.OpsContextProvider) PlatformLayerAuthenticationClientProvider(org.platformlayer.auth.client.PlatformLayerAuthenticationClientProvider) ResultSetMappersProvider(com.fathomdb.jpa.impl.ResultSetMappersProvider) GuiceDataSourceProvider(org.platformlayer.jdbc.GuiceDataSourceProvider) JerseyAnnotationDiscovery(org.platformlayer.xaas.discovery.JerseyAnnotationDiscovery) AnnotationDiscovery(org.platformlayer.xaas.discovery.AnnotationDiscovery) PersistentJobRegistry(org.platformlayer.ops.jobstore.PersistentJobRegistry) JerseyAnnotationDiscovery(org.platformlayer.xaas.discovery.JerseyAnnotationDiscovery) URLClassLoader(java.net.URLClassLoader) ExecutorService(java.util.concurrent.ExecutorService) InstrumentedApacheHttpStrategy(org.platformlayer.http.apache.InstrumentedApacheHttpStrategy) BackupContextFactory(org.platformlayer.ops.backups.BackupContextFactory) StubBackupContextFactory(org.platformlayer.ops.backups.StubBackupContextFactory) File(java.io.File) GuiceObjectInjector(org.platformlayer.inject.GuiceObjectInjector) ObjectInjector(org.platformlayer.inject.ObjectInjector) FreemarkerTemplateEngine(org.platformlayer.ops.templates.FreemarkerTemplateEngine) JdbcServiceAuthorizationRepository(org.platformlayer.guice.xaas.JdbcServiceAuthorizationRepository) ServiceAuthorizationRepository(org.platformlayer.xaas.repository.ServiceAuthorizationRepository)

Example 2 with HttpStrategy

use of org.platformlayer.http.HttpStrategy in project platformlayer by platformlayer.

the class ConfigurationOptions method buildPlatformLayerClient.

private HttpPlatformLayerClient buildPlatformLayerClient(Properties properties, boolean debug) {
    HttpStrategy httpStrategy = new JreHttpStrategy();
    // HttpStrategy httpStrategy = new ApacheCommonsHttpStrategy();
    HttpPlatformLayerClient client = HttpPlatformLayerClient.buildUsingProperties(httpStrategy, properties);
    if (debug) {
        client.setDebug(System.err);
    } else {
        // We don't want debug messages to interfere with our output
        // TODO: Fix this so debug output doesn't interfere (stderr?)
        // TODO: Maybe output the debug info only in case of failure?
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        client.setDebug(new PrintStream(baos));
    }
    return client;
}
Also used : HttpPlatformLayerClient(org.platformlayer.HttpPlatformLayerClient) PrintStream(java.io.PrintStream) JreHttpStrategy(org.platformlayer.http.jre.JreHttpStrategy) HttpStrategy(org.platformlayer.http.HttpStrategy) JreHttpStrategy(org.platformlayer.http.jre.JreHttpStrategy) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 3 with HttpStrategy

use of org.platformlayer.http.HttpStrategy in project platformlayer by platformlayer.

the class PlatformLayerTestContext method buildPlatformLayerClient.

public PlatformLayerClient buildPlatformLayerClient() throws IOException, OpsException {
    PlatformLayerClient client;
    if (configFile == null) {
        throw new IllegalArgumentException("Config file is required");
    }
    InputStream is = null;
    try {
        if (!configFile.exists()) {
            throw new FileNotFoundException("Configuration file not found: " + configFile);
        }
        is = new FileInputStream(configFile);
        Properties properties = new Properties();
        try {
            properties.load(is);
        } catch (IOException e) {
            throw new IOException("Error reading configuration file", e);
        }
        HttpStrategy httpStrategy = new JreHttpStrategy();
        client = HttpPlatformLayerClient.buildUsingProperties(httpStrategy, properties);
    } finally {
        if (is != System.in) {
            IoUtils.safeClose(is);
        }
    }
    return client;
}
Also used : HttpPlatformLayerClient(org.platformlayer.HttpPlatformLayerClient) PlatformLayerClient(org.platformlayer.PlatformLayerClient) TypedPlatformLayerClient(org.platformlayer.TypedPlatformLayerClient) JreHttpStrategy(org.platformlayer.http.jre.JreHttpStrategy) HttpStrategy(org.platformlayer.http.HttpStrategy) JreHttpStrategy(org.platformlayer.http.jre.JreHttpStrategy) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Aggregations

HttpStrategy (org.platformlayer.http.HttpStrategy)3 HttpPlatformLayerClient (org.platformlayer.HttpPlatformLayerClient)2 PlatformLayerClient (org.platformlayer.PlatformLayerClient)2 JreHttpStrategy (org.platformlayer.http.jre.JreHttpStrategy)2 EncryptionStore (com.fathomdb.crypto.EncryptionStore)1 ResultSetMappersProvider (com.fathomdb.jpa.impl.ResultSetMappersProvider)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 PrintStream (java.io.PrintStream)1 URLClassLoader (java.net.URLClassLoader)1 Properties (java.util.Properties)1 ExecutorService (java.util.concurrent.ExecutorService)1 JAXBContext (javax.xml.bind.JAXBContext)1 TypedPlatformLayerClient (org.platformlayer.TypedPlatformLayerClient)1 PlatformLayerAuthenticationClientProvider (org.platformlayer.auth.client.PlatformLayerAuthenticationClientProvider)1 PlatformlayerAuthenticationService (org.platformlayer.auth.system.PlatformlayerAuthenticationService)1