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

Commit 8faf1cf

Browse files
committed
Beginning of Netty server, fix jooby-project#35
1 parent 41130d6 commit 8faf1cf

29 files changed

+1180
-44
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ language: java
22
jdk:
33
- oraclejdk8
44
after_success:
5-
- mvn -Pcoverage clean package coveralls:report
5+
- mvn clean package coveralls:report -P coverage

coverage-report/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<source>${project.parent.basedir}/jooby-jdbc/src/main/java</source>
4141
<source>${project.parent.basedir}/jooby-undertow/src/main/java</source>
4242
<source>${project.parent.basedir}/jooby-jetty/src/main/java</source>
43+
<source>${project.parent.basedir}/jooby-netty/src/main/java</source>
4344
</sources>
4445
</configuration>
4546
</execution>
@@ -185,6 +186,12 @@
185186
<version>${project.version}</version>
186187
</dependency>
187188

189+
<dependency>
190+
<groupId>org.jooby</groupId>
191+
<artifactId>jooby-netty</artifactId>
192+
<version>${project.version}</version>
193+
</dependency>
194+
188195
<!-- H2 database -->
189196
<dependency>
190197
<groupId>com.h2database</groupId>

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@
1717
public class BodyParamFeature extends ServerFeature {
1818

1919
private static class Bean {
20+
private Object value;
2021

22+
public Bean(final Object value) {
23+
this.value = value;
24+
}
25+
26+
@Override
27+
public String toString() {
28+
return value.toString();
29+
}
2130
}
2231

2332
@Path("/r")
@@ -35,7 +44,7 @@ public Bean body(final Bean param) throws IOException {
3544

3645
param((type, values, ctx) -> {
3746
if (values != null) {
38-
return new Bean();
47+
return new Bean(values[0]);
3948
}
4049
return ctx.convert(type, values);
4150
});
@@ -49,7 +58,7 @@ public void format(final Object body, final Body.Writer writer) throws Exception
4958
public Writer openStream() throws IOException {
5059
return out;
5160
}
52-
}.write("{}"));
61+
}.write(body.toString()));
5362
}
5463

5564
@Override

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

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,21 @@ public String list(final List<Cookie> cookies) {
2424
}
2525
}
2626

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

4143
{
4244

@@ -71,12 +73,16 @@ public String list(final List<Cookie> cookies) {
7173
public void responseCookie() throws Exception {
7274
request()
7375
.get("/set")
74-
.expect("{name=X, value=Optional[x], domain=Optional.empty, path=/set, maxAge=-1, secure=false}")
76+
.expect(
77+
"{name=X, value=Optional[x], domain=Optional.empty, path=/set, maxAge=-1, secure=false}")
7578
.header("Set-Cookie", setCookie -> {
76-
assertFirst(setCookie, "X=x; Version=1; Path=/set", "X=x;Version=1;Path=/set");
79+
String undertow = "X=x; Version=1; Path=/set";
80+
String jetty = "X=x;Version=1;Path=/set";
81+
String netty = "X=x; Path=\"/set\"; Version=1";
82+
assertFirst(setCookie, undertow, jetty, netty);
7783
request()
7884
.get("/get")
79-
.header("Cookie", "X=x; $Path=/set")
85+
.header("Cookie", "X=x; $Path=/set; $Version=1")
8086
.expect(200)
8187
.expect("present");
8288
});
@@ -94,17 +100,20 @@ public void noCookies() throws Exception {
94100
public void clearCookie() throws Exception {
95101
request()
96102
.get("/set")
97-
.expect("{name=X, value=Optional[x], domain=Optional.empty, path=/set, maxAge=-1, secure=false}")
103+
.expect(
104+
"{name=X, value=Optional[x], domain=Optional.empty, path=/set, maxAge=-1, secure=false}")
98105
.header("Set-Cookie", setCookie -> {
99-
assertFirst(setCookie, "X=x; Version=1; Path=/set", "X=x;Version=1;Path=/set");
106+
assertFirst(setCookie, "X=x; Version=1; Path=/set", "X=x;Version=1;Path=/set",
107+
"X=x; Path=\"/set\"; Version=1");
100108
request()
101109
.get("/clear")
102-
.header("Cookie", "X=x; $Path=/clear")
110+
.header("Cookie", "X=x; $Path=/clear; $Version=1")
103111
.expect(200)
104112
.header("Set-Cookie", 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");
113+
String undertow = "X=x; Version=1; Path=/clear; Max-Age=0";
114+
String jetty = "X=x;Path=/clear;Expires=Thu, 01-Jan-1970 00:00:00 GMT";
115+
String netty = "X=x; Max-Age=0; Path=\"/clear\"; Version=1";
116+
assertFirst(expiredCookie, undertow, jetty, netty);
108117
});
109118
});
110119

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.jooby.integration;
2+
3+
import org.jooby.test.ServerFeature;
4+
import org.junit.Test;
5+
6+
public class HelloFeature extends ServerFeature {
7+
8+
{
9+
get("/", req -> "Hello");
10+
11+
get("/bye", req -> "bye!");
12+
}
13+
14+
@Test
15+
public void hello() throws Exception {
16+
request()
17+
.get("/")
18+
.expect("Hello");
19+
20+
request()
21+
.get("/bye")
22+
.expect("bye!");
23+
}
24+
25+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ public static class Resource {
2424
@POST
2525
public String form(final String name, final int age, final Upload myfile) throws IOException {
2626
try (Upload upload = myfile) {
27+
assertEquals(true, myfile.file().exists());
2728
return name + " " + age + " " + upload.name() + " " + myfile.type().name();
29+
} finally {
30+
assertEquals(false, myfile.file().exists());
2831
}
2932
}
3033

@@ -34,7 +37,10 @@ public String multiplesFiles(final List<Upload> uploads) throws IOException {
3437
StringBuilder buffer = new StringBuilder();
3538
for (Upload upload : uploads) {
3639
try (Upload u = upload) {
40+
assertEquals(true, upload.file().exists());
3741
buffer.append(u.name()).append(" ");
42+
} finally {
43+
assertEquals(false, upload.file().exists());
3844
}
3945
}
4046
return buffer.toString();

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public class RequestIPFeature extends ServerFeature {
1313

1414
get("/hostname", (req) -> req.hostname());
1515

16+
get("/protocol", (req) -> req.protocol());
17+
1618
}
1719

1820
@Test
@@ -34,4 +36,11 @@ public void hostname() throws Exception {
3436
});
3537
}
3638

39+
@Test
40+
public void protocol() throws Exception {
41+
request()
42+
.get("/protocol")
43+
.expect("HTTP/1.1");
44+
}
45+
3746
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,14 @@ public void cookieConfig() throws Exception {
5959
.splitToList(value)
6060
);
6161

62+
System.out.println(setCookie);
6263
assertTrue(setCookie.remove(0).startsWith("custom.sid"));
63-
assertTrue(setCookie.remove("Path=/session"));
64-
assertTrue(setCookie.remove("HttpOnly"));
64+
assertTrue(setCookie.remove("Path=/session") || setCookie.remove("Path=\"/session\""));
65+
assertTrue(setCookie.remove("HttpOnly") || setCookie.remove("HTTPOnly"));
6566
assertTrue(setCookie.remove("Max-Age=60"));
6667
assertTrue(setCookie.remove("Domain=localhost"));
6768
assertTrue(setCookie.remove("Version=1"));
69+
setCookie.remove("Comment=\"jooby cookie\"");
6870
if (setCookie.size() > 0) {
6971
// Expires is optional on version=1?
7072
assertTrue(setCookie.remove(0).startsWith(

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ public void cookieConfig() throws Exception {
5252
.splitToList(value));
5353

5454
assertTrue(setCookie.remove(0).startsWith("custom.sid"));
55-
assertTrue(setCookie.remove("Path=/session"));
56-
assertTrue(setCookie.remove("HttpOnly"));
55+
assertTrue(setCookie.remove("Path=/session") || setCookie.remove("Path=\"/session\""));
56+
assertTrue(setCookie.remove("HttpOnly") || setCookie.remove("HTTPOnly"));
5757
assertTrue(setCookie.remove("Max-Age=60"));
5858
assertTrue(setCookie.remove("Domain=localhost"));
5959
assertTrue(setCookie.remove("Version=1"));
60+
setCookie.remove("Comment=\"jooby cookie\"");
6061
if (setCookie.size() > 0) {
6162
// Expires is optional on version=1?
6263
assertTrue(setCookie.remove(0).startsWith(

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ public void cookieConfig() throws Exception {
4343
List<String> setCookie = Lists.newArrayList(Splitter.onPattern(";\\s*")
4444
.splitToList(value));
4545
assertTrue(setCookie.remove(0).startsWith("custom.sid="));
46-
assertTrue(setCookie.remove("Path=/session"));
47-
assertTrue(setCookie.remove("HttpOnly"));
46+
assertTrue(setCookie.remove("Path=/session") || setCookie.remove("Path=\"/session\""));
47+
assertTrue(setCookie.remove("HttpOnly") || setCookie.remove("HTTPOnly"));
4848
assertTrue(setCookie.remove("Max-Age=60"));
4949
assertTrue(setCookie.remove("Version=1"));
50+
setCookie.remove("Comment=\"jooby cookie\"");
5051
if (setCookie.size() > 0) {
5152
// Expires is optional on version=1?
5253
assertTrue(setCookie.remove(0).startsWith(

0 commit comments

Comments
 (0)