Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit 41130d6

Browse files
committed
make the web server pluggable jooby-project#34
* runtime discover of server * add the start of servlet module * add the start of the jetty module
1 parent 2071f2e commit 41130d6

File tree

59 files changed

+1531
-123
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1531
-123
lines changed

coverage-report/pom.xml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
<source>${project.parent.basedir}/jooby-hbs/src/main/java</source>
3939
<source>${project.parent.basedir}/jooby-jackson/src/main/java</source>
4040
<source>${project.parent.basedir}/jooby-jdbc/src/main/java</source>
41+
<source>${project.parent.basedir}/jooby-undertow/src/main/java</source>
42+
<source>${project.parent.basedir}/jooby-jetty/src/main/java</source>
4143
</sources>
4244
</configuration>
4345
</execution>
@@ -170,6 +172,19 @@
170172
<version>${project.version}</version>
171173
</dependency>
172174

175+
<!-- Servers -->
176+
<dependency>
177+
<groupId>org.jooby</groupId>
178+
<artifactId>jooby-undertow</artifactId>
179+
<version>${project.version}</version>
180+
</dependency>
181+
182+
<dependency>
183+
<groupId>org.jooby</groupId>
184+
<artifactId>jooby-jetty</artifactId>
185+
<version>${project.version}</version>
186+
</dependency>
187+
173188
<!-- H2 database -->
174189
<dependency>
175190
<groupId>com.h2database</groupId>
@@ -236,14 +251,6 @@
236251
<scope>test</scope>
237252
</dependency>
238253

239-
<!-- Servers -->
240-
<dependency>
241-
<groupId>org.jooby</groupId>
242-
<artifactId>jooby-undertow</artifactId>
243-
<version>${project.version}</version>
244-
<scope>test</scope>
245-
</dependency>
246-
247254
</dependencies>
248255

249256
</project>

coverage-report/src/test/java/org/jooby/integration/CookiesFeature.java

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package org.jooby.integration;
22

3+
import static org.junit.Assert.assertArrayEquals;
34
import static org.junit.Assert.assertEquals;
45

6+
import java.util.Arrays;
57
import java.util.List;
68
import java.util.Optional;
79

810
import org.jooby.Cookie;
911
import org.jooby.mvc.Path;
1012
import org.jooby.test.ServerFeature;
11-
import org.junit.Before;
1213
import org.junit.Test;
1314

1415
public class CookiesFeature extends ServerFeature {
@@ -23,29 +24,29 @@ public String list(final List<Cookie> cookies) {
2324
}
2425
}
2526

26-
@Before
27-
public void debug() {
28-
java.util.logging.Logger.getLogger("httpclient.wire.header").setLevel(
29-
java.util.logging.Level.FINEST);
30-
// java.util.logging.Logger.getLogger("httpclient.wire.content").setLevel(java.util.logging.Level.FINEST);
31-
32-
System.setProperty("org.apache.commons.logging.Log",
33-
"org.apache.commons.logging.impl.SimpleLog");
34-
System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
35-
System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug");
36-
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "debug");
37-
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.headers", "debug");
38-
}
27+
// @Before
28+
// public void debug() {
29+
// java.util.logging.Logger.getLogger("httpclient.wire.header").setLevel(
30+
// java.util.logging.Level.FINEST);
31+
// // java.util.logging.Logger.getLogger("httpclient.wire.content").setLevel(java.util.logging.Level.FINEST);
32+
//
33+
// System.setProperty("org.apache.commons.logging.Log",
34+
// "org.apache.commons.logging.impl.SimpleLog");
35+
// System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
36+
// System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug");
37+
// System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "debug");
38+
// System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.headers", "debug");
39+
// }
3940

4041
{
4142

4243
get("/set", (req, rsp) -> {
43-
rsp.cookie(new Cookie.Definition("X", "x").path("/set")).send("done");
44+
Cookie cookie = new Cookie.Definition("X", "x").path("/set").toCookie();
45+
rsp.cookie(cookie).send(cookie);
4446
});
4547

4648
get("/get",
4749
(req, rsp) -> {
48-
System.out.println(req.cookies());
4950
assertEquals(
5051
"[{name=X, value=Optional[x], domain=Optional.empty, path=/set, maxAge=-1, secure=false}]",
5152
req.cookies().toString());
@@ -70,9 +71,9 @@ public void debug() {
7071
public void responseCookie() throws Exception {
7172
request()
7273
.get("/set")
73-
.expect(200)
74+
.expect("{name=X, value=Optional[x], domain=Optional.empty, path=/set, maxAge=-1, secure=false}")
7475
.header("Set-Cookie", setCookie -> {
75-
assertEquals("X=x; path=/set", setCookie);
76+
assertFirst(setCookie, "X=x; Version=1; Path=/set", "X=x;Version=1;Path=/set");
7677
request()
7778
.get("/get")
7879
.header("Cookie", "X=x; $Path=/set")
@@ -93,16 +94,17 @@ public void noCookies() throws Exception {
9394
public void clearCookie() throws Exception {
9495
request()
9596
.get("/set")
96-
.expect(200)
97+
.expect("{name=X, value=Optional[x], domain=Optional.empty, path=/set, maxAge=-1, secure=false}")
9798
.header("Set-Cookie", setCookie -> {
98-
assertEquals("X=x; path=/set", setCookie);
99+
assertFirst(setCookie, "X=x; Version=1; Path=/set", "X=x;Version=1;Path=/set");
99100
request()
100101
.get("/clear")
101102
.header("Cookie", "X=x; $Path=/clear")
102103
.expect(200)
103104
.header("Set-Cookie", expiredCookie -> {
104-
assertEquals("X=x; path=/clear; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:00 GMT",
105-
expiredCookie);
105+
assertFirst(expiredCookie,
106+
"X=x; path=/clear; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:00 GMT",
107+
"X=x;Path=/clear;Expires=Thu, 01-Jan-1970 00:00:00 GMT");
106108
});
107109
});
108110

@@ -119,4 +121,13 @@ public void listCookies() throws Exception {
119121

120122
}
121123

124+
private void assertFirst(final String found, final String... expectations) {
125+
for (String expect : expectations) {
126+
if (expect.equals(found)) {
127+
return;
128+
}
129+
}
130+
assertArrayEquals("expected " + Arrays.toString(expectations) + " found " + found,
131+
expectations, new String[]{found });
132+
}
122133
}

coverage-report/src/test/java/org/jooby/integration/RequestCharsetFeature.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
public class RequestCharsetFeature extends ServerFeature {
77

88
{
9-
10-
get("/", (req, resp) ->
11-
resp.send(req.charset()));
12-
9+
get("/", (req, resp) -> resp.send(req.charset()));
1310
}
1411

1512
@Test

coverage-report/src/test/java/org/jooby/integration/RequestIPFeature.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.jooby.integration;
22

3+
import static org.junit.Assert.fail;
4+
35
import org.jooby.test.ServerFeature;
46
import org.junit.Test;
57

@@ -24,7 +26,12 @@ public void ip() throws Exception {
2426
public void hostname() throws Exception {
2527
request()
2628
.get("/hostname")
27-
.expect("localhost");
29+
.expect(rsp -> {
30+
if ("localhost".equals(rsp) || "127.0.0.1".equals(rsp)) {
31+
return;
32+
}
33+
fail(rsp);
34+
});
2835
}
2936

3037
}

coverage-report/src/test/java/org/jooby/integration/RequestScopedFeature.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class RequestScopedFeature extends ServerFeature {
1515
@RequestScoped
1616
public static class RequestScopedObject {
1717

18-
private static int instances = 0;
18+
static int instances = 0;
1919

2020
{
2121
instances += 1;
@@ -32,7 +32,7 @@ public static class DefScope {
3232

3333
static int instances = 0;
3434

35-
static {
35+
{
3636
instances += 1;
3737
}
3838

@@ -58,7 +58,7 @@ public static class SingletonScope {
5858

5959
static int instances = 0;
6060

61-
static {
61+
{
6262
instances += 1;
6363
}
6464

@@ -92,6 +92,10 @@ public String m() {
9292

9393
@Test
9494
public void numberOfInstances() throws Exception {
95+
RequestScopedObject.instances = 0;
96+
DefScope.instances = 0;
97+
SingletonScope.instances = 0;
98+
9599
request()
96100
.get("/")
97101
.expect("1");
@@ -102,7 +106,7 @@ public void numberOfInstances() throws Exception {
102106

103107
request()
104108
.get("/r")
105-
.expect("d1:3");
109+
.expect("d2:3");
106110

107111
request()
108112
.get("/s")

coverage-report/src/test/java/org/jooby/integration/ScopeOfMvcRouteFeature.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class ScopeOfMvcRouteFeature extends ServerFeature {
1313

1414
public static class RequestScoped {
1515

16-
private static int instances = 0;
16+
static int instances = 0;
1717

1818
{
1919
instances += 1;
@@ -29,7 +29,7 @@ public String toString() {
2929
@Singleton
3030
public static class Single {
3131

32-
private static int instances = 0;
32+
static int instances = 0;
3333

3434
private Provider<RequestScoped> requestScoped;
3535

@@ -49,7 +49,7 @@ public Object m() {
4949
@Path("/p")
5050
public static class Proto {
5151

52-
private static int instances = 0;
52+
static int instances = 0;
5353
private RequestScoped requestScoped;
5454

5555
@Inject
@@ -74,6 +74,10 @@ public Object m() {
7474

7575
@Test
7676
public void singleton() throws Exception {
77+
RequestScoped.instances = 0;
78+
Single.instances = 0;
79+
Proto.instances = 0;
80+
7781
request()
7882
.get("/s")
7983
.expect("1=1");
@@ -90,17 +94,21 @@ public void singleton() throws Exception {
9094

9195
@Test
9296
public void proto() throws Exception {
97+
RequestScoped.instances = 0;
98+
Single.instances = 0;
99+
Proto.instances = 0;
100+
93101
request()
94102
.get("/p")
95-
.expect("1=4");
103+
.expect("1=1");
96104

97105
request()
98106
.get("/p")
99-
.expect("2=5");
107+
.expect("2=2");
100108

101109
request()
102110
.get("/p")
103-
.expect("3=6");
111+
.expect("3=3");
104112

105113
}
106114

coverage-report/src/test/java/org/jooby/integration/session/SessionConfigCookieFeature.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.jooby.integration.session;
22

3-
import static org.junit.Assert.assertEquals;
43
import static org.junit.Assert.assertTrue;
54

65
import java.time.Instant;
@@ -61,13 +60,16 @@ public void cookieConfig() throws Exception {
6160
);
6261

6362
assertTrue(setCookie.remove(0).startsWith("custom.sid"));
64-
assertTrue(setCookie.remove("path=/session"));
63+
assertTrue(setCookie.remove("Path=/session"));
6564
assertTrue(setCookie.remove("HttpOnly"));
6665
assertTrue(setCookie.remove("Max-Age=60"));
67-
assertTrue(setCookie.remove("domain=localhost"));
68-
assertEquals(1, setCookie.size());
69-
assertTrue(setCookie.remove(0).startsWith(
70-
"Expires=" + formatter.format(utc).replace("GMT", "")));
66+
assertTrue(setCookie.remove("Domain=localhost"));
67+
assertTrue(setCookie.remove("Version=1"));
68+
if (setCookie.size() > 0) {
69+
// Expires is optional on version=1?
70+
assertTrue(setCookie.remove(0).startsWith(
71+
"Expires=" + formatter.format(utc).replace("GMT", "")));
72+
}
7173
});
7274
}
7375

coverage-report/src/test/java/org/jooby/integration/session/SessionCookieFeature.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.jooby.integration.session;
22

3-
import static org.junit.Assert.assertEquals;
43
import static org.junit.Assert.assertTrue;
54

65
import java.time.Instant;
@@ -53,13 +52,16 @@ public void cookieConfig() throws Exception {
5352
.splitToList(value));
5453

5554
assertTrue(setCookie.remove(0).startsWith("custom.sid"));
56-
assertTrue(setCookie.remove("path=/session"));
55+
assertTrue(setCookie.remove("Path=/session"));
5756
assertTrue(setCookie.remove("HttpOnly"));
5857
assertTrue(setCookie.remove("Max-Age=60"));
59-
assertTrue(setCookie.remove("domain=localhost"));
60-
assertEquals(1, setCookie.size());
61-
assertTrue(setCookie.remove(0).startsWith(
62-
"Expires=" + formatter.format(utc).replace("GMT", "")));
58+
assertTrue(setCookie.remove("Domain=localhost"));
59+
assertTrue(setCookie.remove("Version=1"));
60+
if (setCookie.size() > 0) {
61+
// Expires is optional on version=1?
62+
assertTrue(setCookie.remove(0).startsWith(
63+
"Expires=" + formatter.format(utc).replace("GMT", "")));
64+
}
6365
});
6466

6567
}

coverage-report/src/test/java/org/jooby/integration/session/SessionCookieNoSecretFeature.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.jooby.integration.session;
22

3-
import static org.junit.Assert.assertEquals;
43
import static org.junit.Assert.assertTrue;
54

65
import java.time.Instant;
@@ -44,12 +43,15 @@ public void cookieConfig() throws Exception {
4443
List<String> setCookie = Lists.newArrayList(Splitter.onPattern(";\\s*")
4544
.splitToList(value));
4645
assertTrue(setCookie.remove(0).startsWith("custom.sid="));
47-
assertTrue(setCookie.remove("path=/session"));
46+
assertTrue(setCookie.remove("Path=/session"));
4847
assertTrue(setCookie.remove("HttpOnly"));
4948
assertTrue(setCookie.remove("Max-Age=60"));
50-
assertEquals(1, setCookie.size());
51-
assertTrue(setCookie.remove(0).startsWith(
52-
"Expires=" + formatter.format(utc).replace("GMT", "")));
49+
assertTrue(setCookie.remove("Version=1"));
50+
if (setCookie.size() > 0) {
51+
// Expires is optional on version=1?
52+
assertTrue(setCookie.remove(0).startsWith(
53+
"Expires=" + formatter.format(utc).replace("GMT", "")));
54+
}
5355
});
5456

5557
}

coverage-report/src/test/java/org/jooby/integration/session/ShouldDestroyAndExpireCookieFeature.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public void shouldDestroyAndExpireCookie() throws Exception {
5151
.expect(200)
5252
.header("Set-Cookie", setCookie -> {
5353
assertNotNull(setCookie);
54-
assertTrue(setCookie.endsWith("01-Jan-1970 00:00:00 GMT"));
54+
if (!setCookie.endsWith("01-Jan-1970 00:00:00 GMT;Max-Age=0")) {
55+
assertTrue(setCookie.endsWith("Max-Age=0"));
56+
}
5557
});
5658

5759
latch.await();

0 commit comments

Comments
 (0)