Skip to content

Commit

Permalink
add HttpClient info to UserAgent
Browse files Browse the repository at this point in the history
  • Loading branch information
jenschude committed Dec 20, 2024
1 parent 99f1f3b commit 0939d12
Show file tree
Hide file tree
Showing 19 changed files with 201 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.commercetools.http.asynchttp.AsyncHttpClientSolutionInfo
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.commercetools.http.javanet.JavaNetHttpClientSolutionInfo
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.commercetools.http.okhttp3.OkHttpClientSolutionInfo
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.commercetools.http.okhttp4.OkHttpClientSolutionInfo
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.commercetools.http.netty.NettyHttpClientSolutionInfo
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ private static String getSolutionInfoString(List<SolutionInfo> 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())
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 0939d12

Please sign in to comment.