All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zalando.logbook.LogbookCreator Maven / Gradle / Ivy

There is a newer version: 3.10.0
Show newest version
package org.zalando.logbook;

import lombok.Singular;

import javax.annotation.Nullable;
import java.util.List;
import java.util.function.Predicate;

public final class LogbookCreator {

    LogbookCreator() {
        // package private so we can trick code coverage
    }

    @lombok.Builder(builderClassName = "Builder")
    private static Logbook create(
            @Nullable final Predicate condition,
            @Singular final List rawRequestFilters,
            @Singular final List rawResponseFilters,
            @Singular final List queryFilters,
            @Singular final List headerFilters,
            @Singular final List bodyFilters,
            @Singular final List requestFilters,
            @Singular final List responseFilters,
            @Nullable final HttpLogFormatter formatter,
            @Nullable final HttpLogWriter writer) {

        @Nullable final RawRequestFilter rawRequestFilter = rawRequestFilters.stream()
                .reduce(RawRequestFilter::merge)
                .orElse(null);

        @Nullable final RawResponseFilter rawResponseFilter = rawResponseFilters.stream()
                .reduce(RawResponseFilter::merge)
                .orElse(null);

        @Nullable final QueryFilter queryFilter = queryFilters.stream()
                .reduce(QueryFilter::merge)
                .orElse(null);

        @Nullable final HeaderFilter headerFilter = headerFilters.stream()
                .reduce(HeaderFilter::merge)
                .orElse(null);

        @Nullable final BodyFilter bodyFilter = bodyFilters.stream()
                .reduce(BodyFilter::merge)
                .orElse(null);

        @Nullable final RequestFilter requestFilter = requestFilters.stream()
                .reduce(RequestFilter::merge)
                .orElse(null);

        @Nullable final ResponseFilter responseFilter = responseFilters.stream()
                .reduce(ResponseFilter::merge)
                .orElse(null);

        final LogbookFactory factory = LogbookFactory.INSTANCE;

        return factory.create(
                condition,
                rawRequestFilter,
                rawResponseFilter,
                queryFilter,
                headerFilter,
                bodyFilter,
                requestFilter,
                responseFilter,
                formatter,
                writer);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy