Package com.jetdrone.vertx.yoke

Examples of com.jetdrone.vertx.yoke.Middleware


    @Test
    public void issue121() {
        //route everything start with hello
        Pattern p = Pattern.compile("^/hello(/|$).*");
        new com.jetdrone.vertx.yoke.middleware.Router().get(p, new Middleware() {
            @Override
            public void handle(@NotNull YokeRequest request, @NotNull Handler<Object> next) {

            }
        });
View Full Code Here


public class YokeRequestTest extends TestVerticle {

    @Test
    public void testAccept() {
        final Yoke yoke = new Yoke(this);
        yoke.use(new Middleware() {
            @Override
            public void handle(@NotNull YokeRequest request, @NotNull Handler<Object> next) {
                assertNotNull(request.accepts("application/json"));
                testComplete();
            }
View Full Code Here

    }

    @Test
    public void testNormalizedPath() {
        final Yoke yoke = new Yoke(this);
        yoke.use(new Middleware() {
            @Override
            public void handle(@NotNull YokeRequest request, @NotNull Handler<Object> next) {
                assertEquals("/pom.xml", request.normalizedPath());
                testComplete();
            }
View Full Code Here

    }

    @Test
    public void testNormalizedPath2() {
        final Yoke yoke = new Yoke(this);
        yoke.use(new Middleware() {
            @Override
            public void handle(@NotNull YokeRequest request, @NotNull Handler<Object> next) {
                assertEquals("/", request.normalizedPath());
                testComplete();
            }
View Full Code Here

    public void process(Router router, Object instance, Class<?> clazz, Field field) {
        // NOOP
    }

    private static Middleware wrap(final Object instance, final MethodHandle m) {
        return new Middleware() {
            @Override
            public void handle(@NotNull YokeRequest request, @NotNull Handler<Object> next) {
                try {
                    m.invoke(instance, request, next);
                } catch (Throwable e) {
View Full Code Here

    }

    @Test
    public void testNormalizedPath3() {
        final Yoke yoke = new Yoke(this);
        yoke.use(new Middleware() {
            @Override
            public void handle(@NotNull YokeRequest request, @NotNull Handler<Object> next) {
                assertNull(request.normalizedPath());
                testComplete();
            }
View Full Code Here

                        request.response().end("<a href='/login'> Login</a>");
                    }
                }
            });

            get("/profile", formAuth.RequiredAuth, new Middleware() {
                @Override
                public void handle(YokeRequest request, Handler<Object> next) {
                    JsonObject session = request.get("session");
                    request.response().setContentType("text/html");
                    request.response().end("Profile page of " + session.getString("user") + "<br>" + " click to <a href='/logout'>logout</a>");
View Full Code Here

        app.use(new BodyParser());
        app.use(new CookieParser());
        app.use(new Session(mac));
        app.use(oauthProvider);
        app.use(new Router() {{
            get("/", new Middleware() {
                @Override
                public void handle(final YokeRequest request, final Handler<Object> next) {
                    request.loadSessionData(new Handler<JsonObject>() {
                        @Override
                        public void handle(JsonObject session) {
                            if (session == null) {
                                request.response().end("home, logged in? false");
                            } else {
                                System.out.println(session.encodePrettily());
                                request.response().end("home, logged in? " + (session.getString("user") != null));
                            }
                        }
                    });
                }
            });

            get("/login", new Middleware() {
                @Override
                public void handle(final YokeRequest request, Handler<Object> next) {
                    request.loadSessionData(new Handler<JsonObject>() {
                        @Override
                        public void handle(JsonObject session) {
                            if (session != null && session.getString("user") != null) {
                                request.response().redirect(303, "/");
                                return;
                            }

                            String next_url = request.getParameter("next", "/");
                            request.response().end("<html><form method=\"post\" action=\"/login\"><input type=\"hidden\" name=\"next\" value=\"" + next_url + "\"><input type=\"text\" placeholder=\"username\" name=\"username\"><input type=\"password\" placeholder=\"password\" name=\"password\"><button type=\"submit\">Login</button></form>");
                        }
                    });
                }
            });

            post("/login", new Middleware() {
                @Override
                public void handle(final YokeRequest request, final Handler<Object> next) {
                    JsonObject session = new JsonObject();
                    session.putString("user", request.getFormParameter("username"));

                    request.saveSessionData(session, new Handler<String>() {
                        @Override
                        public void handle(String status) {
                            if (!"ok".equals(status)) {
                                next.handle(status);
                                return;
                            }
                            request.response().redirect(303, request.getFormParameter("next", "/"));
                        }
                    });
                }
            });

            get("/logout", new Middleware() {
                @Override
                public void handle(YokeRequest request, Handler<Object> next) {
                    request.destroySession();
                    request.response().redirect(303, "/");
                }
            });

            get("/protected_resource", new Middleware() {
                @Override
                public void handle(YokeRequest request, Handler<Object> next) {
                        if (request.getParameter("access_token") != null) {
                            String accessToken = request.getParameter("access_token");
                            request.response().end(new JsonObject().putString("access_token", accessToken));
View Full Code Here

        jRouter.handle(request, next);
    }

    private static Middleware wrapClosure(final Closure closure) {
        final int params = closure.getMaximumNumberOfParameters();
        return new Middleware() {
            @Override
            public void handle(@NotNull YokeRequest request, @NotNull Handler<Object> next) {
                if (params == 1) {
                    closure.call(request);
                } else if (params == 2) {
View Full Code Here

public class AppTest extends TestVerticle {

    @Test
    public void testApp() {
        final Yoke yoke = new Yoke(this);
        yoke.use(new Middleware() {
            @Override
            public void handle(@NotNull YokeRequest request, @NotNull Handler<Object> next) {
                request.response().end("OK");
            }
        });
View Full Code Here

TOP

Related Classes of com.jetdrone.vertx.yoke.Middleware

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.