Package com.vtence.molecule.lib

Examples of com.vtence.molecule.lib.AbstractMiddleware


    private Matcher<Request> none() {
        return Matchers.nothing();
    }

    private AbstractMiddleware filter(final String name) {
        return new AbstractMiddleware() {
            public void handle(Request request, Response response) throws Exception {
                forward(request, response);
                response.set("content", format("%s(%s)", name, response.get("content")));
            }
        };
View Full Code Here


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

        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

Related Classes of com.vtence.molecule.lib.AbstractMiddleware

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.