Package ratpack.util.internal

Examples of ratpack.util.internal.TypeCoercingProperties


    Properties overrideProperties = deprefixGlobalProperties(globalProperties);
    String configResourceValue = overrideProperties.getProperty(CONFIG_RESOURCE_PROPERTY, CONFIG_RESOURCE_DEFAULT);
    URL configResourceUrl = classLoader.getResource(configResourceValue);
    Path configPath = determineConfigPath(workingDir, configResourceValue, configResourceUrl);
    Properties fileProperties = consolidateProperties(configPath, overrideProperties, defaultProperties);
    return new TypeCoercingProperties(fileProperties, classLoader);
  }
View Full Code Here


  }

  public static LaunchConfig createLaunchConfig(LaunchConfigData data) {
    Properties properties = data.getProperties();
    Map<String, String> envVars = data.getEnvVars();
    TypeCoercingProperties props = new TypeCoercingProperties(properties, data.getClassLoader());
    try {
      Class<HandlerFactory> handlerFactoryClass;
      handlerFactoryClass = props.asClass(HANDLER_FACTORY, HandlerFactory.class);
      if (handlerFactoryClass == null) {
        throw new LaunchException("No handler factory class specified (config property: " + HANDLER_FACTORY + ")");
      }

      int defaultPort = DEFAULT_PORT;
      if (envVars.containsKey(Environment.PORT)) {
        try {
          String stringValue = envVars.get(Environment.PORT);
          defaultPort = Integer.valueOf(stringValue);
        } catch (NumberFormatException e) {
          throw new LaunchException("Environment var '" + Environment.PORT + "' is not an integer", e);
        }
      }

      int port = props.asInt(PORT, defaultPort);
      InetAddress address = props.asInetAddress(ADDRESS);
      URI publicAddress = props.asURI(PUBLIC_ADDRESS);
      boolean development = props.asBoolean(DEVELOPMENT, false);
      int threads = props.asInt(THREADS, DEFAULT_THREADS);
      List<String> indexFiles = props.asList(INDEX_FILES);
      InputStream sslKeystore = props.asStream(SSL_KEYSTORE_FILE);
      String sslKeystorePassword = props.asString(SSL_KEYSTORE_PASSWORD, "");
      int maxContentLength = props.asInt(MAX_CONTENT_LENGTH, DEFAULT_MAX_CONTENT_LENGTH);
      boolean timeResponses = props.asBoolean(TIME_RESPONSES, false);
      boolean compressResponses = props.asBoolean(COMPRESS_RESPONSES, false);
      long compressionMinSize = props.asLong(COMPRESSION_MIN_SIZE, DEFAULT_COMPRESSION_MIN_SIZE);
      List<String> compressionMimeTypeWhiteList = props.asList(COMPRESSION_MIME_TYPE_WHITE_LIST);
      List<String> compressionMimeTypeBlackList = props.asList(COMPRESSION_MIME_TYPE_BLACK_LIST);

      Map<String, String> otherProperties = Maps.newHashMap();
      PropertiesUtil.extractProperties("other.", properties, otherProperties);

      HandlerFactory handlerFactory;
View Full Code Here

  public Map<String, String> getEnvVars() {
    return envVars;
  }

  public TypeCoercingProperties getTypeCoercingProperties() {
    return new TypeCoercingProperties(properties, classLoader);
  }
View Full Code Here

   *
   * @return the launch config
   * @throws ConfigurationException if there's an error building the launch config
   */
  public LaunchConfig build() throws ConfigurationException {
    TypeCoercingProperties props = LaunchConfigsInternal.consolidatePropertiesFromGlobalProperties(workingDir, classLoader, overrideProperties, defaultProperties);
    if (configurationSource == null) {
      if (byteSource == null) {
        byteSource = props.asByteSource(LaunchConfigs.Property.CONFIGURATION_FILE);
      }
      configurationSource = new DefaultConfigurationSource(classLoader, byteSource, overrideProperties, defaultProperties);
    }
    ConfigurationFactoryFactory configurationFactoryFactory = new DefaultConfigurationFactoryFactory(classLoader);
    ConfigurationFactory configurationFactory = configurationFactoryFactory.build(configurationSource);
    if (configurationClass == null) {
      try {
        configurationClass = props.asClass(LaunchConfigs.Property.CONFIGURATION_CLASS, Configuration.class);
      } catch (ClassNotFoundException ex) {
        throw new ConfigurationException("Could not load specified configuration class", ex);
      }
    }
    Configuration configuration = configurationFactory.build(configurationClass, configurationSource);
View Full Code Here

    this.classLoader = classLoader;
  }

  @Override
  public ConfigurationFactory build(ConfigurationSource configurationSource) throws ConfigurationException {
    TypeCoercingProperties props = LaunchConfigsInternal.consolidatePropertiesFromGlobalProperties(
      StandardSystemProperty.USER_DIR.value(), classLoader, configurationSource.getOverrideProperties(), configurationSource.getDefaultProperties());
    try {
      Class<ConfigurationFactory> configurationFactoryClass = props.asClass(CONFIGURATION_FACTORY, ConfigurationFactory.class);
      if (configurationFactoryClass != null) {
        return configurationFactoryClass.newInstance();
      }
    } catch (ReflectiveOperationException ex) {
      throw new ConfigurationException("Could not instantiate specified configuration factory class " + props.asString(CONFIGURATION_FACTORY, null), ex);
    }
    ServiceLoader<ConfigurationFactory> serviceLoader = ServiceLoader.load(ConfigurationFactory.class, classLoader);
    try {
      return Iterables.getOnlyElement(serviceLoader, new DefaultConfigurationFactory());
    } catch (IllegalArgumentException ex) {
View Full Code Here

  }

  private void populateLaunchConfigFactory(LaunchConfigData data, DefaultLaunchConfigFactory launchConfigFactory) {
    Properties properties = data.getProperties();
    Map<String, String> envVars = data.getEnvVars();
    TypeCoercingProperties props = data.getTypeCoercingProperties();
    Class<HandlerFactory> handlerFactoryClass;
    try {
      handlerFactoryClass = props.asClass(HANDLER_FACTORY, HandlerFactory.class);
      if (handlerFactoryClass == null) {
        throw new LaunchException("No handler factory class specified (config property: " + HANDLER_FACTORY + ")");
      }

      int defaultPort = LaunchConfig.DEFAULT_PORT;
      if (envVars.containsKey(LaunchConfigs.Environment.PORT)) {
        try {
          String stringValue = envVars.get(LaunchConfigs.Environment.PORT);
          defaultPort = Integer.valueOf(stringValue);
        } catch (NumberFormatException e) {
          throw new LaunchException("Environment var '" + LaunchConfigs.Environment.PORT + "' is not an integer", e);
        }
      }

      int port = props.asInt(PORT, defaultPort);
      InetAddress address = props.asInetAddress(ADDRESS);
      URI publicAddress = props.asURI(PUBLIC_ADDRESS);
      boolean development = props.asBoolean(DEVELOPMENT, false);
      int threads = props.asInt(THREADS, DEFAULT_THREADS);
      List<String> indexFiles = props.asList(INDEX_FILES);
      String sslKeystore = props.asString(SSL_KEYSTORE_FILE, null);
      String sslKeystorePassword = props.asString(SSL_KEYSTORE_PASSWORD, "");
      int maxContentLength = props.asInt(MAX_CONTENT_LENGTH, DEFAULT_MAX_CONTENT_LENGTH);
      boolean timeResponses = props.asBoolean(TIME_RESPONSES, false);
      boolean compressResponses = props.asBoolean(COMPRESS_RESPONSES, false);
      long compressionMinSize = props.asLong(COMPRESSION_MIN_SIZE, DEFAULT_COMPRESSION_MIN_SIZE);
      List<String> compressionMimeTypeWhiteList = props.asList(COMPRESSION_MIME_TYPE_WHITE_LIST);
      List<String> compressionMimeTypeBlackList = props.asList(COMPRESSION_MIME_TYPE_BLACK_LIST);

      Map<String, String> otherProperties = Maps.newHashMap();
      PropertiesUtil.extractProperties("other.", properties, otherProperties);

      launchConfigFactory.setBaseDir(data.getBaseDir());
View Full Code Here

TOP

Related Classes of ratpack.util.internal.TypeCoercingProperties

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.