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

io.vrap.rmf.base.client.MiddlewareFactory Maven / Gradle / Ivy

There is a newer version: 17.15.1
Show newest version
package io.vrap.rmf.base.client;

import io.vrap.rmf.base.client.http.*;
import io.vrap.rmf.base.client.oauth2.TokenSupplier;
import org.apache.commons.lang3.SystemUtils;
import org.slf4j.Logger;

import java.util.List;
import java.util.function.Supplier;

import static java.util.Arrays.asList;

public class MiddlewareFactory {
    public static List createDefault(final TokenSupplier tokenSupplier, final InternalLoggerFactory internalLoggerFactory)
    {
        return createDefault(tokenSupplier, internalLoggerFactory, MiddlewareFactory::buildUserAgent);
    }

    public static List createDefault(final TokenSupplier tokenSupplier, final InternalLoggerFactory internalLoggerFactory, final Supplier userAgent)
    {
        final OAuthHandler oAuthHandler = new OAuthHandler(tokenSupplier);
        return asList(
                (request, next) -> next.apply(request.withHeader(ApiHttpHeaders.USER_AGENT, userAgent.get())),
                new ErrorMiddleware(),
                new InternalLoggerMiddleware(internalLoggerFactory),
                new OAuthMiddleware(oAuthHandler)
        );
    }

    public static String buildUserAgent() {
        String runtimeVersion = SystemUtils.JAVA_RUNTIME_VERSION;
        String osName = SystemUtils.OS_NAME;
        String osArch = SystemUtils.OS_ARCH;
        String sdkVersion = BuildInfo.VERSION;
        return "commercetools-java-sdks/" + sdkVersion + " " + " Java/" + runtimeVersion + " (" + osName + "; " + osArch + ")";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy