Search in sources :

Example 26 with Connector

use of org.eclipse.jetty.server.Connector in project ats-framework by Axway.

the class ContainerStarter method startServer.

/**
     * Method for starting the Jetty server with the ATS Agent webapp.
     * @param port the port on which to start the server.
     * @return the started server.
     * @throws IOException
     */
private static Server startServer() throws IOException {
    addAppender();
    final int agentPort = getAgentDefaultPort();
    log.info("Starting ATS agent at port: " + agentPort);
    final String jettyHome = getJettyHome();
    logSystemInformation(jettyHome);
    // start the server
    Connector connector = new SelectChannelConnector();
    connector.setPort(agentPort);
    Server server = new Server();
    server.setConnectors(new Connector[] { connector });
    WebAppContext webApp = new WebAppContext();
    webApp.setContextPath("/agentapp");
    webApp.setWar(jettyHome + "/webapp/agentapp.war");
    server.setHandler(webApp);
    server.setStopAtShutdown(true);
    setExtraClasspath(webApp, jettyHome);
    try {
        server.start();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
    log.info("ATS agent started");
    return server;
}
Also used : SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) Connector(org.eclipse.jetty.server.Connector) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) Server(org.eclipse.jetty.server.Server) SocketException(java.net.SocketException) AgentException(com.axway.ats.agentapp.standalone.exceptions.AgentException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 27 with Connector

use of org.eclipse.jetty.server.Connector in project jena by apache.

the class ManagementServer method createManagementServer.

public static Server createManagementServer(int mgtPort) {
    Fuseki.serverLog.info("Adding management functions");
    // Separate Jetty server
    Server server = new Server();
    //        BlockingChannelConnector bcConnector = new BlockingChannelConnector() ;
    //        bcConnector.setUseDirectBuffers(false) ;
    //        Connector connector = bcConnector ;
    Connector connector = new SelectChannelConnector();
    // Ignore idle time. 
    // If set, then if this goes off, it keeps going off and you get a lot of log messages.
    // Jetty outputs a lot of messages if this goes off.
    connector.setMaxIdleTime(0);
    connector.setPort(mgtPort);
    server.addConnector(connector);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setErrorHandler(new FusekiErrorHandler());
    server.setHandler(context);
    // Add the server control servlet
    addServlet(context, new MgtCmdServlet(), "/mgt");
    addServlet(context, new DumpServlet(), "/dump");
    addServlet(context, new StatsServlet(), "/stats");
    addServlet(context, new PingServlet(), "/ping");
    return server;
// Old plan
//      // Development : server control panel.
//      addServlet(context, new ServerServlet(), "/server") ;
//      addServlet(context, new ActionBackup(), "/backup") ;
}
Also used : Connector(org.eclipse.jetty.server.Connector) SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) DumpServlet(org.apache.jena.fuseki.servlets.DumpServlet) FusekiErrorHandler(org.apache.jena.fuseki.server.FusekiErrorHandler) Server(org.eclipse.jetty.server.Server) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 28 with Connector

use of org.eclipse.jetty.server.Connector in project lucene-solr by apache.

the class JettySolrRunner method getBaseUrl.

/**
   * Returns a base URL consisting of the protocol, host, and port for a
   * Connector in use by the Jetty Server contained in this runner.
   */
public URL getBaseUrl() {
    String protocol = null;
    try {
        Connector[] conns = server.getConnectors();
        if (0 == conns.length) {
            throw new IllegalStateException("Jetty Server has no Connectors");
        }
        ServerConnector c = (ServerConnector) conns[0];
        if (c.getLocalPort() < 0) {
            throw new IllegalStateException("Jetty Connector is not open: " + c.getLocalPort());
        }
        protocol = c.getDefaultProtocol().startsWith("SSL") ? "https" : "http";
        return new URL(protocol, c.getHost(), c.getLocalPort(), config.context);
    } catch (MalformedURLException e) {
        throw new IllegalStateException("Java could not make sense of protocol: " + protocol, e);
    }
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ServerConnector(org.eclipse.jetty.server.ServerConnector) Connector(org.eclipse.jetty.server.Connector) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL)

Example 29 with Connector

use of org.eclipse.jetty.server.Connector 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();
}
Also used : Expectations(org.jmock.Expectations) Dictionary(java.util.Dictionary) SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) Connector(org.eclipse.jetty.server.Connector) ComponentContext(org.osgi.service.component.ComponentContext) Server(org.eclipse.jetty.server.Server) TopologyConnectorServlet(org.apache.sling.discovery.base.connectors.ping.TopologyConnectorServlet) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpContext(org.osgi.service.http.HttpContext) Mockery(org.jmock.Mockery) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) HttpService(org.osgi.service.http.HttpService) TopologyConnectorServlet(org.apache.sling.discovery.base.connectors.ping.TopologyConnectorServlet) Servlet(javax.servlet.Servlet) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 30 with Connector

use of org.eclipse.jetty.server.Connector in project gerrit by GerritCodeReview.

the class JettyServer method listen.

private Connector[] listen(Server server, Config cfg) {
    // OpenID and certain web-based single-sign-on products can cause
    // some very long headers, especially in the Referer header. We
    // need to use a larger default header size to ensure we have
    // the space required.
    //
    final int requestHeaderSize = cfg.getInt("httpd", "requestheadersize", 16386);
    final URI[] listenUrls = listenURLs(cfg);
    final boolean reuseAddress = cfg.getBoolean("httpd", "reuseaddress", true);
    final int acceptors = cfg.getInt("httpd", "acceptorThreads", 2);
    final AuthType authType = cfg.getEnum("auth", null, "type", AuthType.OPENID);
    reverseProxy = isReverseProxied(listenUrls);
    final Connector[] connectors = new Connector[listenUrls.length];
    for (int idx = 0; idx < listenUrls.length; idx++) {
        final URI u = listenUrls[idx];
        final int defaultPort;
        final ServerConnector c;
        HttpConfiguration config = defaultConfig(requestHeaderSize);
        if (AuthType.CLIENT_SSL_CERT_LDAP.equals(authType) && !"https".equals(u.getScheme())) {
            throw new IllegalArgumentException("Protocol '" + u.getScheme() + "' " + " not supported in httpd.listenurl '" + u + "' when auth.type = '" + AuthType.CLIENT_SSL_CERT_LDAP.name() + "'; only 'https' is supported");
        }
        if ("http".equals(u.getScheme())) {
            defaultPort = 80;
            c = newServerConnector(server, acceptors, config);
        } else if ("https".equals(u.getScheme())) {
            SslContextFactory ssl = new SslContextFactory();
            final Path keystore = getFile(cfg, "sslkeystore", "etc/keystore");
            String password = cfg.getString("httpd", null, "sslkeypassword");
            if (password == null) {
                password = "gerrit";
            }
            ssl.setKeyStorePath(keystore.toAbsolutePath().toString());
            ssl.setTrustStorePath(keystore.toAbsolutePath().toString());
            ssl.setKeyStorePassword(password);
            ssl.setTrustStorePassword(password);
            if (AuthType.CLIENT_SSL_CERT_LDAP.equals(authType)) {
                ssl.setNeedClientAuth(true);
                Path crl = getFile(cfg, "sslcrl", "etc/crl.pem");
                if (Files.exists(crl)) {
                    ssl.setCrlPath(crl.toAbsolutePath().toString());
                    ssl.setValidatePeerCerts(true);
                }
            }
            defaultPort = 443;
            config.addCustomizer(new SecureRequestCustomizer());
            c = new ServerConnector(server, null, null, null, 0, acceptors, new SslConnectionFactory(ssl, "http/1.1"), new HttpConnectionFactory(config));
        } else if ("proxy-http".equals(u.getScheme())) {
            defaultPort = 8080;
            config.addCustomizer(new ForwardedRequestCustomizer());
            c = newServerConnector(server, acceptors, config);
        } else if ("proxy-https".equals(u.getScheme())) {
            defaultPort = 8080;
            config.addCustomizer(new ForwardedRequestCustomizer());
            config.addCustomizer(new HttpConfiguration.Customizer() {

                @Override
                public void customize(Connector connector, HttpConfiguration channelConfig, Request request) {
                    request.setScheme(HttpScheme.HTTPS.asString());
                    request.setSecure(true);
                }
            });
            c = newServerConnector(server, acceptors, config);
        } else {
            throw new IllegalArgumentException("Protocol '" + u.getScheme() + "' " + " not supported in httpd.listenurl '" + u + "';" + " only 'http', 'https', 'proxy-http, 'proxy-https'" + " are supported");
        }
        try {
            if (u.getHost() == null && (//
            u.getAuthority().equals("*") || u.getAuthority().startsWith("*:"))) {
                // Bind to all local addresses. Port wasn't parsed right by URI
                // due to the illegal host of "*" so replace with a legal name
                // and parse the URI.
                //
                final URI r = new URI(u.toString().replace('*', 'A')).parseServerAuthority();
                c.setHost(null);
                c.setPort(0 < r.getPort() ? r.getPort() : defaultPort);
            } else {
                final URI r = u.parseServerAuthority();
                c.setHost(r.getHost());
                c.setPort(0 <= r.getPort() ? r.getPort() : defaultPort);
            }
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException("Invalid httpd.listenurl " + u, e);
        }
        c.setInheritChannel(cfg.getBoolean("httpd", "inheritChannel", false));
        c.setReuseAddress(reuseAddress);
        c.setIdleTimeout(cfg.getTimeUnit("httpd", null, "idleTimeout", 30000L, MILLISECONDS));
        connectors[idx] = c;
    }
    return connectors;
}
Also used : Path(java.nio.file.Path) ServerConnector(org.eclipse.jetty.server.ServerConnector) Connector(org.eclipse.jetty.server.Connector) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) Request(org.eclipse.jetty.server.Request) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) URISyntaxException(java.net.URISyntaxException) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) URI(java.net.URI) ForwardedRequestCustomizer(org.eclipse.jetty.server.ForwardedRequestCustomizer) ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) AuthType(com.google.gerrit.extensions.client.AuthType) ForwardedRequestCustomizer(org.eclipse.jetty.server.ForwardedRequestCustomizer) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer)

Aggregations

Connector (org.eclipse.jetty.server.Connector)61 Server (org.eclipse.jetty.server.Server)29 ServerConnector (org.eclipse.jetty.server.ServerConnector)20 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)18 IOException (java.io.IOException)12 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)12 NetworkConnector (org.eclipse.jetty.server.NetworkConnector)12 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)11 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)10 SelectChannelConnector (org.eclipse.jetty.server.nio.SelectChannelConnector)8 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)8 Test (org.junit.Test)7 Handler (org.eclipse.jetty.server.Handler)6 ServletException (javax.servlet.ServletException)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 EndPoint (org.eclipse.jetty.io.EndPoint)5 Request (org.eclipse.jetty.server.Request)5 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)5 ByteBuffer (java.nio.ByteBuffer)4