Skip to content

Commit

Permalink
[Java] Introduce "enableForcedPost". deprecate other ones (#99)
Browse files Browse the repository at this point in the history
* feat: forced post

* Update CHANGELOG.md

* renaming config call

* changelog

---------

Co-authored-by: ArtursK <[email protected]>
  • Loading branch information
arifBurakDemiray and ArtursKadikis authored Oct 6, 2023
1 parent 517b2fa commit e897ff9
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 26 deletions.
23 changes: 17 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -28,16 +29,19 @@
* "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:
* "getApplicationName"
* "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"
Expand Down Expand Up @@ -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
29 changes: 20 additions & 9 deletions sdk-java/src/main/java/ly/count/sdk/java/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
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;
import org.junit.Test;
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;
Expand All @@ -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
Expand Down

0 comments on commit e897ff9

Please sign in to comment.