Search in sources :

Example 16 with HttpConfiguration

use of org.eclipse.jetty.server.HttpConfiguration 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 17 with HttpConfiguration

use of org.eclipse.jetty.server.HttpConfiguration 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)

Example 18 with HttpConfiguration

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

the class AbstractTest method start.

protected void start(Handler handler) throws Exception {
    prepareServer(new HTTP2ServerConnectionFactory(new HttpConfiguration()));
    server.setHandler(handler);
    server.start();
    prepareClient();
    client.start();
}
Also used : RawHTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.RawHTTP2ServerConnectionFactory) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration)

Example 19 with HttpConfiguration

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

the class SecuredRedirectHandler method handle.

@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    HttpChannel channel = baseRequest.getHttpChannel();
    if (baseRequest.isSecure() || (channel == null)) {
        // nothing to do
        return;
    }
    HttpConfiguration httpConfig = channel.getHttpConfiguration();
    if (httpConfig == null) {
        // no config, show error
        response.sendError(HttpStatus.FORBIDDEN_403, "No http configuration available");
        return;
    }
    if (httpConfig.getSecurePort() > 0) {
        String scheme = httpConfig.getSecureScheme();
        int port = httpConfig.getSecurePort();
        String url = URIUtil.newURI(scheme, baseRequest.getServerName(), port, baseRequest.getRequestURI(), baseRequest.getQueryString());
        response.setContentLength(0);
        response.sendRedirect(url);
    } else {
        response.sendError(HttpStatus.FORBIDDEN_403, "Not Secure");
    }
    baseRequest.setHandled(true);
}
Also used : HttpChannel(org.eclipse.jetty.server.HttpChannel) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration)

Example 20 with HttpConfiguration

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

the class AsyncServletIOTest method setUp.

@Before
public void setUp() throws Exception {
    HttpConfiguration http_config = new HttpConfiguration();
    http_config.setOutputBufferSize(4096);
    _connector = new ServerConnector(_server, new HttpConnectionFactory(http_config));
    _server.setConnectors(new Connector[] { _connector });
    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/ctx");
    context.addEventListener(new DebugListener());
    _server.setHandler(context);
    _servletHandler = context.getServletHandler();
    ServletHolder holder = new ServletHolder(_servlet0);
    holder.setAsyncSupported(true);
    _servletHandler.addServletWithMapping(holder, "/path/*");
    ServletHolder holder2 = new ServletHolder(_servlet2);
    holder2.setAsyncSupported(true);
    _servletHandler.addServletWithMapping(holder2, "/path2/*");
    ServletHolder holder3 = new ServletHolder(_servlet3);
    holder3.setAsyncSupported(true);
    _servletHandler.addServletWithMapping(holder3, "/path3/*");
    ServletHolder holder4 = new ServletHolder(_servlet4);
    holder4.setAsyncSupported(true);
    _servletHandler.addServletWithMapping(holder4, "/path4/*");
    _server.start();
    _port = _connector.getLocalPort();
    _owp.set(0);
    _oda.set(0);
    _read.set(0);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) DebugListener(org.eclipse.jetty.server.DebugListener) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) Before(org.junit.Before)

Aggregations

HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)199 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)148 ServerConnector (org.eclipse.jetty.server.ServerConnector)148 Server (org.eclipse.jetty.server.Server)103 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)88 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)88 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)81 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)42 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)40 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)34 IOException (java.io.IOException)24 Connector (org.eclipse.jetty.server.Connector)23 File (java.io.File)20 HTTP2ServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory)18 HttpServletRequest (javax.servlet.http.HttpServletRequest)17 ServletException (javax.servlet.ServletException)15 HttpServletResponse (javax.servlet.http.HttpServletResponse)15 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)15 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)15 HTTP2CServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory)13