Search in sources :

Example 76 with ServerConnector

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

the class JspIncludeTest method startServer.

@BeforeClass
public static void startServer() throws Exception {
    // Setup Server
    server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(0);
    server.addConnector(connector);
    // Setup WebAppContext
    File testWebAppDir = MavenTestingUtils.getProjectDir("src/test/webapp");
    // Prepare WebApp libs
    File libDir = new File(testWebAppDir, "WEB-INF/lib");
    FS.ensureDirExists(libDir);
    File testTagLibDir = MavenTestingUtils.getProjectDir("src/test/taglibjar");
    JAR.create(testTagLibDir, new File(libDir, "testtaglib.jar"));
    // Configure WebAppContext
    Configuration.ClassList classlist = Configuration.ClassList.setServerDefault(server);
    classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration");
    WebAppContext context = new WebAppContext();
    context.setContextPath("/");
    File scratchDir = MavenTestingUtils.getTargetFile("tests/" + JspIncludeTest.class.getSimpleName() + "-scratch");
    FS.ensureEmpty(scratchDir);
    JspConfig.init(context, testWebAppDir.toURI(), scratchDir);
    server.setHandler(context);
    // Start Server
    server.start();
    // Figure out Base URI
    String host = connector.getHost();
    if (host == null) {
        host = "localhost";
    }
    int port = connector.getLocalPort();
    baseUri = new URI(String.format("http://%s:%d/", host, port));
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Server(org.eclipse.jetty.server.Server) Configuration(org.eclipse.jetty.webapp.Configuration) Matchers.containsString(org.hamcrest.Matchers.containsString) File(java.io.File) URI(java.net.URI) BeforeClass(org.junit.BeforeClass)

Example 77 with ServerConnector

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

the class OneConnector method main.

public static void main(String[] args) throws Exception {
    // The Server
    Server server = new Server();
    // HTTP connector
    ServerConnector http = new ServerConnector(server);
    http.setHost("localhost");
    http.setPort(8080);
    http.setIdleTimeout(30000);
    // Set the connector
    server.addConnector(http);
    // Set a handler
    server.setHandler(new HelloHandler());
    // Start the server
    server.start();
    server.join();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server)

Example 78 with ServerConnector

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

the class ProxyServer method main.

public static void main(String[] args) throws Exception {
    Server server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(8888);
    server.addConnector(connector);
    // Setup proxy handler to handle CONNECT methods
    ConnectHandler proxy = new ConnectHandler();
    server.setHandler(proxy);
    // Setup proxy servlet
    ServletContextHandler context = new ServletContextHandler(proxy, "/", ServletContextHandler.SESSIONS);
    ServletHolder proxyServlet = new ServletHolder(ProxyServlet.class);
    proxyServlet.setInitParameter("blackList", "www.eclipse.org");
    context.addServlet(proxyServlet, "/*");
    server.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ConnectHandler(org.eclipse.jetty.proxy.ConnectHandler) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 79 with ServerConnector

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

the class AbstractHttpClientServerTest method start.

public void start(Handler handler) throws Exception {
    server = new Server();
    ServerFCGIConnectionFactory fcgiConnectionFactory = new ServerFCGIConnectionFactory(new HttpConfiguration());
    serverBufferPool = new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged());
    connector = new ServerConnector(server, null, null, serverBufferPool, 1, Math.max(1, Runtime.getRuntime().availableProcessors() / 2), fcgiConnectionFactory);
    //        connector.setPort(9000);
    server.addConnector(connector);
    server.setHandler(handler);
    server.start();
    QueuedThreadPool executor = new QueuedThreadPool();
    executor.setName(executor.getName() + "-client");
    client = new HttpClient(new HttpClientTransportOverFCGI(1, false, "") {

        @Override
        public HttpDestination newHttpDestination(Origin origin) {
            return new HttpDestinationOverFCGI(client, origin) {

                @Override
                protected DuplexConnectionPool newConnectionPool(HttpClient client) {
                    return new LeakTrackingConnectionPool(this, client.getMaxConnectionsPerDestination(), this) {

                        @Override
                        protected void leaked(LeakDetector.LeakInfo leakInfo) {
                            connectionLeaks.incrementAndGet();
                        }
                    };
                }
            };
        }
    }, null);
    client.setExecutor(executor);
    clientBufferPool = new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged());
    client.setByteBufferPool(clientBufferPool);
    client.start();
}
Also used : Origin(org.eclipse.jetty.client.Origin) HttpDestinationOverFCGI(org.eclipse.jetty.fcgi.client.http.HttpDestinationOverFCGI) Server(org.eclipse.jetty.server.Server) LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) ServerConnector(org.eclipse.jetty.server.ServerConnector) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) HttpClient(org.eclipse.jetty.client.HttpClient) LeakTrackingConnectionPool(org.eclipse.jetty.client.LeakTrackingConnectionPool) HttpClientTransportOverFCGI(org.eclipse.jetty.fcgi.client.http.HttpClientTransportOverFCGI)

Example 80 with ServerConnector

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

the class FastCGIProxyServletTest method prepare.

public void prepare(HttpServlet servlet) throws Exception {
    QueuedThreadPool serverThreads = new QueuedThreadPool();
    serverThreads.setName("server");
    server = new Server(serverThreads);
    httpConnector = new ServerConnector(server);
    server.addConnector(httpConnector);
    fcgiConnector = new ServerConnector(server, new ServerFCGIConnectionFactory(new HttpConfiguration(), sendStatus200));
    server.addConnector(fcgiConnector);
    final String contextPath = "/";
    context = new ServletContextHandler(server, contextPath);
    final String servletPath = "/script";
    FastCGIProxyServlet fcgiServlet = new FastCGIProxyServlet() {

        @Override
        protected String rewriteTarget(HttpServletRequest request) {
            return "http://localhost:" + fcgiConnector.getLocalPort() + servletPath + request.getServletPath();
        }
    };
    ServletHolder fcgiServletHolder = new ServletHolder(fcgiServlet);
    fcgiServletHolder.setName("fcgi");
    fcgiServletHolder.setInitParameter(FastCGIProxyServlet.SCRIPT_ROOT_INIT_PARAM, "/scriptRoot");
    fcgiServletHolder.setInitParameter("proxyTo", "http://localhost");
    fcgiServletHolder.setInitParameter(FastCGIProxyServlet.SCRIPT_PATTERN_INIT_PARAM, "(.+?\\.php)");
    context.addServlet(fcgiServletHolder, "*.php");
    context.addServlet(new ServletHolder(servlet), servletPath + "/*");
    QueuedThreadPool clientThreads = new QueuedThreadPool();
    clientThreads.setName("client");
    client = new HttpClient();
    client.setExecutor(clientThreads);
    server.addBean(client);
    server.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpServletRequest(javax.servlet.http.HttpServletRequest) Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpClient(org.eclipse.jetty.client.HttpClient) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) ServerFCGIConnectionFactory(org.eclipse.jetty.fcgi.server.ServerFCGIConnectionFactory) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Aggregations

ServerConnector (org.eclipse.jetty.server.ServerConnector)291 Server (org.eclipse.jetty.server.Server)213 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)91 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)83 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)67 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)64 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)55 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)53 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)45 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)45 URI (java.net.URI)37 Test (org.junit.Test)32 File (java.io.File)30 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