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

Commit 9898fe3

Browse files
committed
Fix some javadoc errors
1 parent cc8e2df commit 9898fe3

Some content is hidden

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

50 files changed

+688
-578
lines changed

README.md

Lines changed: 104 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import org.jooby.Jooby;
1111
public class App extends Jooby {
1212

1313
{
14-
get("/", (req, res) ->
15-
res.send("Hey Jooby!")
14+
get("/", (req, rsp) ->
15+
rsp.send("Hey Jooby!")
1616
);
1717
}
1818

@@ -94,7 +94,7 @@ contents (work in progress)
9494
- [inline](#inline)
9595
- [external](#external)
9696
- [mvc routes](#mvc routes)
97-
- [router vs filter](#router vs filter)
97+
- [route handler vs filter](#route handler vs filter)
9898
- [request params](#request params)
9999
- [param types](#param types)
100100
- [path](#path)
@@ -103,6 +103,7 @@ contents (work in progress)
103103
- [param precedence](#param precedence)
104104
- [optional params](#optional params)
105105
- [request headers](#request headers)
106+
- [web sockets](#web sockets)
106107

107108
getting started
108109
=====
@@ -150,12 +151,14 @@ App.java
150151

151152
import org.jooby.Jooby;
152153

153-
public class App extends Jooby {
154+
public class App extends Jooby { // 1
154155

155156
{
156-
assets("/assets/**"); // 1. static files under assets
157+
// 2 routes
158+
get("/favicon.ico");
159+
assets("/assets/**");
157160

158-
get("/", html("welcome.html")); // 2. default route
161+
get("/", file("welcome.html"));
159162
}
160163

161164
public static void main(final String[] args) throws Exception {
@@ -198,13 +201,13 @@ API is short and easy to learn, around 30 classes.
198201
The most notable classes are: [Jooby.Module], [Route] and [WebSocket].
199202

200203
### dependencies
201-
* [Jetty](https://www.eclipse.org/jetty/) as HTTP NIO Web Server
204+
* [Jetty](https://www.eclipse.org/jetty/) for HTTP NIO Web Server
202205
* [Guice](https://github.com/google/guice) for Dependency Injection
203-
* [Config](https://github.com/typesafehub/config) for a powerful config system
206+
* [Config](https://github.com/typesafehub/config) for configuration management
204207

205208
Jooby is organized as a set of reusable modules (a.k.a middleware in [Express](http://expressjs.com/)).
206-
A module does as minimum as possible and it should NOT make strong/hard decisions for you, or when it does, it must be 100% configurable.
207-
For example, a module for the popular [Hibernate]() library should do:
209+
A module should do as minimum as possible and it should NOT make strong/hard decisions for you, or when it does, it must be 100% configurable.
210+
For example, a module for the popular [Hibernate]() library should:
208211

209212
1) create a session factory
210213

@@ -218,30 +221,30 @@ but NOT:
218221

219222
2) wrap Hibernate API or similar
220223

221-
If a module does as minimum as possible, developers have the power! of setup/configure or take real advantage of native library features without noise.
224+
If a module does as minimum as possible, developers have the power! of setup/configure and take real advantage of native library features without noise.
222225

223226

224227
## routes
225228

226229
Like in [Express](http://expressjs.com/) routes can be chained/stacked and executed in the same order they are defined.
227230

228-
A route is represent by [Route] and there are two types of handlers: [Router] and [Filter].
231+
A route is represent by [Route] and there are two types of handlers: [Route.Handler] and [Route.Filter].
229232

230233
A handler is basically the callback executed while a route is the whole thing: verb, path, handler, etc...
231234

232235

233236
```java
234237
{
235-
get("/", (req, res) ->
238+
get("/", (req, rsp) ->
236239
log.info("first")
237240
);
238241

239-
get("/", (req, res) ->
242+
get("/", (req, rsp) ->
240243
log.info("second")
241244
);
242245

243-
get("/", (req, res) ->
244-
res.send("last")
246+
get("/", (req, rsp) ->
247+
rsp.send("last")
245248
);
246249
}
247250
```
@@ -284,13 +287,13 @@ In addition to Ant-style path pattern, variables pattern are also possible:
284287

285288
```java
286289
{
287-
get("/users/:id", (req, res) ->
288-
res.send(req.param("id").stringValue())
290+
get("/users/:id", (req, rsp) ->
291+
rsp.send(req.param("id").stringValue())
289292
);
290293

291294
// or with braces
292-
get("/users/{id}", (req, res) ->
293-
res.send(req.param("id").stringValue())
295+
get("/users/{id}", (req, rsp) ->
296+
rsp.send(req.param("id").stringValue())
294297
);
295298
}
296299
```
@@ -305,9 +308,9 @@ Inline routes use lambdas and are useful for quickstart and/or small/simple appl
305308

306309
```java
307310
{
308-
get("/", (req, res) -> res.send(req.path()));
311+
get("/", (req, rsp) -> rsp.send(req.path()));
309312

310-
post("/", (req, res) -> res.send(req.path()));
313+
post("/", (req, rsp) -> rsp.send(req.path()));
311314

312315
... etc...
313316
}
@@ -323,10 +326,10 @@ External routes are declared in a separated class and looks like:
323326
}
324327

325328
...
326-
public class ExternalRoute implements Router {
329+
public class ExternalRoute implements Route.Handler {
327330

328-
public void handle(Request req, Response res) throws Exeption {
329-
res.send(req.path());
331+
public void handle(Request req, Response rsp) throws Exeption {
332+
rsp.send(req.path());
330333
}
331334

332335
}
@@ -343,8 +346,8 @@ Of course this is also possible with Java 8:
343346
...
344347
public class ExternalRoute {
345348

346-
public static void callback(Request req, Response res) throws Exeption {
347-
res.send(req.path());
349+
public static void callback(Request req, Response rsp) throws Exeption {
350+
rsp.send(req.path());
348351
}
349352
}
350353
```
@@ -353,46 +356,46 @@ public class ExternalRoute {
353356
Mvc routes are very similar to controllers in [Spring](http://spring.io/) or resources in [Jersey](https://jersey.java.net/).
354357
They are covered later.
355358

356-
### router vs filter
359+
### route handler vs filter
357360

358-
There are two types of handlers [Router] and [Filter]. The difference between them rely in the way
361+
There are two types of handlers [Route.Handler] and [Route.Filter]. The difference between them rely in the way
359362
they allow/denied the execution of the next route in the chain. The next examples are identical:
360363

361364
```java
362365
{
363-
get("/", (req, res) -> {
366+
get("/", (req, rsp) -> {
364367
log.info("first");
365368
});
366369

367-
get("/", (req, res) -> {
370+
get("/", (req, rsp) -> {
368371
log.info("second");
369372
});
370373

371-
get("/", (req, res) ->
372-
res.send("last")
374+
get("/", (req, rsp) ->
375+
rsp.send("last")
373376
);
374377
}
375378
```
376379

377380
```java
378381
{
379-
get("/", (req, res, chain) -> {
382+
get("/", (req, rsp, chain) -> {
380383
log.info("first");
381-
chain.next(req, res);
384+
chain.next(req, rsp);
382385
});
383386

384-
get("/", (req, res, chain) -> {
387+
get("/", (req, rsp, chain) -> {
385388
log.info("second");
386-
chain.next(req, res);
389+
chain.next(req, rsp);
387390
});
388391

389-
get("/", (req, res) ->
390-
res.send("last")
392+
get("/", (req, rsp) ->
393+
rsp.send("last")
391394
);
392395
}
393396
```
394397

395-
A [Router] **always** call the next route in the chain, while a [Filter] might or mightn't call the next route in chain.
398+
A [Route.Handler] **always** call the next route in the chain, while a [Route.Filter] might or mightn't call the next route in chain.
396399

397400
### request params
398401

@@ -459,7 +462,7 @@ For example:
459462

460463
Give us:
461464

462-
get("/user:name", (req, res) -> {
465+
get("/user:name", (req, rsp) -> {
463466
List<String> name = req.param("name").toList(String.class);
464467
// path
465468
assertEquals("first", name.get(0));
@@ -485,3 +488,63 @@ It's identical on how request params work, except that API call is:
485488

486489
String header = req.header("header").stringValue();
487490

491+
## web sockets
492+
493+
Writing WebSockets is pretty easy in Jooby:
494+
495+
```java
496+
import org.joobby.Jooby;
497+
498+
public class App extends Jooby {
499+
500+
{
501+
// 1.
502+
ws("/", (socket) -> {
503+
// 2. connected
504+
505+
socket.onMessage(message -> {
506+
// 4. listen for a message
507+
System.out.println("received " + message.stringValue());
508+
});
509+
510+
// 3. send a message
511+
socket.send("connected");
512+
});
513+
}
514+
515+
}
516+
```
517+
518+
A websocket is listen at ```/```. The path can be as simple or complex as you need:
519+
520+
```java
521+
"/user/:id"
522+
"/events/*"
523+
"/events/**/*"
524+
etc...
525+
```
526+
527+
The socket callback will be executed everytime a client is connected. From there you can send messages, listen for messages, or errors.
528+
529+
### data types
530+
531+
```java
532+
ws("/", (socket) -> {
533+
534+
socket.onMessage(message -> {
535+
// client sent a JSON formatted message and it is parsed as MyObject
536+
MyObject object = message.to(MyObject.class);
537+
});
538+
539+
MyObject value = ...;
540+
// MyObject will be serialized as JSON
541+
socket.send(value);
542+
})
543+
.consumes("application/json")
544+
.produces("application/json");
545+
```
546+
547+
Please note that consumes/produces don't do content negotiation (like they do in routes). On WebSockets they are used to choose/pick a body (de)serializer.
548+
549+
550+
For more information checkout the [WebSocket doc]()

jooby-hbm/src/main/java/org/jooby/hbm/Hbm.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private Route.Filter readWriteTrx(final Key<EntityManager> key) {
140140
log.debug(" starting transaction: {}", trx);
141141
trx.begin();
142142

143-
// invoke next router
143+
// invoke next handler
144144
chain.next(req, new Response.Forwarding(resp) {
145145

146146
void setReadOnly(final Session session, final boolean readOnly) {

jooby-tests/src/test/java/org/jooby/AcceptHeaderFeature.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
public class AcceptHeaderFeature extends ServerFeature {
1010

1111
{
12-
get("/", (req, res) -> res.send(req.accept()));
12+
get("/", (req, rsp) -> rsp.send(req.accept()));
1313

1414
get("/accept",
15-
(req, res) -> res.send(req.accepts(req.param("type").toList(MediaType.class))
15+
(req, rsp) -> rsp.send(req.accepts(req.param("type").toList(MediaType.class))
1616
.map(MediaType::toString).orElse("nope")));
1717
}
1818

jooby-tests/src/test/java/org/jooby/AllParamsFeature.java

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

1414
{
1515

16-
post("/:name", (req, res) -> {
16+
post("/:name", (req, rsp) -> {
1717
Map<String, Mutant> params = req.params();
1818
assertEquals("a", params.get("name").toList(String.class).get(0));
1919
assertEquals("b", params.get("name").toList(String.class).get(1));
@@ -22,7 +22,7 @@ public class AllParamsFeature extends ServerFeature {
2222
assertEquals("a1", params.get("p1").stringValue());
2323
assertEquals("a2", params.get("p2").stringValue());
2424

25-
res.send("done");
25+
rsp.send("done");
2626
});
2727

2828
}

jooby-tests/src/test/java/org/jooby/CharsetHeaderFeature.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
public class CharsetHeaderFeature extends ServerFeature {
1111

1212
{
13-
get("/", (req, res) -> res.send(req.charset()));
13+
get("/", (req, rsp) -> rsp.send(req.charset()));
1414
}
1515

1616
@Test

jooby-tests/src/test/java/org/jooby/ContentTypeHeaderFeature.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
public class ContentTypeHeaderFeature extends ServerFeature {
99

1010
{
11-
get("/", (req, res) -> res.send(req.type()));
11+
get("/", (req, rsp) -> rsp.send(req.type()));
1212
}
1313

1414
@Test

jooby-tests/src/test/java/org/jooby/CookiesFeature.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public class CookiesFeature extends ServerFeature {
1414

1515
{
1616

17-
get("/set", (req, res) -> {
18-
res.cookie(new Cookie.Definition("X", "x").path("/set")).send("done");
17+
get("/set", (req, rsp) -> {
18+
rsp.cookie(new Cookie.Definition("X", "x").path("/set")).send("done");
1919
});
2020

2121
}

jooby-tests/src/test/java/org/jooby/DestroySessionByTimeoutFeature.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public String generateID(final long seed) {
4646
use(store)
4747
.timeout(1);
4848

49-
get("/timeout", (req, res) -> {
49+
get("/timeout", (req, rsp) -> {
5050
req.session();
51-
res.send("timeout");
51+
rsp.send("timeout");
5252
});
5353

5454
}

jooby-tests/src/test/java/org/jooby/DestroySessionFeature.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ public String generateID(final long seed) {
4545
{
4646
use(store);
4747

48-
get("/destroy", (req, res) -> {
48+
get("/destroy", (req, rsp) -> {
4949
req.session().destroy();
50-
res.send("destroy");
50+
rsp.send("destroy");
5151
});
5252

5353
}

0 commit comments

Comments
 (0)