use of org.eclipse.jetty.server.nio.SelectChannelConnector in project sling by apache.
the class VirtualInstance method startJetty.
public synchronized void startJetty() throws Throwable {
if (jettyServer != null) {
return;
}
servletContext = new ServletContextHandler(ServletContextHandler.NO_SECURITY);
servletContext.setContextPath("/");
TopologyConnectorServlet servlet = new TopologyConnectorServlet();
PrivateAccessor.setField(servlet, "config", config);
PrivateAccessor.setField(servlet, "clusterViewService", clusterViewService);
PrivateAccessor.setField(servlet, "announcementRegistry", announcementRegistry);
Mockery context = new JUnit4Mockery();
final HttpService httpService = context.mock(HttpService.class);
context.checking(new Expectations() {
{
allowing(httpService).registerServlet(with(any(String.class)), with(any(Servlet.class)), with(any(Dictionary.class)), with(any(HttpContext.class)));
}
});
PrivateAccessor.setField(servlet, "httpService", httpService);
ComponentContext cc = null;
PrivateAccessor.invoke(servlet, "activate", new Class[] { ComponentContext.class }, new Object[] { cc });
ServletHolder holder = new ServletHolder(servlet);
servletContext.addServlet(holder, "/system/console/topology/*");
jettyServer = new Server();
jettyServer.setHandler(servletContext);
Connector connector = new SelectChannelConnector();
jettyServer.setConnectors(new Connector[] { connector });
jettyServer.start();
}
use of org.eclipse.jetty.server.nio.SelectChannelConnector in project cdap by caskdata.
the class ExternalAuthenticationServer method startUp.
@Override
protected void startUp() throws Exception {
try {
server = new Server();
try {
bindAddress = InetAddress.getByName(cConfiguration.get(Constants.Security.AUTH_SERVER_BIND_ADDRESS));
} catch (UnknownHostException e) {
LOG.error("Error finding host to connect to.", e);
throw e;
}
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);
} catch (Exception e) {
LOG.error("Error while starting Authentication Server.", e);
}
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)));
}
use of org.eclipse.jetty.server.nio.SelectChannelConnector in project webservices-axiom by apache.
the class ScenarioTestCase method setUp.
@Override
protected void setUp() throws Exception {
server = new Server();
// Set up a custom thread pool to improve thread names (for logging purposes)
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setName("jetty");
server.setThreadPool(threadPool);
Connector connector = new SelectChannelConnector();
connector.setPort(0);
server.setConnectors(new Connector[] { connector });
ServletContextHandler handler = new ServletContextHandler(server, "/");
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setContextClass(GenericWebApplicationContext.class);
servlet.setContextInitializers(new ApplicationContextInitializer<ConfigurableApplicationContext>() {
public void initialize(ConfigurableApplicationContext applicationContext) {
configureContext((GenericWebApplicationContext) applicationContext, config.getServerMessageFactoryConfigurator(), new ClassPathResource("server.xml", ScenarioTestCase.this.getClass()));
}
});
ServletHolder servletHolder = new ServletHolder(servlet);
servletHolder.setName("spring-ws");
servletHolder.setInitOrder(1);
handler.addServlet(servletHolder, "/*");
server.start();
context = new GenericXmlApplicationContext();
MockPropertySource propertySource = new MockPropertySource("client-properties");
propertySource.setProperty("port", connector.getLocalPort());
context.getEnvironment().getPropertySources().replace(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, propertySource);
configureContext(context, config.getClientMessageFactoryConfigurator(), new ClassPathResource("client.xml", getClass()));
context.refresh();
}
use of org.eclipse.jetty.server.nio.SelectChannelConnector in project processdash by dtuma.
the class WebServer method addPort.
/** Start listening for connections on an additional port */
public void addPort(int port) throws IOException {
ADD_PORT_PERMISSION.checkPermission();
// on the requested port, do nothing.
for (Connector c : server.getConnectors()) {
if (c instanceof SelectChannelConnector) {
SelectChannelConnector conn = (SelectChannelConnector) c;
if (conn.getPort() == port)
return;
}
}
for (int retries = 50; retries-- > 0; ) {
try {
// create a new listener on the given port
SelectChannelConnector c = new SelectChannelConnector();
if (allowingRemoteConnections != ALLOW_REMOTE_ALWAYS)
c.setHost("127.0.0.1");
c.setPort(port);
c.setServer(server);
// attempt to start listening. This will throw an exception if
// the given port is already in use.
c.start();
// if the connection started successfully, add it to the
// server and record the port in our data structures.
server.addConnector(c);
this.port = port;
DEFAULT_ENV.put("SERVER_PORT", Integer.toString(this.port));
break;
} catch (Exception e) {
// if we were unable to listen on the given port, increment
// the number and try listening on the next higher port.
port++;
}
}
}
use of org.eclipse.jetty.server.nio.SelectChannelConnector in project http-request by kevinsawicki.
the class ServerTestCase method setUp.
/**
* Set up server with handler
*
* @param handler
* @return port
* @throws Exception
*/
public static String setUp(final Handler handler) throws Exception {
server = new Server();
if (handler != null)
server.setHandler(handler);
Connector connector = new SelectChannelConnector();
connector.setPort(0);
server.setConnectors(new Connector[] { connector });
server.start();
proxy = new Server();
Connector proxyConnector = new SelectChannelConnector();
proxyConnector.setPort(0);
proxy.setConnectors(new Connector[] { proxyConnector });
ServletHandler proxyHandler = new ServletHandler();
RequestHandler proxyCountingHandler = new RequestHandler() {
@Override
public void handle(Request request, HttpServletResponse response) {
proxyHitCount.incrementAndGet();
String auth = request.getHeader("Proxy-Authorization");
auth = auth.substring(auth.indexOf(' ') + 1);
try {
auth = B64Code.decode(auth, CHARSET_UTF8);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
int colon = auth.indexOf(':');
proxyUser.set(auth.substring(0, colon));
proxyPassword.set(auth.substring(colon + 1));
request.setHandled(false);
}
};
HandlerList handlerList = new HandlerList();
handlerList.addHandler(proxyCountingHandler);
handlerList.addHandler(proxyHandler);
proxy.setHandler(handlerList);
ServletHolder proxyHolder = proxyHandler.addServletWithMapping("org.eclipse.jetty.servlets.ProxyServlet", "/");
proxyHolder.setAsyncSupported(true);
proxy.start();
proxyPort = proxyConnector.getLocalPort();
return "http://localhost:" + connector.getLocalPort();
}
Aggregations