use of org.eclipse.jetty.server.ServerConnector in project hadoop by apache.
the class HttpServer2 method getConnectorAddress.
/**
* Get the address that corresponds to a particular connector.
*
* @return the corresponding address for the connector, or null if there's no
* such connector or the connector is not bounded or was closed.
*/
public InetSocketAddress getConnectorAddress(int index) {
Preconditions.checkArgument(index >= 0);
if (index > webServer.getConnectors().length)
return null;
ServerConnector c = (ServerConnector) webServer.getConnectors()[index];
if (c.getLocalPort() == -1 || c.getLocalPort() == -2) {
// The connector is not bounded or was closed
return null;
}
return new InetSocketAddress(c.getHost(), c.getLocalPort());
}
use of org.eclipse.jetty.server.ServerConnector in project hadoop by apache.
the class TestJettyHelper method createJettyServer.
private Server createJettyServer() {
try {
InetAddress localhost = InetAddress.getByName("localhost");
String host = "localhost";
ServerSocket ss = new ServerSocket(0, 50, localhost);
int port = ss.getLocalPort();
ss.close();
Server server = new Server();
ServerConnector conn = new ServerConnector(server);
HttpConfiguration http_config = new HttpConfiguration();
http_config.setRequestHeaderSize(JettyUtils.HEADER_SIZE);
http_config.setResponseHeaderSize(JettyUtils.HEADER_SIZE);
http_config.setSecureScheme("https");
http_config.addCustomizer(new SecureRequestCustomizer());
ConnectionFactory connFactory = new HttpConnectionFactory(http_config);
conn.addConnectionFactory(connFactory);
conn.setHost(host);
conn.setPort(port);
if (ssl) {
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setNeedClientAuth(false);
sslContextFactory.setKeyStorePath(keyStore);
sslContextFactory.setKeyStoreType(keyStoreType);
sslContextFactory.setKeyStorePassword(keyStorePassword);
conn.addFirstConnectionFactory(new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()));
}
server.addConnector(conn);
return server;
} catch (Exception ex) {
throw new RuntimeException("Could not start embedded servlet container, " + ex.getMessage(), ex);
}
}
use of org.eclipse.jetty.server.ServerConnector in project hadoop by apache.
the class TestWebDelegationToken method createJettyServer.
protected Server createJettyServer() {
try {
jetty = new Server(0);
((ServerConnector) jetty.getConnectors()[0]).setHost("localhost");
return jetty;
} catch (Exception ex) {
throw new RuntimeException("Could not setup Jetty: " + ex.getMessage(), ex);
}
}
use of org.eclipse.jetty.server.ServerConnector in project hadoop by apache.
the class TestWebAppProxyServlet method start.
/**
* Simple http server. Server should send answer with status 200
*/
@BeforeClass
public static void start() throws Exception {
server = new Server(0);
((QueuedThreadPool) server.getThreadPool()).setMaxThreads(10);
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/foo");
server.setHandler(context);
context.addServlet(new ServletHolder(TestServlet.class), "/bar");
((ServerConnector) server.getConnectors()[0]).setHost("localhost");
server.start();
originalPort = ((ServerConnector) server.getConnectors()[0]).getLocalPort();
LOG.info("Running embedded servlet container at: http://localhost:" + originalPort);
// This property needs to be set otherwise CORS Headers will be dropped
// by HttpUrlConnection
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
}
use of org.eclipse.jetty.server.ServerConnector in project hbase by apache.
the class HttpServer method toString.
/**
* Return the host and port of the HttpServer, if live
* @return the classname and any HTTP URL
*/
@Override
public String toString() {
if (listeners.isEmpty()) {
return "Inactive HttpServer";
} else {
StringBuilder sb = new StringBuilder("HttpServer (").append(isAlive() ? STATE_DESCRIPTION_ALIVE : STATE_DESCRIPTION_NOT_LIVE).append("), listening at:");
for (ListenerInfo li : listeners) {
ServerConnector l = li.listener;
sb.append(l.getHost()).append(":").append(l.getPort()).append("/,");
}
return sb.toString();
}
}
Aggregations