Search in sources :

Example 66 with Connector

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

the class WsProducerConsumerTest method startTestServer.

public void startTestServer() throws Exception {
    // start a simple websocket echo service
    server = new Server(PORT);
    Connector connector = new ServerConnector(server);
    server.addConnector(connector);
    ServletContextHandler ctx = new ServletContextHandler();
    ctx.setContextPath("/");
    ctx.addServlet(TestServletFactory.class.getName(), "/*");
    server.setHandler(ctx);
    server.start();
    assertTrue(server.isStarted());
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ServerConnector(org.eclipse.jetty.server.ServerConnector) Connector(org.eclipse.jetty.server.Connector) Server(org.eclipse.jetty.server.Server) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 67 with Connector

use of org.eclipse.jetty.server.Connector in project symmetric-ds by JumpMind.

the class SymmetricWebServer method getConnectors.

protected Connector[] getConnectors(Server server, int port, int securePort, Mode mode) {
    ArrayList<Connector> connectors = new ArrayList<Connector>();
    HttpConfiguration httpConfig = new HttpConfiguration();
    if (mode.equals(Mode.HTTPS) || mode.equals(Mode.MIXED)) {
        httpConfig.setSecureScheme("https");
        httpConfig.setSecurePort(securePort);
    }
    httpConfig.setOutputBufferSize(32768);
    if (mode.equals(Mode.HTTP) || mode.equals(Mode.MIXED)) {
        ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(httpConfig));
        http.setPort(port);
        http.setHost(host);
        http.setIdleTimeout(maxIdleTime);
        connectors.add(http);
        log.info(String.format("About to start %s web server on host:port %s:%s", name, host == null ? "default" : host, port));
    }
    if (mode.equals(Mode.HTTPS) || mode.equals(Mode.MIXED)) {
        ISecurityService securityService = SecurityServiceFactory.create(SecurityServiceType.SERVER, new TypedProperties(System.getProperties()));
        securityService.installDefaultSslCert(host);
        String keyStorePassword = System.getProperty(SecurityConstants.SYSPROP_KEYSTORE_PASSWORD);
        keyStorePassword = (keyStorePassword != null) ? keyStorePassword : SecurityConstants.KEYSTORE_PASSWORD;
        SslContextFactory sslConnectorFactory = new SslContextFactory();
        sslConnectorFactory.setKeyManagerPassword(keyStorePassword);
        /* Prevent POODLE attack */
        String ignoredProtocols = System.getProperty(SecurityConstants.SYSPROP_SSL_IGNORE_PROTOCOLS);
        if (ignoredProtocols != null && ignoredProtocols.length() > 0) {
            String[] protocols = ignoredProtocols.split(",");
            sslConnectorFactory.addExcludeProtocols(protocols);
        } else {
            sslConnectorFactory.addExcludeProtocols("SSLv3");
        }
        String ignoredCiphers = System.getProperty(SecurityConstants.SYSPROP_SSL_IGNORE_CIPHERS);
        if (ignoredCiphers != null && ignoredCiphers.length() > 0) {
            String[] ciphers = ignoredCiphers.split(",");
            sslConnectorFactory.addExcludeCipherSuites(ciphers);
        }
        sslConnectorFactory.setCertAlias(System.getProperty(SecurityConstants.SYSPROP_KEYSTORE_CERT_ALIAS, SecurityConstants.ALIAS_SYM_PRIVATE_KEY));
        sslConnectorFactory.setKeyStore(securityService.getKeyStore());
        sslConnectorFactory.setTrustStore(securityService.getTrustStore());
        HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
        httpsConfig.addCustomizer(new SecureRequestCustomizer());
        ServerConnector https = new ServerConnector(server, new SslConnectionFactory(sslConnectorFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig));
        https.setPort(securePort);
        https.setIdleTimeout(maxIdleTime);
        https.setHost(host);
        connectors.add(https);
        log.info(String.format("About to start %s web server on secure host:port %s:%s", name, host == null ? "default" : host, securePort));
    }
    return connectors.toArray(new Connector[connectors.size()]);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Connector(org.eclipse.jetty.server.Connector) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ArrayList(java.util.ArrayList) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) TypedProperties(org.jumpmind.properties.TypedProperties) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ServerConnector(org.eclipse.jetty.server.ServerConnector) ISecurityService(org.jumpmind.security.ISecurityService) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory)

Example 68 with Connector

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

the class SPARQLServer method defaultServerConfig.

private static Server defaultServerConfig(int port, boolean loopback) {
    // Server, with one NIO-based connector, large input buffer size (for
    // long URLs, POSTed forms (queries, updates)).
    Server server = new Server();
    // Using "= new SelectChannelConnector() ;" on Darwin (OS/X) causes
    // problems
    // with initialization not seen (thread scheduling?) in Joseki.
    // BlockingChannelConnector is better for pumping large responses back
    // but there have been observed problems with DirectMemory allocation
    // (-XX:MaxDirectMemorySize=1G does not help)
    // Connector connector = new SelectChannelConnector() ;
    // Connector and specific settings.
    BlockingChannelConnector bcConnector = new BlockingChannelConnector();
    // bcConnector.setUseDirectBuffers(false) ;
    Connector connector = bcConnector;
    // Ignore. 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
    connector.setMaxIdleTime(0);
    // goes off.
    if (loopback)
        connector.setHost("localhost");
    connector.setPort(port);
    // Some people do try very large operations ...
    connector.setRequestHeaderSize(64 * 1024);
    connector.setRequestBufferSize(5 * 1024 * 1024);
    connector.setResponseBufferSize(5 * 1024 * 1024);
    server.addConnector(connector);
    return server;
}
Also used : BlockingChannelConnector(org.eclipse.jetty.server.nio.BlockingChannelConnector) Connector(org.eclipse.jetty.server.Connector) Server(org.eclipse.jetty.server.Server) BlockingChannelConnector(org.eclipse.jetty.server.nio.BlockingChannelConnector)

Example 69 with Connector

use of org.eclipse.jetty.server.Connector in project qi4j-sdk by Qi4j.

the class AbstractJettyMixin method stopJetty.

@Override
public final void stopJetty() throws Exception {
    server.stop();
    for (Connector connector : server.getConnectors()) {
        connector.stop();
    }
    server = null;
}
Also used : JettyConfigurationHelper.configureConnector(org.qi4j.library.http.JettyConfigurationHelper.configureConnector) NetworkConnector(org.eclipse.jetty.server.NetworkConnector) ServerConnector(org.eclipse.jetty.server.ServerConnector) Connector(org.eclipse.jetty.server.Connector)

Example 70 with Connector

use of org.eclipse.jetty.server.Connector in project qi4j-sdk by Qi4j.

the class AbstractJettyMixin method interfacesServed.

@Override
@SuppressWarnings("ValueOfIncrementOrDecrementUsed")
public final Interface[] interfacesServed() {
    Connector[] connectors = server.getConnectors();
    Interface[] result = new Interface[connectors.length];
    int index = 0;
    for (Connector connector : connectors) {
        if (connector instanceof NetworkConnector) {
            NetworkConnector netConnector = (NetworkConnector) connector;
            String host = configuration().hostName().get();
            if (host == null) {
                host = netConnector.getHost();
                if (// If serving all interfaces.
                host == null) {
                    try {
                        host = InetAddress.getLocalHost().getHostAddress();
                    } catch (UnknownHostException e) {
                        InternalError error = new InternalError("UnknownHost for local interface.");
                        error.initCause(e);
                        throw error;
                    }
                }
            }
            result[index++] = new InterfaceImpl(host, netConnector.getPort(), servedProtocol());
        }
    }
    return result;
}
Also used : JettyConfigurationHelper.configureConnector(org.qi4j.library.http.JettyConfigurationHelper.configureConnector) NetworkConnector(org.eclipse.jetty.server.NetworkConnector) ServerConnector(org.eclipse.jetty.server.ServerConnector) Connector(org.eclipse.jetty.server.Connector) UnknownHostException(java.net.UnknownHostException) NetworkConnector(org.eclipse.jetty.server.NetworkConnector)

Aggregations

Connector (org.eclipse.jetty.server.Connector)79 Server (org.eclipse.jetty.server.Server)41 ServerConnector (org.eclipse.jetty.server.ServerConnector)25 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)22 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)17 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)15 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)13 IOException (java.io.IOException)12 NetworkConnector (org.eclipse.jetty.server.NetworkConnector)12 Test (org.junit.Test)11 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)10 SelectChannelConnector (org.eclipse.jetty.server.nio.SelectChannelConnector)8 Test (org.testng.annotations.Test)8 Handler (org.eclipse.jetty.server.Handler)7 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)6 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)6 ServletException (javax.servlet.ServletException)5