Search in sources :

Example 1 with Decorator

use of org.apache.hc.core5.function.Decorator in project httpcomponents-core by apache.

the class ClassicTestServer method start.

public void start(final Http1Config http1Config, final HttpProcessor httpProcessor, final Decorator<HttpServerRequestHandler> handlerDecorator) throws IOException {
    if (serverRef.get() == null) {
        final HttpServerRequestHandler handler = new BasicHttpServerRequestHandler(registry);
        final HttpService httpService = new HttpService(httpProcessor != null ? httpProcessor : HttpProcessors.server(), handlerDecorator != null ? handlerDecorator.decorate(handler) : new BasicHttpServerExpectationDecorator(handler), DefaultConnectionReuseStrategy.INSTANCE, LoggingHttp1StreamListener.INSTANCE);
        final HttpServer server = new HttpServer(0, httpService, null, socketConfig, sslContext != null ? sslContext.getServerSocketFactory() : ServerSocketFactory.getDefault(), new LoggingBHttpServerConnectionFactory(sslContext != null ? URIScheme.HTTPS.id : URIScheme.HTTP.id, http1Config != null ? http1Config : Http1Config.DEFAULT, CharCodingConfig.DEFAULT), null, LoggingExceptionListener.INSTANCE);
        if (serverRef.compareAndSet(null, server)) {
            server.start();
        }
    } else {
        throw new IllegalStateException("Server already running");
    }
}
Also used : BasicHttpServerExpectationDecorator(org.apache.hc.core5.http.io.support.BasicHttpServerExpectationDecorator) HttpServerRequestHandler(org.apache.hc.core5.http.io.HttpServerRequestHandler) BasicHttpServerRequestHandler(org.apache.hc.core5.http.io.support.BasicHttpServerRequestHandler) HttpService(org.apache.hc.core5.http.impl.io.HttpService) HttpServer(org.apache.hc.core5.http.impl.bootstrap.HttpServer) BasicHttpServerRequestHandler(org.apache.hc.core5.http.io.support.BasicHttpServerRequestHandler)

Example 2 with Decorator

use of org.apache.hc.core5.function.Decorator in project httpcomponents-core by apache.

the class H2TestServer method start.

public InetSocketAddress start(final HttpProcessor httpProcessor, final Decorator<AsyncServerExchangeHandler> exchangeHandlerDecorator, final H2Config h2Config) throws Exception {
    start(new InternalServerProtocolNegotiationStarter(httpProcessor != null ? httpProcessor : H2Processors.server(), new DefaultAsyncResponseExchangeHandlerFactory(registry, exchangeHandlerDecorator != null ? exchangeHandlerDecorator : BasicAsyncServerExpectationDecorator::new), HttpVersionPolicy.FORCE_HTTP_2, h2Config, Http1Config.DEFAULT, CharCodingConfig.DEFAULT, sslContext, sslSessionInitializer, sslSessionVerifier));
    final Future<ListenerEndpoint> future = listen(new InetSocketAddress(0));
    final ListenerEndpoint listener = future.get();
    return (InetSocketAddress) listener.getAddress();
}
Also used : ListenerEndpoint(org.apache.hc.core5.reactor.ListenerEndpoint) InetSocketAddress(java.net.InetSocketAddress) DefaultAsyncResponseExchangeHandlerFactory(org.apache.hc.core5.http.nio.support.DefaultAsyncResponseExchangeHandlerFactory)

Example 3 with Decorator

use of org.apache.hc.core5.function.Decorator in project httpcomponents-core by apache.

the class H2TestServer method start.

public InetSocketAddress start(final HttpProcessor httpProcessor, final Decorator<AsyncServerExchangeHandler> exchangeHandlerDecorator, final Http1Config http1Config) throws Exception {
    start(new InternalServerProtocolNegotiationStarter(httpProcessor != null ? httpProcessor : HttpProcessors.server(), new DefaultAsyncResponseExchangeHandlerFactory(registry, exchangeHandlerDecorator != null ? exchangeHandlerDecorator : BasicAsyncServerExpectationDecorator::new), HttpVersionPolicy.FORCE_HTTP_1, H2Config.DEFAULT, http1Config, CharCodingConfig.DEFAULT, sslContext, sslSessionInitializer, sslSessionVerifier));
    final Future<ListenerEndpoint> future = listen(new InetSocketAddress(0));
    final ListenerEndpoint listener = future.get();
    return (InetSocketAddress) listener.getAddress();
}
Also used : ListenerEndpoint(org.apache.hc.core5.reactor.ListenerEndpoint) InetSocketAddress(java.net.InetSocketAddress) DefaultAsyncResponseExchangeHandlerFactory(org.apache.hc.core5.http.nio.support.DefaultAsyncResponseExchangeHandlerFactory)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)2 DefaultAsyncResponseExchangeHandlerFactory (org.apache.hc.core5.http.nio.support.DefaultAsyncResponseExchangeHandlerFactory)2 ListenerEndpoint (org.apache.hc.core5.reactor.ListenerEndpoint)2 HttpServer (org.apache.hc.core5.http.impl.bootstrap.HttpServer)1 HttpService (org.apache.hc.core5.http.impl.io.HttpService)1 HttpServerRequestHandler (org.apache.hc.core5.http.io.HttpServerRequestHandler)1 BasicHttpServerExpectationDecorator (org.apache.hc.core5.http.io.support.BasicHttpServerExpectationDecorator)1 BasicHttpServerRequestHandler (org.apache.hc.core5.http.io.support.BasicHttpServerRequestHandler)1