All Downloads are FREE. Search and download functionalities are using the official Maven repository.

netflix.karyon.examples.hellonoss.server.simple.module.RouterWithInterceptors Maven / Gradle / Ivy

The newest version!
package netflix.karyon.examples.hellonoss.server.simple.module;

import io.netty.buffer.ByteBuf;
import io.reactivex.netty.protocol.http.server.HttpServerRequest;
import io.reactivex.netty.protocol.http.server.HttpServerResponse;
import io.reactivex.netty.protocol.http.server.RequestHandler;
import netflix.karyon.examples.hellonoss.common.LoggingInterceptor;
import netflix.karyon.examples.hellonoss.common.auth.AuthInterceptor;
import netflix.karyon.examples.hellonoss.common.auth.AuthenticationServiceImpl;
import netflix.karyon.examples.hellonoss.server.simple.SimpleRouter;
import netflix.karyon.transport.http.HttpInterceptorSupport;
import netflix.karyon.transport.http.HttpRequestHandler;
import rx.Observable;

/**
 * @author Nitesh Kant
 */
public class RouterWithInterceptors implements RequestHandler {

    private final HttpRequestHandler delegate;

    public RouterWithInterceptors() {
        SimpleRouter router = new SimpleRouter();
        HttpInterceptorSupport interceptorSupport = new HttpInterceptorSupport();
        interceptorSupport.forUri("/*").intercept(new LoggingInterceptor());
        interceptorSupport.forUri("/hello").intercept(new AuthInterceptor(new AuthenticationServiceImpl()));
        delegate = new HttpRequestHandler(router, interceptorSupport);
    }

    @Override
    public Observable handle(HttpServerRequest request, HttpServerResponse response) {
        return delegate.handle(request, response);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy