Search in sources :

Example 1 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 2 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 3 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 4 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 5 with ServerConnector

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

the class HttpServer2 method stop.

/**
   * stop the server
   */
public void stop() throws Exception {
    MultiException exception = null;
    for (ServerConnector c : listeners) {
        try {
            c.close();
        } catch (Exception e) {
            LOG.error("Error while stopping listener for webapp" + webAppContext.getDisplayName(), e);
            exception = addMultiException(exception, e);
        }
    }
    try {
        // explicitly destroy the secret provider
        secretProvider.destroy();
        // clear & stop webAppContext attributes to avoid memory leaks.
        webAppContext.clearAttributes();
        webAppContext.stop();
    } catch (Exception e) {
        LOG.error("Error while stopping web app context for webapp " + webAppContext.getDisplayName(), e);
        exception = addMultiException(exception, e);
    }
    try {
        webServer.stop();
    } catch (Exception e) {
        LOG.error("Error while stopping web server for webapp " + webAppContext.getDisplayName(), e);
        exception = addMultiException(exception, e);
    }
    if (exception != null) {
        exception.ifExceptionThrow();
    }
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) MultiException(org.eclipse.jetty.util.MultiException) ServletException(javax.servlet.ServletException) MultiException(org.eclipse.jetty.util.MultiException) FileNotFoundException(java.io.FileNotFoundException) BindException(java.net.BindException) InterruptedIOException(java.io.InterruptedIOException) HadoopIllegalArgumentException(org.apache.hadoop.HadoopIllegalArgumentException) IOException(java.io.IOException)

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