use of org.eclipse.jetty.server.Connector in project apex-malhar by apache.
the class MrMonitoringApplicationTest method testApplication.
@Test
public void testApplication() throws Exception {
Configuration conf = new Configuration(false);
conf.addResource("dt-site-monitoring.xml");
Server server = new Server(0);
Servlet servlet = new SamplePubSubWebSocketServlet();
ServletHolder sh = new ServletHolder(servlet);
ServletContextHandler contextHandler = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
contextHandler.addServlet(sh, "/pubsub");
contextHandler.addServlet(sh, "/*");
server.start();
Connector[] connector = server.getConnectors();
conf.set("dt.attr.GATEWAY_CONNECT_ADDRESS", "localhost:" + connector[0].getLocalPort());
MRMonitoringApplication application = new MRMonitoringApplication();
LocalMode lma = LocalMode.newInstance();
lma.prepareDAG(application, conf);
LocalMode.Controller lc = lma.getController();
lc.run(10000);
server.stop();
}
use of org.eclipse.jetty.server.Connector in project scheduling by ow2-proactive.
the class JettyStarter method configureHttps.
private Connector[] configureHttps(int httpPort, int httpsPort, boolean redirectHttpToHttps, Server server, HttpConfiguration httpConfiguration) {
Connector[] connectors;
SslContextFactory sslContextFactory = new SslContextFactory();
if (WebProperties.WEB_HTTPS_PROTOCOLS_INCLUDED.isSet()) {
sslContextFactory.setIncludeProtocols(WebProperties.WEB_HTTPS_PROTOCOLS_INCLUDED.getValueAsList(",").toArray(new String[0]));
}
if (WebProperties.WEB_HTTPS_PROTOCOLS_EXCLUDED.isSet()) {
sslContextFactory.setExcludeProtocols(WebProperties.WEB_HTTPS_PROTOCOLS_EXCLUDED.getValueAsList(",").toArray(new String[0]));
}
if (WebProperties.WEB_HTTPS_CYPHERS_INCLUDED_ADD.isSet()) {
List<String> includedCyphers = Arrays.asList(sslContextFactory.getIncludeCipherSuites());
includedCyphers.addAll(WebProperties.WEB_HTTPS_CYPHERS_INCLUDED_ADD.getValueAsList(","));
sslContextFactory.setIncludeCipherSuites(includedCyphers.toArray(new String[0]));
}
if (WebProperties.WEB_HTTPS_CYPHERS_EXCLUDED_ADD.isSet()) {
sslContextFactory.addExcludeCipherSuites(WebProperties.WEB_HTTPS_CYPHERS_EXCLUDED_ADD.getValueAsList(",").toArray(new String[0]));
}
if (WebProperties.WEB_HTTPS_RENEGOTIATION_ALLOWED.isSet()) {
sslContextFactory.setRenegotiationAllowed(WebProperties.WEB_HTTPS_RENEGOTIATION_ALLOWED.getValueAsBoolean());
}
if (WebProperties.WEB_HTTPS_SECURE_RANDOM_ALGORITHM.isSet()) {
sslContextFactory.setSecureRandomAlgorithm(WebProperties.WEB_HTTPS_SECURE_RANDOM_ALGORITHM.getValueAsString());
}
if (WebProperties.WEB_HTTPS_KEY_FACTORY_ALGORITHM.isSet()) {
sslContextFactory.setSslKeyManagerFactoryAlgorithm(WebProperties.WEB_HTTPS_KEY_FACTORY_ALGORITHM.getValueAsString());
}
if (WebProperties.WEB_HTTPS_TRUST_FACTORY_ALGORITHM.isSet()) {
sslContextFactory.setTrustManagerFactoryAlgorithm(WebProperties.WEB_HTTPS_TRUST_FACTORY_ALGORITHM.getValueAsString());
}
if (WebProperties.WEB_HTTPS_MAX_CERT_PATH.isSet()) {
sslContextFactory.setMaxCertPathLength(WebProperties.WEB_HTTPS_MAX_CERT_PATH.getValueAsInt());
}
if (WebProperties.WEB_HTTPS_CERT_ALIAS.isSet()) {
sslContextFactory.setCertAlias(WebProperties.WEB_HTTPS_CERT_ALIAS.getValueAsString());
}
if (WebProperties.WEB_HTTPS_ENABLE_CRLDP.isSet()) {
sslContextFactory.setEnableCRLDP(WebProperties.WEB_HTTPS_ENABLE_CRLDP.getValueAsBoolean());
}
if (WebProperties.WEB_HTTPS_CRL_PATH.isSet()) {
sslContextFactory.setCrlPath(WebProperties.WEB_HTTPS_CRL_PATH.getValueAsString());
}
if (WebProperties.WEB_HTTPS_ENABLE_OCSP.isSet()) {
sslContextFactory.setEnableOCSP(WebProperties.WEB_HTTPS_ENABLE_OCSP.getValueAsBoolean());
}
if (WebProperties.WEB_HTTPS_OCSP_RESPONDER_URL.isSet()) {
sslContextFactory.setOcspResponderURL(WebProperties.WEB_HTTPS_OCSP_RESPONDER_URL.getValueAsString());
}
if (WebProperties.WEB_HTTPS_SESSION_CACHING.isSet()) {
sslContextFactory.setSessionCachingEnabled(WebProperties.WEB_HTTPS_SESSION_CACHING.getValueAsBoolean());
}
if (WebProperties.WEB_HTTPS_SESSION_CACHE_SIZE.isSet()) {
sslContextFactory.setSslSessionCacheSize(WebProperties.WEB_HTTPS_SESSION_CACHE_SIZE.getValueAsInt());
}
if (WebProperties.WEB_HTTPS_SESSION_TIMEOUT.isSet()) {
sslContextFactory.setSslSessionTimeout(WebProperties.WEB_HTTPS_SESSION_TIMEOUT.getValueAsInt());
}
String httpsKeystore = WebProperties.WEB_HTTPS_KEYSTORE.getValueAsStringOrNull();
String httpsKeystorePassword = WebProperties.WEB_HTTPS_KEYSTORE_PASSWORD.getValueAsStringOrNull();
checkPropertyNotNull(WebProperties.WEB_HTTPS_KEYSTORE.getKey(), httpsKeystore);
checkPropertyNotNull(WebProperties.WEB_HTTPS_KEYSTORE_PASSWORD.getKey(), httpsKeystorePassword);
sslContextFactory.setKeyStorePath(absolutePathOrRelativeToSchedulerHome(httpsKeystore));
sslContextFactory.setKeyStorePassword(httpsKeystorePassword);
if (WebProperties.WEB_HTTPS_TRUSTSTORE.isSet() && WebProperties.WEB_HTTPS_TRUSTSTORE_PASSWORD.isSet()) {
String httpsTrustStore = WebProperties.WEB_HTTPS_TRUSTSTORE.getValueAsString();
String httpsTrustStorePassword = WebProperties.WEB_HTTPS_TRUSTSTORE_PASSWORD.getValueAsString();
sslContextFactory.setTrustStorePath(httpsTrustStore);
sslContextFactory.setTrustStorePassword(httpsTrustStorePassword);
}
HttpConfiguration secureHttpConfiguration = new HttpConfiguration(httpConfiguration);
secureHttpConfiguration.addCustomizer(new SecureRequestCustomizer());
secureHttpConfiguration.setSecurePort(httpsPort);
secureHttpConfiguration.setSecureScheme("https");
secureHttpConfiguration.setSendDateHeader(false);
secureHttpConfiguration.setSendServerVersion(false);
// Connector to listen for HTTPS requests
ServerConnector httpsConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.toString()), new HttpConnectionFactory(secureHttpConfiguration));
httpsConnector.setName(HTTPS_CONNECTOR_NAME);
httpsConnector.setPort(httpsPort);
httpsConnector.setIdleTimeout(WebProperties.WEB_IDLE_TIMEOUT.getValueAsLong());
if (redirectHttpToHttps) {
// The next two settings allow !403 errors to be redirected to HTTPS
httpConfiguration.setSecureScheme("https");
httpConfiguration.setSecurePort(httpsPort);
// Connector to listen for HTTP requests that are redirected to HTTPS
ServerConnector httpConnector = createHttpConnector(server, httpConfiguration, httpPort);
connectors = new Connector[] { httpConnector, httpsConnector };
} else {
connectors = new Connector[] { httpsConnector };
}
return connectors;
}
use of org.eclipse.jetty.server.Connector in project cxf by apache.
the class JettyHTTPServerEngineFactoryHolder method init.
public void init() {
try {
Element element = StaxUtils.read(new StringReader(parsedElement)).getDocumentElement();
JettyHTTPServerEngineFactoryConfigType config = getJaxbObject(element, JettyHTTPServerEngineFactoryConfigType.class);
Bus defaultBus = BusFactory.getDefaultBus();
factory = new JettyHTTPServerEngineFactory(defaultBus);
Map<String, ThreadingParameters> threadingParametersMap = new TreeMap<>();
if (config.getIdentifiedThreadingParameters() != null) {
for (ThreadingParametersIdentifiedType threads : config.getIdentifiedThreadingParameters()) {
ThreadingParameters rThreads = new ThreadingParameters();
String id = threads.getId();
if (threads.getThreadingParameters().getMaxThreads() != null) {
rThreads.setMaxThreads(threads.getThreadingParameters().getMaxThreads());
}
if (threads.getThreadingParameters().getMinThreads() != null) {
rThreads.setMinThreads(threads.getThreadingParameters().getMinThreads());
}
rThreads.setThreadNamePrefix(threads.getThreadingParameters().getThreadNamePrefix());
threadingParametersMap.put(id, rThreads);
}
factory.setThreadingParametersMap(threadingParametersMap);
}
// SSL
Map<String, TLSServerParameters> sslMap = new TreeMap<>();
if (config.getIdentifiedTLSServerParameters() != null) {
for (TLSServerParametersIdentifiedType t : config.getIdentifiedTLSServerParameters()) {
try {
TLSServerParameters parameter = new TLSServerParametersConfig(t.getTlsServerParameters());
sslMap.put(t.getId(), parameter);
} catch (Exception e) {
throw new RuntimeException("Could not configure TLS for id " + t.getId(), e);
}
}
factory.setTlsServerParametersMap(sslMap);
}
// Engines
List<JettyHTTPServerEngine> engineList = new ArrayList<>();
for (JettyHTTPServerEngineConfigType engine : config.getEngine()) {
JettyHTTPServerEngine eng = new JettyHTTPServerEngine(factory.getMBeanContainer(), engine.getHost(), engine.getPort());
if (engine.getConnector() != null && connectorMap != null) {
// we need to setup the Connector from the connectorMap
Connector connector = connectorMap.get(engine.getPort().toString());
if (connector != null) {
eng.setConnector(connector);
} else {
throw new RuntimeException("Could not find the connector instance for engine with port" + engine.getPort().toString());
}
}
if (engine.getHandlers() != null && handlersMap != null) {
List<Handler> handlers = handlersMap.get(engine.getPort().toString());
if (handlers != null) {
eng.setHandlers(handlers);
} else {
throw new RuntimeException("Could not find the handlers instance for engine with port" + engine.getPort().toString());
}
}
if (engine.isContinuationsEnabled() != null) {
eng.setContinuationsEnabled(engine.isContinuationsEnabled());
}
if (engine.isSendServerVersion() != null) {
eng.setSendServerVersion(engine.isSendServerVersion());
}
if (engine.getHost() != null && !StringUtils.isEmpty(engine.getHost())) {
eng.setHost(engine.getHost());
}
if (engine.getMaxIdleTime() != null) {
eng.setMaxIdleTime(engine.getMaxIdleTime());
}
if (engine.getPort() != null) {
eng.setPort(engine.getPort());
}
if (engine.isReuseAddress() != null) {
eng.setReuseAddress(engine.isReuseAddress());
}
if (engine.isSessionSupport() != null) {
eng.setSessionSupport(engine.isSessionSupport());
}
if (engine.getSessionTimeout() != null) {
eng.setSessionTimeout(engine.getSessionTimeout().intValue());
}
if (engine.getThreadingParameters() != null) {
ThreadingParametersType threads = engine.getThreadingParameters();
ThreadingParameters rThreads = new ThreadingParameters();
if (threads.getMaxThreads() != null) {
rThreads.setMaxThreads(threads.getMaxThreads());
}
if (threads.getMinThreads() != null) {
rThreads.setMinThreads(threads.getMinThreads());
}
eng.setThreadingParameters(rThreads);
}
// eng.setServer(engine.getTlsServerParameters());
if (engine.getTlsServerParameters() != null && (engine.getTlsServerParameters().getKeyManagers() != null || engine.getTlsServerParameters().getTrustManagers() != null)) {
try {
TLSServerParameters parameter = new TLSServerParametersConfig(engine.getTlsServerParameters());
eng.setTlsServerParameters(parameter);
} catch (Exception e) {
throw new RuntimeException("Could not configure TLS for engine on " + eng.getHost() + ":" + eng.getPort(), e);
}
}
eng.finalizeConfig();
engineList.add(eng);
}
factory.setEnginesList(engineList);
// Unravel this completely.
factory.initComplete();
} catch (Exception e) {
throw new RuntimeException("Could not process configuration.", e);
}
}
use of org.eclipse.jetty.server.Connector in project leopard by tanhaichao.
the class MyJettyServer method start.
public Server start(int port) throws Exception {
System.setProperty("spring.profiles.active", "jetty");
List<ServerConnector> connectorList = this.listPort(port);
Connector[] connectors = new Connector[connectorList.size()];
connectorList.toArray(connectors);
server.setConnectors(connectors);
HandlerCollection handlers = new HandlerCollection();
// webappService.addHandler(new WorkbenchHandler(server));//TODO
handlers.addHandler(webappService.getContextHandlerCollection());
new HandlerServiceImpl().execute(handlers);
handlers.addHandler(new RestartingHandler());
server.setHandler(handlers);
System.out.println("started");
logger.info("jetty started");
server.start();
return server;
}
use of org.eclipse.jetty.server.Connector in project cdap by caskdata.
the class ExternalAuthenticationServer method startUp.
@Override
protected void startUp() throws Exception {
server = new Server();
InetAddress bindAddress = InetAddress.getByName(cConfiguration.get(Constants.Security.AUTH_SERVER_BIND_ADDRESS));
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMaxThreads(maxThreads);
server.setThreadPool(threadPool);
initHandlers();
ServletContextHandler context = new ServletContextHandler();
context.setServer(server);
context.addServlet(HttpServletDispatcher.class, "/");
context.addEventListener(new AuthenticationGuiceServletContextListener(handlers));
context.setSecurityHandler(authenticationHandler);
// Status endpoint should be handled without the authentication
ContextHandler statusContext = new ContextHandler();
statusContext.setContextPath(Constants.EndPoints.STATUS);
statusContext.setServer(server);
statusContext.setHandler(new StatusRequestHandler());
if (cConfiguration.getBoolean(Constants.Security.SSL.EXTERNAL_ENABLED, false)) {
SslContextFactory sslContextFactory = new SslContextFactory();
String keyStorePath = sConfiguration.get(Constants.Security.AuthenticationServer.SSL_KEYSTORE_PATH);
String keyStorePassword = sConfiguration.get(Constants.Security.AuthenticationServer.SSL_KEYSTORE_PASSWORD);
String keyStoreType = sConfiguration.get(Constants.Security.AuthenticationServer.SSL_KEYSTORE_TYPE, Constants.Security.AuthenticationServer.DEFAULT_SSL_KEYSTORE_TYPE);
String keyPassword = sConfiguration.get(Constants.Security.AuthenticationServer.SSL_KEYPASSWORD);
Preconditions.checkArgument(keyStorePath != null, "Key Store Path Not Configured");
Preconditions.checkArgument(keyStorePassword != null, "KeyStore Password Not Configured");
sslContextFactory.setKeyStorePath(keyStorePath);
sslContextFactory.setKeyStorePassword(keyStorePassword);
sslContextFactory.setKeyStoreType(keyStoreType);
if (keyPassword != null && keyPassword.length() != 0) {
sslContextFactory.setKeyManagerPassword(keyPassword);
}
String trustStorePath = cConfiguration.get(Constants.Security.AuthenticationServer.SSL_TRUSTSTORE_PATH);
if (StringUtils.isNotEmpty(trustStorePath)) {
String trustStorePassword = cConfiguration.get(Constants.Security.AuthenticationServer.SSL_TRUSTSTORE_PASSWORD);
String trustStoreType = cConfiguration.get(Constants.Security.AuthenticationServer.SSL_TRUSTSTORE_TYPE, Constants.Security.AuthenticationServer.DEFAULT_SSL_KEYSTORE_TYPE);
// SSL handshaking will involve requesting for a client certificate, if cert is not provided
// server continues with the connection but the client is considered to be unauthenticated
sslContextFactory.setWantClientAuth(true);
sslContextFactory.setTrustStore(trustStorePath);
sslContextFactory.setTrustStorePassword(trustStorePassword);
sslContextFactory.setTrustStoreType(trustStoreType);
sslContextFactory.setValidateCerts(true);
}
// TODO Figure out how to pick a certificate from key store
SslSelectChannelConnector sslConnector = new SslSelectChannelConnector(sslContextFactory);
sslConnector.setHost(bindAddress.getCanonicalHostName());
sslConnector.setPort(port);
server.setConnectors(new Connector[] { sslConnector });
} else {
SelectChannelConnector connector = new SelectChannelConnector();
connector.setHost(bindAddress.getCanonicalHostName());
connector.setPort(port);
server.setConnectors(new Connector[] { connector });
}
HandlerCollection handlers = new HandlerCollection();
handlers.addHandler(statusContext);
handlers.addHandler(context);
// AuditLogHandler must be last, since it needs the response that was sent to the client
handlers.addHandler(auditLogHandler);
server.setHandler(handlers);
try {
server.start();
} catch (Exception e) {
if ((Throwables.getRootCause(e) instanceof BindException)) {
throw new ServiceBindException("Authentication Server", bindAddress.getCanonicalHostName(), port, e);
}
throw e;
}
// assumes we only have one connector
Connector connector = server.getConnectors()[0];
InetSocketAddress inetSocketAddress = new InetSocketAddress(connector.getHost(), connector.getLocalPort());
serviceCancellable = discoveryService.register(ResolvingDiscoverable.of(new Discoverable(Constants.Service.EXTERNAL_AUTHENTICATION, inetSocketAddress)));
}
Aggregations