Search in sources :

Example 1 with PathMatcher

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));
}
Also used : PathMatcher(io.helidon.webserver.PathMatcher) Test(org.junit.jupiter.api.Test)

Example 2 with PathMatcher

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();
}
Also used : Config(io.helidon.config.Config) ZonedDateTime(java.time.ZonedDateTime) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Level(java.util.logging.Level) ServerRequest(io.helidon.webserver.ServerRequest) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) PathMatcher(io.helidon.webserver.PathMatcher) Matcher(java.util.regex.Matcher) ServerResponse(io.helidon.webserver.ServerResponse) Clock(java.time.Clock) Pattern(java.util.regex.Pattern) Service(io.helidon.webserver.Service) LinkedList(java.util.LinkedList) Routing(io.helidon.webserver.Routing) Collections(java.util.Collections) PathMatcher(io.helidon.webserver.PathMatcher) ZonedDateTime(java.time.ZonedDateTime)

Aggregations

PathMatcher (io.helidon.webserver.PathMatcher)2 Config (io.helidon.config.Config)1 Routing (io.helidon.webserver.Routing)1 ServerRequest (io.helidon.webserver.ServerRequest)1 ServerResponse (io.helidon.webserver.ServerResponse)1 Service (io.helidon.webserver.Service)1 Clock (java.time.Clock)1 ZonedDateTime (java.time.ZonedDateTime)1 Collections (java.util.Collections)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 TimeUnit (java.util.concurrent.TimeUnit)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Test (org.junit.jupiter.api.Test)1