@@ -62,41 +62,41 @@ public class RouterImpl implements Router {
6262 private static class Stack {
6363 private String pattern ;
6464 private Executor executor ;
65- private List <Route .Decorator > filters = new ArrayList <>();
65+ private List <Route .Decorator > decoratorList = new ArrayList <>();
6666 private List <Route .Before > beforeList = new ArrayList <>();
67- private List <Route .After > afters = new ArrayList <>();
67+ private List <Route .After > afterList = new ArrayList <>();
6868
6969 public Stack (String pattern ) {
7070 this .pattern = pattern ;
7171 }
7272
7373 public void then (Route .Decorator filter ) {
74- filters .add (filter );
74+ decoratorList .add (filter );
7575 }
7676
7777 public void then (Route .After after ) {
78- afters .add (after );
78+ afterList .add (after );
7979 }
8080
8181 public void then (Route .Before before ) {
8282 beforeList .add (before );
8383 }
8484
85- public Stream <Route .Decorator > toFilter () {
86- return filters .stream ();
85+ public Stream <Route .Decorator > toDecorator () {
86+ return decoratorList .stream ();
8787 }
8888
8989 public Stream <Route .After > toAfter () {
90- return afters .stream ();
90+ return afterList .stream ();
9191 }
9292
9393 public Stream <Route .Before > toBefore () {
9494 return beforeList .stream ();
9595 }
9696
9797 public void clear () {
98- this .filters .clear ();
99- this .afters .clear ();
98+ this .decoratorList .clear ();
99+ this .afterList .clear ();
100100 this .beforeList .clear ();
101101 executor = null ;
102102 }
@@ -356,32 +356,26 @@ private Route defineRoute(@Nonnull String method, @Nonnull String pattern,
356356 stack .stream ().filter (it -> it .pattern != null ).forEach (it -> pat .append (it .pattern ));
357357 pat .append (pattern );
358358
359- /** Decorators: */
360- List <Route .Decorator > filters = stack .stream ()
361- .flatMap (Stack ::toFilter )
362- .collect (Collectors .toList ());
363-
364359 /** Before: */
365360 Route .Before before = stack .stream ()
366361 .flatMap (Stack ::toBefore )
367362 .reduce (null , (it , next ) -> it == null ? next : it .then (next ));
368363
369- /** Pipeline: */
370- // Route.Handler pipeline = before == null ? handler : before.then(handler);
364+ /** Decorator: */
365+ Route .Decorator decorator = stack .stream ()
366+ .flatMap (Stack ::toDecorator )
367+ .reduce (null , (it , next ) -> it == null ? next : it .then (next ));
371368
372369 /** After: */
373370 Route .After after = stack .stream ()
374371 .flatMap (Stack ::toAfter )
375372 .reduce (null , (it , next ) -> it == null ? next : it .then (next ));
376373
377- // if (after != null) {
378- // pipeline = pipeline.then(after);
379- // }
380-
381374 /** Route: */
382375 String safePattern = normalizePath (pat .toString (), options .isCaseSensitive (),
383376 options .isIgnoreTrailingSlash ());
384- Route route = new Route (method , safePattern , null , handler , before , after , renderer , parsers );
377+ Route route = new Route (method , safePattern , null , handler , before , decorator , after , renderer ,
378+ parsers );
385379 Stack stack = this .stack .peekLast ();
386380 if (stack .executor != null ) {
387381 routeExecutor .put (route , stack .executor );
@@ -422,11 +416,20 @@ private Route defineRoute(@Nonnull String method, @Nonnull String pattern,
422416 if (route .getConsumes ().size () > 0 ) {
423417 before = before == null ? SUPPORT_MEDIA_TYPE : SUPPORT_MEDIA_TYPE .then (before );
424418 }
425- Route .Handler pipeline = route .getHandler ();
419+
420+ Route .Decorator decorator = route .getDecorator ();
421+ Route .Handler handler = route .getHandler ();
422+ Route .Handler pipeline ;
423+ if (decorator == null ) {
424+ pipeline = handler ;
425+ } else {
426+ pipeline = decorator .then (handler );
427+ }
426428
427429 if (before != null ) {
428430 pipeline = before .then (pipeline );
429431 }
432+
430433 Route .After after = route .getAfter ();
431434 if (after != null ) {
432435 pipeline = pipeline .then (after );
@@ -558,8 +561,8 @@ public void destroy() {
558561 }
559562
560563 private Router newStack (@ Nonnull String pattern , @ Nonnull Runnable action ,
561- Route .Decorator ... filter ) {
562- return newStack (push (pattern ), action , filter );
564+ Route .Decorator ... decorator ) {
565+ return newStack (push (pattern ), action , decorator );
563566 }
564567
565568 private Stack push () {
@@ -638,7 +641,8 @@ private void find(String prefix, Class type, Sneaky.Consumer<MvcMethod> consumer
638641 if (executor == null ) {
639642 // TODO: replace with usage exception
640643 throw new IllegalArgumentException (
641- "Missing executor: " + executorKey + ", required by: " + mvc .getMethod ().getDeclaringClass ().getName () + "." + mvc .getMethod ()
644+ "Missing executor: " + executorKey + ", required by: " + mvc .getMethod ()
645+ .getDeclaringClass ().getName () + "." + mvc .getMethod ()
642646 .getName () + ", at line: " + mvc .getLine ());
643647 }
644648 dispatch (executor , () -> consumer .accept (mvc ));
0 commit comments