Search in sources :

Example 1 with AjpOpenListener

use of io.undertow.server.protocol.ajp.AjpOpenListener in project wildfly by wildfly.

the class AjpListenerService method createOpenListener.

@Override
protected OpenListener createOpenListener() {
    AjpOpenListener ajpOpenListener = new AjpOpenListener(getBufferPool().get(), OptionMap.builder().addAll(commonOptions).addAll(listenerOptions).set(UndertowOptions.ENABLE_CONNECTOR_STATISTICS, getUndertowService().isStatisticsEnabled()).getMap());
    ajpOpenListener.setScheme(scheme);
    return ajpOpenListener;
}
Also used : AjpOpenListener(io.undertow.server.protocol.ajp.AjpOpenListener)

Example 2 with AjpOpenListener

use of io.undertow.server.protocol.ajp.AjpOpenListener in project undertow by undertow-io.

the class DefaultServer method runInternal.

private static void runInternal(final RunNotifier notifier) {
    if (openssl && OPENSSL_FAILURE != null) {
        throw new RuntimeException(OPENSSL_FAILURE);
    }
    if (first) {
        first = false;
        xnio = Xnio.getInstance("nio", DefaultServer.class.getClassLoader());
        try {
            worker = xnio.createWorker(OptionMap.builder().set(Options.WORKER_IO_THREADS, 8).set(Options.CONNECTION_HIGH_WATER, 1000000).set(Options.CONNECTION_LOW_WATER, 1000000).set(Options.WORKER_TASK_CORE_THREADS, 30).set(Options.WORKER_TASK_MAX_THREADS, 30).set(Options.TCP_NODELAY, true).set(Options.CORK, true).getMap());
            serverOptions = OptionMap.builder().set(Options.TCP_NODELAY, true).set(Options.BACKLOG, 1000).set(Options.REUSE_ADDRESSES, true).set(Options.BALANCING_TOKENS, 1).set(Options.BALANCING_CONNECTIONS, 2).getMap();
            final SSLContext serverContext = createSSLContext(loadKeyStore(SERVER_KEY_STORE), loadKeyStore(SERVER_TRUST_STORE), false);
            UndertowXnioSsl ssl = new UndertowXnioSsl(worker.getXnio(), OptionMap.EMPTY, SSL_BUFFER_POOL, serverContext);
            if (ajp) {
                openListener = new AjpOpenListener(pool);
                acceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(openListener));
                if (apache) {
                    int port = 8888;
                    server = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), port), acceptListener, serverOptions);
                } else {
                    server = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), 7777 + PROXY_OFFSET), acceptListener, serverOptions);
                    proxyOpenListener = new HttpOpenListener(pool, OptionMap.create(UndertowOptions.BUFFER_PIPELINED_DATA, true));
                    proxyAcceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(proxyOpenListener));
                    proxyServer = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), getHostPort(DEFAULT)), proxyAcceptListener, serverOptions);
                    proxyOpenListener.setRootHandler(new ProxyHandler(loadBalancingProxyClient = new LoadBalancingProxyClient(GSSAPIAuthenticationMechanism.EXCLUSIVITY_CHECKER).addHost(new URI("ajp", null, getHostAddress(DEFAULT), getHostPort(DEFAULT) + PROXY_OFFSET, "/", null, null)), 120000, HANDLE_404));
                    proxyServer.resumeAccepts();
                }
            } else if (h2 && isAlpnEnabled()) {
                openListener = new Http2OpenListener(pool, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true, UndertowOptions.HTTP2_PADDING_SIZE, 10));
                acceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(new AlpnOpenListener(pool).addProtocol(Http2OpenListener.HTTP2, (io.undertow.server.DelegateOpenListener) openListener, 10)));
                SSLContext clientContext = createSSLContext(loadKeyStore(CLIENT_KEY_STORE), loadKeyStore(CLIENT_TRUST_STORE), true);
                server = ssl.createSslConnectionServer(worker, new InetSocketAddress(getHostAddress("default"), 7777 + PROXY_OFFSET), acceptListener, serverOptions);
                server.resumeAccepts();
                proxyOpenListener = new HttpOpenListener(pool, OptionMap.create(UndertowOptions.BUFFER_PIPELINED_DATA, true));
                proxyAcceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(proxyOpenListener));
                proxyServer = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), getHostPort(DEFAULT)), proxyAcceptListener, serverOptions);
                ProxyHandler proxyHandler = new ProxyHandler(loadBalancingProxyClient = new LoadBalancingProxyClient(GSSAPIAuthenticationMechanism.EXCLUSIVITY_CHECKER).addHost(new URI("h2", null, getHostAddress(DEFAULT), getHostPort(DEFAULT) + PROXY_OFFSET, "/", null, null), null, new UndertowXnioSsl(xnio, OptionMap.EMPTY, SSL_BUFFER_POOL, clientContext), OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)), 120000, HANDLE_404);
                setupProxyHandlerForSSL(proxyHandler);
                proxyOpenListener.setRootHandler(proxyHandler);
                proxyServer.resumeAccepts();
            } else if (h2c || h2cUpgrade) {
                openListener = new HttpOpenListener(pool, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true, UndertowOptions.HTTP2_PADDING_SIZE, 10));
                acceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(openListener));
                InetSocketAddress targetAddress = new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), getHostPort(DEFAULT) + PROXY_OFFSET);
                server = worker.createStreamConnectionServer(targetAddress, acceptListener, serverOptions);
                proxyOpenListener = new HttpOpenListener(pool, OptionMap.create(UndertowOptions.BUFFER_PIPELINED_DATA, true));
                proxyAcceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(proxyOpenListener));
                proxyServer = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), getHostPort(DEFAULT)), proxyAcceptListener, serverOptions);
                ProxyHandler proxyHandler = new ProxyHandler(loadBalancingProxyClient = new LoadBalancingProxyClient(GSSAPIAuthenticationMechanism.EXCLUSIVITY_CHECKER).addHost(new URI(h2cUpgrade ? "http" : "h2c-prior", null, getHostAddress(DEFAULT), getHostPort(DEFAULT) + PROXY_OFFSET, "/", null, null), null, null, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)), 30000, HANDLE_404);
                setupProxyHandlerForSSL(proxyHandler);
                proxyOpenListener.setRootHandler(proxyHandler);
                proxyServer.resumeAccepts();
            } else if (https) {
                XnioSsl clientSsl = new UndertowXnioSsl(xnio, OptionMap.EMPTY, SSL_BUFFER_POOL, createClientSslContext());
                openListener = new HttpOpenListener(pool, OptionMap.create(UndertowOptions.BUFFER_PIPELINED_DATA, true));
                acceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(openListener));
                server = ssl.createSslConnectionServer(worker, new InetSocketAddress(getHostAddress("default"), 7777 + PROXY_OFFSET), acceptListener, serverOptions);
                server.getAcceptSetter().set(acceptListener);
                server.resumeAccepts();
                proxyOpenListener = new HttpOpenListener(pool, OptionMap.create(UndertowOptions.BUFFER_PIPELINED_DATA, true));
                proxyAcceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(proxyOpenListener));
                proxyServer = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), getHostPort(DEFAULT)), proxyAcceptListener, serverOptions);
                ProxyHandler proxyHandler = new ProxyHandler(loadBalancingProxyClient = new LoadBalancingProxyClient(GSSAPIAuthenticationMechanism.EXCLUSIVITY_CHECKER).addHost(new URI("https", null, getHostAddress(DEFAULT), getHostPort(DEFAULT) + PROXY_OFFSET, "/", null, null), clientSsl), 30000, HANDLE_404);
                setupProxyHandlerForSSL(proxyHandler);
                proxyOpenListener.setRootHandler(proxyHandler);
                proxyServer.resumeAccepts();
            } else {
                if (h2) {
                    UndertowLogger.ROOT_LOGGER.error("HTTP2 selected but Netty ALPN was not on the boot class path");
                }
                openListener = new HttpOpenListener(pool, OptionMap.create(UndertowOptions.BUFFER_PIPELINED_DATA, true, UndertowOptions.ENABLE_CONNECTOR_STATISTICS, true));
                acceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(openListener));
                if (!proxy) {
                    server = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), getHostPort(DEFAULT)), acceptListener, serverOptions);
                } else {
                    InetSocketAddress targetAddress = new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), getHostPort(DEFAULT) + PROXY_OFFSET);
                    server = worker.createStreamConnectionServer(targetAddress, acceptListener, serverOptions);
                    proxyOpenListener = new HttpOpenListener(pool, OptionMap.create(UndertowOptions.BUFFER_PIPELINED_DATA, true));
                    proxyAcceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(proxyOpenListener));
                    proxyServer = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), getHostPort(DEFAULT)), proxyAcceptListener, serverOptions);
                    ProxyHandler proxyHandler = new ProxyHandler(loadBalancingProxyClient = new LoadBalancingProxyClient(GSSAPIAuthenticationMechanism.EXCLUSIVITY_CHECKER).addHost(new URI("http", null, getHostAddress(DEFAULT), getHostPort(DEFAULT) + PROXY_OFFSET, "/", null, null)), 30000, HANDLE_404);
                    setupProxyHandlerForSSL(proxyHandler);
                    proxyOpenListener.setRootHandler(proxyHandler);
                    proxyServer.resumeAccepts();
                }
            }
            if (h2cUpgrade) {
                openListener.setRootHandler(new Http2UpgradeHandler(rootHandler));
            } else {
                openListener.setRootHandler(rootHandler);
            }
            server.resumeAccepts();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        notifier.addListener(new RunListener() {

            @Override
            public void testRunFinished(final Result result) throws Exception {
                server.close();
                stopSSLServer();
                worker.shutdown();
            }
        });
    }
}
Also used : AlpnOpenListener(io.undertow.server.protocol.http.AlpnOpenListener) XnioSsl(org.xnio.ssl.XnioSsl) UndertowXnioSsl(io.undertow.protocols.ssl.UndertowXnioSsl) Http2UpgradeHandler(io.undertow.server.protocol.http2.Http2UpgradeHandler) ProxyHandler(io.undertow.server.handlers.proxy.ProxyHandler) InetSocketAddress(java.net.InetSocketAddress) Xnio(org.xnio.Xnio) SSLContext(javax.net.ssl.SSLContext) Http2OpenListener(io.undertow.server.protocol.http2.Http2OpenListener) URI(java.net.URI) KeyStoreException(java.security.KeyStoreException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) LoadBalancingProxyClient(io.undertow.server.handlers.proxy.LoadBalancingProxyClient) RunListener(org.junit.runner.notification.RunListener) Result(org.junit.runner.Result) AjpOpenListener(io.undertow.server.protocol.ajp.AjpOpenListener) UndertowXnioSsl(io.undertow.protocols.ssl.UndertowXnioSsl) HttpOpenListener(io.undertow.server.protocol.http.HttpOpenListener)

Example 3 with AjpOpenListener

use of io.undertow.server.protocol.ajp.AjpOpenListener in project undertow by undertow-io.

the class DefaultServer method startServer.

/**
 * Starts the server if it is not up, and initiates the static fields in this class. This method is invoked
 * automatically once before your tests are triggered when using {@code DefaultServer} as a {@code Runner}.
 * After this method executes, getter methods can be invoked safely.
 * <p>
 * To perform an action in your test before the server starts, such as {@link #setServerOptions(OptionMap)},
 * use {@link BeforeServerStarts @BeforeServerStarts} methods. To perform an action precisely after the server
 * starts and before the test method runs, use {@code @BeforeClass} or {@code @Before} methods.
 */
public static boolean startServer() {
    if (openssl && OPENSSL_FAILURE != null) {
        throw new RuntimeException(OPENSSL_FAILURE);
    }
    if (server != null) {
        return false;
    }
    Xnio xnio = Xnio.getInstance("nio", DefaultServer.class.getClassLoader());
    try {
        worker = xnio.createWorker(OptionMap.builder().set(Options.WORKER_IO_THREADS, 8).set(Options.CONNECTION_HIGH_WATER, 1000000).set(Options.CONNECTION_LOW_WATER, 1000000).set(Options.WORKER_TASK_CORE_THREADS, 30).set(Options.WORKER_TASK_MAX_THREADS, 30).set(Options.TCP_NODELAY, true).set(Options.CORK, true).getMap());
        serverOptions = serverOptionMapBuilder.set(Options.TCP_NODELAY, true).set(Options.BACKLOG, 1000).set(Options.REUSE_ADDRESSES, true).set(Options.BALANCING_TOKENS, 1).set(Options.BALANCING_CONNECTIONS, 2).getMap();
        final SSLContext serverContext = createSSLContext(loadKeyStore(SERVER_KEY_STORE), loadKeyStore(SERVER_TRUST_STORE), false);
        UndertowXnioSsl ssl = new UndertowXnioSsl(worker.getXnio(), OptionMap.EMPTY, SSL_BUFFER_POOL, serverContext);
        if (ajp) {
            openListener = new AjpOpenListener(pool);
            acceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(openListener));
            if (apache) {
                int port = 8888;
                server = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), port), acceptListener, serverOptions);
            } else {
                server = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), 7777 + PROXY_OFFSET), acceptListener, serverOptions);
                proxyOpenListener = new HttpOpenListener(pool, OptionMap.create(UndertowOptions.BUFFER_PIPELINED_DATA, true));
                proxyAcceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(proxyOpenListener));
                proxyServer = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), getHostPort(DEFAULT)), proxyAcceptListener, serverOptions);
                loadBalancingProxyClient = new LoadBalancingProxyClient(GSSAPIAuthenticationMechanism.EXCLUSIVITY_CHECKER).addHost(new URI("ajp", null, getHostAddress(DEFAULT), getHostPort(DEFAULT) + PROXY_OFFSET, "/", null, null));
                ProxyHandler proxyHandler = ProxyHandler.builder().setProxyClient(loadBalancingProxyClient).setMaxRequestTime(120000).setNext(HANDLE_404).setReuseXForwarded(true).build();
                proxyOpenListener.setRootHandler(proxyHandler);
                proxyServer.resumeAccepts();
            }
        } else if (h2 && isAlpnEnabled()) {
            openListener = new Http2OpenListener(pool, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true, UndertowOptions.HTTP2_PADDING_SIZE, 10));
            acceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(new AlpnOpenListener(pool).addProtocol(Http2OpenListener.HTTP2, (io.undertow.server.DelegateOpenListener) openListener, 10)));
            SSLContext clientContext = createSSLContext(loadKeyStore(CLIENT_KEY_STORE), loadKeyStore(CLIENT_TRUST_STORE), true);
            server = ssl.createSslConnectionServer(worker, new InetSocketAddress(getHostAddress("default"), 7777 + PROXY_OFFSET), acceptListener, serverOptions);
            server.resumeAccepts();
            proxyOpenListener = new HttpOpenListener(pool, OptionMap.create(UndertowOptions.BUFFER_PIPELINED_DATA, true));
            proxyAcceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(proxyOpenListener));
            proxyServer = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), getHostPort(DEFAULT)), proxyAcceptListener, serverOptions);
            loadBalancingProxyClient = new LoadBalancingProxyClient(GSSAPIAuthenticationMechanism.EXCLUSIVITY_CHECKER).addHost(new URI("h2", null, getHostAddress(DEFAULT), getHostPort(DEFAULT) + PROXY_OFFSET, "/", null, null), null, new UndertowXnioSsl(xnio, OptionMap.EMPTY, SSL_BUFFER_POOL, clientContext), OptionMap.create(UndertowOptions.ENABLE_HTTP2, true));
            ProxyHandler proxyHandler = ProxyHandler.builder().setProxyClient(loadBalancingProxyClient).setMaxRequestTime(120000).setNext(HANDLE_404).setReuseXForwarded(true).build();
            setupProxyHandlerForSSL(proxyHandler);
            proxyOpenListener.setRootHandler(proxyHandler);
            proxyServer.resumeAccepts();
        } else if (h2c || h2cUpgrade) {
            openListener = new HttpOpenListener(pool, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true, UndertowOptions.HTTP2_PADDING_SIZE, 10));
            acceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(openListener));
            InetSocketAddress targetAddress = new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), getHostPort(DEFAULT) + PROXY_OFFSET);
            server = worker.createStreamConnectionServer(targetAddress, acceptListener, serverOptions);
            proxyOpenListener = new HttpOpenListener(pool, OptionMap.create(UndertowOptions.BUFFER_PIPELINED_DATA, true));
            proxyAcceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(proxyOpenListener));
            proxyServer = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), getHostPort(DEFAULT)), proxyAcceptListener, serverOptions);
            loadBalancingProxyClient = new LoadBalancingProxyClient(GSSAPIAuthenticationMechanism.EXCLUSIVITY_CHECKER).addHost(new URI(h2cUpgrade ? "http" : "h2c-prior", null, getHostAddress(DEFAULT), getHostPort(DEFAULT) + PROXY_OFFSET, "/", null, null), null, null, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true));
            ProxyHandler proxyHandler = ProxyHandler.builder().setProxyClient(loadBalancingProxyClient).setMaxRequestTime(30000).setNext(HANDLE_404).setReuseXForwarded(true).build();
            setupProxyHandlerForSSL(proxyHandler);
            proxyOpenListener.setRootHandler(proxyHandler);
            proxyServer.resumeAccepts();
        } else if (https) {
            XnioSsl clientSsl = new UndertowXnioSsl(xnio, OptionMap.EMPTY, SSL_BUFFER_POOL, createClientSslContext());
            openListener = new HttpOpenListener(pool, OptionMap.create(UndertowOptions.BUFFER_PIPELINED_DATA, true));
            acceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(openListener));
            server = ssl.createSslConnectionServer(worker, new InetSocketAddress(getHostAddress("default"), 7777 + PROXY_OFFSET), acceptListener, serverOptions);
            server.getAcceptSetter().set(acceptListener);
            server.resumeAccepts();
            proxyOpenListener = new HttpOpenListener(pool, OptionMap.create(UndertowOptions.BUFFER_PIPELINED_DATA, true));
            proxyAcceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(proxyOpenListener));
            proxyServer = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), getHostPort(DEFAULT)), proxyAcceptListener, serverOptions);
            loadBalancingProxyClient = new LoadBalancingProxyClient(GSSAPIAuthenticationMechanism.EXCLUSIVITY_CHECKER).addHost(new URI("https", null, getHostAddress(DEFAULT), getHostPort(DEFAULT) + PROXY_OFFSET, "/", null, null), clientSsl);
            ProxyHandler proxyHandler = ProxyHandler.builder().setProxyClient(loadBalancingProxyClient).setMaxRequestTime(30000).setNext(HANDLE_404).setReuseXForwarded(true).build();
            setupProxyHandlerForSSL(proxyHandler);
            proxyOpenListener.setRootHandler(proxyHandler);
            proxyServer.resumeAccepts();
        } else {
            if (h2) {
                UndertowLogger.ROOT_LOGGER.error("HTTP2 selected but Netty ALPN was not on the boot class path");
            }
            openListener = new HttpOpenListener(pool, OptionMap.builder().set(UndertowOptions.BUFFER_PIPELINED_DATA, true).set(UndertowOptions.ENABLE_CONNECTOR_STATISTICS, true).set(UndertowOptions.REQUIRE_HOST_HTTP11, true).getMap());
            acceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(openListener));
            if (!proxy) {
                server = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), getHostPort(DEFAULT)), acceptListener, serverOptions);
            } else {
                InetSocketAddress targetAddress = new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), getHostPort(DEFAULT) + PROXY_OFFSET);
                server = worker.createStreamConnectionServer(targetAddress, acceptListener, serverOptions);
                proxyOpenListener = new HttpOpenListener(pool, OptionMap.create(UndertowOptions.BUFFER_PIPELINED_DATA, true));
                proxyAcceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(proxyOpenListener));
                proxyServer = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), getHostPort(DEFAULT)), proxyAcceptListener, serverOptions);
                loadBalancingProxyClient = new LoadBalancingProxyClient(GSSAPIAuthenticationMechanism.EXCLUSIVITY_CHECKER).addHost(new URI("http", null, getHostAddress(DEFAULT), getHostPort(DEFAULT) + PROXY_OFFSET, "/", null, null));
                ProxyHandler proxyHandler = ProxyHandler.builder().setProxyClient(loadBalancingProxyClient).setMaxRequestTime(30000).setNext(HANDLE_404).setReuseXForwarded(true).build();
                setupProxyHandlerForSSL(proxyHandler);
                proxyOpenListener.setRootHandler(proxyHandler);
                proxyServer.resumeAccepts();
            }
        }
        if (h2cUpgrade) {
            openListener.setRootHandler(new Http2UpgradeHandler(rootHandler));
        } else {
            openListener.setRootHandler(rootHandler);
        }
        server.resumeAccepts();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return true;
}
Also used : AlpnOpenListener(io.undertow.server.protocol.http.AlpnOpenListener) XnioSsl(org.xnio.ssl.XnioSsl) UndertowXnioSsl(io.undertow.protocols.ssl.UndertowXnioSsl) Http2UpgradeHandler(io.undertow.server.protocol.http2.Http2UpgradeHandler) ProxyHandler(io.undertow.server.handlers.proxy.ProxyHandler) InetSocketAddress(java.net.InetSocketAddress) Xnio(org.xnio.Xnio) SSLContext(javax.net.ssl.SSLContext) SNISSLContext(io.undertow.protocols.ssl.SNISSLContext) Http2OpenListener(io.undertow.server.protocol.http2.Http2OpenListener) URI(java.net.URI) KeyStoreException(java.security.KeyStoreException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) LoadBalancingProxyClient(io.undertow.server.handlers.proxy.LoadBalancingProxyClient) AjpOpenListener(io.undertow.server.protocol.ajp.AjpOpenListener) Xnio(org.xnio.Xnio) UndertowXnioSsl(io.undertow.protocols.ssl.UndertowXnioSsl) HttpOpenListener(io.undertow.server.protocol.http.HttpOpenListener)

Example 4 with AjpOpenListener

use of io.undertow.server.protocol.ajp.AjpOpenListener in project undertow by undertow-io.

the class Undertow method start.

public synchronized void start() {
    UndertowLogger.ROOT_LOGGER.infof("starting server: %s", Version.getFullVersionString());
    xnio = Xnio.getInstance(Undertow.class.getClassLoader());
    channels = new ArrayList<>();
    try {
        if (internalWorker) {
            worker = xnio.createWorker(OptionMap.builder().set(Options.WORKER_IO_THREADS, ioThreads).set(Options.CONNECTION_HIGH_WATER, 1000000).set(Options.CONNECTION_LOW_WATER, 1000000).set(Options.WORKER_TASK_CORE_THREADS, workerThreads).set(Options.WORKER_TASK_MAX_THREADS, workerThreads).set(Options.TCP_NODELAY, true).set(Options.CORK, true).addAll(workerOptions).getMap());
        }
        OptionMap socketOptions = OptionMap.builder().set(Options.WORKER_IO_THREADS, worker.getIoThreadCount()).set(Options.TCP_NODELAY, true).set(Options.REUSE_ADDRESSES, true).set(Options.BALANCING_TOKENS, 1).set(Options.BALANCING_CONNECTIONS, 2).set(Options.BACKLOG, 1000).addAll(this.socketOptions).getMap();
        OptionMap serverOptions = OptionMap.builder().set(UndertowOptions.NO_REQUEST_TIMEOUT, 60 * 1000).addAll(this.serverOptions).getMap();
        ByteBufferPool buffers = this.byteBufferPool;
        if (buffers == null) {
            buffers = new DefaultByteBufferPool(directBuffers, bufferSize, -1, 4);
        }
        listenerInfo = new ArrayList<>();
        for (ListenerConfig listener : listeners) {
            UndertowLogger.ROOT_LOGGER.debugf("Configuring listener with protocol %s for interface %s and port %s", listener.type, listener.host, listener.port);
            final HttpHandler rootHandler = listener.rootHandler != null ? listener.rootHandler : this.rootHandler;
            OptionMap socketOptionsWithOverrides = OptionMap.builder().addAll(socketOptions).addAll(listener.overrideSocketOptions).getMap();
            if (listener.type == ListenerType.AJP) {
                AjpOpenListener openListener = new AjpOpenListener(buffers, serverOptions);
                openListener.setRootHandler(rootHandler);
                final ChannelListener<StreamConnection> finalListener;
                if (listener.useProxyProtocol) {
                    finalListener = new ProxyProtocolOpenListener(openListener, null, buffers, OptionMap.EMPTY);
                } else {
                    finalListener = openListener;
                }
                ChannelListener<AcceptingChannel<StreamConnection>> acceptListener = ChannelListeners.openListenerAdapter(finalListener);
                AcceptingChannel<? extends StreamConnection> server = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(listener.host), listener.port), acceptListener, socketOptionsWithOverrides);
                server.resumeAccepts();
                channels.add(server);
                listenerInfo.add(new ListenerInfo("ajp", server.getLocalAddress(), openListener, null, server));
            } else {
                OptionMap undertowOptions = OptionMap.builder().set(UndertowOptions.BUFFER_PIPELINED_DATA, true).addAll(serverOptions).getMap();
                boolean http2 = serverOptions.get(UndertowOptions.ENABLE_HTTP2, false);
                if (listener.type == ListenerType.HTTP) {
                    HttpOpenListener openListener = new HttpOpenListener(buffers, undertowOptions);
                    HttpHandler handler = rootHandler;
                    if (http2) {
                        handler = new Http2UpgradeHandler(handler);
                    }
                    openListener.setRootHandler(handler);
                    final ChannelListener<StreamConnection> finalListener;
                    if (listener.useProxyProtocol) {
                        finalListener = new ProxyProtocolOpenListener(openListener, null, buffers, OptionMap.EMPTY);
                    } else {
                        finalListener = openListener;
                    }
                    ChannelListener<AcceptingChannel<StreamConnection>> acceptListener = ChannelListeners.openListenerAdapter(finalListener);
                    AcceptingChannel<? extends StreamConnection> server = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(listener.host), listener.port), acceptListener, socketOptionsWithOverrides);
                    server.resumeAccepts();
                    channels.add(server);
                    listenerInfo.add(new ListenerInfo("http", server.getLocalAddress(), openListener, null, server));
                } else if (listener.type == ListenerType.HTTPS) {
                    OpenListener openListener;
                    HttpOpenListener httpOpenListener = new HttpOpenListener(buffers, undertowOptions);
                    httpOpenListener.setRootHandler(rootHandler);
                    if (http2) {
                        AlpnOpenListener alpn = new AlpnOpenListener(buffers, undertowOptions, httpOpenListener);
                        Http2OpenListener http2Listener = new Http2OpenListener(buffers, undertowOptions);
                        http2Listener.setRootHandler(rootHandler);
                        alpn.addProtocol(Http2OpenListener.HTTP2, http2Listener, 10);
                        alpn.addProtocol(Http2OpenListener.HTTP2_14, http2Listener, 7);
                        openListener = alpn;
                    } else {
                        openListener = httpOpenListener;
                    }
                    UndertowXnioSsl xnioSsl;
                    if (listener.sslContext != null) {
                        xnioSsl = new UndertowXnioSsl(xnio, OptionMap.create(Options.USE_DIRECT_BUFFERS, true), listener.sslContext, sslEngineDelegatedTaskExecutor);
                    } else {
                        OptionMap.Builder builder = OptionMap.builder().addAll(socketOptionsWithOverrides);
                        if (!socketOptionsWithOverrides.contains(Options.SSL_PROTOCOL)) {
                            builder.set(Options.SSL_PROTOCOL, "TLSv1.2");
                        }
                        xnioSsl = new UndertowXnioSsl(xnio, OptionMap.create(Options.USE_DIRECT_BUFFERS, true), JsseSslUtils.createSSLContext(listener.keyManagers, listener.trustManagers, new SecureRandom(), builder.getMap()), sslEngineDelegatedTaskExecutor);
                    }
                    AcceptingChannel<? extends StreamConnection> sslServer;
                    if (listener.useProxyProtocol) {
                        ChannelListener<AcceptingChannel<StreamConnection>> acceptListener = ChannelListeners.openListenerAdapter(new ProxyProtocolOpenListener(openListener, xnioSsl, buffers, socketOptionsWithOverrides));
                        sslServer = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(listener.host), listener.port), (ChannelListener) acceptListener, socketOptionsWithOverrides);
                    } else {
                        ChannelListener<AcceptingChannel<StreamConnection>> acceptListener = ChannelListeners.openListenerAdapter(openListener);
                        sslServer = xnioSsl.createSslConnectionServer(worker, new InetSocketAddress(Inet4Address.getByName(listener.host), listener.port), (ChannelListener) acceptListener, socketOptionsWithOverrides);
                    }
                    sslServer.resumeAccepts();
                    channels.add(sslServer);
                    listenerInfo.add(new ListenerInfo("https", sslServer.getLocalAddress(), openListener, xnioSsl, sslServer));
                }
            }
        }
    } catch (Exception e) {
        if (internalWorker && worker != null) {
            worker.shutdownNow();
        }
        throw new RuntimeException(e);
    }
}
Also used : DefaultByteBufferPool(io.undertow.server.DefaultByteBufferPool) ByteBufferPool(io.undertow.connector.ByteBufferPool) AlpnOpenListener(io.undertow.server.protocol.http.AlpnOpenListener) ChannelListener(org.xnio.ChannelListener) InetSocketAddress(java.net.InetSocketAddress) Http2OpenListener(io.undertow.server.protocol.http2.Http2OpenListener) ProxyProtocolOpenListener(io.undertow.server.protocol.proxy.ProxyProtocolOpenListener) HttpHandler(io.undertow.server.HttpHandler) DefaultByteBufferPool(io.undertow.server.DefaultByteBufferPool) Http2UpgradeHandler(io.undertow.server.protocol.http2.Http2UpgradeHandler) Http2OpenListener(io.undertow.server.protocol.http2.Http2OpenListener) AlpnOpenListener(io.undertow.server.protocol.http.AlpnOpenListener) ProxyProtocolOpenListener(io.undertow.server.protocol.proxy.ProxyProtocolOpenListener) AjpOpenListener(io.undertow.server.protocol.ajp.AjpOpenListener) OpenListener(io.undertow.server.OpenListener) HttpOpenListener(io.undertow.server.protocol.http.HttpOpenListener) SecureRandom(java.security.SecureRandom) StreamConnection(org.xnio.StreamConnection) IOException(java.io.IOException) AjpOpenListener(io.undertow.server.protocol.ajp.AjpOpenListener) OptionMap(org.xnio.OptionMap) HttpOpenListener(io.undertow.server.protocol.http.HttpOpenListener) UndertowXnioSsl(io.undertow.protocols.ssl.UndertowXnioSsl) AcceptingChannel(org.xnio.channels.AcceptingChannel)

Aggregations

AjpOpenListener (io.undertow.server.protocol.ajp.AjpOpenListener)4 UndertowXnioSsl (io.undertow.protocols.ssl.UndertowXnioSsl)3 AlpnOpenListener (io.undertow.server.protocol.http.AlpnOpenListener)3 HttpOpenListener (io.undertow.server.protocol.http.HttpOpenListener)3 Http2OpenListener (io.undertow.server.protocol.http2.Http2OpenListener)3 Http2UpgradeHandler (io.undertow.server.protocol.http2.Http2UpgradeHandler)3 IOException (java.io.IOException)3 InetSocketAddress (java.net.InetSocketAddress)3 LoadBalancingProxyClient (io.undertow.server.handlers.proxy.LoadBalancingProxyClient)2 ProxyHandler (io.undertow.server.handlers.proxy.ProxyHandler)2 URI (java.net.URI)2 KeyManagementException (java.security.KeyManagementException)2 KeyStoreException (java.security.KeyStoreException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 UnrecoverableKeyException (java.security.UnrecoverableKeyException)2 CertificateException (java.security.cert.CertificateException)2 SSLContext (javax.net.ssl.SSLContext)2 Xnio (org.xnio.Xnio)2 XnioSsl (org.xnio.ssl.XnioSsl)2 ByteBufferPool (io.undertow.connector.ByteBufferPool)1