From e897ff9ed95527090ba39e99e21e010416ee9479 Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray <57103426+arifBurakDemiray@users.noreply.github.com> Date: Fri, 6 Oct 2023 11:31:22 +0300 Subject: [PATCH] [Java] Introduce "enableForcedPost". deprecate other ones (#99) * feat: forced post * Update CHANGELOG.md * renaming config call * changelog --------- Co-authored-by: ArtursK --- CHANGELOG.md | 23 +++++++++++---- .../main/java/ly/count/sdk/java/Config.java | 29 +++++++++++++------ .../sdk/java/internal/InternalConfig.java | 4 +-- .../ly/count/sdk/java/internal/Transport.java | 2 +- .../count/sdk/java/internal/ConfigTests.java | 15 +++++----- 5 files changed, 47 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f456dfc44..e27f665ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,21 +1,22 @@ 23.8.0 + * !! Major breaking change !! The following methods and their functionality are deprecated from the "UserEditor" interface and will not function anymore: * "addToCohort(key)" * "removeFromCohort(key)" - + * Added the feedback widget feature. Added consent for it "Config.Feature.Feedback". * Feedback module is accessible through "Countly::instance()::feedback()" call. - + * Deprecated call "Countly::getSession" is removed * Deprecated call "resetDeviceId" is removed + * Deprecated the init time configuration of 'setEventsBufferSize(eventsBufferSize)'. Introduced replacement 'setEventQueueSizeToSend(eventsQueueSize)' * Deprecated the init time configuration of 'setSendUpdateEachSeconds(sendUpdateEachSeconds)'. Introduced replacement 'setUpdateSessionTimerDelay(delay)' * In Countly class, the old "init(directory,config)" method is deprecated, use "init(config)" instead via "instance()" call. * Deprecated "Countly::stop(boolean)" call, use "Countly::halt" or "Countly::stop" instead via "instance()" call. -* Deprecated "Countly::event" call, deprecated builder pattern. Use "Countly::events" instead. -* Deprecated "Usage::event" call, deprecated builder pattern. Use "Countly::events" instead. -* Deprecated "Countly::stop(boolean)" call, use "Countly::halt" instead via "instance()" call. +* Deprecated "Countly::event" call, deprecated builder pattern. Use "Countly::events" instead via "instance()" call. * Deprecated "Countly::timedEvent(String)" call, use "Countly::events::startEvent" instead via "instance()" call. +* Deprecated "Config::setUsePOST" and "Config::enableUsePOST" calls, use "Config::enableForcedHTTPPost" instead. * The following methods are deprecated from the "Event" interface: * "record" * "endAndRecord" @@ -28,9 +29,11 @@ * "isInvalid" 22.09.2 + * Fixed internal log calls that did not respect the configured log level and did not work with the log listener. 22.09.1 + * Adding a way to override metrics sent by "begin session" requests. * Fixed bug where "setApplicationVersion" would not set the application version in metrics * ! Minor breaking change ! The following methods and their functionality are deprecated from the "Config" class and will not function anymore: @@ -38,6 +41,7 @@ * "setApplicationName" 22.09.0 + * The "resetDeviceId", "login", and "logout" have been deprecated. * ! Minor breaking change ! The following methods and their functionality are deprecated from the "Config" class and will not function anymore: * "enableTestMode" @@ -70,30 +74,37 @@ * ! Minor breaking change ! It is not possible to set the logging tag anymore. * Fixed a bug where the wrong platform field value was being sent in the view request. * Fixed a bug where view duration was reported in ms and not s. -* Updated JSON library version from "20180813" to "20230227". +* Updated JSON library version from "20180813" to "20230227". 20.11.5 + * Fixed a bug where the backend mode module produces "null pointer exceptions" in case not initialized. 20.11.4 + * Adding mitigations to an issue that would surface when stopping a view that was not started. 20.11.3 + * Fixed a threading issue in the backend mode feature. 20.11.2 + * Added backend mode feature and a new configuration field to enable it. 20.11.1 + * Fixed a bug related to server response handling. * Fixed a potential issue with parameters tampering protection while adding checksum. 20.11.0 + * Added a new method to retrieve the current device id. * Added new methods to change device ID with and without server merge. * "Countly::getSession" has been deprecated and this is going to be removed in the future. * "resetDeviceId" in the SDK public methods has been deprecated and this is going to be removed in the future. 19.09-sdk2-rc + * initial SDK release * MavenCentral rerelease diff --git a/sdk-java/src/main/java/ly/count/sdk/java/Config.java b/sdk-java/src/main/java/ly/count/sdk/java/Config.java index 14c5eae6b..fc7ea9389 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/Config.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/Config.java @@ -299,7 +299,7 @@ public boolean restore(byte[] data, Log L) { /** * Force usage of POST method for all requests */ - protected boolean usePOST = false; + protected boolean forceHTTPPost = false; /** * This would be a special state where the majority of the SDK calls don't work anymore and only a few special calls work. @@ -760,20 +760,31 @@ public DeviceIdStrategy getDeviceIdStrategyEnum() { * Force usage of POST method for all requests * * @return {@code this} instance for method chaining + * @deprecated use {@link #enableForcedHTTPPost()} instead */ public Config enableUsePOST() { - this.usePOST = true; + return enableForcedHTTPPost(); + } + + /** + * Force usage of POST method for all requests + * + * @return {@code this} instance for method chaining + */ + public Config enableForcedHTTPPost() { + this.forceHTTPPost = true; return this; } /** * Force usage of POST method for all requests. * - * @param usePOST whether to force using POST method for all requests or not + * @param forcePost whether to force using POST method for all requests or not * @return {@code this} instance for method chaining + * @deprecated please use {@link #enableForcedHTTPPost()} instead */ - public Config setUsePOST(boolean usePOST) { - this.usePOST = usePOST; + public Config setUsePOST(boolean forcePost) { + this.forceHTTPPost = forcePost; return this; } @@ -1297,12 +1308,12 @@ public String getCustomDeviceId() { } /** - * Getter for {@link #usePOST} + * Getter for {@link #forceHTTPPost} * - * @return {@link #usePOST} value + * @return {@link #forceHTTPPost} value */ - public boolean isUsePOST() { - return usePOST; + public boolean isHTTPPostForced() { + return forceHTTPPost; } /** diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/InternalConfig.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/InternalConfig.java index db8b2beab..85f818119 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/InternalConfig.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/InternalConfig.java @@ -121,7 +121,7 @@ public byte[] store(Log L) { stream.writeUTF(sdkVersion); stream.writeObject("name"); stream.writeObject(applicationVersion); - stream.writeBoolean(usePOST); + stream.writeBoolean(forceHTTPPost); stream.writeObject(salt); stream.writeInt(networkConnectionTimeout); stream.writeInt(networkReadTimeout); @@ -220,7 +220,7 @@ public boolean restore(byte[] data, Log L) { sdkVersion = stream.readUTF(); String throwawayApplicationName = (String) stream.readObject();//we are only reading this for backwards compatibility. Throw away in the future applicationVersion = (String) stream.readObject(); - usePOST = stream.readBoolean(); + forceHTTPPost = stream.readBoolean(); salt = (String) stream.readObject(); networkConnectionTimeout = stream.readInt(); networkReadTimeout = stream.readInt(); diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/Transport.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/Transport.java index 75ec7caf4..bc23a430c 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/Transport.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/Transport.java @@ -129,7 +129,7 @@ HttpURLConnection connection(final Request request, final User user) throws IOEx String path = config.getServerURL().toString() + endpoint; String picture = request.params.remove(UserEditorImpl.PICTURE_PATH); - boolean usingGET = !config.isUsePOST() && request.isGettable(config.getServerURL()) && Utils.isEmptyOrNull(picture); + boolean usingGET = !config.isHTTPPostForced() && request.isGettable(config.getServerURL()) && Utils.isEmptyOrNull(picture); if (usingGET && config.getParameterTamperingProtectionSalt() != null) { request.params.add(CHECKSUM, Utils.digestHex(PARAMETER_TAMPERING_DIGEST, request.params.toString() + config.getParameterTamperingProtectionSalt(), L)); diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/ConfigTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/ConfigTests.java index 1f756fd0c..f99166fec 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/ConfigTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/ConfigTests.java @@ -1,5 +1,8 @@ package ly.count.sdk.java.internal; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; import ly.count.sdk.java.Config; import org.junit.Assert; import org.junit.Before; @@ -7,10 +10,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; - @RunWith(JUnit4.class) public class ConfigTests extends BaseTestsCore { private InternalConfig internalConfig; @@ -31,16 +30,16 @@ public void testServerUrlAndAppKey() throws Exception { @Test public void testRequestMethod() { - Assert.assertFalse(internalConfig.isUsePOST()); + Assert.assertFalse(internalConfig.isHTTPPostForced()); internalConfig.enableUsePOST(); - Assert.assertTrue(internalConfig.isUsePOST()); + Assert.assertTrue(internalConfig.isHTTPPostForced()); internalConfig.setUsePOST(false); - Assert.assertFalse(internalConfig.isUsePOST()); + Assert.assertFalse(internalConfig.isHTTPPostForced()); internalConfig.setUsePOST(true); - Assert.assertTrue(internalConfig.isUsePOST()); + Assert.assertTrue(internalConfig.isHTTPPostForced()); } @Test