|
| 1 | +package com.baeldung.jooby; |
| 2 | + |
| 3 | +import org.jooby.Jooby; |
| 4 | +import org.jooby.Mutant; |
| 5 | +import org.jooby.Session; |
| 6 | +import org.jooby.jedis.Redis; |
| 7 | +import org.jooby.jedis.RedisSessionStore; |
| 8 | + |
| 9 | +import com.baeldung.jooby.bean.Employee; |
| 10 | + |
| 11 | +public class App extends Jooby { |
| 12 | + |
| 13 | + { |
| 14 | + port(8080); |
| 15 | + securePort(8443); |
| 16 | + } |
| 17 | + |
| 18 | + { |
| 19 | + get("/", () -> "Hello World!"); |
| 20 | + } |
| 21 | + |
| 22 | + { |
| 23 | + get("/user/{id}", req -> "Hello user : " + req.param("id").value()); |
| 24 | + get("/user/:id", req -> "Hello user: " + req.param("id").value()); |
| 25 | + get("/uid:{id}", req -> "Hello User with id : uid" + req.param("id").value()); |
| 26 | + } |
| 27 | + |
| 28 | + { |
| 29 | + onStart(() -> { |
| 30 | + System.out.println("starting app"); |
| 31 | + }); |
| 32 | + |
| 33 | + onStop(() -> { |
| 34 | + System.out.println("stopping app"); |
| 35 | + }); |
| 36 | + |
| 37 | + onStarted(() -> { |
| 38 | + System.out.println("app started"); |
| 39 | + }); |
| 40 | + } |
| 41 | + |
| 42 | + { |
| 43 | + get("/login", () -> "Hello from Baeldung"); |
| 44 | + } |
| 45 | + |
| 46 | + { |
| 47 | + post("/save", req -> { |
| 48 | + Mutant token = req.param("token"); |
| 49 | + return token.intValue(); |
| 50 | + }); |
| 51 | + } |
| 52 | + |
| 53 | + { |
| 54 | + { |
| 55 | + assets("/employee", "form.html"); |
| 56 | + } |
| 57 | + |
| 58 | + post("/submitForm", req -> { |
| 59 | + Employee employee = req.params(Employee.class); |
| 60 | + // TODO |
| 61 | + return "empoyee data saved successfullly"; |
| 62 | + }); |
| 63 | + } |
| 64 | + |
| 65 | + { |
| 66 | + get("/filter", (req, resp, chain) -> { |
| 67 | + // TODO |
| 68 | + // resp.send(...); |
| 69 | + chain.next(req, resp); |
| 70 | + }); |
| 71 | + get("/filter", (req, resp) -> { |
| 72 | + resp.send("filter response"); |
| 73 | + }); |
| 74 | + } |
| 75 | + |
| 76 | + { |
| 77 | +// cookieSession(); |
| 78 | + |
| 79 | +// use(new Redis()); |
| 80 | +// |
| 81 | +// session(RedisSessionStore.class); |
| 82 | + |
| 83 | + get("/session", req -> { |
| 84 | + Session session = req.session(); |
| 85 | + session.set("token", "value"); |
| 86 | + return session.get("token").value(); |
| 87 | + }); |
| 88 | + } |
| 89 | + |
| 90 | + public static void main(final String[] args) { |
| 91 | + |
| 92 | + run(App::new, args); |
| 93 | + } |
| 94 | + |
| 95 | +} |
0 commit comments