Package com.vtence.molecule.routing

Examples of com.vtence.molecule.routing.DynamicRoutes


import java.io.IOException;

public class RoutingExample {

    public void run(WebServer server) throws IOException {
        server.start(new DynamicRoutes() {{

            map("/").to(new Application() {
                public void handle(Request request, Response response) throws Exception {
                    response.body("Welcome!");
                }
View Full Code Here


        final Template layout = templates.named("layout");
        final Template greeting = templates.named("greeting");

        // Apply a common layout to all rendered pages
        server.filter("/", Layout.html(layout))
              .start(new DynamicRoutes() {{
                  get("/hello").to(new Application() {
                      public void handle(final Request request, final Response response) throws Exception {
                          response.contentType("text/html; charset=utf-8");
                          String name = request.parameter("name") != null ? request.parameter("name") : "World";
                          // Mustache can use any object or a Map as a rendering context
View Full Code Here

        server.add(new HttpMethodOverride());

        final Map<Integer, Album> albums = new TreeMap<Integer, Album>();
        final Sequence sequence = new Sequence();

        server.start((new DynamicRoutes() {{
            get("/albums").to(new Application() {
                public void handle(Request request, Response response) throws Exception {
                    TextBody body = new TextBody();
                    for (int id : albums.keySet()) {
                        Album album = albums.get(id);
View Full Code Here

    public void run(WebServer server) throws IOException {
        // Track sessions using a cookie strategy and an in-memory session pool
        sessionTracker = new CookieSessionTracker(new SessionPool(new SecureIdentifierPolicy(), clock));
        server.add(sessionTracker)
              .start(new DynamicRoutes() {{
                         map("/").to(new Application() {
                             public void handle(Request request, Response response) throws Exception {
                                 Session session = Session.get(request);
                                 String username = session.contains("username") ? session.<String>get("username") : "Guest";
                                 response.body("Hello, " + username);
View Full Code Here

            }
        };

        // All requests to /private/... go through the authentication filter
        server.filter("/private", authenticate)
              .start(new DynamicRoutes() {{
                  // This route is private thus requires authentication
                  get("/private/area").to(new Application() {
                      public void handle(Request request, Response response) throws Exception {
                          response.body("Hello, " + request.attribute("user") + "!");
                      }
View Full Code Here

TOP

Related Classes of com.vtence.molecule.routing.DynamicRoutes

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.