This repository was archived by the owner on Mar 3, 2026. It is now read-only.
forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPipelineImpl.java
More file actions
58 lines (52 loc) · 1.38 KB
/
Copy pathPipelineImpl.java
File metadata and controls
58 lines (52 loc) · 1.38 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
package io.jooby.internal;
import io.jooby.Context;
import io.jooby.Err;
import io.jooby.Route;
import org.jooby.funzy.Throwing;
import static org.jooby.funzy.Throwing.isFatal;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PipelineImpl implements Route.Pipeline {
private final RouteImpl[] routes;
private final Route.ErrHandler err;
private int r;
public PipelineImpl(RouteImpl[] routes, Route.ErrHandler err) {
this.routes = routes;
this.err = err;
}
public void resume(Context ctx) {
r -= 1;
next(ctx);
}
@Override public void next(Context ctx) {
if (ctx.committed()) {
return;
}
if (r < routes.length) {
RouteImpl route = routes[r++];
ctx.route(route);
try {
route.handler.handle(ctx, this);
} catch (Context.Dispatched dispatched) {
throw dispatched;
} catch (Throwable x) {
handleError(ctx, x);
}
} else {
ctx.end();
}
}
private void handleError(Context ctx, Throwable x) {
try {
Err err = x instanceof Err ? (Err) x : new Err(500, x);
this.err.handle(ctx, err);
} catch (Throwable errx) {
Logger log = LoggerFactory.getLogger(Err.class);
log.error("execution of error handler resulted in a new exception", errx);
}
// rethrow fatal exception
if (isFatal(x)) {
throw Throwing.sneakyThrow(x);
}
}
}