Search in sources :

Example 6 with ServerConnector

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());
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) InetSocketAddress(java.net.InetSocketAddress)

Example 7 with ServerConnector

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);
    }
}
Also used : SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ServerSocket(java.net.ServerSocket) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) MalformedURLException(java.net.MalformedURLException) UnknownHostException(java.net.UnknownHostException) ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) InetAddress(java.net.InetAddress)

Example 8 with ServerConnector

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);
    }
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) AuthenticationException(org.apache.hadoop.security.authentication.client.AuthenticationException) ServletException(javax.servlet.ServletException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException)

Example 9 with ServerConnector

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");
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) BeforeClass(org.junit.BeforeClass)

Example 10 with ServerConnector

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();
    }
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector)

Aggregations

ServerConnector (org.eclipse.jetty.server.ServerConnector)272 Server (org.eclipse.jetty.server.Server)205 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)80 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)73 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)63 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)53 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)51 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)49 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)42 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)40 URI (java.net.URI)37 Test (org.junit.Test)31 File (java.io.File)28 BeforeClass (org.junit.BeforeClass)28 IOException (java.io.IOException)26 Before (org.junit.Before)25 BeforeClass (org.testng.annotations.BeforeClass)22 ServletException (javax.servlet.ServletException)21 HttpServletRequest (javax.servlet.http.HttpServletRequest)19 HttpServletResponse (javax.servlet.http.HttpServletResponse)18