use of io.helidon.webserver.PathMatcher in project helidon by oracle.
the class AccessLogSupportTest method testExcludePaths.
@Test
void testExcludePaths() {
AccessLogSupport accessLog = AccessLogSupport.builder().excludePaths("/metrics", "/health*").build();
assertThat(accessLog.excludePaths().size(), is(2));
PathMatcher pathMatcher1 = accessLog.excludePaths().get(0);
assertThat(pathMatcher1.match("/metrics").matches(), is(true));
PathMatcher pathMatcher2 = accessLog.excludePaths().get(1);
assertThat(pathMatcher2.match("/health").matches(), is(true));
assertThat(pathMatcher2.match("/healthy").matches(), is(true));
}
use of io.helidon.webserver.PathMatcher in project helidon by oracle.
the class AccessLogSupport method handle.
private void handle(ServerRequest req, ServerResponse res) {
// Check if this path should be excluded from access log
if (excludePaths.size() > 0) {
for (PathMatcher matcher : excludePaths) {
PathMatcher.Result r = matcher.match(req.path().toString());
if (r.matches()) {
req.next();
return;
}
}
}
ZonedDateTime now = ZonedDateTime.now(clock);
long nanoNow = System.nanoTime();
logFormat.forEach(entry -> entry.accept(req, res));
res.whenSent().thenAccept(aResponse -> log(req, aResponse, now, nanoNow)).exceptionally(throwable -> {
log(req, res, now, nanoNow);
return null;
});
req.next();
}
Aggregations