Package spark

Examples of spark.Route


                } catch (NumberFormatException ex) {
                    return 1;
                }
            }
        });
        get(new Route("/plaintext") {
            @Override
            public Object handle(final Request request, final Response response) {
                response.type(CONTENT_TYPE_TEXT);
                return MESSAGE;
            }
View Full Code Here


import spark.Route;
import spark.Spark;

public class SparkRoutes {
    public static void main(String[] args) {
        Spark.get(new Route("/") {
            @Override
            public Object handle(final Request request, final Response response) {
                return "Hello World\n";
            }
        });

        Spark.get(new Route("/test") {
            @Override
            public Object handle(final Request request, final Response response) {
                return "This is a test page\n";
            }
        });

        Spark.get(new Route("/echo/:thing") {
            @Override
            public Object handle(final Request request, final Response response) {
                return request.params(":thing");
            }
        });
View Full Code Here

    public static void main(String[] args) {
        final Configuration configuration = new Configuration();
        configuration.setClassForTemplateLoading(
                HelloWorldSparkFreemarkerStyle.class, "/");

        Spark.get(new Route("/") {
            @Override
            public Object handle(final Request request,
                                 final Response response) {
                StringWriter writer = new StringWriter();
                try {
View Full Code Here

        // Configure Freemarker
        final Configuration configuration = new Configuration();
        configuration.setClassForTemplateLoading(SparkFormHandling.class, "/");

        // Configure routes
        Spark.get(new Route("/") {
            @Override
            public Object handle(final Request request, final Response response) {
                try {

                    Map<String, Object> fruitsMap = new HashMap<String, Object>();
                    fruitsMap.put("fruits",
                            Arrays.asList("apple", "orange", "banana", "peach"));

                    Template fruitPickerTemplate =
                            configuration.getTemplate("fruitPicker.ftl");
                    StringWriter writer = new StringWriter();
                    fruitPickerTemplate.process(fruitsMap, writer);
                    return writer;

                } catch (Exception e) {
                    halt(500);
                    return null;
                }
            }
        });

        Spark.post(new Route("/favorite_fruit") {
            @Override
            public Object handle(final Request request, final Response response) {
                final String fruit = request.queryParams("fruit");
                if (fruit == null) {
                    return "Why don't you pick one?";
View Full Code Here

        DB database = client.getDB("course");
        final DBCollection collection = database.getCollection("hello");


        Spark.get(new Route("/") {
            @Override
            public Object handle(final Request request,
                                 final Response response) {
                StringWriter writer = new StringWriter();
                try {
View Full Code Here

import spark.Route;
import spark.Spark;

public class HelloWorldSparkStyle {
    public static void main(String[] args) {
        Spark.get(new Route("/") {
            @Override
            public Object handle(final Request request,
                                 final Response response) {
                return "Hello World From Spark\n";
            }
View Full Code Here

        // start up background thread
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        executorService.submit(new StreamMeetupComTask(metrics));

        // start up web app
        get(new Route("/") {
            @Override
            public Object handle(Request request, Response response) {
                return "this is /";
            }
        });

        post(new Route("/checkout") {
            @Override
            public Object handle(Request request, Response response) {
                // emulate calling external payment API
                Timer.Context timer = metrics.timer("payment.runtime").time();
View Full Code Here

  private static void startApi(CommandLineArgs args, Client esNodeClient, final NominatimUpdater nominatimUpdater) {
    setPort(args.getListenPort());
    setIpAddress(args.getListenIp());

    get(new Route("/nominatim-update") {
      @Override
      public Object handle(Request request, Response response) {
        Thread nominatimUpdaterThread = new Thread() {
          @Override
          public void run() {
View Full Code Here

        MongoClient client = new MongoClient(new ServerAddress("localhost", 27017));

        DB database = client.getDB("m101");
        final DBCollection collection = database.getCollection("funnynumbers");

        Spark.get(new Route("/") {
            @Override
            public Object handle(final Request request,
                                 final Response response) {
                StringWriter writer = new StringWriter();
                try {
View Full Code Here

    public static void main(String[] args) {

        setPort(9090); // Spark will run on port 9090

        Route formula;

        post(formula = new Route("/formula") {
            @Override
            public Object handle(Request rqst, Response rspns) {
                rspns.header("Content-type", "text/html");
                String c = rqst.queryParams("c").toString()// formula as JSON
                String r = genifer.sendFormula(c).toString();
                return r;    // ignore return value for now
            }
        });

        get(formula = new Route("/formula/:id") {
      @Override
            public Object handle(Request rqst, Response rspns) {
                rspns.header("Content-type", "text/html");
                String id = rqst.params(":id").toString();    // index into KB
                String r = genifer.getFormula(id).toString();
                return r;
            }
      });

        Route formularize;

        post(formularize = new Route("/formularize") {
            @Override
            public Object handle(Request rqst, Response rspns) {
                rspns.header("Content-type", "text/html");
        // c = list of links, d = list of words
                String c = rqst.queryParams("c").toString();
                String d = rqst.queryParams("d").toString();
                String r = genifer.formularize(c, d).toString();
                return r;
            }
        });
        get(formularize);

        Route eval;

        post(eval = new Route("/eval") {
            @Override
            public Object handle(Request rqst, Response rspns) {
                rspns.header("Content-type", "text/html");
                String c = rqst.queryParams("c").toString();
                String r = genifer.eval(c).toString();
                r = r.replaceAll("\n", "<br/>");
                return r;
            }
        });
        get(eval);

        Route saveDatabase;

        post(new Route("/saveDatabase") {
            @Override
            public Object handle(Request rqst, Response rspns) {
           // System.out.println("saving database....");
                rspns.header("Content-type", "text/html");
           // String list = rqst.queryParams().toString();
           // System.out.println("params are: " + list);
                String data = rqst.queryParams("data").toString();
                // System.out.println("data is: " + data.substring(0, 100));
           try {
              PrintWriter out = new PrintWriter("web/database-out.txt");
              out.print(data);
              out.close();
              catch (FileNotFoundException ex) {
              Logger.getLogger(GeniferWeb.class.getName()).log(Level.SEVERE, null, ex);
           }
           return "Database saved";
        }
      });


        get(new Route("/*") {

            @Override
            public Object handle(Request rqst, Response rspns) {

              String url = rqst.pathInfo();
View Full Code Here

TOP

Related Classes of spark.Route

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.