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

netflix.karyon.examples.hellonoss.server.simple.SimpleRouter Maven / Gradle / Ivy

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

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.health.HealthCheck;
import netflix.karyon.transport.http.SimpleUriRouter;
import netflix.karyon.transport.http.health.HealthCheckEndpoint;
import rx.Observable;

/**
 * A {@link RequestHandler} implementation for this example.
 *
 * @author Nitesh Kant
 */
public class SimpleRouter implements RequestHandler {

    private final SimpleUriRouter delegate;

    public SimpleRouter() {
        final HelloWorldEndpoint endpoint = new HelloWorldEndpoint();
        delegate = new SimpleUriRouter();

        delegate.addUri("/healthcheck",
                        new HealthCheckEndpoint(new HealthCheck()))
                .addUri("/hello",
                        new RequestHandler() {
                            @Override
                            public Observable handle(
                                    HttpServerRequest request,
                                    HttpServerResponse response) {
                                return endpoint.sayHello(response);
                            }
                        })
                .addUri("/hello/to/*",
                        new RequestHandler() {
                            @Override
                            public Observable handle(HttpServerRequest request,
                                                           HttpServerResponse response) {
                                return endpoint.sayHelloToUser(request, response);
                            }
                        });
    }

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy