删除编译错误
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
#application.secret = 2o128940921eo298e21
|
||||
#db = /url/to/the/datastore
|
||||
|
||||
#redis = "redis://localhost:6379"
|
||||
@@ -0,0 +1,83 @@
|
||||
<?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>
|
||||
<groupId>com.baeldung.jooby</groupId>
|
||||
<artifactId>jooby</artifactId>
|
||||
<version>1.0</version>
|
||||
<name>jooby</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>web-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.jooby</groupId>
|
||||
<artifactId>jooby</artifactId>
|
||||
<version>${jooby.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jooby</groupId>
|
||||
<artifactId>jooby-test</artifactId>
|
||||
<version>${jooby.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jooby</groupId>
|
||||
<artifactId>jooby-jetty</artifactId>
|
||||
<version>${jooby.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jooby</groupId>
|
||||
<artifactId>jooby-redis</artifactId>
|
||||
<version>${jooby.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
<scope>test</scope>
|
||||
<version>${rest-assured.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>${squareup.okhttp.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>${maven-shade-plugin.version}</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>io.jooby</groupId>
|
||||
<artifactId>jooby-maven-plugin</artifactId>
|
||||
<version>${jooby.version}</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven-compiler.version}</version>
|
||||
<configuration>
|
||||
<compilerArgs>
|
||||
<arg>-parameters</arg>
|
||||
</compilerArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<jooby.version>2.16.1</jooby.version>
|
||||
<rest-assured.version>3.1.1</rest-assured.version>
|
||||
<application.class>com.baeldung.jooby.App</application.class>
|
||||
<maven-shade-plugin.version>3.2.4</maven-shade-plugin.version>
|
||||
<maven-compiler.version>3.8.1</maven-compiler.version>
|
||||
<squareup.okhttp.version>4.9.1</squareup.okhttp.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,18 @@
|
||||
<!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">
|
||||
<label>Employed id:</label><br>
|
||||
<input name="id"/><br>
|
||||
<label>Name:</label><br>
|
||||
<input name="name"/><br>
|
||||
<label>Email:</label><br>
|
||||
<input name="email"/><br><br>
|
||||
<input type="submit" value="Submit"/>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,123 @@
|
||||
package com.baeldung.jooby;
|
||||
|
||||
import com.baeldung.jooby.bean.Employee;
|
||||
|
||||
import io.jooby.Jooby;
|
||||
import io.jooby.ServerOptions;
|
||||
import io.jooby.Session;
|
||||
import io.jooby.SessionStore;
|
||||
|
||||
public class App extends Jooby {
|
||||
{
|
||||
setServerOptions(new ServerOptions().setPort(8080)
|
||||
.setSecurePort(8433));
|
||||
}
|
||||
|
||||
{
|
||||
get("/", ctx -> "Hello World!");
|
||||
}
|
||||
|
||||
{
|
||||
get("/user/{id}", ctx -> "Hello user : " + ctx.path("id")
|
||||
.value());
|
||||
get("/user/:id", ctx -> "Hello user: " + ctx.path("id")
|
||||
.value());
|
||||
get("/uid:{id}", ctx -> "Hello User with id : uid = " + ctx.path("id")
|
||||
.value());
|
||||
}
|
||||
|
||||
{
|
||||
onStarting(() -> System.out.println("starting app"));
|
||||
|
||||
onStop(() -> System.out.println("stopping app"));
|
||||
|
||||
onStarted(() -> System.out.println("app started"));
|
||||
}
|
||||
|
||||
{
|
||||
get("/login", ctx -> "Hello from Baeldung");
|
||||
}
|
||||
|
||||
{
|
||||
post("/save", ctx -> {
|
||||
String userId = ctx.query("id")
|
||||
.value();
|
||||
return userId;
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
{
|
||||
assets("/employee", "public/form.html");
|
||||
}
|
||||
|
||||
post("/submitForm", ctx -> {
|
||||
Employee employee = ctx.path(Employee.class);
|
||||
// ...
|
||||
return "employee data saved successfully";
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
decorator(next -> ctx -> {
|
||||
System.out.println("first");
|
||||
// Moves execution to next handler: second
|
||||
return next.apply(ctx);
|
||||
});
|
||||
decorator(next -> ctx -> {
|
||||
System.out.println("second");
|
||||
// Moves execution to next handler: third
|
||||
return next.apply(ctx);
|
||||
});
|
||||
|
||||
get("/handler", ctx -> "third");
|
||||
}
|
||||
|
||||
{
|
||||
get("/sessionInMemory", ctx -> {
|
||||
Session session = ctx.session();
|
||||
session.put("token", "value");
|
||||
return session.get("token")
|
||||
.value();
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
String secret = "super secret token";
|
||||
|
||||
setSessionStore(SessionStore.signed(secret));
|
||||
|
||||
get("/signedSession", ctx -> {
|
||||
Session session = ctx.session();
|
||||
session.put("token", "value");
|
||||
return session.get("token")
|
||||
.value();
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
get("/sessionInMemoryRedis", ctx -> {
|
||||
Session session = ctx.session();
|
||||
session.put("token", "value");
|
||||
return session.get("token")
|
||||
.value();
|
||||
});
|
||||
}
|
||||
|
||||
/* This will work once redis is installed locally
|
||||
{
|
||||
install(new RedisModule("redis"));
|
||||
setSessionStore(new RedisSessionStore(require(RedisClient.class)));
|
||||
get("/redisSession", ctx -> {
|
||||
Session session = ctx.session();
|
||||
session.put("token", "value");
|
||||
return session.get("token");
|
||||
});
|
||||
}*/
|
||||
|
||||
public static void main(final String[] args) {
|
||||
runApp(args, App::new);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.jooby.mvc;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import io.jooby.ModelAndView;
|
||||
import io.jooby.annotations.GET;
|
||||
import io.jooby.annotations.Path;
|
||||
|
||||
@Path("/hello")
|
||||
public class GetController {
|
||||
|
||||
@GET
|
||||
public String hello() {
|
||||
return "Hello Baeldung";
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/home")
|
||||
public ModelAndView home() {
|
||||
return new ModelAndView("welcome.html", new HashMap<>());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.jooby.mvc;
|
||||
|
||||
import io.jooby.annotations.POST;
|
||||
import io.jooby.annotations.Path;
|
||||
|
||||
@Path("/submit")
|
||||
public class PostController {
|
||||
|
||||
@POST
|
||||
public String hello() {
|
||||
return "Submit Baeldung";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.baeldung.jooby;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import io.jooby.JoobyTest;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
@JoobyTest(value = App.class, port = 8080)
|
||||
class AppLiveTest {
|
||||
|
||||
static OkHttpClient client = new OkHttpClient();
|
||||
|
||||
@Test
|
||||
void given_defaultUrl_expect_fixedString() {
|
||||
Request request = new Request.Builder().url("http://localhost:8080")
|
||||
.build();
|
||||
try (Response response = client.newCall(request)
|
||||
.execute()) {
|
||||
assertEquals("Hello World!", response.body()
|
||||
.string());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.jooby;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import io.jooby.MockRouter;
|
||||
|
||||
public class AppUnitTest {
|
||||
|
||||
@Test
|
||||
public void given_defaultUrl_with_mockrouter_expect_fixedString() {
|
||||
MockRouter router = new MockRouter(new App());
|
||||
assertEquals("Hello World!", router.get("/")
|
||||
.value());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user