Search in sources :

Example 1 with BasicServerExchangeHandler

use of org.apache.hc.core5.http.nio.support.BasicServerExchangeHandler in project californium by eclipse.

the class HttpServer method registerProxy.

/**
 * Register proxy request handler.
 *
 * The proxy handler is used for all requests, which contains a
 * {@code absoluteURI}, which is not related to one of the used virtual
 * handlers.
 *
 * @param <T> request presentation
 * @param requestHandler request handler to register
 * @throws NullPointerException if request handler is {@code null}
 * @throws IllegalStateException if server was already started
 * @see #registerVirtual(String, String, AsyncServerRequestHandler)
 * @see <a href="https://tools.ietf.org/html/rfc2616#section-5.1.2" target=
 *      "_blank"> RFC2616, HTTP/1.1 - 5.1.2 Request-URI</a>
 * @since 3.0
 */
public <T> void registerProxy(final AsyncServerRequestHandler<T> requestHandler) {
    if (server != null) {
        throw new IllegalStateException("http server already started!");
    }
    Args.notNull(requestHandler, "Request handler");
    proxyServerFilter = new TerminalAsyncServerFilter(new HandlerFactory<AsyncServerExchangeHandler>() {

        @Override
        public AsyncServerExchangeHandler create(HttpRequest request, HttpContext context) throws HttpException {
            return new BasicServerExchangeHandler<>(requestHandler);
        }
    });
}
Also used : HttpRequest(org.apache.hc.core5.http.HttpRequest) HandlerFactory(org.apache.hc.core5.http.nio.HandlerFactory) HttpContext(org.apache.hc.core5.http.protocol.HttpContext) TerminalAsyncServerFilter(org.apache.hc.core5.http.nio.support.TerminalAsyncServerFilter) BasicServerExchangeHandler(org.apache.hc.core5.http.nio.support.BasicServerExchangeHandler)

Aggregations

HttpRequest (org.apache.hc.core5.http.HttpRequest)1 HandlerFactory (org.apache.hc.core5.http.nio.HandlerFactory)1 BasicServerExchangeHandler (org.apache.hc.core5.http.nio.support.BasicServerExchangeHandler)1 TerminalAsyncServerFilter (org.apache.hc.core5.http.nio.support.TerminalAsyncServerFilter)1 HttpContext (org.apache.hc.core5.http.protocol.HttpContext)1