Skip to content

Commit 1fdf21c

Browse files
committed
rename interceptor events #315
1 parent 4a8dd17 commit 1fdf21c

7 files changed

Lines changed: 128 additions & 127 deletions

File tree

coverage-report/src/test/java/org/jooby/issues/Issue315.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class Issue315 extends ServerFeature {
1515
{
1616
AtomicInteger inc = new AtomicInteger(1);
1717

18-
after("/err", (req, rsp, cause) -> {
18+
complete("/err", (req, rsp, cause) -> {
1919
assertTrue(cause.isPresent());
2020
});
2121

@@ -41,26 +41,26 @@ public class Issue315 extends ServerFeature {
4141
buff.append("a");
4242
});
4343

44-
after("/buff", (req, rsp, cause) -> {
44+
complete("/buff", (req, rsp, cause) -> {
4545
buff.append("b");
4646
});
4747
get("/buff", () -> buff);
4848

49-
before("/chain", (req, rsp, result) -> {
49+
after("/chain", (req, rsp, result) -> {
5050
String v = result.get();
5151
result.set("<" + v + ">");
5252
return result;
5353
});
5454

55-
before("/chain", (req, rsp, result) -> {
55+
after("/chain", (req, rsp, result) -> {
5656
String v = result.get();
5757
result.set("-" + v + "-");
5858
return result;
5959
});
6060

6161
get("/chain", () -> "v");
6262

63-
after("/async", (req, rsp, cause) -> {
63+
complete("/async", (req, rsp, cause) -> {
6464
assertEquals(false, cause.isPresent());
6565
});
6666

@@ -73,13 +73,13 @@ public class Issue315 extends ServerFeature {
7373
inc.incrementAndGet();
7474
});
7575

76-
before((req, rsp, result) -> {
76+
after((req, rsp, result) -> {
7777
Integer i = result.get();
7878
result.set(i + 2);
7979
return result;
8080
});
8181

82-
after((req, rsp, cause) -> {
82+
complete((req, rsp, cause) -> {
8383
inc.incrementAndGet();
8484
});
8585

jooby/src/main/java/org/jooby/Jooby.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -957,14 +957,14 @@ public Route.Definition before(final String method, final String pattern,
957957
}
958958

959959
@Override
960-
public Route.Definition before(final String method, final String pattern,
961-
final Route.BeforeSend handler) {
960+
public Route.Definition after(final String method, final String pattern,
961+
final Route.After handler) {
962962
return appendDefinition(new Route.Definition(method, pattern, handler));
963963
}
964964

965965
@Override
966-
public Route.Definition after(final String method, final String pattern,
967-
final Route.After handler) {
966+
public Route.Definition complete(final String method, final String pattern,
967+
final Route.Complete handler) {
968968
return appendDefinition(new Route.Definition(method, pattern, handler));
969969
}
970970

jooby/src/main/java/org/jooby/Route.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,14 +1546,14 @@ default void handle(final Request req, final Response rsp, final Chain chain) th
15461546
}
15471547

15481548
/**
1549-
* <h2>before send</h2>
1549+
* <h2>after</h2>
15501550
*
15511551
* Allows for customized response before send it. It will be invoked at the time a response need
15521552
* to be send.
15531553
*
15541554
* <pre>{@code
15551555
* {
1556-
* before("GET", "*", (req, rsp, result) -> {
1556+
* after("GET", "*", (req, rsp, result) -> {
15571557
* // your code goes here
15581558
* return result;
15591559
* });
@@ -1563,29 +1563,29 @@ default void handle(final Request req, final Response rsp, final Chain chain) th
15631563
* You are allowed to modify the request, response and result objects. The handler returns a
15641564
* {@link Result} which can be the same or an entirely new {@link Result}.
15651565
*
1566-
* Please note that the <code>before send</code> handler is just syntax sugar for
1566+
* Please note that the <code>after</code> handler is just syntax sugar for
15671567
* {@link Route.Filter}.
1568-
* For example, the <code>before send</code> handler was implemented as:
1568+
* For example, the <code>after</code> handler was implemented as:
15691569
*
15701570
* <pre>{@code
15711571
* {
15721572
* use("GET", "*", (req, rsp, chain) -> {
15731573
* chain.next(req, new Response.Forwarding(rsp) {
15741574
* public void send(Result result) {
1575-
* rsp.send(before(req, rsp, result);
1575+
* rsp.send(after(req, rsp, result);
15761576
* }
15771577
* });
15781578
* });
15791579
* }
15801580
* }</pre>
15811581
*
1582-
* Due <code>before send</code> is implemented by wrapping the {@link Response} object. A
1583-
* <code>before send</code> handler must to be registered before the actual handler you want to
1582+
* Due <code>after</code> is implemented by wrapping the {@link Response} object. A
1583+
* <code>after</code> handler must to be registered before the actual handler you want to
15841584
* intercept.
15851585
*
15861586
* <pre>{@code
15871587
* {
1588-
* before("GET", "/path", (req, rsp, result) -> {
1588+
* after("GET", "/path", (req, rsp, result) -> {
15891589
* // your code goes here
15901590
* return result;
15911591
* });
@@ -1606,7 +1606,7 @@ default void handle(final Request req, final Response rsp, final Chain chain) th
16061606
* @author edgar
16071607
* @since 1.0.0.CR
16081608
*/
1609-
interface BeforeSend extends Filter {
1609+
interface After extends Filter {
16101610
@Override
16111611
default void handle(final Request req, final Response rsp, final Chain chain) throws Throwable {
16121612
chain.next(req, new Response.Forwarding(rsp) {
@@ -1632,13 +1632,13 @@ public void send(final Result result) throws Exception {
16321632
}
16331633

16341634
/**
1635-
* <h2>after</h2>
1635+
* <h2>complete</h2>
16361636
*
16371637
* Allows for log and cleanup a request. It will be invoked after we send a response.
16381638
*
16391639
* <pre>{@code
16401640
* {
1641-
* after((req, rsp, cause) -> {
1641+
* complete((req, rsp, cause) -> {
16421642
* // your code goes here
16431643
* });
16441644
* }
@@ -1647,11 +1647,11 @@ public void send(final Result result) throws Exception {
16471647
* You are NOT allowed to modify the request and response objects. The <code>cause</code> is an
16481648
* {@link Optional} with a {@link Throwable} useful to identify problems.
16491649
*
1650-
* The goal of the <code>after</code> handler is to probably cleanup request object and log
1650+
* The goal of the <code>complete</code> handler is to probably cleanup request object and log
16511651
* responses.
16521652
*
1653-
* Please note that the <code>after</code> handler is just syntax sugar for {@link Route.Filter}.
1654-
* For example, the <code>after</code> handler was implemented as:
1653+
* Please note that the <code>complete</code> handler is just syntax sugar for {@link Route.Filter}.
1654+
* For example, the <code>complete</code> handler was implemented as:
16551655
*
16561656
* <pre>{@code
16571657
* {
@@ -1662,18 +1662,18 @@ public void send(final Result result) throws Exception {
16621662
* } catch (Throwable cause) {
16631663
* err = Optional.of(cause);
16641664
* } finally {
1665-
* after(req, rsp, err);
1665+
* complete(req, rsp, err);
16661666
* }
16671667
* });
16681668
* }
16691669
* }</pre>
16701670
*
1671-
* An <code>after</code> handler must to be registered before the actual handler you want to
1671+
* An <code>complete</code> handler must to be registered before the actual handler you want to
16721672
* intercept.
16731673
*
16741674
* <pre>{@code
16751675
* {
1676-
* after((req, rsp, cause) -> {
1676+
* complete((req, rsp, cause) -> {
16771677
* // your code goes here
16781678
* });
16791679
*
@@ -1709,7 +1709,7 @@ public void send(final Result result) throws Exception {
17091709
* });
17101710
*
17111711
* // commit/rollback transaction
1712-
* after((req, rsp, cause) -> {
1712+
* complete((req, rsp, cause) -> {
17131713
* // unbind connection from request
17141714
* try(Connection connection = req.unset("connection").get()) {
17151715
* Transaction trx = connection.getTransaction();
@@ -1732,7 +1732,7 @@ public void send(final Result result) throws Exception {
17321732
* @author edgar
17331733
* @since 1.0.0.CR
17341734
*/
1735-
interface After extends Filter {
1735+
interface Complete extends Filter {
17361736

17371737
@Override
17381738
default void handle(final Request req, final Response rsp, final Chain chain) throws Throwable {

0 commit comments

Comments
 (0)