Examples of Middleware


Examples of com.jetdrone.vertx.yoke.Middleware

public class Issue130 extends TestVerticle {

    @Test
    public void testRegEx() {
        Yoke yoke = new Yoke(this);
        yoke.use(new com.jetdrone.vertx.yoke.middleware.Router().get(Pattern.compile("^/url/.*"), new Middleware() {
            @Override
            public void handle(@NotNull YokeRequest request, @NotNull Handler<Object> next) {
                request.response().end("OK");
            }
        }));
View Full Code Here

Examples of com.jetdrone.vertx.yoke.Middleware

    }

    @Test
    public void testRegExEscaped() {
        Yoke yoke = new Yoke(this);
        yoke.use(new com.jetdrone.vertx.yoke.middleware.Router().get(Pattern.compile("^/url/.*"), new Middleware() {
            @Override
            public void handle(@NotNull YokeRequest request, @NotNull Handler<Object> next) {
                request.response().end("OK");
            }
        }));
View Full Code Here

Examples of com.jetdrone.vertx.yoke.Middleware

            out.close();
            final String location = temp.getAbsolutePath();

            Yoke yoke = new Yoke(this);
            yoke.engine("mvel", new MVELEngine(""));
            yoke.use(new Middleware() {
                @Override
                public void handle(YokeRequest request, Handler<Object> next) {
                    request.put("name", "Paulo");
                    request.response().render(location, next);
                }
View Full Code Here

Examples of com.jetdrone.vertx.yoke.Middleware

            out.close();
            final String location = temp.getAbsolutePath();

            Yoke yoke = new Yoke(this);
            yoke.engine("shtml", new com.jetdrone.vertx.yoke.engine.StringPlaceholderEngine(""));
            yoke.use(new Middleware() {
                @Override
                public void handle(@NotNull YokeRequest request, @NotNull Handler<Object> next) {
                    request.put("name", "Paulo");
                    request.response().render(location, next);
                }
View Full Code Here

Examples of com.jetdrone.vertx.yoke.Middleware

                public String exec(Map<String, Object> context, Object... args) {
                    return "Paulo " + args[0];
                }
            });
            yoke.engine("shtml", new com.jetdrone.vertx.yoke.engine.StringPlaceholderEngine(""));
            yoke.use(new Middleware() {
                @Override
                public void handle(@NotNull YokeRequest request, @NotNull Handler<Object> next) {
                    request.put("name", "Paulo");
                    request.response().render(location, next);
                }
View Full Code Here

Examples of com.jetdrone.vertx.yoke.Middleware

            out.close();
            final String location = temp.getAbsolutePath();

            Yoke yoke = new Yoke(this);
            yoke.engine("mvel", new MVELEngine(""));
            yoke.use(new Middleware() {
                @Override
                public void handle(YokeRequest request, Handler<Object> next) {
                    List<Map<String, String>> list = new ArrayList<>();
                    Map<String, String> item = new HashMap<>();
                    item.put("uri", "a");
View Full Code Here

Examples of com.vtence.molecule.lib.Middleware

public class FilterMap extends AbstractMiddleware {

    private final Map<Matcher<? super Request>, Middleware> filters = new LinkedHashMap<Matcher<? super Request>, Middleware>();

    public void handle(Request request, Response response) throws Exception {
        Middleware filter = filterMappedTo(request);
        filter.connectTo(successor);
        filter.handle(request, response);
    }
View Full Code Here

Examples of com.vtence.molecule.lib.Middleware

        filter.connectTo(successor);
        filter.handle(request, response);
    }

    private Middleware filterMappedTo(Request request) {
        Middleware bestMatch = new PassThrough();
        for (Matcher<? super Request> requestMatcher : filters.keySet()) {
            if (requestMatcher.matches(request)) bestMatch = filters.get(requestMatcher);
        }
        return bestMatch;
    }
View Full Code Here

Examples of com.vtence.molecule.lib.Middleware

public class CustomMiddlewareExample {

    public void run(WebServer server) throws IOException {

        // An example of performing some work before handling control to the next or application
        Middleware getFirefox = new AbstractMiddleware() {
            public void handle(Request request, Response response) throws Exception {
                // Tell IE users to get Firefox
                String userAgent = request.header("User-Agent");
                if (userAgent != null && userAgent.contains("MSIE")) {
                    response.redirectTo("http://www.mozilla.org");
                } else {
                    // Hand over control to next application in the stack
                    forward(request, response);
                }
            }
        };

        // An example of performing additional work after getting control back
        // (there's already a middleware for that, btw)
        Middleware contentLengthHeader = new AbstractMiddleware() {
            public void handle(Request request, Response response) throws Exception {
                forward(request, response);
                // Set content length header on the response
                response.contentLength(response.size());
            }
View Full Code Here

Examples of com.vtence.molecule.lib.Middleware

        users.put("admin", "admin");
    }

    public void run(WebServer server) throws IOException {
        // An an authentication filter that checks against a map of authorized users
        Middleware authenticate = new AbstractMiddleware() {
            public void handle(Request request, Response response) throws Exception {
                String user = request.parameter("username");
                String password = request.parameter("password");

                String token = users.get(user);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.