diff --git a/commercetools/commercetools-apachehttp-client/src/main/java/com/commercetools/http/apachehttp/ApacheHttpClientSolutionInfo.java b/commercetools/commercetools-apachehttp-client/src/main/java/com/commercetools/http/apachehttp/ApacheHttpClientSolutionInfo.java index 00bcba8987f..3490d37c19c 100644 --- a/commercetools/commercetools-apachehttp-client/src/main/java/com/commercetools/http/apachehttp/ApacheHttpClientSolutionInfo.java +++ b/commercetools/commercetools-apachehttp-client/src/main/java/com/commercetools/http/apachehttp/ApacheHttpClientSolutionInfo.java @@ -1,10 +1,12 @@ package com.commercetools.http.apachehttp; +import io.vrap.rmf.base.client.SolutionInfo; + import org.apache.hc.client5.http.classic.HttpClient; import org.apache.hc.core5.util.VersionInfo; -public class ApacheHttpClientSolutionInfo extends io.vrap.rmf.base.client.SolutionInfo { +public class ApacheHttpClientSolutionInfo extends SolutionInfo { public ApacheHttpClientSolutionInfo() { setName("ApacheHttpAsyncClient"); setVersion( diff --git a/commercetools/commercetools-apachehttp-client/src/test/java/com/commercetools/http/apachehttp/SolutionInfoTest.java b/commercetools/commercetools-apachehttp-client/src/test/java/com/commercetools/http/apachehttp/SolutionInfoTest.java new file mode 100644 index 00000000000..2edc0b515c0 --- /dev/null +++ b/commercetools/commercetools-apachehttp-client/src/test/java/com/commercetools/http/apachehttp/SolutionInfoTest.java @@ -0,0 +1,14 @@ + +package com.commercetools.http.apachehttp; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +public class SolutionInfoTest { + @Test + public void version() { + String version = new ApacheHttpClientSolutionInfo().getVersion(); + + Assertions.assertThat(version).isEqualTo("5.4.1"); + } +} diff --git a/commercetools/commercetools-async-http-client/src/main/java/com/commercetools/http/asynchttp/AsyncHttpClientSolutionInfo.java b/commercetools/commercetools-async-http-client/src/main/java/com/commercetools/http/asynchttp/AsyncHttpClientSolutionInfo.java new file mode 100644 index 00000000000..ceaa22852e3 --- /dev/null +++ b/commercetools/commercetools-async-http-client/src/main/java/com/commercetools/http/asynchttp/AsyncHttpClientSolutionInfo.java @@ -0,0 +1,14 @@ + +package com.commercetools.http.asynchttp; + +import io.vrap.rmf.base.client.SolutionInfo; +import io.vrap.rmf.base.client.VersionLoader; + +public class AsyncHttpClientSolutionInfo extends SolutionInfo { + + public AsyncHttpClientSolutionInfo() { + setName("AsyncHttpAsyncClient"); + setVersion(VersionLoader.loadVersionInfo("org.asynchttpclient", "async-http-client", "pom.properties", + "version", this.getClass().getClassLoader())); + } +} diff --git a/commercetools/commercetools-async-http-client/src/main/resources/META-INF/services/io.vrap.rmf.base.client.SolutionInfo b/commercetools/commercetools-async-http-client/src/main/resources/META-INF/services/io.vrap.rmf.base.client.SolutionInfo new file mode 100644 index 00000000000..97eeac311ab --- /dev/null +++ b/commercetools/commercetools-async-http-client/src/main/resources/META-INF/services/io.vrap.rmf.base.client.SolutionInfo @@ -0,0 +1 @@ +com.commercetools.http.asynchttp.AsyncHttpClientSolutionInfo diff --git a/commercetools/commercetools-async-http-client/src/test/java/com/commercetools/http/asynchttpclient/SolutionInfoTest.java b/commercetools/commercetools-async-http-client/src/test/java/com/commercetools/http/asynchttpclient/SolutionInfoTest.java new file mode 100644 index 00000000000..ca4046fa09f --- /dev/null +++ b/commercetools/commercetools-async-http-client/src/test/java/com/commercetools/http/asynchttpclient/SolutionInfoTest.java @@ -0,0 +1,16 @@ + +package com.commercetools.http.asynchttpclient; + +import com.commercetools.http.asynchttp.AsyncHttpClientSolutionInfo; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +public class SolutionInfoTest { + @Test + public void version() { + String version = new AsyncHttpClientSolutionInfo().getVersion(); + + Assertions.assertThat(version).isEqualTo("2.12.3"); + } +} diff --git a/commercetools/commercetools-javanet-client/src/main/java/com/commercetools/http/javanet/JavaNetHttpClientSolutionInfo.java b/commercetools/commercetools-javanet-client/src/main/java/com/commercetools/http/javanet/JavaNetHttpClientSolutionInfo.java new file mode 100644 index 00000000000..a1486b802eb --- /dev/null +++ b/commercetools/commercetools-javanet-client/src/main/java/com/commercetools/http/javanet/JavaNetHttpClientSolutionInfo.java @@ -0,0 +1,14 @@ + +package com.commercetools.http.javanet; + +import io.vrap.rmf.base.client.SolutionInfo; + +import org.apache.commons.lang3.SystemUtils; + +public class JavaNetHttpClientSolutionInfo extends SolutionInfo { + + public JavaNetHttpClientSolutionInfo() { + setName("JavaNetHttpClient"); + setVersion(SystemUtils.JAVA_RUNTIME_VERSION); + } +} diff --git a/commercetools/commercetools-javanet-client/src/main/resources/META-INF/services/io.vrap.rmf.base.client.SolutionInfo b/commercetools/commercetools-javanet-client/src/main/resources/META-INF/services/io.vrap.rmf.base.client.SolutionInfo new file mode 100644 index 00000000000..56e446e8ac2 --- /dev/null +++ b/commercetools/commercetools-javanet-client/src/main/resources/META-INF/services/io.vrap.rmf.base.client.SolutionInfo @@ -0,0 +1 @@ +com.commercetools.http.javanet.JavaNetHttpClientSolutionInfo diff --git a/commercetools/commercetools-javanet-client/src/test/java/com/commercetools/http/javanet/SolutionInfoTest.java b/commercetools/commercetools-javanet-client/src/test/java/com/commercetools/http/javanet/SolutionInfoTest.java new file mode 100644 index 00000000000..43fb10b9317 --- /dev/null +++ b/commercetools/commercetools-javanet-client/src/test/java/com/commercetools/http/javanet/SolutionInfoTest.java @@ -0,0 +1,14 @@ + +package com.commercetools.http.javanet; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +public class SolutionInfoTest { + @Test + public void version() { + String version = new JavaNetHttpClientSolutionInfo().getVersion(); + + Assertions.assertThat(version).isNotEmpty(); + } +} diff --git a/commercetools/commercetools-okhttp-client3/src/main/java/com/commercetools/http/okhttp3/OkHttpClientSolutionInfo.java b/commercetools/commercetools-okhttp-client3/src/main/java/com/commercetools/http/okhttp3/OkHttpClientSolutionInfo.java new file mode 100644 index 00000000000..ae9d4f5fc80 --- /dev/null +++ b/commercetools/commercetools-okhttp-client3/src/main/java/com/commercetools/http/okhttp3/OkHttpClientSolutionInfo.java @@ -0,0 +1,14 @@ + +package com.commercetools.http.okhttp3; + +import io.vrap.rmf.base.client.SolutionInfo; +import io.vrap.rmf.base.client.VersionLoader; + +public class OkHttpClientSolutionInfo extends SolutionInfo { + + public OkHttpClientSolutionInfo() { + setName("OkHttpClient"); + setVersion(VersionLoader.loadVersionInfo("com.squareup.okhttp3", "okhttp", "pom.properties", "version", + this.getClass().getClassLoader())); + } +} diff --git a/commercetools/commercetools-okhttp-client3/src/main/resources/META-INF/services/io.vrap.rmf.base.client.SolutionInfo b/commercetools/commercetools-okhttp-client3/src/main/resources/META-INF/services/io.vrap.rmf.base.client.SolutionInfo new file mode 100644 index 00000000000..a801f94812d --- /dev/null +++ b/commercetools/commercetools-okhttp-client3/src/main/resources/META-INF/services/io.vrap.rmf.base.client.SolutionInfo @@ -0,0 +1 @@ +com.commercetools.http.okhttp3.OkHttpClientSolutionInfo diff --git a/commercetools/commercetools-okhttp-client3/src/test/java/com/commercetools/http/okhttp3/SolutionInfoTest.java b/commercetools/commercetools-okhttp-client3/src/test/java/com/commercetools/http/okhttp3/SolutionInfoTest.java new file mode 100644 index 00000000000..30c274fa731 --- /dev/null +++ b/commercetools/commercetools-okhttp-client3/src/test/java/com/commercetools/http/okhttp3/SolutionInfoTest.java @@ -0,0 +1,14 @@ + +package com.commercetools.http.okhttp3; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +public class SolutionInfoTest { + @Test + public void version() { + String version = new OkHttpClientSolutionInfo().getVersion(); + + Assertions.assertThat(version).isEqualTo("3.14.9"); + } +} diff --git a/commercetools/commercetools-okhttp-client4/src/main/java/com/commercetools/http/okhttp4/OkHttpClientSolutionInfo.java b/commercetools/commercetools-okhttp-client4/src/main/java/com/commercetools/http/okhttp4/OkHttpClientSolutionInfo.java new file mode 100644 index 00000000000..9222279fc28 --- /dev/null +++ b/commercetools/commercetools-okhttp-client4/src/main/java/com/commercetools/http/okhttp4/OkHttpClientSolutionInfo.java @@ -0,0 +1,14 @@ + +package com.commercetools.http.okhttp4; + +import io.vrap.rmf.base.client.SolutionInfo; + +import okhttp3.OkHttp; + +public class OkHttpClientSolutionInfo extends SolutionInfo { + + public OkHttpClientSolutionInfo() { + setName("OkHttpClient"); + setVersion(OkHttp.VERSION); + } +} diff --git a/commercetools/commercetools-okhttp-client4/src/main/resources/META-INF/services/io.vrap.rmf.base.client.SolutionInfo b/commercetools/commercetools-okhttp-client4/src/main/resources/META-INF/services/io.vrap.rmf.base.client.SolutionInfo new file mode 100644 index 00000000000..63d60f0e3e1 --- /dev/null +++ b/commercetools/commercetools-okhttp-client4/src/main/resources/META-INF/services/io.vrap.rmf.base.client.SolutionInfo @@ -0,0 +1 @@ +com.commercetools.http.okhttp4.OkHttpClientSolutionInfo diff --git a/commercetools/commercetools-okhttp-client4/src/test/java/com/commercetools/http/okhttp4/SolutionInfoTest.java b/commercetools/commercetools-okhttp-client4/src/test/java/com/commercetools/http/okhttp4/SolutionInfoTest.java new file mode 100644 index 00000000000..71ab1fa7bda --- /dev/null +++ b/commercetools/commercetools-okhttp-client4/src/test/java/com/commercetools/http/okhttp4/SolutionInfoTest.java @@ -0,0 +1,14 @@ + +package com.commercetools.http.okhttp4; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +public class SolutionInfoTest { + @Test + public void version() { + String version = new OkHttpClientSolutionInfo().getVersion(); + + Assertions.assertThat(version).isEqualTo("3.14.9"); + } +} diff --git a/commercetools/commercetools-reactornetty-client/src/main/java/com/commercetools/http/netty/NettyHttpClientSolutionInfo.java b/commercetools/commercetools-reactornetty-client/src/main/java/com/commercetools/http/netty/NettyHttpClientSolutionInfo.java new file mode 100644 index 00000000000..d91eb8ae3b6 --- /dev/null +++ b/commercetools/commercetools-reactornetty-client/src/main/java/com/commercetools/http/netty/NettyHttpClientSolutionInfo.java @@ -0,0 +1,14 @@ + +package com.commercetools.http.netty; + +import io.vrap.rmf.base.client.SolutionInfo; + +import reactor.netty.http.client.HttpClient; + +public class NettyHttpClientSolutionInfo extends SolutionInfo { + + public NettyHttpClientSolutionInfo() { + setName("NettyHttpClient"); + setVersion(HttpClient.class.getPackage().getImplementationVersion()); + } +} diff --git a/commercetools/commercetools-reactornetty-client/src/main/resources/META-INF/services/io.vrap.rmf.base.client.SolutionInfo b/commercetools/commercetools-reactornetty-client/src/main/resources/META-INF/services/io.vrap.rmf.base.client.SolutionInfo new file mode 100644 index 00000000000..3c112e4202d --- /dev/null +++ b/commercetools/commercetools-reactornetty-client/src/main/resources/META-INF/services/io.vrap.rmf.base.client.SolutionInfo @@ -0,0 +1 @@ +com.commercetools.http.netty.NettyHttpClientSolutionInfo diff --git a/commercetools/commercetools-reactornetty-client/src/test/java/com/commercetools/http/netty/SolutionInfoTest.java b/commercetools/commercetools-reactornetty-client/src/test/java/com/commercetools/http/netty/SolutionInfoTest.java new file mode 100644 index 00000000000..bac8a081fb4 --- /dev/null +++ b/commercetools/commercetools-reactornetty-client/src/test/java/com/commercetools/http/netty/SolutionInfoTest.java @@ -0,0 +1,14 @@ + +package com.commercetools.http.netty; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +public class SolutionInfoTest { + @Test + public void version() { + String version = new NettyHttpClientSolutionInfo().getVersion(); + + Assertions.assertThat(version).isEqualTo("1.1.19"); + } +} diff --git a/rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/UserAgentUtils.java b/rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/UserAgentUtils.java index d60d9c0140e..54e393a393b 100644 --- a/rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/UserAgentUtils.java +++ b/rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/UserAgentUtils.java @@ -55,7 +55,10 @@ private static String getSolutionInfoString(List additionalSolutio public static String format(final SolutionInfo solutionInfo) { final StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(solutionInfo.getName()).append("/").append(solutionInfo.getVersion()); + stringBuilder.append(solutionInfo.getName()); + if (isNotEmpty(solutionInfo.getVersion())) { + stringBuilder.append("/").append(solutionInfo.getVersion()); + } if (isNotEmpty(solutionInfo.getWebsite()) && isNotEmpty(solutionInfo.getEmergencyContact())) { stringBuilder.append(" ("); final String details = Stream.of(solutionInfo.getWebsite(), solutionInfo.getEmergencyContact()) diff --git a/rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/VersionLoader.java b/rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/VersionLoader.java new file mode 100644 index 00000000000..1968e42a5e4 --- /dev/null +++ b/rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/VersionLoader.java @@ -0,0 +1,33 @@ + +package io.vrap.rmf.base.client; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Optional; +import java.util.Properties; + +public class VersionLoader { + + public static String loadVersionInfo(final String groupId, final String artifactId, final String versionFile, + final String versionProperty, final ClassLoader classLoader) { + Properties loadedProps = null; + try { + try (final InputStream is = classLoader + .getResourceAsStream("META-INF/maven/" + groupId + "/" + artifactId + "/" + versionFile)) { + if (is != null) { + final Properties props = new Properties(); + props.load(is); + loadedProps = props; + } + } + } + catch (final IOException ignored) { + } + + if (loadedProps != null) { + return Optional.ofNullable(loadedProps.get(versionProperty)).map(Object::toString).orElse(null); + } + + return null; + } +}