Skip to content

Commit e897ff9

Browse files
[Java] Introduce "enableForcedPost". deprecate other ones (#99)
* feat: forced post * Update CHANGELOG.md * renaming config call * changelog --------- Co-authored-by: ArtursK <[email protected]>
1 parent 517b2fa commit e897ff9

File tree

5 files changed

+47
-26
lines changed

5 files changed

+47
-26
lines changed

CHANGELOG.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
23.8.0
2+
23
* !! Major breaking change !! The following methods and their functionality are deprecated from the "UserEditor" interface and will not function anymore:
34
* "addToCohort(key)"
45
* "removeFromCohort(key)"
5-
6+
67
* Added the feedback widget feature. Added consent for it "Config.Feature.Feedback".
78
* Feedback module is accessible through "Countly::instance()::feedback()" call.
8-
9+
910
* Deprecated call "Countly::getSession" is removed
1011
* Deprecated call "resetDeviceId" is removed
12+
1113
* Deprecated the init time configuration of 'setEventsBufferSize(eventsBufferSize)'. Introduced replacement 'setEventQueueSizeToSend(eventsQueueSize)'
1214
* Deprecated the init time configuration of 'setSendUpdateEachSeconds(sendUpdateEachSeconds)'. Introduced replacement 'setUpdateSessionTimerDelay(delay)'
1315
* In Countly class, the old "init(directory,config)" method is deprecated, use "init(config)" instead via "instance()" call.
1416
* Deprecated "Countly::stop(boolean)" call, use "Countly::halt" or "Countly::stop" instead via "instance()" call.
15-
* Deprecated "Countly::event" call, deprecated builder pattern. Use "Countly::events" instead.
16-
* Deprecated "Usage::event" call, deprecated builder pattern. Use "Countly::events" instead.
17-
* Deprecated "Countly::stop(boolean)" call, use "Countly::halt" instead via "instance()" call.
17+
* Deprecated "Countly::event" call, deprecated builder pattern. Use "Countly::events" instead via "instance()" call.
1818
* Deprecated "Countly::timedEvent(String)" call, use "Countly::events::startEvent" instead via "instance()" call.
19+
* Deprecated "Config::setUsePOST" and "Config::enableUsePOST" calls, use "Config::enableForcedHTTPPost" instead.
1920
* The following methods are deprecated from the "Event" interface:
2021
* "record"
2122
* "endAndRecord"
@@ -28,16 +29,19 @@
2829
* "isInvalid"
2930

3031
22.09.2
32+
3133
* Fixed internal log calls that did not respect the configured log level and did not work with the log listener.
3234

3335
22.09.1
36+
3437
* Adding a way to override metrics sent by "begin session" requests.
3538
* Fixed bug where "setApplicationVersion" would not set the application version in metrics
3639
* ! Minor breaking change ! The following methods and their functionality are deprecated from the "Config" class and will not function anymore:
3740
* "getApplicationName"
3841
* "setApplicationName"
3942

4043
22.09.0
44+
4145
* The "resetDeviceId", "login", and "logout" have been deprecated.
4246
* ! Minor breaking change ! The following methods and their functionality are deprecated from the "Config" class and will not function anymore:
4347
* "enableTestMode"
@@ -70,30 +74,37 @@
7074
* ! Minor breaking change ! It is not possible to set the logging tag anymore.
7175
* Fixed a bug where the wrong platform field value was being sent in the view request.
7276
* Fixed a bug where view duration was reported in ms and not s.
73-
* Updated JSON library version from "20180813" to "20230227".
77+
* Updated JSON library version from "20180813" to "20230227".
7478

7579
20.11.5
80+
7681
* Fixed a bug where the backend mode module produces "null pointer exceptions" in case not initialized.
7782

7883
20.11.4
84+
7985
* Adding mitigations to an issue that would surface when stopping a view that was not started.
8086

8187
20.11.3
88+
8289
* Fixed a threading issue in the backend mode feature.
8390

8491
20.11.2
92+
8593
* Added backend mode feature and a new configuration field to enable it.
8694

8795
20.11.1
96+
8897
* Fixed a bug related to server response handling.
8998
* Fixed a potential issue with parameters tampering protection while adding checksum.
9099

91100
20.11.0
101+
92102
* Added a new method to retrieve the current device id.
93103
* Added new methods to change device ID with and without server merge.
94104
* "Countly::getSession" has been deprecated and this is going to be removed in the future.
95105
* "resetDeviceId" in the SDK public methods has been deprecated and this is going to be removed in the future.
96106

97107
19.09-sdk2-rc
108+
98109
* initial SDK release
99110
* MavenCentral rerelease

sdk-java/src/main/java/ly/count/sdk/java/Config.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ public boolean restore(byte[] data, Log L) {
299299
/**
300300
* Force usage of POST method for all requests
301301
*/
302-
protected boolean usePOST = false;
302+
protected boolean forceHTTPPost = false;
303303

304304
/**
305305
* 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() {
760760
* Force usage of POST method for all requests
761761
*
762762
* @return {@code this} instance for method chaining
763+
* @deprecated use {@link #enableForcedHTTPPost()} instead
763764
*/
764765
public Config enableUsePOST() {
765-
this.usePOST = true;
766+
return enableForcedHTTPPost();
767+
}
768+
769+
/**
770+
* Force usage of POST method for all requests
771+
*
772+
* @return {@code this} instance for method chaining
773+
*/
774+
public Config enableForcedHTTPPost() {
775+
this.forceHTTPPost = true;
766776
return this;
767777
}
768778

769779
/**
770780
* Force usage of POST method for all requests.
771781
*
772-
* @param usePOST whether to force using POST method for all requests or not
782+
* @param forcePost whether to force using POST method for all requests or not
773783
* @return {@code this} instance for method chaining
784+
* @deprecated please use {@link #enableForcedHTTPPost()} instead
774785
*/
775-
public Config setUsePOST(boolean usePOST) {
776-
this.usePOST = usePOST;
786+
public Config setUsePOST(boolean forcePost) {
787+
this.forceHTTPPost = forcePost;
777788
return this;
778789
}
779790

@@ -1297,12 +1308,12 @@ public String getCustomDeviceId() {
12971308
}
12981309

12991310
/**
1300-
* Getter for {@link #usePOST}
1311+
* Getter for {@link #forceHTTPPost}
13011312
*
1302-
* @return {@link #usePOST} value
1313+
* @return {@link #forceHTTPPost} value
13031314
*/
1304-
public boolean isUsePOST() {
1305-
return usePOST;
1315+
public boolean isHTTPPostForced() {
1316+
return forceHTTPPost;
13061317
}
13071318

13081319
/**

sdk-java/src/main/java/ly/count/sdk/java/internal/InternalConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public byte[] store(Log L) {
121121
stream.writeUTF(sdkVersion);
122122
stream.writeObject("name");
123123
stream.writeObject(applicationVersion);
124-
stream.writeBoolean(usePOST);
124+
stream.writeBoolean(forceHTTPPost);
125125
stream.writeObject(salt);
126126
stream.writeInt(networkConnectionTimeout);
127127
stream.writeInt(networkReadTimeout);
@@ -220,7 +220,7 @@ public boolean restore(byte[] data, Log L) {
220220
sdkVersion = stream.readUTF();
221221
String throwawayApplicationName = (String) stream.readObject();//we are only reading this for backwards compatibility. Throw away in the future
222222
applicationVersion = (String) stream.readObject();
223-
usePOST = stream.readBoolean();
223+
forceHTTPPost = stream.readBoolean();
224224
salt = (String) stream.readObject();
225225
networkConnectionTimeout = stream.readInt();
226226
networkReadTimeout = stream.readInt();

sdk-java/src/main/java/ly/count/sdk/java/internal/Transport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ HttpURLConnection connection(final Request request, final User user) throws IOEx
129129

130130
String path = config.getServerURL().toString() + endpoint;
131131
String picture = request.params.remove(UserEditorImpl.PICTURE_PATH);
132-
boolean usingGET = !config.isUsePOST() && request.isGettable(config.getServerURL()) && Utils.isEmptyOrNull(picture);
132+
boolean usingGET = !config.isHTTPPostForced() && request.isGettable(config.getServerURL()) && Utils.isEmptyOrNull(picture);
133133

134134
if (usingGET && config.getParameterTamperingProtectionSalt() != null) {
135135
request.params.add(CHECKSUM, Utils.digestHex(PARAMETER_TAMPERING_DIGEST, request.params.toString() + config.getParameterTamperingProtectionSalt(), L));

sdk-java/src/test/java/ly/count/sdk/java/internal/ConfigTests.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package ly.count.sdk.java.internal;
22

3+
import java.net.URL;
4+
import java.util.HashMap;
5+
import java.util.Map;
36
import ly.count.sdk.java.Config;
47
import org.junit.Assert;
58
import org.junit.Before;
69
import org.junit.Test;
710
import org.junit.runner.RunWith;
811
import org.junit.runners.JUnit4;
912

10-
import java.net.URL;
11-
import java.util.HashMap;
12-
import java.util.Map;
13-
1413
@RunWith(JUnit4.class)
1514
public class ConfigTests extends BaseTestsCore {
1615
private InternalConfig internalConfig;
@@ -31,16 +30,16 @@ public void testServerUrlAndAppKey() throws Exception {
3130

3231
@Test
3332
public void testRequestMethod() {
34-
Assert.assertFalse(internalConfig.isUsePOST());
33+
Assert.assertFalse(internalConfig.isHTTPPostForced());
3534

3635
internalConfig.enableUsePOST();
37-
Assert.assertTrue(internalConfig.isUsePOST());
36+
Assert.assertTrue(internalConfig.isHTTPPostForced());
3837

3938
internalConfig.setUsePOST(false);
40-
Assert.assertFalse(internalConfig.isUsePOST());
39+
Assert.assertFalse(internalConfig.isHTTPPostForced());
4140

4241
internalConfig.setUsePOST(true);
43-
Assert.assertTrue(internalConfig.isUsePOST());
42+
Assert.assertTrue(internalConfig.isHTTPPostForced());
4443
}
4544

4645
@Test

0 commit comments

Comments
 (0)