Search in sources :

Example 16 with ServerConnector

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

the class JettyHttpComponent9 method createConnectorJettyInternal.

protected AbstractConnector createConnectorJettyInternal(Server server, JettyHttpEndpoint endpoint, SslContextFactory sslcf) {
    try {
        String host = endpoint.getHttpUri().getHost();
        int porto = endpoint.getPort();
        org.eclipse.jetty.server.HttpConfiguration httpConfig = new org.eclipse.jetty.server.HttpConfiguration();
        httpConfig.setSendServerVersion(endpoint.isSendServerVersion());
        httpConfig.setSendDateHeader(endpoint.isSendDateHeader());
        httpConfig.setSendDateHeader(endpoint.isSendDateHeader());
        if (requestBufferSize != null) {
        // Does not work
        //httpConfig.setRequestBufferSize(requestBufferSize);
        }
        if (requestHeaderSize != null) {
            httpConfig.setRequestHeaderSize(requestHeaderSize);
        }
        if (responseBufferSize != null) {
            httpConfig.setOutputBufferSize(responseBufferSize);
        }
        if (responseHeaderSize != null) {
            httpConfig.setResponseHeaderSize(responseHeaderSize);
        }
        if (useXForwardedForHeader) {
            httpConfig.addCustomizer(new ForwardedRequestCustomizer());
        }
        HttpConnectionFactory httpFactory = new org.eclipse.jetty.server.HttpConnectionFactory(httpConfig);
        ArrayList<ConnectionFactory> connectionFactories = new ArrayList<ConnectionFactory>();
        ServerConnector result = new org.eclipse.jetty.server.ServerConnector(server);
        if (sslcf != null) {
            httpConfig.addCustomizer(new org.eclipse.jetty.server.SecureRequestCustomizer());
            SslConnectionFactory scf = new org.eclipse.jetty.server.SslConnectionFactory(sslcf, "HTTP/1.1");
            connectionFactories.add(scf);
            // The protocol name can be "SSL" or "SSL-HTTP/1.1" depending on the version of Jetty
            result.setDefaultProtocol(scf.getProtocol());
        }
        connectionFactories.add(httpFactory);
        result.setConnectionFactories(connectionFactories);
        result.setPort(porto);
        if (host != null) {
            result.setHost(host);
        }
        if (getSslSocketConnectorProperties() != null && "https".equals(endpoint.getProtocol())) {
            // must copy the map otherwise it will be deleted
            Map<String, Object> properties = new HashMap<String, Object>(getSslSocketConnectorProperties());
            IntrospectionSupport.setProperties(sslcf, properties);
            if (properties.size() > 0) {
                throw new IllegalArgumentException("There are " + properties.size() + " parameters that couldn't be set on the SocketConnector." + " Check the uri if the parameters are spelt correctly and that they are properties of the SelectChannelConnector." + " Unknown parameters=[" + properties + "]");
            }
        }
        return result;
    } catch (Exception e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
    }
}
Also used : HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) JettyHttpEndpoint(org.apache.camel.component.jetty.JettyHttpEndpoint) URISyntaxException(java.net.URISyntaxException) ForwardedRequestCustomizer(org.eclipse.jetty.server.ForwardedRequestCustomizer) ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory)

Example 17 with ServerConnector

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

the class WssProducerTest method getConnector.

@Override
protected Connector getConnector() throws Exception {
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setSslContext(defineSSLContextServerParameters().createSSLContext(camelContext));
    ServerConnector https = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, null));
    return https;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory)

Example 18 with ServerConnector

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

the class CometdComponent method connect.

/**
     * Connects the URL specified on the endpoint to the specified processor.
     */
public void connect(CometdProducerConsumer prodcon) throws Exception {
    Server server = null;
    // Make sure that there is a connector for the requested endpoint.
    CometdEndpoint endpoint = prodcon.getEndpoint();
    String connectorKey = endpoint.getProtocol() + ":" + endpoint.getUri().getHost() + ":" + endpoint.getPort();
    synchronized (connectors) {
        ConnectorRef connectorRef = connectors.get(connectorKey);
        if (connectorRef == null) {
            ServerConnector connector;
            server = createServer();
            if ("cometds".equals(endpoint.getProtocol())) {
                connector = getSslSocketConnector(server);
            } else {
                connector = new ServerConnector(server);
            }
            connector.setPort(endpoint.getPort());
            connector.setHost(endpoint.getUri().getHost());
            if ("localhost".equalsIgnoreCase(endpoint.getUri().getHost())) {
                LOG.warn("You use localhost interface! It means that no external connections will be available." + " Don't you want to use 0.0.0.0 instead (all network interfaces)?");
            }
            server.addConnector(connector);
            CometDServlet servlet = createServletForConnector(server, connector, endpoint);
            connectorRef = new ConnectorRef(connector, servlet, server);
            server.start();
            connectors.put(connectorKey, connectorRef);
        } else {
            connectorRef.increment();
        }
        BayeuxServerImpl bayeux = connectorRef.servlet.getBayeux();
        if (securityPolicy != null) {
            bayeux.setSecurityPolicy(securityPolicy);
        }
        if (extensions != null) {
            for (BayeuxServer.Extension extension : extensions) {
                bayeux.addExtension(extension);
            }
        }
        if (serverListeners != null) {
            for (BayeuxServer.BayeuxServerListener serverListener : serverListeners) {
                bayeux.addListener(serverListener);
            }
        }
        prodcon.setBayeux(bayeux);
    }
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) BayeuxServerImpl(org.cometd.server.BayeuxServerImpl) Server(org.eclipse.jetty.server.Server) BayeuxServer(org.cometd.bayeux.server.BayeuxServer) BayeuxServer(org.cometd.bayeux.server.BayeuxServer) CometDServlet(org.cometd.server.CometDServlet)

Example 19 with ServerConnector

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

the class CometdComponent method getSslSocketConnector.

protected ServerConnector getSslSocketConnector(Server server) throws Exception {
    ServerConnector sslSocketConnector = null;
    if (sslContextParameters != null) {
        SslContextFactory sslContextFactory = new CometdComponentSslContextFactory();
        sslContextFactory.setSslContext(sslContextParameters.createSSLContext(getCamelContext()));
        sslSocketConnector = new ServerConnector(server, sslContextFactory);
    } else {
        SslContextFactory sslContextFactory = new SslContextFactory();
        sslContextFactory.setKeyStorePassword(sslKeyPassword);
        sslContextFactory.setKeyManagerPassword(sslPassword);
        if (sslKeystore != null) {
            sslContextFactory.setKeyStorePath(sslKeystore);
        }
        sslSocketConnector = new ServerConnector(server, sslContextFactory);
    }
    return sslSocketConnector;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory)

Example 20 with ServerConnector

use of org.eclipse.jetty.server.ServerConnector in project jetty.project by eclipse.

the class WeldInitializationTest method startServer.

@BeforeClass
public static void startServer() throws Exception {
    JettyLogHandler.config();
    server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(0);
    server.addConnector(connector);
    EmbeddedCdiHandler context = new EmbeddedCdiHandler();
    File baseDir = MavenTestingUtils.getTestResourcesDir();
    context.setBaseResource(Resource.newResource(baseDir));
    context.setContextPath("/");
    server.setHandler(context);
    // Add some servlets
    context.addServlet(TimeServlet.class, "/time");
    context.addServlet(RequestInfoServlet.class, "/req-info");
    server.start();
    String host = connector.getHost();
    if (host == null) {
        host = "localhost";
    }
    int port = connector.getLocalPort();
    serverHttpURI = new URI(String.format("http://%s:%d/", host, port));
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) Matchers.containsString(org.hamcrest.Matchers.containsString) File(java.io.File) URI(java.net.URI) BeforeClass(org.junit.BeforeClass)

Aggregations

ServerConnector (org.eclipse.jetty.server.ServerConnector)287 Server (org.eclipse.jetty.server.Server)211 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)87 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)80 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)66 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)61 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)52 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)52 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)44 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)43 URI (java.net.URI)37 Test (org.junit.Test)32 File (java.io.File)29 BeforeClass (org.junit.BeforeClass)29 IOException (java.io.IOException)27 Before (org.junit.Before)25 BeforeClass (org.testng.annotations.BeforeClass)22 ServletException (javax.servlet.ServletException)21 HttpServletRequest (javax.servlet.http.HttpServletRequest)19 Connector (org.eclipse.jetty.server.Connector)19