private void readObject(ObjectInputStream ios) { this.theConfig = ConfigProviderResolver.instance().getConfig(); } }
SerializableConfig() { this.theConfig = ConfigProviderResolver.instance().getConfig(); }
private Object getConfigValue(CreationalContext<Object> context) { return getConfigValue((MpConfig) ConfigProviderResolver.instance().getConfig(), qualifier); }
@Override public void configure(MpServiceContext serviceContext) { MpConfig config = (MpConfig) ConfigProviderResolver.instance().getConfig(); MetricsSupport.create(config.helidonConfig()) .update(serviceContext.serverRoutingBuilder()); } }
/** * Load this builder from a configuration. * * @param config configuration to load from * @return updated builder instance */ public Builder config(Config config) { config.get("optional").asBoolean().ifPresent(this::optional); config.get("authenticate").asBoolean().ifPresent(this::authenticate); config.get("propagate").asBoolean().ifPresent(this::propagate); config.get("allow-impersonation").asBoolean().ifPresent(this::allowImpersonation); config.get("principal-type").asString().as(SubjectType::valueOf).ifPresent(this::subjectType); config.get("atn-token.handler").as(TokenHandler::create).ifPresent(this::atnTokenHandler); config.get("atn-token").ifExists(this::verifyKeys); config.get("atn-token.jwt-audience").asString().ifPresent(this::expectedAudience); config.get("atn-token.default-key-id").asString().ifPresent(this::defaultKeyId); config.get("atn-token.verify-key").asString().ifPresent(this::publicKeyPath); config.get("sign-token").ifExists(outbound -> outboundConfig(OutboundConfig.create(outbound))); config.get("sign-token").ifExists(this::outbound); org.eclipse.microprofile.config.Config mpConfig = ConfigProviderResolver.instance().getConfig(); mpConfig.getOptionalValue(CONFIG_PUBLIC_KEY, String.class).ifPresent(this::publicKey); mpConfig.getOptionalValue(CONFIG_PUBLIC_KEY_PATH, String.class).ifPresent(this::publicKeyPath); mpConfig.getOptionalValue(CONFIG_EXPECTED_ISSUER, String.class).ifPresent(this::expectedIssuer); return this; }
MicroprofileClientBuilder() { ClientBuilder availableBuilder = ClientBuilder.newBuilder(); if (availableBuilder instanceof ResteasyClientBuilder) { this.builderDelegate = (ResteasyClientBuilder) availableBuilder; this.configurationWrapper = new ConfigurationWrapper(this.builderDelegate.getConfiguration()); Config cfg = null; try { ConfigProviderResolver.instance(); cfg = ConfigProvider.getConfig(); } catch (IllegalStateException ise) { //ignore } this.config = cfg; } else { throw new IllegalStateException("Incompatible client builder found " + availableBuilder.getClass()); } }
private void readObject(ObjectInputStream ios) { this.theConfig = ConfigProviderResolver.instance().getConfig(); } }
SerializableConfig() { this.theConfig = ConfigProviderResolver.instance().getConfig(); }
public void shutdown(@Observes BeforeShutdown bsd) { ConfigProviderResolver.instance().releaseConfig(config); }
private Object getConfigValue(CreationalContext<Object> context) { return getConfigValue((MpConfig) ConfigProviderResolver.instance().getConfig(), qualifier); }
@Test public void testAutoDiscoveredConfigureSources() { Config config = ConfigProviderResolver.instance().getBuilder().addDefaultSources().addDiscoveredSources().build(); Assert.assertEquals(config.getValue("tck.config.test.customDbConfig.key1", String.class), "valueFromDb1"); } @Test
@Test(expectedExceptions = IllegalArgumentException.class) public void testAutoDiscoveredConverterNotAddedAutomatically() { Config config = ConfigProviderResolver.instance().getBuilder().addDefaultSources().addDiscoveredSources().build(); Pizza dVaule = config.getValue("tck.config.test.customDbConfig.key3", Pizza.class); Assert.fail("The auto discovered converter should not be added automatically."); } }
MicroprofileClientBuilder() { ClientBuilder availableBuilder = ClientBuilder.newBuilder(); if (availableBuilder instanceof ResteasyClientBuilder) { this.builderDelegate = (ResteasyClientBuilder) availableBuilder; this.configurationWrapper = new ConfigurationWrapper(this.builderDelegate.getConfiguration()); Config cfg = null; try { ConfigProviderResolver.instance(); cfg = ConfigProvider.getConfig(); } catch (IllegalStateException ise) { //ignore } this.config = cfg; } else { throw new IllegalStateException("Incompatible client builder found " + availableBuilder.getClass()); } }
@Test public void testDonaldConversionWithLambdaConverter() { Config newConfig = ConfigProviderResolver.instance().getBuilder().addDefaultSources() .withConverter(Donald.class, 100, (s) -> Donald.iLikeDonald(s)) .build(); Donald donald = newConfig.getValue("tck.config.test.javaconfig.converter.donaldname", Donald.class); Assert.assertNotNull(donald); Assert.assertEquals(donald.getName(), "Duck"); }
@Test public void testAutoDiscoveredConverterManuallyAdded() { Config config = ConfigProviderResolver.instance().getBuilder().addDefaultSources().addDiscoveredSources().addDiscoveredConverters().build(); Pizza dVaule = config.getValue("tck.config.test.customDbConfig.key3", Pizza.class); Assert.assertEquals(dVaule.getSize(), "big"); Assert.assertEquals(dVaule.getFlavor(), "cheese"); }
@Override public void undeploy(DeploymentUnit context) { Module module = context.getAttachment(Attachments.MODULE); try { ConfigProviderResolver.instance().releaseConfig(ConfigProvider.getConfig(module.getClassLoader())); } catch (IllegalStateException e) { // Do nothing } } }
@Override public void configure(MpServiceContext serviceContext) { MpConfig config = (MpConfig) ConfigProviderResolver.instance().getConfig(); MetricsSupport.create(config.helidonConfig()) .update(serviceContext.serverRoutingBuilder()); } }
@Test public void testDuckConversionWithMultipleConverters() { // defines 2 config with the converters defined in different orders. // Order must not matter, the UpperCaseDuckConverter must always be used as it has the highest priority Config config1 = ConfigProviderResolver.instance().getBuilder().addDefaultSources() .withConverters(new UpperCaseDuckConverter(), new DuckConverter()) .build(); Config config2 = ConfigProviderResolver.instance().getBuilder().addDefaultSources() .withConverters(new DuckConverter(), new UpperCaseDuckConverter()) .build(); Duck duck = config1.getValue("tck.config.test.javaconfig.converter.duckname", Duck.class); Assert.assertNotNull(duck); Assert.assertEquals(duck.getName(), "HANNELORE", "The converter with the highest priority (UpperCaseDuckConverter) must be used."); duck = config2.getValue("tck.config.test.javaconfig.converter.duckname", Duck.class); Assert.assertNotNull(duck); // the UpperCaseDuckConverter has highest priority Assert.assertEquals(duck.getName(), "HANNELORE", "The converter with the highest priority (UpperCaseDuckConverter) must be used."); }
@Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); Module module = deploymentUnit.getAttachment(Attachments.MODULE); SmallRyeConfigBuilder builder = new SmallRyeConfigBuilder(); builder.forClassLoader(module.getClassLoader()) .addDefaultSources() .addDiscoveredSources() .addDiscoveredConverters(); addConfigSourcesFromServices(builder, phaseContext.getServiceRegistry(), module.getClassLoader()); Config config = builder.build(); ConfigProviderResolver.instance().registerConfig(config, module.getClassLoader()); if (WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) { WeldPortableExtensions extensions = WeldPortableExtensions.getPortableExtensions(deploymentUnit); extensions.registerExtensionInstance(new ConfigExtension(), deploymentUnit); } }