isSsl = true;
} else if (!url.getProtocol().equals("http")) {
throw new UnsupportedOperationException("Protocol " + url.getProtocol() + " is not supported");
}
// Create a new server
Connector connector;
if (isSsl && ssl.isManaged()) {
String keyStore = ssl.getKeyStore();
if (keyStore == null) {
throw new IllegalArgumentException("keyStore must be set");
}
ServiceMixSslSocketConnector sslConnector = new ServiceMixSslSocketConnector();
sslConnector.setSslKeyManagerFactoryAlgorithm(ssl.getKeyManagerFactoryAlgorithm());
sslConnector.setSslTrustManagerFactoryAlgorithm(ssl.getTrustManagerFactoryAlgorithm());
sslConnector.setProtocol(ssl.getProtocol());
sslConnector.setConfidentialPort(url.getPort());
sslConnector.setKeystore(keyStore);
sslConnector.setKeyAlias(ssl.getKeyAlias());
sslConnector.setTrustStore(ssl.getTrustStore());
sslConnector.setNeedClientAuth(ssl.isNeedClientAuth());
sslConnector.setWantClientAuth(ssl.isWantClientAuth());
sslConnector.setKeystoreManager(getConfiguration().getKeystoreManager());
connector = sslConnector;
} else if (isSsl) {
String keyStore = ssl.getKeyStore();
if (keyStore == null) {
keyStore = System.getProperty("javax.net.ssl.keyStore", "");
if (keyStore == null) {
throw new IllegalArgumentException("keyStore or system property javax.net.ssl.keyStore must be set");
}
}
if (keyStore.startsWith("classpath:")) {
try {
String res = keyStore.substring(10);
URL resurl = new ClassPathResource(res).getURL();
keyStore = resurl.toString();
} catch (IOException e) {
throw new JBIException("Unable to find keystore " + keyStore, e);
}
}
String keyStorePassword = ssl.getKeyStorePassword();
if (keyStorePassword == null) {
keyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword");
if (keyStorePassword == null) {
throw new IllegalArgumentException("keyStorePassword or system property javax.net.ssl.keyStorePassword must be set");
}
}
SslSocketConnector sslConnector = new SslSocketConnector();
sslConnector.setSslKeyManagerFactoryAlgorithm(ssl.getKeyManagerFactoryAlgorithm());
sslConnector.setSslTrustManagerFactoryAlgorithm(ssl.getTrustManagerFactoryAlgorithm());
sslConnector.setProtocol(ssl.getProtocol());
sslConnector.setConfidentialPort(url.getPort());
sslConnector.setPassword(ssl.getKeyStorePassword());
sslConnector.setKeyPassword(ssl.getKeyPassword() != null ? ssl.getKeyPassword() : keyStorePassword);
sslConnector.setKeystore(keyStore);
sslConnector.setKeystoreType(ssl.getKeyStoreType());
sslConnector.setNeedClientAuth(ssl.isNeedClientAuth());
sslConnector.setWantClientAuth(ssl.isWantClientAuth());
connector = sslConnector;
} else {
String connectorClassName = configuration.getJettyConnectorClassName();
try {
connector = (Connector) Class.forName(connectorClassName).newInstance();
} catch (Exception e) {
logger.warn("Could not create a jetty connector of class '" + connectorClassName + "'. Defaulting to " + HttpConfiguration.DEFAULT_JETTY_CONNECTOR_CLASS_NAME);
if (logger.isDebugEnabled()) {
logger.debug("Reason: " + e.getMessage(), e);
}
connector = (Connector) Class.forName(HttpConfiguration.DEFAULT_JETTY_CONNECTOR_CLASS_NAME).newInstance();
}
}
connector.setHost(url.getHost());
connector.setPort(url.getPort());
Server server = new Server();
server.setThreadPool(new ThreadPoolWrapper());
server.setConnectors(new Connector[] { connector });
ContextHandlerCollection contexts = new ContextHandlerCollection();
HandlerCollection handlers = new HandlerCollection();