Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
908c7b5
moving jmh into libraries module
AbhinabKanrar Jun 5, 2017
4202dd3
refactoring jmh
AbhinabKanrar Jun 7, 2017
b42a5e5
Merge branch 'master' into master
zhendrikse Jun 7, 2017
34704c4
Update pom.xml
zhendrikse Jun 7, 2017
fc4a818
manual algorightm
AbhinabKanrar Jun 16, 2017
87351d7
with BM result
AbhinabKanrar Jun 17, 2017
75ca775
fix for space issue
AbhinabKanrar Jun 18, 2017
3a31078
Fixed indentation
zhendrikse Jun 18, 2017
d97b7b6
Merge branch 'master' into master
zhendrikse Jun 18, 2017
33082cf
change as per suggestion
AbhinabKanrar Jun 21, 2017
f32c5c0
Merge branch 'master' of https://github.com/AbhinabKanrar/tutorials
AbhinabKanrar Jun 21, 2017
59df78e
Merge branch 'master' into master
AbhinabKanrar Jun 21, 2017
21e6bb8
vavr either
AbhinabKanrar Jun 30, 2017
51b5052
adding unit test and othe rutilities
AbhinabKanrar Jul 1, 2017
b293b9b
adding concurrent module
AbhinabKanrar Jul 15, 2017
b17a7ac
concurrent package description
AbhinabKanrar Jul 15, 2017
885591c
concurrent package description
AbhinabKanrar Jul 15, 2017
1ae46ce
Update EitherUnitTest.java
AbhinabKanrar Jul 15, 2017
8aa9d5d
Merge branch 'master' into master
AbhinabKanrar Jul 15, 2017
36346f4
introducing lambda expression
AbhinabKanrar Jul 22, 2017
a001ed5
Merge branch 'master' into master
AbhinabKanrar Jul 22, 2017
7f8e5e2
jooby project
AbhinabKanrar Jul 29, 2017
ebb4c2c
Merge branch 'master' into master
AbhinabKanrar Jul 29, 2017
5488e9f
jooby project
AbhinabKanrar Jul 29, 2017
dd983c9
Merge branch 'master' of https://github.com/AbhinabKanrar/tutorials
AbhinabKanrar Jul 29, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ public void start() {
}
}
}

2 changes: 2 additions & 0 deletions jooby/conf/application.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#application.secret = 2o128940921eo298e21
#db = /url/to/the/datastore
42 changes: 42 additions & 0 deletions jooby/conf/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="15 seconds" debug="false">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>[%d{ISO8601}]-[%thread] %-5level %logger - %msg%n</pattern>
</encoder>
</appender>

<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>log/jooby.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>log/jooby.%d{yyyy-MM-dd}.log</fileNamePattern>
<totalSizeCap>1mb</totalSizeCap>
<maxHistory>7</maxHistory>
</rollingPolicy>

<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
</encoder>
</appender>

<appender name="ACCESS" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>log/access.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>log/access.%d{yyyy-MM-dd}.log</fileNamePattern>
<totalSizeCap>1mb</totalSizeCap>
<maxHistory>7</maxHistory>
</rollingPolicy>

<encoder>
<pattern>%msg%n</pattern>
</encoder>
</appender>

<logger name="org.jooby.RequestLogger" additivity="false">
<appender-ref ref="ACCESS" />
</logger>

<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>
56 changes: 56 additions & 0 deletions jooby/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>jooby</artifactId>
<groupId>com.baeldung.jooby</groupId>
<version>1.0</version>
<name>jooby</name>

<parent>
<groupId>org.jooby</groupId>
<artifactId>modules</artifactId>
<version>1.1.3</version>
</parent>

<properties>
<jooby.version>1.1.3</jooby.version>
<application.class>com.baeldung.jooby.App</application.class>
</properties>

<dependencies>
<dependency>
<groupId>org.jooby</groupId>
<artifactId>jooby-netty</artifactId>
</dependency>
<dependency>
<groupId>org.jooby</groupId>
<artifactId>jooby-jedis</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
17 changes: 17 additions & 0 deletions jooby/public/form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form enctype="application/x-www-form-urlencoded" action="/submitForm" method="post">
<input name="id" />
<input name="name" />
<input name="email" />
<input name="phone" />
<input name="address" />
<input type="submit" value="Submit"/>
</form>
</body>
</html>
10 changes: 10 additions & 0 deletions jooby/public/welcome.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
i m welcomed
</body>
</html>
41 changes: 41 additions & 0 deletions jooby/src/etc/stork.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Name of application (make sure it has no spaces)
name: "${project.artifactId}"

# Display name of application (can have spaces)
display_name: "${project.name}"

# Type of launcher (CONSOLE or DAEMON)
type: DAEMON

# Java class to run
main_class: "${application.class}"

domain: "${project.groupId}"

short_description: "${project.artifactId}"

# Platform launchers to generate (WINDOWS, LINUX, MAC_OSX)
# Linux launcher is suitable for Bourne shells (e.g. Linux/BSD)
platforms: [ LINUX ]

# Working directory for app
# RETAIN will not change the working directory
# APP_HOME will change the working directory to the home of the app
# (where it was intalled) before running the main class
working_dir_mode: RETAIN

# Minimum version of java required (system will be searched for acceptable jvm)
min_java_version: "1.8"

# Min/max fixed memory (measured in MB)
min_java_memory: 512
max_java_memory: 512

# Min/max memory by percentage of system
#min_java_memory_pct: 10
#max_java_memory_pct: 20

# Try to create a symbolic link to java executable in <app_home>/run with
# the name of "<app_name>-java" so that commands like "ps" will make it
# easier to find your app
symlink_java: true
95 changes: 95 additions & 0 deletions jooby/src/main/java/com/baeldung/jooby/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.baeldung.jooby;

import org.jooby.Jooby;
import org.jooby.Mutant;
import org.jooby.Session;
import org.jooby.jedis.Redis;
import org.jooby.jedis.RedisSessionStore;

import com.baeldung.jooby.bean.Employee;

public class App extends Jooby {

{
port(8080);
securePort(8443);
}

{
get("/", () -> "Hello World!");
}

{
get("/user/{id}", req -> "Hello user : " + req.param("id").value());
get("/user/:id", req -> "Hello user: " + req.param("id").value());
get("/uid:{id}", req -> "Hello User with id : uid" + req.param("id").value());
}

{
onStart(() -> {
System.out.println("starting app");
});

onStop(() -> {
System.out.println("stopping app");
});

onStarted(() -> {
System.out.println("app started");
});
}

{
get("/login", () -> "Hello from Baeldung");
}

{
post("/save", req -> {
Mutant token = req.param("token");
return token.intValue();
});
}

{
{
assets("/employee", "form.html");
}

post("/submitForm", req -> {
Employee employee = req.params(Employee.class);
// TODO
return "empoyee data saved successfullly";
});
}

{
get("/filter", (req, resp, chain) -> {
// TODO
// resp.send(...);
chain.next(req, resp);
});
get("/filter", (req, resp) -> {
resp.send("filter response");
});
}

{
// cookieSession();

// use(new Redis());
//
// session(RedisSessionStore.class);

get("/session", req -> {
Session session = req.session();
session.set("token", "value");
return session.get("token").value();
});
}

public static void main(final String[] args) {

run(App::new, args);
}

}
20 changes: 20 additions & 0 deletions jooby/src/main/java/com/baeldung/jooby/bean/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.baeldung.jooby.bean;

public class Employee {

String id;
String name;
String email;
String phone;
String address;

public Employee(String id, String name, String email, String phone, String address) {
super();
this.id = id;
this.name = name;
this.email = email;
this.phone = phone;
this.address = address;
}

}
22 changes: 22 additions & 0 deletions jooby/src/main/java/com/baeldung/jooby/mvc/GetController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.baeldung.jooby.mvc;

import org.jooby.Result;
import org.jooby.Results;
import org.jooby.mvc.GET;
import org.jooby.mvc.Path;

@Path("/hello")
public class GetController {

@GET
public String hello() {
return "Hello Baeldung";
}

@GET
@Path("/home")
public Result home() {
return Results.html("welcome").put("model", new Object());
}

}
14 changes: 14 additions & 0 deletions jooby/src/main/java/com/baeldung/jooby/mvc/PostController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.baeldung.jooby.mvc;

import org.jooby.mvc.POST;
import org.jooby.mvc.Path;

@Path("/submit")
public class PostController {

@POST
public String hello() {
return "Submit Baeldung";
}

}
29 changes: 29 additions & 0 deletions jooby/src/test/java/com/baeldung/jooby/AppTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.baeldung.jooby;

import static io.restassured.RestAssured.get;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;

import org.jooby.test.JoobyRule;
import org.jooby.test.MockRouter;
import org.junit.ClassRule;
import org.junit.Test;

public class AppTest {

@ClassRule
public static JoobyRule app = new JoobyRule(new App());

@Test
public void given_defaultUrl_expect_fixedString() {
get("/").then().assertThat().body(equalTo("Hello World!")).statusCode(200)
.contentType("text/html;charset=UTF-8");
}

@Test
public void given_defaultUrl_with_mockrouter_expect_fixedString() throws Throwable {
String result = new MockRouter(new App()).get("/");
assertEquals("Hello World!", result);
}

}