JAVA-21440: Changes made for upgrade jooby module to 2.16.1 to make j… (#14064)

* JAVA-21440: Chnages made for upgrade jooby module to 2.16.1 to make java-17 compatable

* JAVA-21440: commenting redis code as this will only work in the local or infra should have a redis setup
This commit is contained in:
Bipin kumar 2023-05-21 15:15:40 +05:30 committed by GitHub
parent e6b0ef1d86
commit 3b73517b00
9 changed files with 218 additions and 144 deletions

View File

@ -1,2 +1,4 @@
#application.secret = 2o128940921eo298e21
#db = /url/to/the/datastore
#redis = "redis://localhost:6379"

View File

@ -1,7 +1,7 @@
<?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">
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>
@ -14,26 +14,25 @@
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jooby</groupId>
<artifactId>modules</artifactId>
<version>${jooby.version}</version>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jooby</groupId>
<artifactId>jooby-netty</artifactId>
<groupId>io.jooby</groupId>
<artifactId>jooby</artifactId>
<version>${jooby.version}</version>
</dependency>
<dependency>
<groupId>org.jooby</groupId>
<artifactId>jooby-jedis</artifactId>
<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>
@ -42,23 +41,43 @@
<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>
<groupId>org.apache.maven.plugins</groupId>
<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>1.1.3</jooby.version>
<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>2.4.3</maven-shade-plugin.version>
<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>

View File

@ -1,17 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<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>
<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>

View File

@ -1,95 +1,135 @@
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;
import io.jooby.Jooby;
import io.jooby.ServerOptions;
import io.jooby.Session;
import io.jooby.SessionStore;
import io.jooby.redis.RedisModule;
import io.jooby.redis.RedisSessionStore;
import io.lettuce.core.RedisClient;
public class App extends Jooby {
{
setServerOptions(new ServerOptions().setPort(8080)
.setSecurePort(8433));
}
{
port(8080);
securePort(8443);
}
{
get("/", () -> "Hello World!");
}
{
get("/", ctx -> "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());
}
{
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());
}
{
onStart(() -> {
System.out.println("starting app");
});
{
onStarting(() -> {
System.out.println("starting app");
});
onStop(() -> {
System.out.println("stopping app");
});
onStop(() -> {
System.out.println("stopping app");
});
onStarted(() -> {
System.out.println("app started");
});
}
onStarted(() -> {
System.out.println("app started");
});
}
{
get("/login", () -> "Hello from Baeldung");
}
{
get("/login", ctx -> "Hello from Baeldung");
}
{
post("/save", req -> {
Mutant token = req.param("token");
return token.intValue();
});
}
{
post("/save", ctx -> {
String userId = ctx.query("id")
.value();
return userId;
});
}
{
{
assets("/employee", "form.html");
}
{
{
assets("/employee", "public/form.html");
}
post("/submitForm", req -> {
Employee employee = req.params(Employee.class);
// TODO
return "empoyee data saved successfullly";
});
}
post("/submitForm", ctx -> {
Employee employee = ctx.path(Employee.class);
// TODO
return "employee data saved successfully";
});
{
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);
{
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("/session", req -> {
Session session = req.session();
session.set("token", "value");
return session.get("token").value();
});
}
get("/handler", ctx -> {
return "third";
});
}
public static void main(final String[] args) {
{
get("/sessionInMemory", ctx -> {
Session session = ctx.session();
session.put("token", "value");
return session.get("token")
.value();
});
}
run(App::new, args);
}
{
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);
}
}

View File

@ -1,22 +1,23 @@
package com.baeldung.jooby.mvc;
import org.jooby.Result;
import org.jooby.Results;
import org.jooby.mvc.GET;
import org.jooby.mvc.Path;
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
public String hello() {
return "Hello Baeldung";
}
@GET
@Path("/home")
public Result home() {
return Results.html("welcome").put("model", new Object());
}
@GET
@Path("/home")
public ModelAndView home() {
return new ModelAndView("welcome.html", new HashMap<>());
}
}

View File

@ -1,14 +1,13 @@
package com.baeldung.jooby.mvc;
import org.jooby.mvc.POST;
import org.jooby.mvc.Path;
import io.jooby.annotations.POST;
import io.jooby.annotations.Path;
@Path("/submit")
public class PostController {
@POST
public String hello() {
return "Submit Baeldung";
}
@POST
public String hello() {
return "Submit Baeldung";
}
}

View File

@ -1,21 +1,32 @@
package com.baeldung.jooby;
import static io.restassured.RestAssured.get;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.jooby.test.JoobyRule;
import org.junit.ClassRule;
import org.junit.Test;
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)
public class AppLiveTest {
@ClassRule
public static JoobyRule app = new JoobyRule(new App());
static OkHttpClient client = new OkHttpClient();
@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_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();
}
}
}

View File

@ -2,15 +2,16 @@ package com.baeldung.jooby;
import static org.junit.Assert.assertEquals;
import org.jooby.test.MockRouter;
import org.junit.Test;
import io.jooby.MockRouter;
public class AppUnitTest {
@Test
public void given_defaultUrl_with_mockrouter_expect_fixedString() throws Throwable {
String result = new MockRouter(new App()).get("/");
assertEquals("Hello World!", result);
}
@Test
public void given_defaultUrl_with_mockrouter_expect_fixedString() {
MockRouter router = new MockRouter(new App());
assertEquals("Hello World!", router.get("/")
.value());
}
}

View File

@ -24,7 +24,7 @@
<module>javax-servlets</module>
<module>javax-servlets-2</module>
<module>jee-7</module>
<!--<module>jooby</module>-->
<module>jooby</module>
<module>linkrest</module>
<!-- <module>ninja</module>-->
<!-- <module>play-modules</module> --> <!-- Not a maven project -->