forked from actframework/actframework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequestHandlerProxy.java
More file actions
703 lines (630 loc) · 25.7 KB
/
RequestHandlerProxy.java
File metadata and controls
703 lines (630 loc) · 25.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
package act.handler.builtin.controller;
/*-
* #%L
* ACT Framework
* %%
* Copyright (C) 2014 - 2017 ActFramework
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import static org.osgl.http.H.Method.GET;
import static org.osgl.http.H.Method.POST;
import act.Act;
import act.ActResponse;
import act.Destroyable;
import act.app.ActionContext;
import act.app.App;
import act.app.AppInterceptorManager;
import act.app.event.SysEventId;
import act.controller.CacheSupportMetaInfo;
import act.controller.ResponseCache;
import act.controller.meta.*;
import act.handler.RequestHandlerBase;
import act.security.CORS;
import act.security.CSRF;
import act.util.AnnotatedClassFinder;
import act.util.Global;
import act.util.MissingAuthenticationHandler;
import act.view.ActErrorResult;
import act.view.RenderAny;
import act.xio.WebSocketConnectionHandler;
import org.osgl.$;
import org.osgl.cache.CacheService;
import org.osgl.exception.UnexpectedException;
import org.osgl.http.H;
import org.osgl.logging.L;
import org.osgl.logging.Logger;
import org.osgl.mvc.result.ErrorResult;
import org.osgl.mvc.result.Result;
import org.osgl.util.E;
import org.osgl.util.S;
import java.lang.reflect.Method;
import java.util.*;
import java.util.regex.Pattern;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
@ApplicationScoped
public final class RequestHandlerProxy extends RequestHandlerBase {
private static Logger logger = L.get(RequestHandlerProxy.class);
private static final List<BeforeInterceptor> globalBeforeInterceptors = new ArrayList<>();
private static final List<AfterInterceptor> globalAfterInterceptors = new ArrayList<>();
private static final List<FinallyInterceptor> globalFinallyInterceptors = new ArrayList<>();
private static final List<ExceptionInterceptor> globalExceptionInterceptors = new ArrayList<>();
// for @Global on classes
private static final Set<GroupInterceptorMetaInfo> globalFreeStyleInterceptors = new HashSet<>();
// for @Global on methods
private static GroupInterceptorMetaInfo globalFreeStyleInterceptor = new GroupInterceptorMetaInfo();
public static final GroupInterceptorWithResult GLOBAL_BEFORE_INTERCEPTOR = new GroupInterceptorWithResult(globalBeforeInterceptors);
public static final GroupAfterInterceptor GLOBAL_AFTER_INTERCEPTOR = new GroupAfterInterceptor(globalAfterInterceptors);
public static final GroupFinallyInterceptor GLOBAL_FINALLY_INTERCEPTOR = new GroupFinallyInterceptor(globalFinallyInterceptors);
public static final GroupExceptionInterceptor GLOBAL_EXCEPTION_INTERCEPTOR = new GroupExceptionInterceptor(globalExceptionInterceptors);
private App app;
private AppInterceptorManager appInterceptor;
private CacheService cache;
private String controllerClassName;
private String actionMethodName;
private String actionPath;
private Method actionMethod;
private volatile ControllerAction actionHandler = null;
private List<BeforeInterceptor> beforeInterceptors = new ArrayList<>();
private List<AfterInterceptor> afterInterceptors = new ArrayList<>();
private List<ExceptionInterceptor> exceptionInterceptors = new ArrayList<>();
private List<FinallyInterceptor> finallyInterceptors = new ArrayList<>();
private boolean sessionFree;
private boolean express;
private boolean skipEvents;
private boolean supportCache;
private CacheSupportMetaInfo cacheSupport;
private MissingAuthenticationHandler missingAuthenticationHandler;
private MissingAuthenticationHandler csrfFailureHandler;
private WebSocketConnectionHandler webSocketConnectionHandler;
final GroupInterceptorWithResult BEFORE_INTERCEPTOR = new GroupInterceptorWithResult(beforeInterceptors);
final GroupAfterInterceptor AFTER_INTERCEPTOR = new GroupAfterInterceptor(afterInterceptors);
final GroupFinallyInterceptor FINALLY_INTERCEPTOR = new GroupFinallyInterceptor(finallyInterceptors);
final GroupExceptionInterceptor EXCEPTION_INTERCEPTOR = new GroupExceptionInterceptor(exceptionInterceptors);
@Inject
public RequestHandlerProxy(final String actionMethodName, final App app) {
int pos = actionMethodName.lastIndexOf('.');
final String ERR = "Invalid controller action: %s";
E.illegalArgumentIf(pos < 0, ERR, actionMethodName);
controllerClassName = actionMethodName.substring(0, pos);
E.illegalArgumentIf(S.isEmpty(controllerClassName), ERR, actionMethodName);
this.actionMethodName = actionMethodName.substring(pos + 1);
E.illegalArgumentIf(S.isEmpty(this.actionMethodName), ERR, actionMethodName);
this.actionPath = actionMethodName;
if (app.classLoader() != null) {
cache = app.config().cacheService("action_proxy");
} else {
app.jobManager().on(SysEventId.CLASS_LOADER_INITIALIZED, new Runnable() {
@Override
public void run() {
cache = app.config().cacheService("action_proxy");
}
});
}
this.app = app;
this.appInterceptor = app.interceptorManager();
}
@Override
protected void releaseResources() {
_releaseResourceCollections(afterInterceptors);
_releaseResourceCollections(beforeInterceptors);
_releaseResourceCollections(exceptionInterceptors);
_releaseResourceCollections(finallyInterceptors);
if (null != actionHandler) {
actionHandler.destroy();
actionHandler = null;
}
}
public static void releaseGlobalResources() {
_releaseResourceCollections(globalAfterInterceptors);
_releaseResourceCollections(globalBeforeInterceptors);
_releaseResourceCollections(globalExceptionInterceptors);
_releaseResourceCollections(globalFinallyInterceptors);
_releaseResourceCollections(globalFreeStyleInterceptors);
globalFreeStyleInterceptor.destroy();
// We must recreate this instance to prevent it from
// been reused after destroyed
globalFreeStyleInterceptor = new GroupInterceptorMetaInfo();
}
private static void _releaseResourceCollections(Collection<? extends Destroyable> col) {
Destroyable.Util.destroyAll(col, null);
col.clear();
}
public String controller() {
return controllerClassName;
}
public String action() {
return actionMethodName;
}
public ControllerAction actionHandler() {
ensureAgentsReady();
return actionHandler;
}
@Override
public void handle(ActionContext context) {
ensureAgentsReady();
context.handlerMethod(actionMethod);
if (null != webSocketConnectionHandler) {
webSocketConnectionHandler.handle(context);
return;
}
Result result = null;
try {
H.Method method = context.req().method();
boolean supportCache = this.supportCache && method == GET || (cacheSupport.supportPost && method == POST);
String cacheKey = null;
if (supportCache) {
cacheKey = cacheSupport.cacheKey(context);
ResponseCache cached = this.cache.get(cacheKey);
if (null != cached) {
cached.applyTo(context.prepareRespForResultEvaluation());
return;
}
context.enableCache();
}
saveActionPath(context);
context.startIntercepting();
result = handleBefore(context);
if (null == result) {
context.startHandling();
result = _handle(context);
}
if (context.resp().isClosed()) {
return;
}
context.startIntercepting();
Result afterResult = handleAfter(result, context);
if (null != afterResult) {
result = afterResult;
}
if (null == result) {
result = context.nullValueResult();
}
onResult(result, context);
if (supportCache) {
this.cache.put(cacheKey, context.resp(), cacheSupport.ttl);
}
} catch (Exception e) {
H.Request req = context.req();
logger.error(e, S.concat("Error handling request: [", req.method().name(), "] ", req.url()));
try {
result = handleException(e, context);
} catch (Exception e0) {
logger.error(e0, "Error invoking exception handler");
}
if (null == result) {
result = ActErrorResult.of(e);
}
try {
onResult(result, context);
} catch (Exception e2) {
logger.error(e2, "error rendering exception handle result");
onResult(ActErrorResult.of(e2), context);
}
} finally {
try {
handleFinally(context);
} catch (Exception e) {
logger.error(e, "Error invoking final handler");
}
}
}
@Override
public boolean sessionFree() {
ensureAgentsReady();
return sessionFree;
}
@Override
public void prepareAuthentication(ActionContext context) {
if (null != missingAuthenticationHandler) {
context.forceMissingAuthenticationHandler(missingAuthenticationHandler);
}
if (null != csrfFailureHandler) {
context.forceCsrfCheckingFailureHandler(csrfFailureHandler);
}
}
@Override
public boolean express(ActionContext context) {
return express;
}
@Override
public boolean skipEvents(ActionContext context) {
return skipEvents;
}
protected final void registerBeforeInterceptor(BeforeInterceptor interceptor) {
insertInterceptor(beforeInterceptors, interceptor);
}
protected final void registerAfterInterceptor(AfterInterceptor interceptor) {
insertInterceptor(afterInterceptors, interceptor);
}
protected final void registerExceptionInterceptor(ExceptionInterceptor interceptor) {
insertInterceptor(exceptionInterceptors, interceptor);
}
protected final void registerFinallyInterceptor(FinallyInterceptor interceptor) {
insertInterceptor(finallyInterceptors, interceptor);
}
private void onResult(Result result, ActionContext context) {
context.dissolve();
boolean isRenderAny = false;
try {
if (result instanceof RenderAny) {
RenderAny any = (RenderAny) result;
isRenderAny = true;
any.apply(context);
} else {
H.Request req = context.req();
ActResponse<?> resp = context.prepareRespForResultEvaluation();
if (result instanceof ErrorResult) {
resp.contentType(req.accept());
}
result.apply(req, resp);
}
} catch (RuntimeException e) {
context.cacheTemplate(null);
throw e;
} finally {
if (isRenderAny) {
RenderAny.clearThreadLocals();
}
}
}
private void ensureAgentsReady() {
if (null == actionHandler) {
synchronized (this) {
if (null == actionHandler) {
generateHandlers();
}
}
}
}
// could be used by View to resolve default path to template
private void saveActionPath(ActionContext context) {
context.actionPath(actionPath);
}
private boolean matches(Set<String> patterns) {
if (patterns.contains(actionMethodName) || patterns.contains(actionPath)) {
return true;
}
for (String s : patterns) {
if (Pattern.compile(s).matcher(actionPath).matches()) {
return true;
}
}
return false;
}
private boolean applied(InterceptorMethodMetaInfo interceptor) {
Set<String> blackList = interceptor.blackList();
if (!blackList.isEmpty()) {
return !matches(blackList);
} else {
Set<String> whiteList = interceptor.whiteList();
if (!whiteList.isEmpty()) {
return matches(whiteList);
}
return true;
}
}
private ActionMethodMetaInfo findActionInfoFromParent(ControllerClassMetaInfo ctrlInfo, String methodName) {
ActionMethodMetaInfo actionInfo;
ControllerClassMetaInfo parent = ctrlInfo.parent(true);
if (null == parent) {
throw new UnexpectedException("Cannot find action method meta info: %s", actionPath);
}
while (true) {
actionInfo = parent.action(methodName);
if (null != actionInfo) {
break;
}
parent = parent.parent(true);
if (null == parent) {
break;
}
}
return new ActionMethodMetaInfo($.requireNotNull(actionInfo), ctrlInfo);
}
private WebSocketConnectionHandler tryGenerateWebSocketConnectionHandler(ActionMethodMetaInfo methodInfo) {
WebSocketConnectionHandler wsHandler = Act.network().createWebSocketConnectionHandler(methodInfo);
return null == wsHandler || !wsHandler.isWsHandler() ? null : wsHandler;
}
private void generateHandlers() {
ControllerClassMetaInfo ctrlInfo = app.classLoader().controllerClassMetaInfo(controllerClassName);
ActionMethodMetaInfo actionInfo = ctrlInfo.action(actionMethodName);
if (null == actionInfo) {
actionInfo = findActionInfoFromParent(ctrlInfo, actionMethodName);
}
webSocketConnectionHandler = tryGenerateWebSocketConnectionHandler(actionInfo);
// if (null != webSocketConnectionHandler) {
// return;
// }
Act.Mode mode = Act.mode();
actionHandler = mode.createRequestHandler(actionInfo, app);
actionMethod = actionHandler.invoker().invokeMethod();
sessionFree = actionHandler.sessionFree();
missingAuthenticationHandler = actionHandler.missingAuthenticationHandler();
csrfFailureHandler = actionHandler.csrfFailureHandler();
express = actionHandler.express();
skipEvents = actionHandler.skipEvents();
cacheSupport = actionHandler.cacheSupport();
supportCache = cacheSupport.enabled;
App app = this.app;
if (supportCache) {
cache = app.cache();
}
GroupInterceptorMetaInfo interceptorMetaInfo = new GroupInterceptorMetaInfo(actionInfo.interceptors());
interceptorMetaInfo.mergeFrom(globalFreeStyleInterceptor);
for (GroupInterceptorMetaInfo freeStyleInterceptor : globalFreeStyleInterceptors) {
interceptorMetaInfo.mergeFrom(freeStyleInterceptor);
}
for (InterceptorMethodMetaInfo info : interceptorMetaInfo.beforeList()) {
if (!applied(info)) {
continue;
}
BeforeInterceptor interceptor = mode.createBeforeInterceptor(info, app);
beforeInterceptors.add(interceptor);
sessionFree = sessionFree && interceptor.sessionFree();
express = express && interceptor.express();
}
for (InterceptorMethodMetaInfo info : interceptorMetaInfo.afterList()) {
if (!applied(info)) {
continue;
}
AfterInterceptor interceptor = mode.createAfterInterceptor(info, app);
afterInterceptors.add(interceptor);
sessionFree = sessionFree && interceptor.sessionFree();
express = express && interceptor.express();
}
for (CatchMethodMetaInfo info : interceptorMetaInfo.catchList()) {
if (!applied(info)) {
continue;
}
ExceptionInterceptor interceptor = mode.createExceptionInterceptor(info, app);
exceptionInterceptors.add(interceptor);
sessionFree = sessionFree && interceptor.sessionFree();
express = express && interceptor.express();
}
Collections.sort(exceptionInterceptors);
for (InterceptorMethodMetaInfo info : interceptorMetaInfo.finallyList()) {
if (!applied(info)) {
continue;
}
FinallyInterceptor interceptor = mode.createFinallyInterceptor(info, app);
finallyInterceptors.add(interceptor);
sessionFree = sessionFree && interceptor.sessionFree();
express = express && interceptor.express();
}
}
public void accept(Handler.Visitor visitor) {
ensureAgentsReady();
for (BeforeInterceptor i : globalBeforeInterceptors) {
i.accept(visitor);
}
for (BeforeInterceptor i : beforeInterceptors) {
i.accept(visitor);
}
actionHandler.accept(visitor);
for (AfterInterceptor i : afterInterceptors) {
i.accept(visitor);
}
for (AfterInterceptor i : globalAfterInterceptors) {
i.accept(visitor);
}
for (FinallyInterceptor i : finallyInterceptors) {
i.accept(visitor);
}
for (FinallyInterceptor i : globalFinallyInterceptors) {
i.accept(visitor);
}
for (ExceptionInterceptor i : exceptionInterceptors) {
i.accept(visitor);
}
for (ExceptionInterceptor i : globalExceptionInterceptors) {
i.accept(visitor);
}
}
@Override
public CSRF.Spec csrfSpec() {
ensureAgentsReady();
return actionHandler.csrfSpec();
}
@Override
public String contentSecurityPolicy() {
ensureAgentsReady();
return actionHandler.contentSecurityPolicy();
}
@Override
public boolean disableContentSecurityPolicy() {
ensureAgentsReady();
return actionHandler.disableContentSecurityPolicy();
}
@Override
public CORS.Spec corsSpec() {
ensureAgentsReady();
return actionHandler.corsSpec();
}
private Result handleBefore(ActionContext actionContext) throws Exception {
Result r = GLOBAL_BEFORE_INTERCEPTOR.apply(actionContext);
if (null == r) {
r = appInterceptor.handleBefore(actionContext);
}
if (null == r) {
r = BEFORE_INTERCEPTOR.apply(actionContext);
}
return r;
}
private Result _handle(ActionContext actionContext) throws Exception {
try {
return actionHandler.handle(actionContext);
} catch (Result r) {
return r;
}
}
private Result handleAfter(Result result, ActionContext actionContext) throws Exception {
result = AFTER_INTERCEPTOR.apply(result, actionContext);
result = appInterceptor.handleAfter(result, actionContext);
result = GLOBAL_AFTER_INTERCEPTOR.apply(result, actionContext);
return result;
}
private void handleFinally(ActionContext actionContext) throws Exception {
FINALLY_INTERCEPTOR.apply(actionContext);
appInterceptor.handleFinally(actionContext);
GLOBAL_FINALLY_INTERCEPTOR.apply(actionContext);
}
private Result handleException(Exception ex, ActionContext actionContext) throws Exception {
Result r = EXCEPTION_INTERCEPTOR.apply(ex, actionContext);
if (null == r) {
r = appInterceptor.handleException(ex, actionContext);
}
if (null == r) {
r = GLOBAL_EXCEPTION_INTERCEPTOR.apply(ex, actionContext);
}
return r;
}
@Override
public String toString() {
return actionPath;
}
public static void registerGlobalInterceptor(GroupInterceptorMetaInfo freeStyleInterceptor) {
globalFreeStyleInterceptors.add(freeStyleInterceptor);
}
public static void registerGlobalInterceptor(InterceptorMethodMetaInfo interceptor, InterceptorType type) {
globalFreeStyleInterceptor.add(interceptor, type);
}
public static void registerGlobalInterceptor(BeforeInterceptor interceptor) {
insertInterceptor(globalBeforeInterceptors, interceptor);
}
public static void registerGlobalInterceptor(AfterInterceptor interceptor) {
insertInterceptor(globalAfterInterceptors, interceptor);
}
public static void registerGlobalInterceptor(FinallyInterceptor interceptor) {
insertInterceptor(globalFinallyInterceptors, interceptor);
}
public static void registerGlobalInterceptor(ExceptionInterceptor interceptor) {
insertInterceptor(globalExceptionInterceptors, interceptor);
Collections.sort(globalExceptionInterceptors);
}
@AnnotatedClassFinder(value = Global.class, callOn = SysEventId.PRE_START)
@SuppressWarnings("unused")
public static void registerGlobalInterceptors(Class<?> interceptorClass) {
App app = Act.app();
if (BeforeInterceptor.class.isAssignableFrom(interceptorClass)) {
BeforeInterceptor interceptor = (BeforeInterceptor) app.getInstance(interceptorClass);
registerGlobalInterceptor(interceptor);
} else if (AfterInterceptor.class.isAssignableFrom(interceptorClass)) {
AfterInterceptor interceptor = (AfterInterceptor) app.getInstance(interceptorClass);
registerGlobalInterceptor(interceptor);
} else if (ExceptionInterceptor.class.isAssignableFrom(interceptorClass)) {
ExceptionInterceptor interceptor = (ExceptionInterceptor) app.getInstance(interceptorClass);
registerGlobalInterceptor(interceptor);
} else if (FinallyInterceptor.class.isAssignableFrom(interceptorClass)) {
FinallyInterceptor interceptor = (FinallyInterceptor) app.getInstance(interceptorClass);
registerGlobalInterceptor(interceptor);
} else {
// check if this is a free style interceptor
ControllerClassMetaInfo metaInfo = app.classLoader().controllerClassMetaInfo(interceptorClass.getName());
if (null != metaInfo) {
registerGlobalInterceptor(metaInfo.interceptors());
}
}
}
public static <T extends Handler> void insertInterceptor(List<T> list, T i) {
int sz = list.size();
if (0 == sz) {
list.add(i);
}
ListIterator<T> itr = list.listIterator();
while (itr.hasNext()) {
T t = itr.next();
int n = i.compareTo(t);
if (n < 0) {
itr.add(i);
return;
} else if (n == 0) {
if (i.equals(t)) {
// already exists
return;
} else {
itr.add(i);
return;
}
}
}
list.add(i);
}
public static class GroupInterceptorWithResult {
private List<? extends ActionHandler> interceptors;
public GroupInterceptorWithResult(List<? extends ActionHandler> interceptors) {
this.interceptors = interceptors;
}
public Result apply(ActionContext actionContext) throws Exception {
try {
if (interceptors.isEmpty()) return null;
for (ActionHandler i : interceptors) {
Result r = i.handle(actionContext);
if (null != r) {
return r;
}
}
return null;
} catch (Result r) {
return r;
}
}
}
public static class GroupAfterInterceptor {
private List<? extends AfterInterceptor> interceptors;
public GroupAfterInterceptor(List<? extends AfterInterceptor> interceptors) {
this.interceptors = interceptors;
}
public Result apply(Result result, ActionContext actionContext) throws Exception {
for (AfterInterceptor i : interceptors) {
result = i.handle(result, actionContext);
}
return result;
}
}
public static class GroupFinallyInterceptor {
private List<? extends FinallyInterceptor> interceptors;
public GroupFinallyInterceptor(List<FinallyInterceptor> interceptors) {
this.interceptors = interceptors;
}
public Void apply(ActionContext actionContext) throws Exception {
if (interceptors.isEmpty()) return null;
for (FinallyInterceptor i : interceptors) {
i.handle(actionContext);
}
return null;
}
}
public static class GroupExceptionInterceptor {
private List<? extends ExceptionInterceptor> interceptors;
public GroupExceptionInterceptor(List<? extends ExceptionInterceptor> interceptors) {
this.interceptors = interceptors;
}
public Result apply(Exception e, ActionContext actionContext) throws Exception {
try {
if (interceptors.isEmpty()) return null;
for (ExceptionInterceptor i : interceptors) {
Result r = i.handle(e, actionContext);
if (null != r) {
return r;
}
}
return null;
} catch (Result r) {
return r;
}
}
}
}