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

x33g5p2x  于2022-01-18 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(119)

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

Config.asNode介绍

[英]Returns existing current config node as a Optional instance or Optional#empty() in case of Type#MISSING node.
[中]将现有的当前配置节点作为可选实例返回,如果类型#缺少节点,则返回可选的#empty()。

代码示例

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

  1. /**
  2. * Performs the given action with the config node if node
  3. * {@link #exists() exists}, otherwise does nothing.
  4. *
  5. * @param action the action to be performed if the node exists
  6. * @see #exists()
  7. * @see #type()
  8. */
  9. default void ifExists(Consumer<Config> action) {
  10. asNode().ifPresent(action);
  11. }

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

  1. public <T> Function<T, Supplier<PollingStrategy>> apply(Config config, Class<T> targetType)
  2. throws ConfigMappingException, MissingValueException {
  3. Config properties = config.get(PROPERTIES_KEY) // use properties config node
  4. .asNode()
  5. .orElse(Config.empty(config)); // or empty config node
  6. return OptionalHelper.from(config.get(TYPE_KEY).asString() // `type` is specified
  7. .flatMap(type -> this
  8. .builtin(type, properties, targetType))) // return built-in polling strategy
  9. .or(() -> config.get(CLASS_KEY)
  10. .as(Class.class) // `class` is specified
  11. .flatMap(clazz -> custom(clazz, properties, targetType))) // return custom polling strategy
  12. .asOptional()
  13. .orElseThrow(() -> new ConfigMappingException(config.key(), "Uncompleted polling-strategy configuration."));
  14. }

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

  1. @Override
  2. public RetryPolicy apply(Config config) throws ConfigMappingException, MissingValueException {
  3. Config properties = config.get(PROPERTIES_KEY) // use properties config node
  4. .asNode()
  5. .orElse(Config.empty(config)); // or empty config node
  6. return OptionalHelper.from(config.get(TYPE_KEY).asString() // `type` is specified
  7. .flatMap(type -> this.builtin(type, properties))) // return built-in retry policy
  8. .or(() -> config.get(CLASS_KEY)
  9. .as(Class.class) // `class` is specified
  10. .flatMap(clazz -> custom(clazz, properties))) // return custom retry policy
  11. .asOptional()
  12. .orElseThrow(() -> new ConfigMappingException(config.key(), "Uncompleted retry-policy configuration."));
  13. }

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

  1. /**
  2. * Update builder from configuration. See
  3. * {@link JwtProvider.JwtOutboundTarget#create(Config, TokenHandler)}
  4. * for configuration options description.
  5. *
  6. * @param config to update builder from
  7. * @return updated builder instance
  8. */
  9. public Builder config(Config config) {
  10. config.get("outbound-token")
  11. .asNode()
  12. .map(TokenHandler::create)
  13. .ifPresent(this::tokenHandler);
  14. config.get("jwt-kid").asString().ifPresent(this::jwtKid);
  15. config.get("jwk-kid").asString().ifPresent(this::jwkKid);
  16. config.get("jwt-audience").asString().ifPresent(this::jwtAudience);
  17. config.get("jwt-not-before-seconds").asInt().ifPresent(this::notBeforeSeconds);
  18. config.get("jwt-validity-seconds").asLong().ifPresent(this::validitySeconds);
  19. return this;
  20. }

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

  1. @Override
  2. public ConfigSource apply(Config config) throws ConfigMappingException, MissingValueException {
  3. Config properties = config.get(PROPERTIES_KEY) // use properties config node
  4. .asNode()
  5. .orElse(Config.empty(config)); // or empty config node
  6. return OptionalHelper.from(config.get(TYPE_KEY)
  7. .asString() // `type` is specified
  8. .flatMap(type -> OptionalHelper
  9. .from(builtin(type, properties)) // return built-in source
  10. .or(() -> providers(type, properties))
  11. .asOptional())) // or use sources - custom type to class mapping
  12. .or(() -> config.get(CLASS_KEY)
  13. .as(Class.class) // `class` is specified
  14. .flatMap(clazz -> custom(clazz, properties))) // return custom source
  15. .asOptional()
  16. .orElseThrow(() -> new ConfigMappingException(config.key(), "Uncompleted source configuration."));
  17. }

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

  1. /**
  2. * Load an instance from configuration.
  3. * Expected keys:
  4. * <ul>
  5. * <li>jwt-kid - the key id to put into JWT</li>
  6. * <li>jwk-kid - the key id to look for when signing the JWT</li>
  7. * <li>jwt-audience - the audience of this JWT</li>
  8. * <li>jwt-not-before-seconds - not before seconds</li>
  9. * <li>jwt-validity-seconds - validity of JWT</li>
  10. * </ul>
  11. *
  12. * @param config configuration to load data from
  13. * @param defaultHandler default outbound token handler
  14. * @return a new instance configured from config
  15. * @see #JwtOutboundTarget(TokenHandler, String, String, String, int, long)
  16. */
  17. public static JwtOutboundTarget fromConfig(Config config, TokenHandler defaultHandler) {
  18. TokenHandler tokenHandler = config.get("outbound-token")
  19. .asNode()
  20. .map(TokenHandler::create)
  21. .orElse(defaultHandler);
  22. return new JwtOutboundTarget(
  23. tokenHandler,
  24. config.get("jwt-kid").asString().orElse(null),
  25. config.get("jwk-kid").asString().orElse(null),
  26. config.get("jwt-audience").asString().orElse(null),
  27. config.get("jwt-not-before-seconds").asInt().orElse(5),
  28. config.get("jwt-validity-seconds").asLong().orElse(60L * 60 * 24));
  29. }

代码示例来源:origin: io.helidon.config/helidon-config

  1. /**
  2. * Performs the given action with the config node if node
  3. * {@link #exists() exists}, otherwise does nothing.
  4. *
  5. * @param action the action to be performed if the node exists
  6. * @see #exists()
  7. * @see #type()
  8. */
  9. default void ifExists(Consumer<Config> action) {
  10. asNode().ifPresent(action);
  11. }

代码示例来源:origin: io.helidon.config/helidon-config

  1. @Override
  2. public RetryPolicy apply(Config config) throws ConfigMappingException, MissingValueException {
  3. Config properties = config.get(PROPERTIES_KEY) // use properties config node
  4. .asNode()
  5. .orElse(Config.empty(config)); // or empty config node
  6. return OptionalHelper.from(config.get(TYPE_KEY).asString() // `type` is specified
  7. .flatMap(type -> this.builtin(type, properties))) // return built-in retry policy
  8. .or(() -> config.get(CLASS_KEY)
  9. .as(Class.class) // `class` is specified
  10. .flatMap(clazz -> custom(clazz, properties))) // return custom retry policy
  11. .asOptional()
  12. .orElseThrow(() -> new ConfigMappingException(config.key(), "Uncompleted retry-policy configuration."));
  13. }

代码示例来源:origin: io.helidon.config/helidon-config

  1. public <T> Function<T, Supplier<PollingStrategy>> apply(Config config, Class<T> targetType)
  2. throws ConfigMappingException, MissingValueException {
  3. Config properties = config.get(PROPERTIES_KEY) // use properties config node
  4. .asNode()
  5. .orElse(Config.empty(config)); // or empty config node
  6. return OptionalHelper.from(config.get(TYPE_KEY).asString() // `type` is specified
  7. .flatMap(type -> this
  8. .builtin(type, properties, targetType))) // return built-in polling strategy
  9. .or(() -> config.get(CLASS_KEY)
  10. .as(Class.class) // `class` is specified
  11. .flatMap(clazz -> custom(clazz, properties, targetType))) // return custom polling strategy
  12. .asOptional()
  13. .orElseThrow(() -> new ConfigMappingException(config.key(), "Uncompleted polling-strategy configuration."));
  14. }

代码示例来源:origin: io.helidon.security.providers/helidon-security-providers-jwt

  1. /**
  2. * Update builder from configuration. See
  3. * {@link JwtProvider.JwtOutboundTarget#create(Config, TokenHandler)}
  4. * for configuration options description.
  5. *
  6. * @param config to update builder from
  7. * @return updated builder instance
  8. */
  9. public Builder config(Config config) {
  10. config.get("outbound-token")
  11. .asNode()
  12. .map(TokenHandler::create)
  13. .ifPresent(this::tokenHandler);
  14. config.get("jwt-kid").asString().ifPresent(this::jwtKid);
  15. config.get("jwk-kid").asString().ifPresent(this::jwkKid);
  16. config.get("jwt-audience").asString().ifPresent(this::jwtAudience);
  17. config.get("jwt-not-before-seconds").asInt().ifPresent(this::notBeforeSeconds);
  18. config.get("jwt-validity-seconds").asLong().ifPresent(this::validitySeconds);
  19. return this;
  20. }

代码示例来源:origin: io.helidon.config/helidon-config

  1. @Override
  2. public ConfigSource apply(Config config) throws ConfigMappingException, MissingValueException {
  3. Config properties = config.get(PROPERTIES_KEY) // use properties config node
  4. .asNode()
  5. .orElse(Config.empty(config)); // or empty config node
  6. return OptionalHelper.from(config.get(TYPE_KEY)
  7. .asString() // `type` is specified
  8. .flatMap(type -> OptionalHelper
  9. .from(builtin(type, properties)) // return built-in source
  10. .or(() -> providers(type, properties))
  11. .asOptional())) // or use sources - custom type to class mapping
  12. .or(() -> config.get(CLASS_KEY)
  13. .as(Class.class) // `class` is specified
  14. .flatMap(clazz -> custom(clazz, properties))) // return custom source
  15. .asOptional()
  16. .orElseThrow(() -> new ConfigMappingException(config.key(), "Uncompleted source configuration."));
  17. }

代码示例来源:origin: io.helidon.microprofile.jwt/helidon-microprofile-jwt-auth

  1. /**
  2. * Load an instance from configuration.
  3. * Expected keys:
  4. * <ul>
  5. * <li>jwt-kid - the key id to put into JWT</li>
  6. * <li>jwk-kid - the key id to look for when signing the JWT</li>
  7. * <li>jwt-audience - the audience of this JWT</li>
  8. * <li>jwt-not-before-seconds - not before seconds</li>
  9. * <li>jwt-validity-seconds - validity of JWT</li>
  10. * </ul>
  11. *
  12. * @param config configuration to load data from
  13. * @param defaultHandler default outbound token handler
  14. * @return a new instance configured from config
  15. * @see #JwtOutboundTarget(TokenHandler, String, String, String, int, long)
  16. */
  17. public static JwtOutboundTarget fromConfig(Config config, TokenHandler defaultHandler) {
  18. TokenHandler tokenHandler = config.get("outbound-token")
  19. .asNode()
  20. .map(TokenHandler::create)
  21. .orElse(defaultHandler);
  22. return new JwtOutboundTarget(
  23. tokenHandler,
  24. config.get("jwt-kid").asString().orElse(null),
  25. config.get("jwk-kid").asString().orElse(null),
  26. config.get("jwt-audience").asString().orElse(null),
  27. config.get("jwt-not-before-seconds").asInt().orElse(5),
  28. config.get("jwt-validity-seconds").asLong().orElse(60L * 60 * 24));
  29. }

相关文章