Package ratpack.launch

Examples of ratpack.launch.LaunchException


  private static Handler createHandler(LaunchConfig launchConfig, HandlerFactory handlerFactory) {
    try {
      return handlerFactory.create(launchConfig);
    } catch (Exception e) {
      Throwables.propagateIfInstanceOf(e, BaseDirRequiredException.class);
      throw new LaunchException("Could not create handler via handler factory: " + handlerFactory.getClass().getName(), e);
    }
  }
View Full Code Here


    Path baseDir = configPath.getParent();
    if (baseDir == null && configPath.getFileSystem().provider() instanceof ZipFileSystemProvider) {
      baseDir = Iterables.getFirst(configPath.getFileSystem().getRootDirectories(), null);
    }
    if (baseDir == null) {
      throw new LaunchException("Cannot determine base dir given config resource: " + configPath);
    }
    return baseDir;
  }
View Full Code Here

    Properties fileProperties = new Properties(defaultProperties);
    if (configFile != null && Files.exists(configFile)) {
      try (InputStream inputStream = Files.newInputStream(configFile)) {
        fileProperties.load(inputStream);
      } catch (Exception e) {
        throw new LaunchException("Could not read config file '" + configFile + "'", e);
      }
    }
    fileProperties.putAll(overrideProperties);
    return fileProperties;
  }
View Full Code Here

    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;
      try {
        handlerFactory = handlerFactoryClass.newInstance();
      } catch (Exception e) {
        throw new LaunchException("Could not instantiate handler factory: " + handlerFactoryClass.getName(), e);
      }

      LaunchConfigBuilder launchConfigBuilder = LaunchConfigBuilder.baseDir(data.getBaseDir())
        .port(port)
        .address(address)
        .publicAddress(publicAddress)
        .development(development)
        .threads(threads)
        .maxContentLength(maxContentLength)
        .timeResponses(timeResponses)
        .compressResponses(compressResponses)
        .compressionMinSize(compressionMinSize)
        .compressionWhiteListMimeTypes(compressionMimeTypeWhiteList)
        .compressionBlackListMimeTypes(compressionMimeTypeBlackList)
        .indexFiles(indexFiles)
        .defaultRegistry(data.getDefaultRegistry());

      if (sslKeystore != null) {
        try (InputStream stream = sslKeystore) {
          launchConfigBuilder.ssl(SSLContexts.sslContext(stream, sslKeystorePassword));
        }
      }

      return launchConfigBuilder
        .other(otherProperties)
        .build(handlerFactory);

    } catch (Exception e) {
      if (e instanceof LaunchException) {
        throw (LaunchException) e;
      } else {
        throw new LaunchException("Failed to create launch config with properties: " + properties.toString(), e);
      }
    }
  }
View Full Code Here

    if (scheme.equals("file")) {
      return Paths.get(uri);
    }

    if (!scheme.equals("jar")) {
      throw new LaunchException("Cannot deal with class path resource url: " + uri);
    }

    String s = uri.toString();
    int separator = s.indexOf("!/");
    String entryName = s.substring(separator + 2);
View Full Code Here

  private static URI toUri(URL url) {
    try {
      return url.toURI();
    } catch (URISyntaxException e) {
      throw new LaunchException("Could not convert URL '" + url + "' to URI", e);
    }
  }
View Full Code Here

      }
      running.set(true);
    } catch (Exception e) {
      Throwables.propagateIfInstanceOf(e, BaseDirRequiredException.class);
      Throwables.propagateIfInstanceOf(e, LaunchException.class);
      throw new LaunchException("Unable to launch due to exception", e);
    } finally {
      lifecycleLock.unlock();
    }
  }
View Full Code Here

    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());
      launchConfigFactory.setPort(port);
      launchConfigFactory.setAddress(address);
      launchConfigFactory.setDevelopment(development);
      launchConfigFactory.setThreads(threads);
      launchConfigFactory.setPublicAddress(publicAddress);
      launchConfigFactory.setIndexFiles(indexFiles);
      launchConfigFactory.setOther(otherProperties);
      if (!Strings.isNullOrEmpty(sslKeystore)) {
        launchConfigFactory.setSslKeystore(Paths.get(sslKeystore));
      }
      launchConfigFactory.setSslKeystorePassword(sslKeystorePassword);
      launchConfigFactory.setMaxContentLength(maxContentLength);
      launchConfigFactory.setTimeResponses(timeResponses);
      launchConfigFactory.setCompressResponses(compressResponses);
      launchConfigFactory.setCompressionMinSize(compressionMinSize);
      launchConfigFactory.setCompressionMimeTypeWhiteList(compressionMimeTypeWhiteList);
      launchConfigFactory.setCompressionMimeTypeBlackList(compressionMimeTypeBlackList);
      launchConfigFactory.setHandlerFactoryClass(handlerFactoryClass);
    } catch (Exception e) {
      if (e instanceof LaunchException) {
        throw (LaunchException) e;
      } else {
        throw new LaunchException("Failed to create launch config with properties: " + properties.toString(), e);
      }
    }
  }
View Full Code Here

   */
  public void start() throws Exception {
    try {
      RatpackServerBuilder.build(buildLaunchConfig()).start();
    } catch (ConfigurationException ex) {
      throw new LaunchException("Failed to launch application", ex);
    }
  }
View Full Code Here

TOP

Related Classes of ratpack.launch.LaunchException

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.