Search in sources :

Example 21 with Connector

use of org.eclipse.jetty.server.Connector in project otter by alibaba.

the class JettyEmbedIntegration method main.

public static void main(String[] args) throws Exception {
    Resource jetty_xml = Resource.newSystemResource("jetty/jetty.xml");
    XmlConfiguration configuration = new XmlConfiguration(jetty_xml.getInputStream());
    Server server = (Server) configuration.configure();
    int port = 8081;
    Connector[] connectors = server.getConnectors();
    for (Connector connector : connectors) {
        connector.setPort(port);
    }
    Handler handler = server.getHandler();
    if (handler != null && handler instanceof ServletContextHandler) {
        ServletContextHandler servletHandler = (ServletContextHandler) handler;
        servletHandler.getInitParams().put("org.eclipse.jetty.servlet.Default.resourceBase", "/tmp/");
    }
    server.start();
    server.join();
}
Also used : Connector(org.eclipse.jetty.server.Connector) Server(org.eclipse.jetty.server.Server) Resource(org.eclipse.jetty.util.resource.Resource) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Handler(org.eclipse.jetty.server.Handler) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 22 with Connector

use of org.eclipse.jetty.server.Connector in project otter by alibaba.

the class JettyEmbedServer method afterPropertiesSet.

public void afterPropertiesSet() throws Exception {
    Resource configXml = Resource.newSystemResource(config);
    XmlConfiguration configuration = new XmlConfiguration(configXml.getInputStream());
    server = (Server) configuration.configure();
    Integer port = getPort();
    if (port != null && port > 0) {
        Connector[] connectors = server.getConnectors();
        for (Connector connector : connectors) {
            connector.setPort(port);
        }
    }
    Handler handler = server.getHandler();
    if (handler != null && handler instanceof ServletContextHandler) {
        ServletContextHandler servletHandler = (ServletContextHandler) handler;
        servletHandler.getInitParams().put("org.eclipse.jetty.servlet.Default.resourceBase", htdocsDir);
    }
    server.start();
    if (logger.isInfoEnabled()) {
        logger.info("##Jetty Embed Server is startup!");
    }
}
Also used : Connector(org.eclipse.jetty.server.Connector) Resource(org.eclipse.jetty.util.resource.Resource) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Handler(org.eclipse.jetty.server.Handler) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 23 with Connector

use of org.eclipse.jetty.server.Connector in project rest.li by linkedin.

the class HttpsJettyServer method getConnectors.

@Override
protected Connector[] getConnectors(Server server) {
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(_keyStore);
    sslContextFactory.setKeyStorePassword(_keyStorePassword);
    sslContextFactory.setTrustStorePath(_keyStore);
    sslContextFactory.setTrustStorePassword(_keyStorePassword);
    HttpConfiguration configuration = new HttpConfiguration();
    configuration.addCustomizer(new SecureRequestCustomizer());
    ServerConnector sslConnector = new ServerConnector(server, sslContextFactory, new HttpConnectionFactory(configuration, HttpCompliance.RFC2616));
    sslConnector.setPort(_sslPort);
    Connector[] httpConnectors = super.getConnectors(server);
    Connector[] connectors = new Connector[httpConnectors.length + 1];
    int i = 0;
    for (Connector c : httpConnectors) {
        connectors[i++] = c;
    }
    connectors[i++] = sslConnector;
    return connectors;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ServerConnector(org.eclipse.jetty.server.ServerConnector) Connector(org.eclipse.jetty.server.Connector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration)

Example 24 with Connector

use of org.eclipse.jetty.server.Connector in project rest.li by linkedin.

the class H2cJettyServer method getConnectors.

@Override
protected Connector[] getConnectors(Server server) {
    HttpConfiguration configuration = new HttpConfiguration();
    ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(configuration, HttpCompliance.RFC2616), new HTTP2CServerConnectionFactory(configuration));
    connector.setPort(_port);
    return new Connector[] { connector };
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ServerConnector(org.eclipse.jetty.server.ServerConnector) Connector(org.eclipse.jetty.server.Connector) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HTTP2CServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration)

Example 25 with Connector

use of org.eclipse.jetty.server.Connector in project h2o-3 by h2oai.

the class JettyHTTPD method startHttp.

protected void startHttp() throws Exception {
    _server = new Server();
    //    QueuedThreadPool p = new QueuedThreadPool();
    //    p.setName("jetty-h2o");
    //    p.setMinThreads(3);
    //    p.setMaxThreads(50);
    //    p.setMaxIdleTimeMs(3000);
    //    _server.setThreadPool(p);
    Connector connector = new SocketConnector();
    connector.setHost(_ip);
    connector.setPort(_port);
    createServer(connector);
}
Also used : SslSocketConnector(org.eclipse.jetty.server.ssl.SslSocketConnector) SocketConnector(org.eclipse.jetty.server.bio.SocketConnector) Connector(org.eclipse.jetty.server.Connector) RequestServer(water.api.RequestServer) Server(org.eclipse.jetty.server.Server) SslSocketConnector(org.eclipse.jetty.server.ssl.SslSocketConnector) SocketConnector(org.eclipse.jetty.server.bio.SocketConnector)

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