001 002package io.vrap.rmf.base.client; 003 004import static java.util.Arrays.asList; 005 006import java.util.List; 007import java.util.function.Supplier; 008 009import io.vrap.rmf.base.client.error.HttpExceptionFactory; 010import io.vrap.rmf.base.client.http.*; 011import io.vrap.rmf.base.client.oauth2.TokenSupplier; 012 013import org.apache.commons.lang3.SystemUtils; 014 015/** 016 * @deprecated functionality now available using the {@link ClientBuilder} 017 */ 018@Deprecated 019public class MiddlewareFactory { 020 public static List<Middleware> createDefault(final TokenSupplier tokenSupplier, 021 final InternalLoggerFactory internalLoggerFactory) { 022 return createDefault(tokenSupplier, internalLoggerFactory, MiddlewareFactory::buildUserAgent); 023 } 024 025 public static List<Middleware> createDefault(final TokenSupplier tokenSupplier, 026 final InternalLoggerFactory internalLoggerFactory, final Supplier<String> userAgent) { 027 return createDefault(tokenSupplier, internalLoggerFactory, userAgent, ResponseSerializer.of()); 028 } 029 030 public static List<Middleware> createDefault(final TokenSupplier tokenSupplier, 031 final InternalLoggerFactory internalLoggerFactory, final Supplier<String> userAgent, 032 final ResponseSerializer serializer) { 033 final OAuthHandler oAuthHandler = new OAuthHandler(tokenSupplier); 034 return asList( 035 (request, 036 next) -> next.apply(request.withHeader(ApiHttpHeaders.USER_AGENT, userAgent.get()) 037 .withHeader(ApiHttpHeaders.ACCEPT_ENCODING, "gzip")), 038 ErrorMiddleware.of(HttpExceptionFactory.of(serializer)), InternalLoggerMiddleware.of(internalLoggerFactory), 039 OAuthMiddleware.of(oAuthHandler)); 040 } 041 042 /** 043 * @deprecated use {@link ClientBuilder#buildDefaultUserAgent()} instead 044 * @return user agent string 045 */ 046 @Deprecated 047 public static String buildUserAgent() { 048 String runtimeVersion = SystemUtils.JAVA_RUNTIME_VERSION; 049 String osName = SystemUtils.OS_NAME; 050 String osArch = SystemUtils.OS_ARCH; 051 String sdkVersion = BuildInfo.VERSION; 052 return "commercetools-java-sdks/" + sdkVersion + " " + " Java/" + runtimeVersion + " (" + osName + "; " + osArch 053 + ")"; 054 } 055}