@Produces @Singleton public CuratorFramework create(@ServiceName("ZOOKEEPER") String url, @New CuratorConfig config) throws IOException, InterruptedException { LOG.info("Connecting to ZooKeeper URL: {}", url); CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder() .connectString(url) .connectionTimeoutMs(config.getConnectionTimeOut()) .sessionTimeoutMs(config.getSessionTimeout()) .retryPolicy(new RetryNTimes(config.getRetryMax(), config.getRetryInterval())); if (!Strings.isNullOrBlank(config.getPassword())) { byte[] auth = (DEFAULT_AUTH_USER + ":" + PasswordEncoder.decode(config.getPassword())).getBytes(); builder = builder.authorization(DEFAULT_AUTH_SCHEME, auth); } CuratorFramework curatorFramework = builder.build(); curatorFramework.start(); return curatorFramework; }
@Produces @ApplicationScoped public static IStorage provideStorage(ManagerApiMicroServiceConfig config, @New JpaStorage jpaStorage, @New EsStorage esStorage, IPluginRegistry pluginRegistry) { IStorage storage; if ("jpa".equals(config.getStorageType())) { //$NON-NLS-1$ storage = initJpaStorage(config, jpaStorage); } else if ("es".equals(config.getStorageType())) { //$NON-NLS-1$ storage = initES(config, esStorage); } else { try { storage = createCustomComponent(IStorage.class, config.getStorageType(), config.getStorageProperties(), pluginRegistry); } catch (Throwable t) { throw new RuntimeException("Error or unknown storage type: " + config.getStorageType(), t); //$NON-NLS-1$ } } return storage; }
@Produces @ApplicationScoped public static IStorageQuery provideStorageQuery(ManagerApiMicroServiceConfig config, @New JpaStorage jpaStorage, @New EsStorage esStorage, IPluginRegistry pluginRegistry) { if ("jpa".equals(config.getStorageQueryType())) { //$NON-NLS-1$ return initJpaStorage(config, jpaStorage); } else if ("es".equals(config.getStorageQueryType())) { //$NON-NLS-1$ return initES(config, esStorage); } else { try { return createCustomComponent(IStorageQuery.class, config.getStorageQueryType(), config.getStorageQueryProperties(), pluginRegistry); } catch (Throwable t) { throw new RuntimeException("Error or unknown storage query type: " + config.getStorageType(), t); //$NON-NLS-1$ } } }
@Produces @ApplicationScoped public static IMetricsAccessor provideMetricsAccessor(ManagerApiMicroServiceConfig config, @New NoOpMetricsAccessor noopMetrics, @New ESMetricsAccessor esMetrics, IPluginRegistry pluginRegistry) { IMetricsAccessor metrics; if ("es".equals(config.getMetricsType())) { //$NON-NLS-1$ metrics = esMetrics; } else { try { metrics = createCustomComponent(IMetricsAccessor.class, config.getMetricsType(), config.getMetricsProperties(), pluginRegistry); } catch (Throwable t) { System.err.println("Unknown apiman metrics accessor type: " + config.getMetricsType()); //$NON-NLS-1$ metrics = noopMetrics; } } return metrics; }
@Produces @ApplicationScoped public static IApiKeyGenerator provideApiKeyGenerator(ManagerApiMicroServiceConfig config, IPluginRegistry pluginRegistry, @New UuidApiKeyGenerator uuidApiKeyGen) { IApiKeyGenerator apiKeyGenerator; String type = config.getApiKeyGeneratorType(); if ("uuid".equals(type)) { //$NON-NLS-1$ apiKeyGenerator = uuidApiKeyGen; } else { try { apiKeyGenerator = createCustomComponent(IApiKeyGenerator.class, type, config.getApiKeyGeneratorProperties(), pluginRegistry); } catch (Exception e) { System.err.println("Unknown apiman API key generator type: " + type); //$NON-NLS-1$ System.err.println("Automatically falling back to UUID style API Keys."); //$NON-NLS-1$ apiKeyGenerator = uuidApiKeyGen; } } return apiKeyGenerator; }
@Produces @ApplicationScoped public static IStorage provideStorage(WarApiManagerConfig config, @New JpaStorage jpaStorage, @New EsStorage esStorage, IPluginRegistry pluginRegistry) { IStorage storage; if ("jpa".equals(config.getStorageType())) { //$NON-NLS-1$ storage = initJpaStorage(config, jpaStorage); } else if ("es".equals(config.getStorageType())) { //$NON-NLS-1$ storage = initEsStorage(config, esStorage); } else { try { storage = createCustomComponent(IStorage.class, config.getStorageType(), config.getStorageProperties(), pluginRegistry); } catch (Throwable t) { throw new RuntimeException("Error or unknown storage type: " + config.getStorageType(), t); //$NON-NLS-1$ } } return storage; }
@Produces @ApplicationScoped public static IStorageQuery provideStorageQuery(WarApiManagerConfig config, @New JpaStorage jpaStorage, @New EsStorage esStorage, IStorage storage, IPluginRegistry pluginRegistry) { if ("jpa".equals(config.getStorageType())) { //$NON-NLS-1$ return initJpaStorage(config, jpaStorage); } else if ("es".equals(config.getStorageType())) { //$NON-NLS-1$ return initEsStorage(config, esStorage); } else if (storage != null && storage instanceof IStorageQuery) { return (IStorageQuery) storage; } else { try { return createCustomComponent(IStorageQuery.class, config.getStorageQueryType(), config.getStorageQueryProperties(), pluginRegistry); } catch (Throwable t) { throw new RuntimeException("Error or unknown storage query type: " + config.getStorageType(), t); //$NON-NLS-1$ } } }
@Produces @ApplicationScoped public static IMetricsAccessor provideMetricsAccessor(WarApiManagerConfig config, @New NoOpMetricsAccessor noopMetrics, @New ESMetricsAccessor esMetrics, IPluginRegistry pluginRegistry) { IMetricsAccessor metrics; if ("es".equals(config.getMetricsType())) { //$NON-NLS-1$ metrics = esMetrics; } else if (config.getMetricsType().equals(ESMetricsAccessor.class.getName())) { metrics = esMetrics; } else if ("noop".equals(config.getMetricsType())) { //$NON-NLS-1$ metrics = noopMetrics; } else if (config.getMetricsType().equals(NoOpMetricsAccessor.class.getName())) { metrics = noopMetrics; } else { try { metrics = createCustomComponent(IMetricsAccessor.class, config.getMetricsType(), config.getMetricsProperties(), pluginRegistry); } catch (Throwable t) { System.err.println("Unknown apiman metrics accessor type: " + config.getMetricsType()); //$NON-NLS-1$ metrics = noopMetrics; } } return metrics; }
@Produces @ApplicationScoped public static IApiKeyGenerator provideApiKeyGenerator(WarApiManagerConfig config, @New UuidApiKeyGenerator uuidApiKeyGen, IPluginRegistry pluginRegistry) { IApiKeyGenerator apiKeyGenerator; String type = config.getApiKeyGeneratorType(); if ("uuid".equals(type)) { //$NON-NLS-1$ apiKeyGenerator = uuidApiKeyGen; } else { try { apiKeyGenerator = createCustomComponent(IApiKeyGenerator.class, type, config.getApiKeyGeneratorProperties(), pluginRegistry); } catch (Exception e) { System.err.println("Unknown apiman API key generator type: " + type); //$NON-NLS-1$ System.err.println("Automatically falling back to UUID style API Keys."); //$NON-NLS-1$ apiKeyGenerator = uuidApiKeyGen; } } return apiKeyGenerator; }
@Produces @Dependent @DAO @SuppressWarnings("unchecked") public <T> IDAO<T> produceDaoWithIntegerId(@TransientReference InjectionPoint ip, @TransientReference BeanManager bm, @New @TransientReference IDAOFactory f) { return buildDaoWithOneGenericType(ip, bm, (IDAOFactory<T>) f); }
@Produces @Dependent @DAO @SuppressWarnings("unchecked") public <T> LDAO<T> produceDaoWithLongId(@TransientReference InjectionPoint ip, @TransientReference BeanManager bm, @New @TransientReference LDAOFactory f) { return buildDaoWithOneGenericType(ip, bm, (LDAOFactory<T>) f); }
@Produces @Dependent @Default @SuppressWarnings("unchecked") public <T> IDAO<T> produceUnqualifiedDaoWithIntegerId(@TransientReference InjectionPoint ip, @TransientReference BeanManager bm, @New @TransientReference IDAOFactory f) { return buildDaoWithOneGenericType(ip, bm, (IDAOFactory<T>) f); }
@Produces @Dependent @Default @SuppressWarnings("unchecked") public <T> LDAO<T> produceUnqualifiedDaoWithLongId(@TransientReference InjectionPoint ip, @TransientReference BeanManager bm, @New @TransientReference LDAOFactory f) { return buildDaoWithOneGenericType(ip, bm, (LDAOFactory<T>) f); }
@Produces @Dependent @DAO @SuppressWarnings("unchecked") public <T> DaoWithoutId<T> produceDaoWithoutId(@TransientReference InjectionPoint ip, @TransientReference BeanManager bm, @New @TransientReference DAOFactory f) { return buildDaoWithOneGenericType(ip, bm, (DAOFactory<T>) f); }
@Produces @Dependent @Default @SuppressWarnings("unchecked") public <T> DaoWithoutId<T> produceUnqualifiedDaoWithoutId(@TransientReference InjectionPoint ip, @TransientReference BeanManager bm, @New @TransientReference DAOFactory f) { return buildDaoWithOneGenericType(ip, bm, (DAOFactory<T>) f); }
private static ScopeCacheSupport scopeCacheSupport(Annotation[] annotations) { if (null != filter(annotations, RequestScoped.class) || null != filter(annotations, org.osgl.inject.annotation.RequestScoped.class)) { return RequestScope.INSTANCE; } else if (sessionScoped(annotations)) { return SessionScope.INSTANCE; } else if (null != filter(annotations, Dependent.class) || null != filter(annotations, New.class)) { return DependentScope.INSTANCE; } // Default to Request Scope return RequestScope.INSTANCE; }
@Produces @ServiceName("ZOOKEEPER") public String create(@New ZooKeeperServerConfig serverConfig) throws IOException, InterruptedException { String providedUrl = Systems.getEnvVarOrSystemProperty("ZOOKEEPER_URL", ""); if (Strings.isNullOrEmpty(providedUrl)) { ZooKeeperServerFactory factory = new ZooKeeperServerFactory(serverConfig); return factory.getZooKeeperUrl(); } else { return providedUrl; } }
@Produces @ApplicationScoped public static IDataEncrypter provideDataEncrypter(ManagerApiMicroServiceConfig config, IPluginRegistry pluginRegistry, @New DefaultDataEncrypter defaultEncrypter) { try { IDataEncrypter encrypter = createCustomComponent(IDataEncrypter.class, config.getDataEncrypterType(), config.getDataEncrypterProperties(), pluginRegistry, defaultEncrypter); CurrentDataEncrypter.instance = encrypter; return encrypter; } catch (Throwable t) { throw new RuntimeException("Error or unknown data encrypter type: " + config.getDataEncrypterType(), t); //$NON-NLS-1$ } }
@Produces @ApplicationScoped public static ISecurityContext provideSecurityContext(WarApiManagerConfig config, @New DefaultSecurityContext defaultSC, @New KeycloakSecurityContext keycloakSC) { if ("default".equals(config.getSecurityContextType())) { //$NON-NLS-1$ return defaultSC; } else if ("keycloak".equals(config.getSecurityContextType())) { //$NON-NLS-1$ return keycloakSC; } else { throw new RuntimeException("Unknown security context type: " + config.getSecurityContextType()); //$NON-NLS-1$ } }
@Produces @ApplicationScoped public static IDataEncrypter provideDataEncrypter(@New DefaultDataEncrypter defaultEncrypter, WarApiManagerConfig config, IPluginRegistry pluginRegistry) { try { IDataEncrypter encrypter = createCustomComponent(IDataEncrypter.class, config.getDataEncrypterType(), config.getDataEncrypterProperties(), pluginRegistry, defaultEncrypter); CurrentDataEncrypter.instance = encrypter; return encrypter; } catch (Throwable t) { throw new RuntimeException("Error or unknown data encrypter type: " + config.getDataEncrypterType(), t); //$NON-NLS-1$ } }
@Produces @ApplicationScoped public static IStorage provideStorage(@New JpaStorage jpaStorage, @New EsStorage esStorage) { TestType testType = ManagerTestUtils.getTestType(); if (testType == TestType.jpa) { return jpaStorage; } else if (testType == TestType.es) { esStorage.initialize(); return new TestEsStorageWrapper(ManagerApiTestServer.ES_CLIENT, esStorage); } else { throw new RuntimeException("Unexpected test type: " + testType); } }
@Produces @ApplicationScoped public static IStorageQuery provideStorageQuery(@New JpaStorage jpaStorage, @New EsStorage esStorage) { TestType testType = ManagerTestUtils.getTestType(); if (testType == TestType.jpa) { return jpaStorage; } else if (testType == TestType.es) { esStorage.initialize(); return new TestEsStorageQueryWrapper(ManagerApiTestServer.ES_CLIENT, esStorage); } else { throw new RuntimeException("Unexpected test type: " + testType); } }
@Produces @ApplicationScoped public static IMetricsAccessor provideMetricsAccessor(@New TestMetricsAccessor testMetrics, @New ESMetricsAccessor esMetrics) { boolean enableESMetrics = "true".equals(System.getProperty("apiman-test.es-metrics", "false")); if (enableESMetrics) { return esMetrics; } else { return testMetrics; } }
@Produces @Named("weldArtifactFactoryBatchlet") public WeldArtifactFactoryBatchlet produce(final @New WeldArtifactFactoryBatchlet that) { produced = true; return that; }
@Produces @ApplicationScoped public static ISecurityContext provideSecurityContext(@New DefaultSecurityContext defaultSC) { return defaultSC; }
@Produces @ApplicationScoped public static IApiKeyGenerator provideApiKeyGenerator(@New UuidApiKeyGenerator uuidApiKeyGen) { return uuidApiKeyGen; }
@Produces @ApplicationScoped public static IDataEncrypter provideDataEncrypter(@New DefaultDataEncrypter defaultEncrypter) { CurrentDataEncrypter.instance = defaultEncrypter; return defaultEncrypter; }
public NewLiteral() { this(New.class); }