From 94e9c52e8628b621124ee025486a449b47dbd342 Mon Sep 17 00:00:00 2001 From: Matus Tomlein Date: Thu, 11 Jan 2024 08:04:49 +0100 Subject: [PATCH 01/12] Add builder methods Subject to allow method chaining (close #303) PR #369 --- .../snowplow/tracker/Subject.java | 138 +++++++++++++++++- .../snowplow/tracker/SubjectTest.java | 28 ++++ 2 files changed, 158 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/snowplowanalytics/snowplow/tracker/Subject.java b/src/main/java/com/snowplowanalytics/snowplow/tracker/Subject.java index 64634c57..35bc7299 100644 --- a/src/main/java/com/snowplowanalytics/snowplow/tracker/Subject.java +++ b/src/main/java/com/snowplowanalytics/snowplow/tracker/Subject.java @@ -232,6 +232,17 @@ public void setUserId(String userId) { } } + /** + * Sets the User ID and returns itself + * + * @param userId a user id string + * @return itself + */ + public Subject userId(String userId) { + this.setUserId(userId); + return this; + } + /** * Sets the screen res parameter * @@ -245,6 +256,18 @@ public void setScreenResolution(int width, int height) { } } + /** + * Sets the screen res parameter and returns itself + * + * @param width a width integer + * @param height a height integer + * @return itself + */ + public Subject screenResolution(int width, int height) { + this.setScreenResolution(width, height); + return this; + } + /** * Sets the view port parameter * @@ -258,6 +281,18 @@ public void setViewPort(int width, int height) { } } + /** + * Sets the view port parameter and returns itself + * + * @param width a width integer + * @param height a height integer + * @return itself + */ + public Subject viewPort(int width, int height) { + this.setViewPort(width, height); + return this; + } + /** * Sets the color depth parameter * @@ -269,6 +304,17 @@ public void setColorDepth(int depth) { } } + /** + * Sets the color depth parameter and returns itself + * + * @param depth a color depth integer + * @return itself + */ + public Subject colorDepth(int depth) { + this.setColorDepth(depth); + return this; + } + /** * Sets the timezone parameter. Note that timezone is set by default to the server's timezone * (`TimeZone tz = Calendar.getInstance().getTimeZone().getID()`); @@ -281,6 +327,19 @@ public void setTimezone(String timezone) { } } + /** + * Sets the timezone parameter and returns itself. + * Note that timezone is set by default to the server's timezone + * (`TimeZone tz = Calendar.getInstance().getTimeZone().getID()`) + * + * @param timezone a timezone string + * @return itself + */ + public Subject timezone(String timezone) { + this.setTimezone(timezone); + return this; + } + /** * Sets the language parameter * @@ -293,8 +352,18 @@ public void setLanguage(String language) { } /** - * User inputted ip address for the - * subject. + * Sets the language parameter and returns itself + * + * @param language a language string + * @return itself + */ + public Subject language(String language) { + this.setLanguage(language); + return this; + } + + /** + * User inputted ip address for the subject. * * @param ipAddress an ip address */ @@ -305,8 +374,18 @@ public void setIpAddress(String ipAddress) { } /** - * User inputted useragent for the - * subject. + * Sets the user inputted ip address for the subject and returns itself + * + * @param ipAddress a ipAddress string + * @return itself + */ + public Subject ipAddress(String ipAddress) { + this.setIpAddress(ipAddress); + return this; + } + + /** + * User inputted useragent for the subject. * * @param useragent a useragent */ @@ -317,8 +396,18 @@ public void setUseragent(String useragent) { } /** - * User inputted Domain User Id for the - * subject. + * Sets the user inputted useragent for the subject and returns itself + * + * @param useragent a useragent string + * @return itself + */ + public Subject useragent(String useragent) { + this.setUseragent(useragent); + return this; + } + + /** + * User inputted Domain User Id for the subject. * * @param domainUserId a domain user id */ @@ -329,8 +418,18 @@ public void setDomainUserId(String domainUserId) { } /** - * User inputted Domain Session ID for the - * subject. + * Sets the user inputted Domain User Id for the subject and returns itself + * + * @param domainUserId a domainUserId string + * @return itself + */ + public Subject domainUserId(String domainUserId) { + this.setDomainUserId(domainUserId); + return this; + } + + /** + * User inputted Domain Session ID for the subject. * * @param domainSessionId a domain session id */ @@ -340,6 +439,17 @@ public void setDomainSessionId(String domainSessionId) { } } + /** + * Sets the user inputted Domain Session ID for the subject and returns itself + * + * @param domainSessionId a domainSessionId string + * @return itself + */ + public Subject domainSessionId(String domainSessionId) { + this.setDomainSessionId(domainSessionId); + return this; + } + /** * User inputted Network User ID for the subject. * This overrides the network user ID set by the Collector in response Cookies. @@ -352,6 +462,18 @@ public void setNetworkUserId(String networkUserId) { } } + /** + * Sets the user inputted Network User ID for the subject and returns itself. + * This overrides the network user ID set by the Collector in response Cookies. + * + * @param networkUserId a networkUserId string + * @return itself + */ + public Subject networkUserId(String networkUserId) { + this.setNetworkUserId(networkUserId); + return this; + } + /** * Gets the Subject pairs. * diff --git a/src/test/java/com/snowplowanalytics/snowplow/tracker/SubjectTest.java b/src/test/java/com/snowplowanalytics/snowplow/tracker/SubjectTest.java index 38bad0fe..954636c0 100644 --- a/src/test/java/com/snowplowanalytics/snowplow/tracker/SubjectTest.java +++ b/src/test/java/com/snowplowanalytics/snowplow/tracker/SubjectTest.java @@ -113,6 +113,34 @@ public void testGetSubject() { assertEquals(expected, subject.getSubject()); } + @Test + public void testBuilderMethods() { + Subject subject = new Subject(); + subject + .userId("user1") + .screenResolution(100, 150) + .viewPort(150, 100) + .colorDepth(10) + .timezone("America/Toronto") + .language("EN") + .ipAddress("127.0.0.1") + .useragent("useragent") + .domainUserId("duid") + .domainSessionId("sessionid") + .networkUserId("nuid"); + assertEquals("user1", subject.getSubject().get("uid")); + assertEquals("100x150", subject.getSubject().get("res")); + assertEquals("150x100", subject.getSubject().get("vp")); + assertEquals("10", subject.getSubject().get("cd")); + assertEquals("America/Toronto", subject.getSubject().get("tz")); + assertEquals("EN", subject.getSubject().get("lang")); + assertEquals("127.0.0.1", subject.getSubject().get("ip")); + assertEquals("useragent", subject.getSubject().get("ua")); + assertEquals("duid", subject.getSubject().get("duid")); + assertEquals("sessionid", subject.getSubject().get("sid")); + assertEquals("nuid", subject.getSubject().get("tnuid")); + } + @Test public void testCreateFromConfig() { SubjectConfiguration subjectConfig = new SubjectConfiguration() From 8a03602ec712ab44b82346e565d4fedbb7b16b77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matu=CC=81s=CC=8C=20Tomlein?= Date: Wed, 10 Jan 2024 14:50:35 +0100 Subject: [PATCH 02/12] Bump commons-codec to 1.16 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index ff359110..7b703a51 100644 --- a/build.gradle +++ b/build.gradle @@ -58,8 +58,8 @@ test { dependencies { // Apache Commons - api 'commons-codec:commons-codec:1.15' api 'commons-net:commons-net:3.6' + api 'commons-codec:commons-codec:1.16.0' // Apache HTTP apachehttpSupportApi 'org.apache.httpcomponents:httpclient:4.5.13' From 53749e6da4d14434c3b4cbaa5929392db0bfa854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matu=CC=81s=CC=8C=20Tomlein?= Date: Wed, 10 Jan 2024 14:51:02 +0100 Subject: [PATCH 03/12] Bump commons-net to 3.10 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 7b703a51..2de001a0 100644 --- a/build.gradle +++ b/build.gradle @@ -58,7 +58,7 @@ test { dependencies { // Apache Commons - api 'commons-net:commons-net:3.6' + api 'commons-net:commons-net:3.10.0' api 'commons-codec:commons-codec:1.16.0' // Apache HTTP From 9345e2b665c4ad0634c56d50c1f42f27aea6d5ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matu=CC=81s=CC=8C=20Tomlein?= Date: Wed, 10 Jan 2024 14:52:05 +0100 Subject: [PATCH 04/12] Bump jackson-databind to 2.16.1 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 2de001a0..0bd181e8 100644 --- a/build.gradle +++ b/build.gradle @@ -73,7 +73,7 @@ dependencies { testImplementation 'org.slf4j:slf4j-simple:1.7.36' // Jackson JSON processor - api 'com.fasterxml.jackson.core:jackson-databind:2.13.3' + api 'com.fasterxml.jackson.core:jackson-databind:2.16.1' // Testing libraries testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' From 7497813689e708f4fb7bc9744fe87d26766489f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matu=CC=81s=CC=8C=20Tomlein?= Date: Wed, 10 Jan 2024 14:53:00 +0100 Subject: [PATCH 05/12] Bump junit-jupiter-api to 5.10.1 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 0bd181e8..1f0e57b4 100644 --- a/build.gradle +++ b/build.gradle @@ -76,7 +76,7 @@ dependencies { api 'com.fasterxml.jackson.core:jackson-databind:2.16.1' // Testing libraries - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1' testCompileOnly 'junit:junit:4.13.2' testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' From 4161f838b789b72ee7918f69424e0d4ec5fd545b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matu=CC=81s=CC=8C=20Tomlein?= Date: Wed, 10 Jan 2024 14:56:22 +0100 Subject: [PATCH 06/12] Bump slf4j-simple and slf4j-api to 2.0.11 --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 1f0e57b4..b01e82b0 100644 --- a/build.gradle +++ b/build.gradle @@ -69,8 +69,8 @@ dependencies { okhttpSupportApi 'com.squareup.okhttp3:okhttp:4.9.3' // SLF4J logging API - api 'org.slf4j:slf4j-api:1.7.36' - testImplementation 'org.slf4j:slf4j-simple:1.7.36' + api 'org.slf4j:slf4j-api:2.0.11' + testImplementation 'org.slf4j:slf4j-simple:2.0.11' // Jackson JSON processor api 'com.fasterxml.jackson.core:jackson-databind:2.16.1' From 615ad6236b0f1d90c4103e5bca49602b125590c3 Mon Sep 17 00:00:00 2001 From: Matus Tomlein Date: Thu, 11 Jan 2024 08:05:38 +0100 Subject: [PATCH 07/12] Upgrade okhttp dependency to version 4.12 (close #365) PR #371 --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index b01e82b0..ce73664f 100644 --- a/build.gradle +++ b/build.gradle @@ -66,7 +66,7 @@ dependencies { apachehttpSupportApi 'org.apache.httpcomponents:httpasyncclient:4.1.5' // Square OK HTTP - okhttpSupportApi 'com.squareup.okhttp3:okhttp:4.9.3' + okhttpSupportApi 'com.squareup.okhttp3:okhttp:4.12.0' // SLF4J logging API api 'org.slf4j:slf4j-api:2.0.11' @@ -80,7 +80,7 @@ dependencies { testCompileOnly 'junit:junit:4.13.2' testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' - testImplementation 'com.squareup.okhttp3:mockwebserver:4.9.3' + testImplementation 'com.squareup.okhttp3:mockwebserver:4.12.0' } task sourceJar(type: Jar, dependsOn: 'generateSources') { From 8624fe920646bfb8b0965f821fc862b3d0c48e39 Mon Sep 17 00:00:00 2001 From: Matus Tomlein Date: Thu, 11 Jan 2024 08:06:15 +0100 Subject: [PATCH 08/12] Update to Apache Http Client to v5 (close #364) PR #370 --- build.gradle | 3 +-- .../tracker/http/ApacheHttpClientAdapter.java | 23 +++++++++---------- .../tracker/http/HttpClientAdapterTest.java | 2 +- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/build.gradle b/build.gradle index ce73664f..5d38bc7c 100644 --- a/build.gradle +++ b/build.gradle @@ -62,8 +62,7 @@ dependencies { api 'commons-codec:commons-codec:1.16.0' // Apache HTTP - apachehttpSupportApi 'org.apache.httpcomponents:httpclient:4.5.13' - apachehttpSupportApi 'org.apache.httpcomponents:httpasyncclient:4.1.5' + apachehttpSupportApi 'org.apache.httpcomponents.client5:httpclient5:5.3' // Square OK HTTP okhttpSupportApi 'com.squareup.okhttp3:okhttp:4.12.0' diff --git a/src/main/java/com/snowplowanalytics/snowplow/tracker/http/ApacheHttpClientAdapter.java b/src/main/java/com/snowplowanalytics/snowplow/tracker/http/ApacheHttpClientAdapter.java index f2089cb0..ad83f5f2 100644 --- a/src/main/java/com/snowplowanalytics/snowplow/tracker/http/ApacheHttpClientAdapter.java +++ b/src/main/java/com/snowplowanalytics/snowplow/tracker/http/ApacheHttpClientAdapter.java @@ -12,12 +12,11 @@ */ package com.snowplowanalytics.snowplow.tracker.http; -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.classic.methods.HttpGet; +import org.apache.hc.client5.http.classic.methods.HttpPost; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.io.entity.StringEntity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -117,9 +116,9 @@ public Object getHttpClient() { public int doGet(String url) { try { HttpGet httpGet = new HttpGet(url); - HttpResponse httpResponse = httpClient.execute(httpGet); - httpGet.releaseConnection(); - return httpResponse.getStatusLine().getStatusCode(); + return httpClient.execute(httpGet, response -> { + return response.getCode(); + }); } catch (Exception e) { LOGGER.error("ApacheHttpClient GET Request failed: {}", e.getMessage()); return -1; @@ -140,9 +139,9 @@ public int doPost(String url, String payload) { httpPost.addHeader("Content-Type", Constants.POST_CONTENT_TYPE); StringEntity params = new StringEntity(payload, ContentType.APPLICATION_JSON); httpPost.setEntity(params); - HttpResponse httpResponse = httpClient.execute(httpPost); - httpPost.releaseConnection(); - return httpResponse.getStatusLine().getStatusCode(); + return httpClient.execute(httpPost, response -> { + return response.getCode(); + }); } catch (Exception e) { LOGGER.error("ApacheHttpClient POST Request failed: {}", e.getMessage()); return -1; diff --git a/src/test/java/com/snowplowanalytics/snowplow/tracker/http/HttpClientAdapterTest.java b/src/test/java/com/snowplowanalytics/snowplow/tracker/http/HttpClientAdapterTest.java index a6d42dd5..7c9a8db7 100644 --- a/src/test/java/com/snowplowanalytics/snowplow/tracker/http/HttpClientAdapterTest.java +++ b/src/test/java/com/snowplowanalytics/snowplow/tracker/http/HttpClientAdapterTest.java @@ -23,7 +23,7 @@ import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; -import org.apache.http.impl.client.HttpClients; +import org.apache.hc.client5.http.impl.classic.HttpClients; import org.junit.Assert; import org.junit.Test; From 25a41bab2b9e7f5879bf48ddc2dfabf40ed1162c Mon Sep 17 00:00:00 2001 From: Matus Tomlein Date: Thu, 11 Jan 2024 08:06:49 +0100 Subject: [PATCH 09/12] Update copyright headers in source files (#375) --- LICENSE | 2 +- README.md | 2 +- build.gradle | 4 ++-- examples/benchmarking/build.gradle | 2 +- .../src/jmh/java/com/snowplowanalytics/TrackerBenchmark.java | 2 +- .../src/main/java/com/snowplowanalytics/Main.java | 2 +- .../src/test/java/com/snowplowanalytics/MainTest.java | 2 +- .../snowplowanalytics/snowplow/tracker/DevicePlatform.java | 2 +- .../java/com/snowplowanalytics/snowplow/tracker/Snowplow.java | 2 +- .../java/com/snowplowanalytics/snowplow/tracker/Subject.java | 2 +- .../java/com/snowplowanalytics/snowplow/tracker/Tracker.java | 2 +- .../java/com/snowplowanalytics/snowplow/tracker/Utils.java | 2 +- .../snowplow/tracker/configuration/EmitterConfiguration.java | 2 +- .../snowplow/tracker/configuration/NetworkConfiguration.java | 2 +- .../snowplow/tracker/configuration/SubjectConfiguration.java | 2 +- .../snowplow/tracker/configuration/TrackerConfiguration.java | 2 +- .../snowplow/tracker/constants/Constants.java | 2 +- .../snowplow/tracker/constants/Parameter.java | 2 +- .../snowplow/tracker/emitter/BatchEmitter.java | 2 +- .../snowplow/tracker/emitter/BatchPayload.java | 2 +- .../snowplowanalytics/snowplow/tracker/emitter/Emitter.java | 2 +- .../snowplow/tracker/emitter/EmitterCallback.java | 2 +- .../snowplow/tracker/emitter/EventStore.java | 2 +- .../snowplow/tracker/emitter/FailureType.java | 2 +- .../snowplow/tracker/emitter/InMemoryEventStore.java | 2 +- .../snowplow/tracker/events/AbstractEvent.java | 2 +- .../snowplow/tracker/events/EcommerceTransaction.java | 2 +- .../snowplow/tracker/events/EcommerceTransactionItem.java | 2 +- .../com/snowplowanalytics/snowplow/tracker/events/Event.java | 2 +- .../snowplowanalytics/snowplow/tracker/events/PageView.java | 2 +- .../snowplowanalytics/snowplow/tracker/events/ScreenView.java | 2 +- .../snowplow/tracker/events/SelfDescribing.java | 2 +- .../snowplowanalytics/snowplow/tracker/events/Structured.java | 2 +- .../com/snowplowanalytics/snowplow/tracker/events/Timing.java | 2 +- .../snowplow/tracker/http/AbstractHttpClientAdapter.java | 2 +- .../snowplow/tracker/http/ApacheHttpClientAdapter.java | 2 +- .../snowplow/tracker/http/CollectorCookie.java | 2 +- .../snowplow/tracker/http/CollectorCookieJar.java | 2 +- .../snowplow/tracker/http/HttpClientAdapter.java | 2 +- .../snowplow/tracker/http/OkHttpClientAdapter.java | 2 +- .../snowplowanalytics/snowplow/tracker/payload/Payload.java | 2 +- .../snowplow/tracker/payload/SelfDescribingJson.java | 2 +- .../snowplow/tracker/payload/TrackerParameters.java | 2 +- .../snowplow/tracker/payload/TrackerPayload.java | 2 +- .../com/snowplowanalytics/snowplow/tracker/SnowplowTest.java | 2 +- .../com/snowplowanalytics/snowplow/tracker/SubjectTest.java | 2 +- .../com/snowplowanalytics/snowplow/tracker/TrackerTest.java | 2 +- .../com/snowplowanalytics/snowplow/tracker/UtilsTest.java | 2 +- .../snowplow/tracker/emitter/BatchEmitterBuilderTest.java | 2 +- .../snowplow/tracker/emitter/BatchEmitterTest.java | 2 +- .../snowplow/tracker/emitter/CollectorCookieJarTest.java | 2 +- .../snowplow/tracker/emitter/InMemoryEventStoreTest.java | 2 +- .../snowplow/tracker/http/HttpClientAdapterTest.java | 2 +- .../snowplow/tracker/payload/SelfDescribingJsonTest.java | 2 +- .../snowplow/tracker/payload/TrackerPayloadTest.java | 2 +- 55 files changed, 56 insertions(+), 56 deletions(-) diff --git a/LICENSE b/LICENSE index e0977a71..0e1f4fe1 100644 --- a/LICENSE +++ b/LICENSE @@ -187,7 +187,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2022 Snowplow Analytics Ltd. + Copyright 2014-present Snowplow Analytics Ltd. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index d08123eb..839e8fd3 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ $ java -jar ./build/libs/simple-console-all-0.0.1.jar "http:// Date: Thu, 11 Jan 2024 08:07:46 +0100 Subject: [PATCH 10/12] Add okhttp adapter with cookie jar and remove cookie jar from network configuration (close #361) PR #372 --- .../configuration/NetworkConfiguration.java | 22 ------------- .../tracker/emitter/BatchEmitter.java | 33 ++----------------- .../tracker/http/OkHttpClientAdapter.java | 4 +++ .../OkHttpClientWithCookieJarAdapter.java | 29 ++++++++++++++++ .../tracker/http/HttpClientAdapterTest.java | 8 +---- 5 files changed, 36 insertions(+), 60 deletions(-) create mode 100644 src/main/java/com/snowplowanalytics/snowplow/tracker/http/OkHttpClientWithCookieJarAdapter.java diff --git a/src/main/java/com/snowplowanalytics/snowplow/tracker/configuration/NetworkConfiguration.java b/src/main/java/com/snowplowanalytics/snowplow/tracker/configuration/NetworkConfiguration.java index 2f0915d9..7c33d101 100644 --- a/src/main/java/com/snowplowanalytics/snowplow/tracker/configuration/NetworkConfiguration.java +++ b/src/main/java/com/snowplowanalytics/snowplow/tracker/configuration/NetworkConfiguration.java @@ -13,14 +13,12 @@ package com.snowplowanalytics.snowplow.tracker.configuration; import com.snowplowanalytics.snowplow.tracker.http.HttpClientAdapter; -import okhttp3.CookieJar; public class NetworkConfiguration { private HttpClientAdapter httpClientAdapter = null; // Optional private String collectorUrl = null; // Required if not specifying a httpClientAdapter - private CookieJar cookieJar = null; // Optional // Getters and Setters @@ -40,14 +38,6 @@ public String getCollectorUrl() { return collectorUrl; } - /** - * Returns the OkHttp CookieJar used for persisting cookies. - * @return CookieJar object - */ - public CookieJar getCookieJar() { - return cookieJar; - } - // Constructors /** @@ -94,16 +84,4 @@ public NetworkConfiguration collectorUrl(String collectorUrl) { this.collectorUrl = collectorUrl; return this; } - - /** - * Adds a custom CookieJar to be used with OkHttpClientAdapters. - * Will be ignored if a custom httpClientAdapter is provided. - * - * @param cookieJar the CookieJar to use - * @return itself - */ - public NetworkConfiguration cookieJar(CookieJar cookieJar) { - this.cookieJar = cookieJar; - return this; - } } diff --git a/src/main/java/com/snowplowanalytics/snowplow/tracker/emitter/BatchEmitter.java b/src/main/java/com/snowplowanalytics/snowplow/tracker/emitter/BatchEmitter.java index b40d7497..e4da0792 100644 --- a/src/main/java/com/snowplowanalytics/snowplow/tracker/emitter/BatchEmitter.java +++ b/src/main/java/com/snowplowanalytics/snowplow/tracker/emitter/BatchEmitter.java @@ -29,8 +29,6 @@ import com.snowplowanalytics.snowplow.tracker.payload.SelfDescribingJson; import com.snowplowanalytics.snowplow.tracker.payload.TrackerPayload; -import okhttp3.CookieJar; -import okhttp3.OkHttpClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -77,7 +75,6 @@ public static abstract class Builder> { private EventStore eventStore = null; // Optional private Map customRetryForStatusCodes = null; // Optional private int threadCount = 50; // Optional - private CookieJar cookieJar = null; // Optional private ScheduledExecutorService requestExecutorService = null; // Optional private EmitterCallback callback = null; // Optional @@ -176,18 +173,6 @@ public T requestExecutorService(final ScheduledExecutorService requestExecutorSe return self(); } - /** - * Adds a custom CookieJar to be used with OkHttpClientAdapters. - * Will be ignored if a custom httpClientAdapter is provided. - * - * @param cookieJar the CookieJar to use - * @return itself - */ - public T cookieJar(final CookieJar cookieJar) { - this.cookieJar = cookieJar; - return self(); - } - /** * Provide a custom EmitterCallback to access successfully sent or failed event payloads. * @@ -201,8 +186,7 @@ public T callback(final EmitterCallback callback) { public BatchEmitter build() { NetworkConfiguration networkConfig = new NetworkConfiguration(collectorUrl) - .httpClientAdapter(httpClientAdapter) - .cookieJar(cookieJar); + .httpClientAdapter(httpClientAdapter); EmitterConfiguration emitterConfig = new EmitterConfiguration() .batchSize(batchSize) @@ -240,8 +224,6 @@ public static Builder builder() { * @param emitterConfig an EmitterConfiguration object */ public BatchEmitter(NetworkConfiguration networkConfig, EmitterConfiguration emitterConfig) { - OkHttpClient client; - // Precondition checks if (emitterConfig.getThreadCount() <= 0) { throw new IllegalArgumentException("threadCount must be greater than 0"); @@ -258,18 +240,7 @@ public BatchEmitter(NetworkConfiguration networkConfig, EmitterConfiguration emi } else { Objects.requireNonNull(networkConfig.getCollectorUrl(), "Collector url must be specified if not using a httpClientAdapter"); - if (networkConfig.getCookieJar() != null) { - client = new OkHttpClient.Builder() - .cookieJar(networkConfig.getCookieJar()) - .build(); - } else { - client = new OkHttpClient.Builder().build(); - } - - httpClientAdapter = OkHttpClientAdapter.builder() // use okhttp as a default - .url(networkConfig.getCollectorUrl()) - .httpClient(client) - .build(); + httpClientAdapter = new OkHttpClientAdapter(networkConfig.getCollectorUrl()); } retryDelay = new AtomicInteger(0); diff --git a/src/main/java/com/snowplowanalytics/snowplow/tracker/http/OkHttpClientAdapter.java b/src/main/java/com/snowplowanalytics/snowplow/tracker/http/OkHttpClientAdapter.java index a7492321..925bf70d 100644 --- a/src/main/java/com/snowplowanalytics/snowplow/tracker/http/OkHttpClientAdapter.java +++ b/src/main/java/com/snowplowanalytics/snowplow/tracker/http/OkHttpClientAdapter.java @@ -45,6 +45,10 @@ public OkHttpClientAdapter(String url, OkHttpClient httpClient) { this.httpClient = httpClient; } + public OkHttpClientAdapter(String url) { + this(url, new OkHttpClient.Builder().build()); + } + /** * @deprecated Create HttpClientAdapter directly instead * @param Builder diff --git a/src/main/java/com/snowplowanalytics/snowplow/tracker/http/OkHttpClientWithCookieJarAdapter.java b/src/main/java/com/snowplowanalytics/snowplow/tracker/http/OkHttpClientWithCookieJarAdapter.java new file mode 100644 index 00000000..a8d05d70 --- /dev/null +++ b/src/main/java/com/snowplowanalytics/snowplow/tracker/http/OkHttpClientWithCookieJarAdapter.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024-present Snowplow Analytics Ltd. All rights reserved. + * + * This program is licensed to you under the Apache License Version 2.0, + * and you may not use this file except in compliance with the Apache License Version 2.0. + * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the Apache License Version 2.0 is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. + */ +package com.snowplowanalytics.snowplow.tracker.http; + +// SquareUp +import okhttp3.*; + +/** + * A HttpClient built using OkHttp to send events via GET or POST requests. + * The adapter is configured to use a CollectorCookieJar to store and send cookies set by the collector. + * The cookies are stored in memory. + */ +public class OkHttpClientWithCookieJarAdapter extends OkHttpClientAdapter { + + public OkHttpClientWithCookieJarAdapter(String url) { + super(url, new OkHttpClient.Builder().cookieJar(new CollectorCookieJar()).build()); + } + +} diff --git a/src/test/java/com/snowplowanalytics/snowplow/tracker/http/HttpClientAdapterTest.java b/src/test/java/com/snowplowanalytics/snowplow/tracker/http/HttpClientAdapterTest.java index 7c2483eb..031e67ce 100644 --- a/src/test/java/com/snowplowanalytics/snowplow/tracker/http/HttpClientAdapterTest.java +++ b/src/test/java/com/snowplowanalytics/snowplow/tracker/http/HttpClientAdapterTest.java @@ -145,13 +145,7 @@ public void testGetWithNullArgument() { @Test public void testRequestWithCookies() throws IOException, InterruptedException { - OkHttpClient httpClient = new OkHttpClient.Builder() - .connectTimeout(1, TimeUnit.SECONDS) - .readTimeout(1, TimeUnit.SECONDS) - .writeTimeout(1, TimeUnit.SECONDS) - .cookieJar(new CollectorCookieJar()) - .build(); - adapter = new OkHttpClientAdapter(mockWebServer.url("/").toString(), httpClient); + adapter = new OkHttpClientWithCookieJarAdapter(mockWebServer.url("/").toString()); mockWebServer.enqueue(new MockResponse().addHeader("Set-Cookie", "sp=test")); From 037ee683894250b0c16389ab152c21fe2f6efe13 Mon Sep 17 00:00:00 2001 From: Matus Tomlein Date: Thu, 11 Jan 2024 10:54:45 +0100 Subject: [PATCH 11/12] Remove deprecated APIs (close #373) PR #374 --- .../snowplow/tracker/Subject.java | 158 ------------------ .../snowplow/tracker/Tracker.java | 81 --------- .../snowplow/tracker/constants/Parameter.java | 3 - .../tracker/emitter/BatchEmitter.java | 157 ----------------- .../http/AbstractHttpClientAdapter.java | 52 ------ .../tracker/http/ApacheHttpClientAdapter.java | 53 ------ .../tracker/http/OkHttpClientAdapter.java | 53 ------ .../snowplow/tracker/TrackerTest.java | 1 - .../emitter/BatchEmitterBuilderTest.java | 8 +- 9 files changed, 5 insertions(+), 561 deletions(-) diff --git a/src/main/java/com/snowplowanalytics/snowplow/tracker/Subject.java b/src/main/java/com/snowplowanalytics/snowplow/tracker/Subject.java index 011e4a9a..bba82a15 100644 --- a/src/main/java/com/snowplowanalytics/snowplow/tracker/Subject.java +++ b/src/main/java/com/snowplowanalytics/snowplow/tracker/Subject.java @@ -63,164 +63,6 @@ public Subject(Subject subject){ standardPairs.putAll(subject.getSubject()); } - /** - * @deprecated Use SubjectConfiguration class instead - * @return a SubjectBuilder object - */ - @Deprecated - public static SubjectBuilder builder() { - return new SubjectBuilder(); - } - - /** - * Builder for the Subject - * @deprecated Use SubjectConfiguration class instead - */ - @Deprecated - public static class SubjectBuilder { - - private String userId; // Optional - private int screenResWidth = 0; // Optional - private int screenResHeight = 0; // Optional - private int viewPortWidth = 0; // Optional - private int viewPortHeight = 0; // Optional - private int colorDepth = 0; // Optional - private String timezone = Utils.getTimezone(); // Optional - private String language; // Optional - private String ipAddress; // Optional - private String useragent; // Optional - private String networkUserId; // Optional - private String domainUserId; // Optional - private String domainSessionId; // Optional - - /** - * @param userId a user id string - * @return itself - */ - public SubjectBuilder userId(String userId) { - this.userId = userId; - return this; - } - - /** - * @param width a width integer - * @param height a height integer - * @return itself - */ - public SubjectBuilder screenResolution(int width, int height) { - this.screenResWidth = width; - this.screenResHeight = height; - return this; - } - - /** - * @param width a width integer - * @param height a height integer - * @return itself - */ - public SubjectBuilder viewPort(int width, int height) { - this.viewPortWidth = width; - this.viewPortHeight = height; - return this; - } - - /** - * @param depth a color depth integer - * @return itself - */ - public SubjectBuilder colorDepth(int depth) { - this.colorDepth = depth; - return this; - } - - /** - * Note that timezone is set by default to the server's timezone - * (`TimeZone tz = Calendar.getInstance().getTimeZone().getID()`) - * @param timezone a timezone string - * @return itself - */ - public SubjectBuilder timezone(String timezone) { - this.timezone = timezone; - return this; - } - - /** - * @param language a language string - * @return itself - */ - public SubjectBuilder language(String language) { - this.language = language; - return this; - } - - /** - * @param ipAddress a ipAddress string - * @return itself - */ - public SubjectBuilder ipAddress(String ipAddress) { - this.ipAddress = ipAddress; - return this; - } - - /** - * @param useragent a useragent string - * @return itself - */ - public SubjectBuilder useragent(String useragent) { - this.useragent = useragent; - return this; - } - - /** - * @param networkUserId a networkUserId string - * @return itself - */ - public SubjectBuilder networkUserId(String networkUserId) { - this.networkUserId = networkUserId; - return this; - } - - /** - * @param domainUserId a domainUserId string - * @return itself - */ - public SubjectBuilder domainUserId(String domainUserId) { - this.domainUserId = domainUserId; - return this; - } - - /** - * @param domainSessionId a domainSessionId string - * @return itself - */ - public SubjectBuilder domainSessionId(String domainSessionId) { - this.domainSessionId = domainSessionId; - return this; - } - - /** - * Creates a new Subject - * - * @return a new Subject object - */ - public Subject build() { - SubjectConfiguration subjectConfig = new SubjectConfiguration() - .userId(userId) - .screenResolution(screenResWidth, screenResHeight) - .viewPort(viewPortWidth, viewPortHeight) - .colorDepth(colorDepth) - .timezone(timezone) - .language(language) - .ipAddress(ipAddress) - .useragent(useragent) - .networkUserId(networkUserId) - .domainUserId(domainUserId) - .domainSessionId(domainSessionId); - - return new Subject(subjectConfig); - } - } - /** * Sets the User ID * diff --git a/src/main/java/com/snowplowanalytics/snowplow/tracker/Tracker.java b/src/main/java/com/snowplowanalytics/snowplow/tracker/Tracker.java index da2a107f..8a75e367 100644 --- a/src/main/java/com/snowplowanalytics/snowplow/tracker/Tracker.java +++ b/src/main/java/com/snowplowanalytics/snowplow/tracker/Tracker.java @@ -70,87 +70,6 @@ public Tracker(TrackerConfiguration trackerConfig, Emitter emitter) { this(trackerConfig, emitter, null); } - /** - * Builder for the Tracker - * @deprecated Use TrackerConfiguration class instead - */ - @Deprecated - public static class TrackerBuilder { - - private final Emitter emitter; // Required - private final String namespace; // Required - private final String appId; // Required - private Subject subject = null; // Optional - private DevicePlatform platform = DevicePlatform.ServerSideApp; // Optional - private boolean base64Encoded = true; // Optional - - /** - * @param emitter Emitter to which events will be sent - * @param namespace Identifier for the Tracker instance - * @param appId Application ID - */ - public TrackerBuilder(Emitter emitter, String namespace, String appId) { - this.emitter = emitter; - this.namespace = namespace; - this.appId = appId; - } - - /** - * @param subject Subject to be tracked - * @return itself - */ - public TrackerBuilder subject(Subject subject) { - this.subject = subject; - return this; - } - - /** - * The {@link DevicePlatform} the tracker is running on (default is "srv", ServerSideApp). - * - * @param platform The device platform the tracker is running on - * @return itself - */ - public TrackerBuilder platform(DevicePlatform platform) { - this.platform = platform; - return this; - } - - /** - * Whether JSONs in the payload should be base-64 encoded (default is true) - * - * @param base64 JSONs should be encoded or not - * @return itself - */ - public TrackerBuilder base64(Boolean base64) { - this.base64Encoded = base64; - return this; - } - - /** - * Creates a new Tracker - * - * @return a new Tracker object - */ - public Tracker build() { - TrackerConfiguration trackerConfig = new TrackerConfiguration(namespace, appId) - .platform(platform) - .base64Encoded(base64Encoded); - return new Tracker(trackerConfig, emitter, subject); - } - } - - /** - * @deprecated Use TrackerConfiguration class instead - * @param emitter Emitter object - * @param namespace unique tracker namespace - * @param appId application ID - * @return TrackerBuilder object - */ - @Deprecated - public static TrackerBuilder builder(Emitter emitter, String namespace, String appId) { - return new TrackerBuilder(emitter, namespace, appId); - } - // --- Setters /** diff --git a/src/main/java/com/snowplowanalytics/snowplow/tracker/constants/Parameter.java b/src/main/java/com/snowplowanalytics/snowplow/tracker/constants/Parameter.java index c4b9f38d..19ec1863 100644 --- a/src/main/java/com/snowplowanalytics/snowplow/tracker/constants/Parameter.java +++ b/src/main/java/com/snowplowanalytics/snowplow/tracker/constants/Parameter.java @@ -29,9 +29,6 @@ public class Parameter { public static final String DEVICE_CREATED_TIMESTAMP = "dtm"; public static final String DEVICE_SENT_TIMESTAMP = "stm"; - /** deprecated Indicate the specific timestamp to use. This is kept for compatibility with older versions. */ - @Deprecated - public static final String TIMESTAMP = DEVICE_CREATED_TIMESTAMP; public static final String TRACKER_VERSION = "tv"; public static final String APP_ID = "aid"; public static final String NAMESPACE = "tna"; diff --git a/src/main/java/com/snowplowanalytics/snowplow/tracker/emitter/BatchEmitter.java b/src/main/java/com/snowplowanalytics/snowplow/tracker/emitter/BatchEmitter.java index e4da0792..9c2e7a13 100644 --- a/src/main/java/com/snowplowanalytics/snowplow/tracker/emitter/BatchEmitter.java +++ b/src/main/java/com/snowplowanalytics/snowplow/tracker/emitter/BatchEmitter.java @@ -60,163 +60,6 @@ public class BatchEmitter implements Emitter, Closeable { private final Map customRetryForStatusCodes; private final EmitterCallback callback; - /** - * @deprecated Use NetworkConfiguration/EmitterConfiguration classes instead - * @param Builder - */ - @Deprecated - public static abstract class Builder> { - protected abstract T self(); - - private HttpClientAdapter httpClientAdapter; // Optional - private String collectorUrl = null; // Required if not specifying a httpClientAdapter - private int batchSize = 50; // Optional - private int bufferCapacity = 10000; - private EventStore eventStore = null; // Optional - private Map customRetryForStatusCodes = null; // Optional - private int threadCount = 50; // Optional - private ScheduledExecutorService requestExecutorService = null; // Optional - private EmitterCallback callback = null; // Optional - - /** - * Adds a custom HttpClientAdapter to the Emitter (default is OkHttpClientAdapter). - * - * @param httpClientAdapter the adapter to use - * @return itself - */ - public T httpClientAdapter(final HttpClientAdapter httpClientAdapter) { - this.httpClientAdapter = httpClientAdapter; - return self(); - } - - - /** - * Sets the emitter url for when a httpClientAdapter is not specified. - * It will be used to create the default OkHttpClientAdapter. - * - * @param collectorUrl the url for the default httpClientAdapter - * @return itself - */ - public T url(final String collectorUrl) { - this.collectorUrl = collectorUrl; - return self(); - } - - /** - * The default batch size is 50. - * - * @param batchSize The count of events to send in one HTTP request - * @return itself - */ - public T batchSize(final int batchSize) { - this.batchSize = batchSize; - return self(); - } - - /** - * The default buffer capacity is 10 000 events. - * When the buffer is full (due to network outage), new events are lost. - * - * @param bufferCapacity The maximum capacity of the default InMemoryEventStore event buffer - * @return itself - */ - public T bufferCapacity(final int bufferCapacity) { - this.bufferCapacity = bufferCapacity; - return self(); - } - - /** - * The default EventStore is InMemoryEventStore. - * - * @param eventStore The EventStore to use - * @return itself - */ - public T eventStore(final EventStore eventStore) { - this.eventStore = eventStore; - return self(); - } - - /** - * Set custom retry rules for HTTP status codes received in emit responses from the Collector. - * By default, retry will not occur for status codes 400, 401, 403, 410 or 422. This can be overridden here. - * Note that 2xx codes will never retry as they are considered successful. - * @param customRetryForStatusCodes Mapping of integers (status codes) to booleans (true for retry and false for not retry) - * @return itself - */ - public T customRetryForStatusCodes(Map customRetryForStatusCodes) { - this.customRetryForStatusCodes = customRetryForStatusCodes; - return self(); - } - - /** - * Sets the Thread Count for the ScheduledExecutorService (default is 50). - * - * @param threadCount the size of the thread pool - * @return itself - */ - public T threadCount(final int threadCount) { - this.threadCount = threadCount; - return self(); - } - - /** - * Set a custom ScheduledExecutorService to send http requests (default is ScheduledThreadPoolExecutor). - *

- * Implementation note: Be aware that calling `close()` on a BatchEmitter instance - * has a side-effect and will shutdown that ExecutorService. - * - * @param requestExecutorService the ScheduledExecutorService to use - * @return itself - */ - public T requestExecutorService(final ScheduledExecutorService requestExecutorService) { - this.requestExecutorService = requestExecutorService; - return self(); - } - - /** - * Provide a custom EmitterCallback to access successfully sent or failed event payloads. - * - * @param callback an EmitterCallback - * @return itself - */ - public T callback(final EmitterCallback callback) { - this.callback = callback; - return self(); - } - - public BatchEmitter build() { - NetworkConfiguration networkConfig = new NetworkConfiguration(collectorUrl) - .httpClientAdapter(httpClientAdapter); - - EmitterConfiguration emitterConfig = new EmitterConfiguration() - .batchSize(batchSize) - .bufferCapacity(bufferCapacity) - .eventStore(eventStore) - .customRetryForStatusCodes(customRetryForStatusCodes) - .threadCount(threadCount) - .requestExecutorService(requestExecutorService) - .callback(callback); - - return new BatchEmitter(networkConfig, emitterConfig); - } - } - - private static class Builder2 extends Builder { - @Override - protected Builder2 self() { - return this; - } - } - - /** - * @deprecated Use NetworkConfiguration/EmitterConfiguration classes instead - * @return Builder object - */ - @Deprecated - public static Builder builder() { - return new Builder2(); - } - /** * Creates a BatchEmitter object from configuration objects. * diff --git a/src/main/java/com/snowplowanalytics/snowplow/tracker/http/AbstractHttpClientAdapter.java b/src/main/java/com/snowplowanalytics/snowplow/tracker/http/AbstractHttpClientAdapter.java index bcda41f0..58f586f6 100644 --- a/src/main/java/com/snowplowanalytics/snowplow/tracker/http/AbstractHttpClientAdapter.java +++ b/src/main/java/com/snowplowanalytics/snowplow/tracker/http/AbstractHttpClientAdapter.java @@ -28,58 +28,6 @@ public AbstractHttpClientAdapter(String url) { this.url = url.replaceFirst("/*$", ""); } - /** - * @deprecated Create HttpClientAdapter directly instead - * @param Builder - */ - @Deprecated - public static abstract class Builder> { - - private String url; // Required - protected abstract T self(); - - /** - * Adds a URI to the Client Adapter - * - * @param url the emitter url - * @return itself - */ - public T url(String url) { - this.url = url.replaceFirst("/*$", ""); - return self(); - } - } - - private static class Builder2 extends Builder { - @Override - protected Builder2 self() { - return this; - } - } - - /** - * @deprecated Create HttpClientAdapter directly instead - * @return Builder object - */ - @Deprecated - public static Builder builder() { - return new Builder2(); - } - - /** - * @deprecated Create HttpClientAdapter directly instead - * @param builder Builder object - */ - @Deprecated - protected AbstractHttpClientAdapter(Builder builder) { - // Precondition checks - if (!Utils.isValidUrl(builder.url)) { - throw new IllegalArgumentException(); - } - - this.url = builder.url; - } - /** * Returns the HttpClient URI * diff --git a/src/main/java/com/snowplowanalytics/snowplow/tracker/http/ApacheHttpClientAdapter.java b/src/main/java/com/snowplowanalytics/snowplow/tracker/http/ApacheHttpClientAdapter.java index 56099767..de72604c 100644 --- a/src/main/java/com/snowplowanalytics/snowplow/tracker/http/ApacheHttpClientAdapter.java +++ b/src/main/java/com/snowplowanalytics/snowplow/tracker/http/ApacheHttpClientAdapter.java @@ -43,59 +43,6 @@ public ApacheHttpClientAdapter(String url, CloseableHttpClient httpClient) { this.httpClient = httpClient; } - /** - * @deprecated Create HttpClientAdapter directly instead - * @param Builder - */ - @Deprecated - public static abstract class Builder> extends AbstractHttpClientAdapter.Builder { - - private CloseableHttpClient httpClient; // Required - - /** - * @param httpClient The Apache HTTP Client to use - * @return itself - */ - public T httpClient(CloseableHttpClient httpClient) { - this.httpClient = httpClient; - return self(); - } - - public ApacheHttpClientAdapter build() { - return new ApacheHttpClientAdapter(this); - } - } - - private static class Builder2 extends Builder { - @Override - protected Builder2 self() { - return this; - } - } - - /** - * @deprecated Create HttpClientAdapter directly instead - * @return Builder object - */ - @Deprecated - public static Builder builder() { - return new Builder2(); - } - - /** - * @deprecated Create HttpClientAdapter directly instead - * @param builder Builder object - */ - @Deprecated - protected ApacheHttpClientAdapter(Builder builder) { - super(builder); - - // Precondition checks - Objects.requireNonNull(builder.httpClient); - - this.httpClient = builder.httpClient; - } - /** * Returns the HttpClient in use; it is up to the developer * to cast it back to its original class. diff --git a/src/main/java/com/snowplowanalytics/snowplow/tracker/http/OkHttpClientAdapter.java b/src/main/java/com/snowplowanalytics/snowplow/tracker/http/OkHttpClientAdapter.java index 925bf70d..95df941b 100644 --- a/src/main/java/com/snowplowanalytics/snowplow/tracker/http/OkHttpClientAdapter.java +++ b/src/main/java/com/snowplowanalytics/snowplow/tracker/http/OkHttpClientAdapter.java @@ -49,59 +49,6 @@ public OkHttpClientAdapter(String url) { this(url, new OkHttpClient.Builder().build()); } - /** - * @deprecated Create HttpClientAdapter directly instead - * @param Builder - */ - @Deprecated - public static abstract class Builder> extends AbstractHttpClientAdapter.Builder { - - private OkHttpClient httpClient; // Required - - /** - * @param httpClient The OkHTTP Client to use - * @return itself - */ - public T httpClient(OkHttpClient httpClient) { - this.httpClient = httpClient; - return self(); - } - - public OkHttpClientAdapter build() { - return new OkHttpClientAdapter(this); - } - } - - private static class Builder2 extends Builder { - @Override - protected Builder2 self() { - return this; - } - } - - /** - * @deprecated Create HttpClientAdapter directly instead - * @return Builder object - */ - @Deprecated - public static Builder builder() { - return new Builder2(); - } - - /** - * @deprecated Create HttpClientAdapter directly instead - * @param builder Builder object - */ - @Deprecated - protected OkHttpClientAdapter(Builder builder) { - super(builder); - - // Precondition checks - Objects.requireNonNull(builder.httpClient); - - httpClient = builder.httpClient; - } - /** * Returns the HttpClient in use; it is up to the developer * to cast it back to its original class. diff --git a/src/test/java/com/snowplowanalytics/snowplow/tracker/TrackerTest.java b/src/test/java/com/snowplowanalytics/snowplow/tracker/TrackerTest.java index 73ee9a7b..d35a2b60 100644 --- a/src/test/java/com/snowplowanalytics/snowplow/tracker/TrackerTest.java +++ b/src/test/java/com/snowplowanalytics/snowplow/tracker/TrackerTest.java @@ -15,7 +15,6 @@ import java.util.*; import static java.util.Collections.singletonList; -import com.snowplowanalytics.snowplow.tracker.configuration.EmitterConfiguration; import com.snowplowanalytics.snowplow.tracker.configuration.NetworkConfiguration; import com.snowplowanalytics.snowplow.tracker.configuration.TrackerConfiguration; import com.snowplowanalytics.snowplow.tracker.emitter.BatchEmitter; diff --git a/src/test/java/com/snowplowanalytics/snowplow/tracker/emitter/BatchEmitterBuilderTest.java b/src/test/java/com/snowplowanalytics/snowplow/tracker/emitter/BatchEmitterBuilderTest.java index 8013bd37..dc9efb63 100644 --- a/src/test/java/com/snowplowanalytics/snowplow/tracker/emitter/BatchEmitterBuilderTest.java +++ b/src/test/java/com/snowplowanalytics/snowplow/tracker/emitter/BatchEmitterBuilderTest.java @@ -14,6 +14,7 @@ import com.snowplowanalytics.snowplow.tracker.payload.SelfDescribingJson; import com.snowplowanalytics.snowplow.tracker.payload.TrackerPayload; +import com.snowplowanalytics.snowplow.tracker.configuration.NetworkConfiguration; import com.snowplowanalytics.snowplow.tracker.http.HttpClientAdapter; import org.junit.Assert; import org.junit.Test; @@ -22,13 +23,14 @@ public class BatchEmitterBuilderTest { @Test public void setNeitherHttpClientAdapterOrCollectorUrl_shouldThrowException() { - Exception exception = Assert.assertThrows(Exception.class, () -> BatchEmitter.builder().build()); + String collectorUrl = null; + Exception exception = Assert.assertThrows(Exception.class, () -> new BatchEmitter(new NetworkConfiguration(collectorUrl))); Assert.assertEquals("Collector url must be specified if not using a httpClientAdapter", exception.getMessage()); } @Test public void setCollectorUrlAndNoHttpClientAdapter_shouldInitialiseCorrectly() { - BatchEmitter emitter = BatchEmitter.builder().url("https://mycollector.com").build(); + BatchEmitter emitter = new BatchEmitter(new NetworkConfiguration("https://mycollector.com")); Assert.assertNotNull(emitter); } @@ -56,7 +58,7 @@ public Object getHttpClient() { } }; - BatchEmitter emitter = BatchEmitter.builder().httpClientAdapter(mockHttpClientAdapter).build(); + BatchEmitter emitter = new BatchEmitter(new NetworkConfiguration(mockHttpClientAdapter)); Assert.assertNotNull(emitter); } } From cd0f019a486fb44e928752ff23c9f92544cc4883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matu=CC=81s=CC=8C=20Tomlein?= Date: Fri, 12 Jan 2024 10:38:01 +0100 Subject: [PATCH 12/12] Prepare for 2.0.0 release --- CHANGELOG | 14 ++++++++++++++ build.gradle | 2 +- examples/simple-console/build.gradle | 4 ++-- .../src/main/java/com/snowplowanalytics/Main.java | 4 ++-- .../snowplow/tracker/TrackerTest.java | 2 +- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b62404a5..d55c6742 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,17 @@ +Java 2.0.0 (2024-01-12) +----------------------- +Add builder methods Subject to allow method chaining (#303) +Add okhttp adapter with cookie jar and remove cookie jar from network configuration (#361) +Remove deprecated APIs (#373) +Update to Apache Http Client to v5 (#364) +Upgrade okhttp dependency to version 4.12 (#365) +Bump slf4j-simple and slf4j-api to 2.0.11 +Bump junit-jupiter-api to 5.10.1 +Bump jackson-databind to 2.16.1 +Bump commons-net to 3.10 +Bump commons-codec to 1.16 +Update copyright headers in source files (#375) + Java 1.0.1 (2023-11-06) ----------------------- Fix Issue with OkHttpClientAdapter (#366) (thanks to @eusorov for the contribution!) diff --git a/build.gradle b/build.gradle index ab621a69..e6a84507 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,7 @@ wrapper.gradleVersion = '6.5.0' group = 'com.snowplowanalytics' archivesBaseName = 'snowplow-java-tracker' -version = '1.0.1' +version = '2.0.0' sourceCompatibility = '1.8' targetCompatibility = '1.8' diff --git a/examples/simple-console/build.gradle b/examples/simple-console/build.gradle index 78d31acc..0b134e77 100644 --- a/examples/simple-console/build.gradle +++ b/examples/simple-console/build.gradle @@ -16,9 +16,9 @@ test { } dependencies { - implementation 'com.snowplowanalytics:snowplow-java-tracker:1.+' + implementation 'com.snowplowanalytics:snowplow-java-tracker:2.+' - implementation ('com.snowplowanalytics:snowplow-java-tracker:1.+') { + implementation ('com.snowplowanalytics:snowplow-java-tracker:2.+') { capabilities { requireCapability 'com.snowplowanalytics:snowplow-java-tracker-okhttp-support' } diff --git a/examples/simple-console/src/main/java/com/snowplowanalytics/Main.java b/examples/simple-console/src/main/java/com/snowplowanalytics/Main.java index d1085661..e0f59265 100644 --- a/examples/simple-console/src/main/java/com/snowplowanalytics/Main.java +++ b/examples/simple-console/src/main/java/com/snowplowanalytics/Main.java @@ -86,7 +86,7 @@ public static void main(String[] args) throws InterruptedException { .quantity(2) .name("name") .category("category") - .currency("currency") + .currency("EUR") .customContext(context) .build(); @@ -100,7 +100,7 @@ public static void main(String[] args) throws InterruptedException { .city("city") .state("state") .country("country") - .currency("currency") + .currency("EUR") .items(item) // EcommerceTransactionItem events are added to a parent EcommerceTransaction here .customContext(context) .build(); diff --git a/src/test/java/com/snowplowanalytics/snowplow/tracker/TrackerTest.java b/src/test/java/com/snowplowanalytics/snowplow/tracker/TrackerTest.java index d35a2b60..d6733765 100644 --- a/src/test/java/com/snowplowanalytics/snowplow/tracker/TrackerTest.java +++ b/src/test/java/com/snowplowanalytics/snowplow/tracker/TrackerTest.java @@ -576,7 +576,7 @@ public void testCreateWithConfiguration() { @Test public void testGetTrackerVersion() { Tracker tracker = new Tracker(new TrackerConfiguration("namespace", "an-app-id"), mockEmitter); - assertEquals("java-1.0.1", tracker.getTrackerVersion()); + assertEquals("java-2.0.0", tracker.getTrackerVersion()); } @Test