@@ -86,21 +86,40 @@ public interface Decorator {
8686 * @author edgar
8787 * @since 2.0.0
8888 */
89- public interface Before extends Decorator {
90- @ Nonnull @ Override default Handler apply (@ Nonnull Handler next ) {
89+ public interface Before {
90+ /**
91+ * Execute application code before next handler.
92+ *
93+ * @param ctx Web context.
94+ * @throws Exception If something goes wrong.
95+ */
96+ void apply (@ Nonnull Context ctx ) throws Exception ;
97+
98+ /**
99+ * Chain this filter with next one and produces a new before filter.
100+ *
101+ * @param next Next decorator.
102+ * @return A new decorator.
103+ */
104+ @ Nonnull default Before then (@ Nonnull Before next ) {
91105 return ctx -> {
92- before (ctx );
93- return next .apply (ctx );
106+ apply (ctx );
107+ next .apply (ctx );
94108 };
95109 }
96110
97111 /**
98- * Execute application code before next handler.
112+ * Chain this decorator with a handler and produces a new handler.
99113 *
100- * @param ctx Web context .
101- * @throws Exception If something goes wrong .
114+ * @param next Next handler .
115+ * @return A new handler .
102116 */
103- void before (@ Nonnull Context ctx ) throws Exception ;
117+ @ Nonnull default Handler then (@ Nonnull Handler next ) {
118+ return ctx -> {
119+ apply (ctx );
120+ return next .apply (ctx );
121+ };
122+ }
104123 }
105124
106125 /**
@@ -205,7 +224,7 @@ public interface Handler extends Serializable {
205224
206225 private List <String > pathKeys ;
207226
208- private Decorator before ;
227+ private Before before ;
209228
210229 private Handler handler ;
211230
@@ -241,7 +260,7 @@ public Route(@Nonnull String method,
241260 @ Nonnull List <String > pathKeys ,
242261 @ Nonnull Type returnType ,
243262 @ Nonnull Handler handler ,
244- @ Nullable Decorator before ,
263+ @ Nullable Before before ,
245264 @ Nullable After after ,
246265 @ Nonnull Renderer renderer ,
247266 @ Nonnull Map <String , Parser > parsers ) {
@@ -281,7 +300,7 @@ public Route(@Nonnull String method,
281300 @ Nonnull String pattern ,
282301 @ Nonnull Type returnType ,
283302 @ Nonnull Handler handler ,
284- @ Nullable Decorator before ,
303+ @ Nullable Before before ,
285304 @ Nullable After after ,
286305 @ Nonnull Renderer renderer ,
287306 @ Nonnull Map <String , Parser > parsers ) {
@@ -350,7 +369,7 @@ public Route(@Nonnull String method,
350369 *
351370 * @return Before pipeline or <code>null</code>.
352371 */
353- public @ Nullable Decorator getBefore () {
372+ public @ Nullable Before getBefore () {
354373 return before ;
355374 }
356375
0 commit comments