From e5b2621567b93818afff41bd6e98fbdf674d5dea Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 29 Mar 2024 14:48:49 +0300 Subject: [PATCH 1/2] Mark `aspectjrt` dependency as `implementation` --- CHANGELOG.md | 2 ++ build.gradle | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffb9c7a4..260ec2f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Changelog ## [Unreleased] +### Changed +- Mark `aspectjrt` dependency as `implementation`, by @HardNorth ## [5.2.8] ### Added diff --git a/build.gradle b/build.gradle index bb9dd83e..48b04e30 100644 --- a/build.gradle +++ b/build.gradle @@ -43,13 +43,14 @@ dependencies { api ('com.epam.reportportal:commons-model:5.0.0') { exclude module: 'jackson-databind' } + api 'com.fasterxml.jackson.core:jackson-databind:2.12.7.1' // Access is needed by HTTP loggers to format JSON api 'io.reactivex.rxjava2:rxjava:2.2.10' api 'com.google.code.findbugs:jsr305:3.0.2' api ("com.squareup.retrofit2:retrofit:${project.retrofit_version}") { exclude module: 'okhttp' } - api 'com.fasterxml.jackson.core:jackson-databind:2.12.7.1' // Access is needed by HTTP loggers to format JSON + implementation "com.squareup.okhttp3:okhttp:${project.okhttp_version}" implementation "com.squareup.retrofit2:converter-scalars:${project.retrofit_version}" implementation ("com.squareup.retrofit2:converter-jackson:${project.retrofit_version}") { exclude module: 'jackson-databind' @@ -57,10 +58,8 @@ dependencies { implementation ("com.squareup.retrofit2:adapter-rxjava2:${project.retrofit_version}") { exclude module: 'rxjava' } - implementation "com.squareup.okhttp3:okhttp:${project.okhttp_version}" implementation "com.squareup.okhttp3:logging-interceptor:${project.okhttp_version}" - - api "org.aspectj:aspectjrt:${project.aspectj_version}" + implementation "org.aspectj:aspectjrt:${project.aspectj_version}" implementation "org.aspectj:aspectjweaver:${project.aspectj_version}" implementation 'org.slf4j:slf4j-api:2.0.7' From 63e19d687e702cb69882eaceeeaef9d3c9e71af8 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 1 Apr 2024 13:25:47 +0300 Subject: [PATCH 2/2] Move `CookieJar` object to static final field in ReportPortal class to use one instance for all HTTP clients --- CHANGELOG.md | 1 + .../reportportal/service/ReportPortal.java | 29 ++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 260ec2f4..31b1a751 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [Unreleased] ### Changed - Mark `aspectjrt` dependency as `implementation`, by @HardNorth +- Move `CookieJar` object to static final field in ReportPortal class to use one instance for all HTTP clients, by @HardNorth ## [5.2.8] ### Added diff --git a/src/main/java/com/epam/reportportal/service/ReportPortal.java b/src/main/java/com/epam/reportportal/service/ReportPortal.java index 56097801..b2356cc8 100644 --- a/src/main/java/com/epam/reportportal/service/ReportPortal.java +++ b/src/main/java/com/epam/reportportal/service/ReportPortal.java @@ -73,6 +73,20 @@ public class ReportPortal { private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortal.class); + private static final CookieJar COOKIE_JAR = new CookieJar() { + private final Map> STORAGE = new ConcurrentHashMap<>(); + + @Override + public void saveFromResponse(@Nonnull HttpUrl url, @Nonnull List cookies) { + STORAGE.computeIfAbsent(url.url().getHost(), u -> new CopyOnWriteArrayList<>()).addAll(cookies); + } + + @Override + @Nonnull + public List loadForRequest(@Nonnull HttpUrl url) { + return STORAGE.computeIfAbsent(url.url().getHost(), u -> new CopyOnWriteArrayList<>()); + } + }; private final ListenerParameters parameters; private final LaunchIdLock launchIdLock; @@ -556,20 +570,7 @@ protected OkHttpClient defaultClient(@Nonnull ListenerParameters parameters) { ofNullable(parameters.getHttpReadTimeout()).ifPresent(builder::readTimeout); ofNullable(parameters.getHttpWriteTimeout()).ifPresent(builder::writeTimeout); - builder.retryOnConnectionFailure(true).cookieJar(new CookieJar() { - private final Map> STORAGE = new ConcurrentHashMap<>(); - - @Override - public void saveFromResponse(@Nonnull HttpUrl url, @Nonnull List cookies) { - STORAGE.computeIfAbsent(url.url().getHost(), u -> new CopyOnWriteArrayList<>()).addAll(cookies); - } - - @Override - @Nonnull - public List loadForRequest(@Nonnull HttpUrl url) { - return STORAGE.computeIfAbsent(url.url().getHost(), u -> new CopyOnWriteArrayList<>()); - } - }); + builder.retryOnConnectionFailure(true).cookieJar(COOKIE_JAR); return builder.build(); }