Package com.vtence.molecule

Examples of com.vtence.molecule.Application


    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);
                             }
                         });

                         post("/login").to(new Application() {
                             public void handle(Request request, Response response) throws Exception {
                                 String username = request.parameter("username");
                                 Session session = Session.get(request);
                                 session.put("username", username);
                                 response.redirectTo("/");
                             }
                         });

                         delete("/logout").to(new Application() {
                             public void handle(Request request, Response response) throws Exception {
                                 Session session = Session.get(request);
                                 session.invalidate();
                                 response.redirectTo("/");
                             }
View Full Code Here


public class SimpleExample {

    public void run(WebServer server) throws IOException {
        // Capture internal server errors and display a 500 page
        server.add(new Failsafe());
        server.start(new Application() {
            public void handle(Request request, Response response) throws Exception {
                // An unsupported charset will cause an exception, which will cause the FailSafe middleware
                // to render a 500 page
                Charset encoding = Charset.forName(request.parameter("encoding"));
                // The specified charset will be used automatically to encode the response
View Full Code Here

            }
        };


        // A simple hello world application
        Application helloWorld = new Application() {
            public void handle(Request request, Response response) throws Exception {
                response.contentType("text/html").body("<html><body>Hello, World</body></html>");
            }
        };
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") + "!");
                      }
                  });

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

import java.io.IOException;

public class HelloWorldExample {

    public void run(WebServer server) throws IOException {
        server.start(new Application() {
            public void handle(Request request, Response response) throws Exception {
                response.body("Hello, World!");
            }
        });
    }
View Full Code Here

              // Add ETag if response has no validation information
              .add(new ETag())
              // Compress bodies that are not images
              .add(new Compressor().compressibleTypes(JAVASCRIPT, CSS, HTML))
              .add(assets)
              .start(new Application() {
                  public void handle(Request request, Response response) throws Exception {
                      response.set(CONTENT_TYPE, HTML);
                      response.set(LAST_MODIFIED, request.parameter("timestamp"));
                      response.body(index.render(NO_CONTEXT));
                  }
View Full Code Here

    MockRequest request = new MockRequest();
    MockResponse response = new MockResponse();

    @Test public void
    setsETagByComputingMD5HashOfResponseBody() throws Exception {
        etag.connectTo(new Application() {
            public void handle(Request request, Response response) throws Exception {
                response.body("response body");
            }
        });
        etag.handle(request, response);
View Full Code Here

        response.assertHeader("ETag", "\"91090ad25c02ffd89cd46ae8b28fcdde\"");
    }

    @Test public void
    willNotSetETagIfBodyIsEmpty() throws Exception {
        etag.connectTo(new Application() {
            public void handle(Request request, Response response) throws Exception {
                response.body("");
            }
        });
        etag.handle(request, response);
View Full Code Here

        response.assertNoHeader("ETag");
    }

    @Test public void
    willNotSetETagIfStatusIsNotCacheable() throws Exception {
        etag.connectTo(new Application() {
            public void handle(Request request, Response response) throws Exception {
                response.status(HttpStatus.NOT_FOUND);
                response.body("Not found: resource");
            }
        });
View Full Code Here

        response.assertNoHeader("ETag");
    }

    @Test public void
    willSetETagIfStatusIsCreated() throws Exception {
        etag.connectTo(new Application() {
            public void handle(Request request, Response response) throws Exception {
                response.status(HttpStatus.CREATED);
                response.body("response body");
            }
        });
View Full Code Here

TOP

Related Classes of com.vtence.molecule.Application

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.