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);
}
}
}