Search in sources :

Example 61 with HttpConnectionFactory

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

the class DataConstraintsTest method startServer.

@Before
public void startServer() {
    _server = new Server();
    HttpConnectionFactory http = new HttpConnectionFactory();
    http.getHttpConfiguration().setSecurePort(9999);
    http.getHttpConfiguration().setSecureScheme("BWTP");
    _connector = new LocalConnector(_server, http);
    _connector.setIdleTimeout(300000);
    HttpConnectionFactory https = new HttpConnectionFactory();
    https.getHttpConfiguration().addCustomizer(new HttpConfiguration.Customizer() {

        @Override
        public void customize(Connector connector, HttpConfiguration channelConfig, Request request) {
            request.setScheme(HttpScheme.HTTPS.asString());
            request.setSecure(true);
        }
    });
    _connectorS = new LocalConnector(_server, https);
    _server.setConnectors(new Connector[] { _connector, _connectorS });
    ContextHandler _context = new ContextHandler();
    _session = new SessionHandler();
    _context.setContextPath("/ctx");
    _server.setHandler(_context);
    _context.setHandler(_session);
    _security = new ConstraintSecurityHandler();
    _session.setHandler(_security);
    _security.setHandler(new AbstractHandler() {

        @Override
        public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            baseRequest.setHandled(true);
            response.sendError(404);
        }
    });
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) LocalConnector(org.eclipse.jetty.server.LocalConnector) Connector(org.eclipse.jetty.server.Connector) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) LocalConnector(org.eclipse.jetty.server.LocalConnector) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) IOException(java.io.IOException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) Before(org.junit.Before)

Example 62 with HttpConnectionFactory

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

the class AsyncMiddleManServletTest method startProxy.

private void startProxy(AsyncMiddleManServlet proxyServlet, Map<String, String> initParams) throws Exception {
    QueuedThreadPool proxyPool = new QueuedThreadPool();
    proxyPool.setName("proxy");
    proxy = new Server(proxyPool);
    HttpConfiguration configuration = new HttpConfiguration();
    configuration.setSendDateHeader(false);
    configuration.setSendServerVersion(false);
    String value = initParams.get("outputBufferSize");
    if (value != null)
        configuration.setOutputBufferSize(Integer.valueOf(value));
    proxyConnector = new ServerConnector(proxy, new HttpConnectionFactory(configuration));
    proxy.addConnector(proxyConnector);
    ServletContextHandler proxyContext = new ServletContextHandler(proxy, "/", true, false);
    ServletHolder proxyServletHolder = new ServletHolder(proxyServlet);
    proxyServletHolder.setInitParameters(initParams);
    proxyContext.addServlet(proxyServletHolder, "/*");
    proxy.start();
    stackless = new StacklessLogging(proxyServlet._log);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 63 with HttpConnectionFactory

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

the class ComplianceViolations2616Test method startServer.

@BeforeClass
public static void startServer() throws Exception {
    server = new Server();
    HttpConfiguration config = new HttpConfiguration();
    config.setSendServerVersion(false);
    HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory(config, HttpCompliance.RFC2616);
    httpConnectionFactory.setRecordHttpComplianceViolations(true);
    connector = new LocalConnector(server, null, null, null, -1, httpConnectionFactory);
    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    context.setWelcomeFiles(new String[] { "index.html", "index.jsp", "index.htm" });
    context.addServlet(DumpRequestHeadersServlet.class, "/dump/*");
    context.addFilter(ReportViolationsFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    server.setHandler(context);
    server.addConnector(connector);
    server.start();
}
Also used : Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) LocalConnector(org.eclipse.jetty.server.LocalConnector) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) BeforeClass(org.junit.BeforeClass)

Example 64 with HttpConnectionFactory

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

the class ProxyServletLoadTest method startProxy.

private void startProxy() throws Exception {
    QueuedThreadPool proxyPool = new QueuedThreadPool();
    proxyPool.setName("proxy");
    proxy = new Server(proxyPool);
    HttpConfiguration configuration = new HttpConfiguration();
    configuration.setSendDateHeader(false);
    configuration.setSendServerVersion(false);
    proxyConnector = new ServerConnector(proxy, new HttpConnectionFactory(configuration));
    proxy.addConnector(proxyConnector);
    ServletContextHandler proxyContext = new ServletContextHandler(proxy, "/", true, false);
    ServletHolder proxyServletHolder = new ServletHolder(proxyServlet);
    proxyContext.addServlet(proxyServletHolder, "/*");
    proxy.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 65 with HttpConnectionFactory

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

the class ReverseProxyTest method startProxy.

private void startProxy(Map<String, String> params) throws Exception {
    proxy = new Server();
    HttpConfiguration configuration = new HttpConfiguration();
    configuration.setSendDateHeader(false);
    configuration.setSendServerVersion(false);
    proxyConnector = new ServerConnector(proxy, new HttpConnectionFactory(configuration));
    proxy.addConnector(proxyConnector);
    ServletContextHandler proxyContext = new ServletContextHandler(proxy, "/", true, false);
    ServletHolder proxyServletHolder = new ServletHolder(new AsyncMiddleManServlet() {

        @Override
        protected String rewriteTarget(HttpServletRequest clientRequest) {
            StringBuilder builder = new StringBuilder();
            builder.append(clientRequest.getScheme()).append("://127.0.0.1:");
            builder.append(serverConnector.getLocalPort());
            builder.append(clientRequest.getRequestURI());
            String query = clientRequest.getQueryString();
            if (query != null)
                builder.append("?").append(query);
            return builder.toString();
        }
    });
    if (params != null)
        proxyServletHolder.setInitParameters(params);
    proxyContext.addServlet(proxyServletHolder, "/*");
    proxy.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpServletRequest(javax.servlet.http.HttpServletRequest) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Aggregations

HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)90 ServerConnector (org.eclipse.jetty.server.ServerConnector)79 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)69 Server (org.eclipse.jetty.server.Server)56 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)44 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)43 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)39 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)18 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)16 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)15 File (java.io.File)12 Connector (org.eclipse.jetty.server.Connector)12 IOException (java.io.IOException)11 ServletException (javax.servlet.ServletException)10 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 HTTP2ServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory)9 Before (org.junit.Before)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)8 ALPNServerConnectionFactory (org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory)8 Request (org.eclipse.jetty.server.Request)8