io.helidon.config.Config.asBoolean()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(14.0k)|赞(0)|评价(0)|浏览(150)

本文整理了Java中io.helidon.config.Config.asBoolean()方法的一些代码示例,展示了Config.asBoolean()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Config.asBoolean()方法的具体详情如下:
包路径:io.helidon.config.Config
类名称:Config
方法名:asBoolean

Config.asBoolean介绍

[英]Boolean typed value.
[中]布尔类型值。

代码示例

代码示例来源:origin: oracle/helidon

  1. @Override
  2. public void init(Config config) {
  3. root = config;
  4. /*
  5. * If failOnMissingReferenceSetting has not already been explicitly set
  6. * by the constructor, try to get the setting from the configuration. In
  7. * either case save the result in a simple boolean for efficiency in
  8. * #apply.
  9. */
  10. if (!failOnMissingReferenceSetting.isPresent()) {
  11. failOnMissingReferenceSetting = Optional.of(
  12. config
  13. .get(ConfigFilters.ValueResolvingBuilder.FAIL_ON_MISSING_REFERENCE_KEY_NAME)
  14. .asBoolean()
  15. .orElse(DEFAULT_FAIL_ON_MISSING_REFERENCE_BEHAVIOR));
  16. }
  17. failOnMissingReference = failOnMissingReferenceSetting.get();
  18. }

代码示例来源:origin: oracle/helidon

  1. /**
  2. * Update builder from configuration and set the config to {@link #configuration(io.helidon.config.Config)}.
  3. *
  4. * @param config configuration placed on the key of this provider
  5. * @return updated builder instance
  6. */
  7. public Builder config(Config config) {
  8. configuration(config);
  9. config.get("fail-on-unvalidated").asBoolean().ifPresent(this::failOnUnvalidated);
  10. config.get("fail-if-none-validated").asBoolean().ifPresent(this::failIfNoneValidated);
  11. return this;
  12. }
  13. }

代码示例来源:origin: oracle/helidon

  1. @Override
  2. protected MyConfigSourceBuilder2 init(Config metaConfig) {
  3. metaConfig.get("myProp3").asBoolean().ifPresent(this::myProp3);
  4. return super.init(metaConfig);
  5. }

代码示例来源:origin: oracle/helidon

  1. @Override
  2. protected MyConfigSourceBuilder1 init(Config metaConfig) {
  3. metaConfig.get("myProp3").asBoolean().ifPresent(this::myProp3);
  4. return super.init(metaConfig);
  5. }

代码示例来源:origin: oracle/helidon

  1. private static void register(BaseRegistry registry,
  2. Config config,
  3. Metadata meta,
  4. Metric metric) {
  5. if (registry.config.get(CONFIG_METRIC_ENABLED_BASE + meta.getName() + ".enabled").asBoolean().orElse(true)) {
  6. registry.register(meta, metric);
  7. }
  8. }

代码示例来源:origin: oracle/helidon

  1. /**
  2. * Update this builder from configuration.
  3. *
  4. * @param config config instance located on the key {@link PolicyValidator#configKey()}
  5. * @return updated builder instance
  6. */
  7. public Builder config(Config config) {
  8. config.get("inherit").asBoolean().ifPresent(this::inherit);
  9. config.get("statement").asString().ifPresent(this::statement);
  10. return this;
  11. }

代码示例来源:origin: oracle/helidon

  1. /**
  2. * Initializes config filter instance from configuration properties.
  3. * <p>
  4. * Optional {@code properties}:
  5. * <ul>
  6. * <li>{@code failOnMissingReference} - type {@link Boolean}, see {@link #failOnMissingReference}</li>
  7. * </ul>
  8. *
  9. * @param metaConfig meta-configuration used to initialize returned config filter instance from
  10. * @return new instance of config filter builder described by {@code metaConfig}
  11. * @throws MissingValueException in case the configuration tree does not contain all expected sub-nodes
  12. * required by the mapper implementation to provide instance of Java type.
  13. * @throws ConfigMappingException in case the mapper fails to map the (existing) configuration tree represented by the
  14. * supplied configuration node to an instance of a given Java type.
  15. * @see ConfigFilters#valueResolving()
  16. */
  17. public static ValueResolvingBuilder create(Config metaConfig) throws ConfigMappingException, MissingValueException {
  18. ValueResolvingBuilder builder = new ValueResolvingBuilder();
  19. builder.failOnMissingReference(metaConfig.get(FAIL_ON_MISSING_REFERENCE_KEY_NAME).asBoolean().orElse(false));
  20. return builder;
  21. }

代码示例来源:origin: oracle/helidon

  1. /**
  2. * Load configuration data from configuration.
  3. *
  4. * @param config configuration located the key of this attribute config
  5. * @return updated builder instance
  6. */
  7. public Builder config(Config config) {
  8. config.get("user").asList(String.class).ifPresent(this::addRoles);
  9. config.get("service").asList(String.class).ifPresent(this::addServiceRoles);
  10. config.get("permit-all").asBoolean().ifPresent(this::permitAll);
  11. config.get("deny-all").asBoolean().ifPresent(this::denyAll);
  12. return this;
  13. }
  14. }

代码示例来源:origin: oracle/helidon

  1. private EncryptionFilter(Builder builder, Config config) {
  2. if (builder.fromConfig) {
  3. this.requireEncryption = OptionalHelper.from(EncryptionUtil.getEnv(ConfigProperties.REQUIRE_ENCRYPTION_ENV_VARIABLE)
  4. .map(Boolean::parseBoolean))
  5. .or(() -> config.get(ConfigProperties.REQUIRE_ENCRYPTION_CONFIG_KEY).asBoolean().asOptional())
  6. .asOptional()
  7. .orElse(true);
  8. this.masterPassword = EncryptionUtil.resolveMasterPassword(requireEncryption, config).orElse(null);
  9. this.privateKey = EncryptionUtil.resolvePrivateKey(config.get("security.config.rsa"))
  10. .orElse(null);
  11. } else {
  12. this.requireEncryption = builder.requireEncryption;
  13. this.privateKey = builder.privateKeyConfig.privateKey()
  14. .orElseThrow(() -> new ConfigEncryptionException("Private key configuration is invalid"));
  15. this.masterPassword = builder.masterPassword;
  16. }
  17. if (null != privateKey && !(privateKey instanceof RSAPrivateKey)) {
  18. throw new ConfigEncryptionException("Private key must be an RSA private key, but is: "
  19. + privateKey.getClass().getName());
  20. }
  21. ConfigFilter noOp = (key, stringValue) -> stringValue;
  22. aesFilter = (null == masterPassword ? noOp : (key, stringValue) -> decryptAes(masterPassword, stringValue));
  23. rsaFilter = (null == privateKey ? noOp : (key, stringValue) -> decryptRsa(privateKey, stringValue));
  24. clearFilter = this::clearText;
  25. aliasFilter = (key, stringValue) -> aliased(stringValue, config);
  26. }

代码示例来源:origin: oracle/helidon

  1. static Optional<Resource> fromConfigUrl(Config config, String keyPrefix) {
  2. return config.get(keyPrefix + "-url")
  3. .as(URI.class)
  4. .map(uri -> config.get("proxy-host").asString()
  5. .map(proxyHost -> {
  6. if (config.get(keyPrefix + "-use-proxy").asBoolean().orElse(true)) {
  7. Proxy proxy = new Proxy(Proxy.Type.HTTP,
  8. new InetSocketAddress(proxyHost,
  9. config.get("proxy-port").asInt().orElse(
  10. DEFAULT_PROXY_PORT)));
  11. return Resource.create(uri, proxy);
  12. } else {
  13. return Resource.create(uri);
  14. }
  15. })
  16. .orElseGet(() -> Resource.create(uri)));
  17. }

代码示例来源:origin: oracle/helidon

  1. /**
  2. * Load all properties for this thread pool executor from configuration.
  3. * Expected keys:
  4. * <ul>
  5. * <li>core-pool-size</li>
  6. * <li>is-daemon</li>
  7. * <li>thread-name-prefix</li>
  8. * <li>should-prestart</li>
  9. * </ul>
  10. *
  11. * @param config config located on the key of executor-service
  12. * @return updated builder instance
  13. */
  14. public Builder config(Config config) {
  15. config.get("core-pool-size").asInt().ifPresent(this::corePoolSize);
  16. config.get("is-daemon").asBoolean().ifPresent(this::daemon);
  17. config.get("thread-name-prefix").asString().ifPresent(this::threadNamePrefix);
  18. config.get("should-prestart").asBoolean().ifPresent(this::prestart);
  19. return this;
  20. }
  21. }

代码示例来源:origin: oracle/helidon

  1. @Override
  2. public void filter(ContainerRequestContext requestContext) {
  3. ServerRequest serverRequest = this.request.get();
  4. Tracer tracer = serverRequest.webServer().configuration().tracer();
  5. SpanContext parentSpan = serverRequest.spanContext();
  6. boolean clientEnabled = config.get("tracing.client.enabled").asBoolean().orElse(true);
  7. TracingContext tracingContext = TracingContext.create(tracer, serverRequest.headers().toMap(), clientEnabled);
  8. tracingContext.parentSpan(parentSpan);
  9. TracingContext.set(tracingContext);
  10. }

代码示例来源:origin: oracle/helidon

  1. /**
  2. * Create a builder from configuration.
  3. *
  4. * @param config Config located at http-signatures key
  5. * @return builder instance configured from config
  6. */
  7. public Builder config(Config config) {
  8. config.get("headers").asList(HttpSignHeader.class).ifPresent(list -> list.forEach(this::addAcceptHeader));
  9. config.get("optional").asBoolean().ifPresent(this::optional);
  10. config.get("realm").asString().ifPresent(this::realm);
  11. config.get("sign-headers").as(SignedHeadersConfig::create).ifPresent(this::inboundRequiredHeaders);
  12. outboundConfig = OutboundConfig.create(config);
  13. config.get("inbound.keys")
  14. .asList(InboundClientDefinition::create)
  15. .ifPresent(list -> list.forEach(inbound -> inboundKeys.put(inbound.keyId(), inbound)));
  16. return this;
  17. }

代码示例来源:origin: oracle/helidon

  1. /**
  2. * Load this builder from a configuration.
  3. *
  4. * @param config configuration to load from
  5. * @return updated builder instance
  6. */
  7. public Builder config(Config config) {
  8. config.get("optional").asBoolean().ifPresent(this::optional);
  9. config.get("authenticate").asBoolean().ifPresent(this::authenticate);
  10. config.get("propagate").asBoolean().ifPresent(this::propagate);
  11. config.get("allow-impersonation").asBoolean().ifPresent(this::allowImpersonation);
  12. config.get("principal-type").asString().as(SubjectType::valueOf).ifPresent(this::subjectType);
  13. config.get("atn-token.handler").as(TokenHandler::create).ifPresent(this::atnTokenHandler);
  14. config.get("atn-token").ifExists(this::verifyKeys);
  15. config.get("atn-token.jwt-audience").asString().ifPresent(this::expectedAudience);
  16. config.get("atn-token.default-key-id").asString().ifPresent(this::defaultKeyId);
  17. config.get("atn-token.verify-key").asString().ifPresent(this::publicKeyPath);
  18. config.get("sign-token").ifExists(outbound -> outboundConfig(OutboundConfig.create(outbound)));
  19. config.get("sign-token").ifExists(this::outbound);
  20. org.eclipse.microprofile.config.Config mpConfig = ConfigProviderResolver.instance().getConfig();
  21. mpConfig.getOptionalValue(CONFIG_PUBLIC_KEY, String.class).ifPresent(this::publicKey);
  22. mpConfig.getOptionalValue(CONFIG_PUBLIC_KEY_PATH, String.class).ifPresent(this::publicKeyPath);
  23. mpConfig.getOptionalValue(CONFIG_EXPECTED_ISSUER, String.class).ifPresent(this::expectedIssuer);
  24. return this;
  25. }

代码示例来源:origin: oracle/helidon

  1. /**
  2. * Initialize builder from specified configuration properties.
  3. * <p>
  4. * Supported configuration {@code properties}:
  5. * <ul>
  6. * <li>{@code optional} - type {@code boolean}, see {@link #optional()}</li>
  7. * <li>{@code polling-strategy} - see {@link PollingStrategy} for details about configuration format,
  8. * see {@link #pollingStrategy(Supplier)} or {@link #pollingStrategy(Function)}</li>
  9. * </ul>
  10. *
  11. * @param metaConfig configuration properties used to initialize a builder instance.
  12. * @return modified builder instance
  13. */
  14. protected B init(Config metaConfig) {
  15. //optional / mandatory
  16. metaConfig.get(OPTIONAL_KEY)
  17. .asBoolean()
  18. .filter(value -> value) //filter `true` only
  19. .ifPresent(value -> optional());
  20. //polling-strategy
  21. metaConfig.get(POLLING_STRATEGY_KEY)
  22. .ifExists(cfg -> pollingStrategy(PollingStrategyConfigMapper.instance().apply(cfg, targetType)));
  23. //retry-policy
  24. metaConfig.get(RETRY_POLICY_KEY)
  25. .as(RetryPolicy::create)
  26. .ifPresent(this::retryPolicy);
  27. return thisBuilder;
  28. }

代码示例来源:origin: oracle/helidon

  1. config.get("cert-alias").asString().ifPresent(this::certAlias);
  2. config.get("cert-chain").asString().ifPresent(this::certChainAlias);
  3. config.get("trust-store").asBoolean().ifPresent(this::trustStore);

代码示例来源:origin: oracle/helidon

  1. /**
  2. * Load all properties for this thread pool executor from configuration.
  3. * Expected keys:
  4. * <ul>
  5. * <li>core-pool-size</li>
  6. * <li>max-pool-size</li>
  7. * <li>keep-alive-minutes</li>
  8. * <li>queue-capacity</li>
  9. * <li>is-daemon</li>
  10. * <li>thread-name-prefix</li>
  11. * <li>should-prestart</li>
  12. * </ul>
  13. *
  14. * @param config config located on the key of executor-service
  15. * @return updated builder instance
  16. */
  17. public Builder config(Config config) {
  18. config.get("core-pool-size").asInt().ifPresent(this::corePoolSize);
  19. config.get("max-pool-size").asInt().ifPresent(this::maxPoolSize);
  20. config.get("keep-alive-minutes").asInt().ifPresent(this::keepAliveMinutes);
  21. config.get("queue-capacity").asInt().ifPresent(this::queueCapacity);
  22. config.get("is-daemon").asBoolean().ifPresent(this::daemon);
  23. config.get("thread-name-prefix").asString().ifPresent(this::threadNamePrefix);
  24. config.get("should-prestart").asBoolean().ifPresent(this::prestart);
  25. return this;
  26. }
  27. }

代码示例来源:origin: oracle/helidon

  1. /**
  2. * Update fields from configuration.
  3. *
  4. * @param config Configuration
  5. * @return updated builder instance
  6. */
  7. public Builder config(Config config) {
  8. config.get("name").asString().ifPresent(this::name);
  9. config.get("default").asBoolean().ifPresent(this::isDefault);
  10. config.get("authentication").asList(FlaggedProvider::create)
  11. .ifPresent(this.authenticators::addAll);
  12. config.get("authorization").asList(FlaggedProvider::create)
  13. .ifPresent(this.authorizers::addAll);
  14. config.get("outbound").asNodeList()
  15. .ifPresent(configs -> configs.forEach(outConfig -> addOutboundProvider(outConfig.get("name")
  16. .asString()
  17. .get())));
  18. return this;
  19. }

代码示例来源:origin: oracle/helidon

  1. /**
  2. * Update this builder from configuration.
  3. *
  4. * @param config Configuration at provider (security.provider.x) key
  5. * @return updated builder instance
  6. */
  7. public Builder config(Config config) {
  8. config.get("optional").asBoolean().ifPresent(this::optional);
  9. config.get("client-id").asString().ifPresent(this::clientId);
  10. config.get("proxy-host").asString().ifPresent(this::proxyHost);
  11. config.get("proxy-port").asInt().ifPresent(this::proxyPort);
  12. config.get("realm").asString().ifPresent(this::realm);
  13. config.get("token").as(TokenHandler::create).ifPresent(this::tokenProvider);
  14. return this;
  15. }
  16. }

代码示例来源:origin: oracle/helidon

  1. /**
  2. * Load this builder from a configuration.
  3. *
  4. * @param config configuration to load from
  5. * @return updated builder instance
  6. */
  7. public Builder config(Config config) {
  8. config.get("optional").as(Boolean.class).ifPresent(this::optional);
  9. config.get("authenticate").as(Boolean.class).ifPresent(this::authenticate);
  10. config.get("propagate").as(Boolean.class).ifPresent(this::propagate);
  11. config.get("allow-impersonation").asBoolean().ifPresent(this::allowImpersonation);
  12. config.get("principal-type").as(SubjectType.class).ifPresent(this::subjectType);
  13. config.get("atn-token.handler").as(TokenHandler.class).ifPresent(this::atnTokenHandler);
  14. config.get("atn-token").ifExists(this::verifyKeys);
  15. config.get("atn-token.jwt-audience").asString().ifPresent(this::expectedAudience);
  16. config.get("sign-token").ifExists(outbound -> outboundConfig(OutboundConfig.create(outbound)));
  17. config.get("sign-token").ifExists(this::outbound);
  18. return this;
  19. }

相关文章