Package com.jetdrone.vertx.yoke

Examples of com.jetdrone.vertx.yoke.Yoke


public class ResponseTime extends TestVerticle {

    @Test
    public void testResponseTime() {
        Yoke yoke = new Yoke(this);
        yoke.use(new com.jetdrone.vertx.yoke.middleware.ResponseTime());
        yoke.use(new Handler<YokeRequest>() {
            @Override
            public void handle(YokeRequest request) {
                request.response().end();
            }
        });
View Full Code Here


public class BasicAuth extends TestVerticle {

    @Test
    public void testBasicAuth() {
        final Yoke yoke = new Yoke(this);
        yoke.use(new com.jetdrone.vertx.yoke.middleware.BasicAuth("Aladdin", "open sesame"));
        yoke.use(new Middleware() {
            @Override
            public void handle(@NotNull YokeRequest request, @NotNull Handler<Object> next) {
                request.response().end();
            }
        });
View Full Code Here

        });
    }

    @Test
    public void testEmptyPassword() {
        final Yoke yoke = new Yoke(this);
        yoke.use(new com.jetdrone.vertx.yoke.middleware.BasicAuth(new AuthHandler() {
            @Override
            public void handle(String username, String password, Handler<JsonObject> result) {
                boolean success = username.equals("Aladdin") && password == null;
                if (success) {
                    result.handle(new JsonObject().putString("username", username));
                } else {
                    result.handle(null);
                }
            }
        }));

        yoke.use(new Middleware() {
            @Override
            public void handle(@NotNull YokeRequest request, @NotNull Handler<Object> next) {
                request.response().end();
            }
        });
View Full Code Here

    };

    @Test
    public void restTest() {

        Yoke yoke = new Yoke(this);
        JsonRestRouter restStore = new JsonRestRouter(dummyStore);
        restStore.rest("/persons", "persons");
        yoke.use(restStore);

        testComplete();
    }
View Full Code Here

public class FormAuthExample extends Verticle {

    @Override
    public void start() {

        final Yoke app = new Yoke(this);
        app.secretSecurity("keyboard cat");

        final Mac hmac = app.security().getMac("HmacSHA256");

        app.use(new BodyParser());
        app.use(new CookieParser(hmac));
        app.use(new Session(hmac));

        final FormAuth formAuth = new FormAuth(new AuthHandler() {
            @Override
            public void handle(String username, String password, Handler<JsonObject> result) {
                if ("foo".equals(username) && "bar".equals(password)) {
                    result.handle(new JsonObject().putString("username", "foo"));
                } else {
                    result.handle(null);
                }
            }
        });

        app.use(formAuth);

        app.use(new Router() {{
            get("/", new Handler<YokeRequest>() {
                @Override
                public void handle(YokeRequest request) {
                    JsonObject session = request.get("session");

                    if (session != null && session.getString("user") != null) {
                        request.response().setContentType("text/html");
                        request.response().end("Welcome " + session.getString("user") + "<br>" + "<a href='/logout'>logout</a>");
                    } else {
                        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>");
                }
            });
        }});

        app.listen(8000);
    }
View Full Code Here

public class YokeBench extends Verticle {

    @Override
    public void start() {

        new Yoke(this)
                .use(new Router()
                        .get("/", new Handler<YokeRequest>() {
                            @Override
                            public void handle(YokeRequest request) {
                                request.response().end("Hello World\n");
View Full Code Here

//
//oauthProvider.on('lookupGrant', function(clientId, clientSecret, code, res, callback) {
//  callback("userId");
//});

        final Yoke app = new Yoke(this);

        app.use(new ErrorHandler(true));

        app.use(new Logger());
        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));
                        } else {
                            // no token found
                            next.handle(403);
                        }
                }
            });
        }});

        app.listen(8081);
    }
View Full Code Here

public class HelmetTest extends TestVerticle {

    @Test
    public void testCacheControl() {
        final Yoke app = new Yoke(this);
        app.use(new CacheControl());
        app.use(new Handler<YokeRequest>() {
            @Override
            public void handle(YokeRequest request) {
                request.response().end("hello");
            }
        });
View Full Code Here

        });
    }

    @Test
    public void testContentTypeOptions() {
        final Yoke app = new Yoke(this);
        app.use(new ContentTypeOptions());
        app.use(new Handler<YokeRequest>() {
            @Override
            public void handle(YokeRequest request) {
                request.response().end("hello");
            }
        });
View Full Code Here

        });
    }

    @Test
    public void testCrossDomain() {
        final Yoke app = new Yoke(this);
        app.use(new CrossDomain());
        app.use(new Handler<YokeRequest>() {
            @Override
            public void handle(YokeRequest request) {
                request.response().end("hello");
            }
        });
View Full Code Here

TOP

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

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.