Skip to content

Commit 74ed6ec

Browse files
version 4.2.2
Added gzip Accept-Encoding HTTPS header in requests sent to an LoginRadius server
1 parent 2bcf57b commit 74ed6ec

File tree

5 files changed

+65
-19
lines changed

5 files changed

+65
-19
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
> **LoginRadius Java SDK Change Log** provides information regarding what has changed, more specifically what changes, improvements and bug fix has been made to the SDK. For more details please refer to the [LoginRadius API Documention(https://github.com/LoginRadius/java-sdk)
22
3+
### Version 4.2.2
4+
Released on **March 26, 2019**
5+
##### Enhancements
6+
7+
- Added gzip Accept-Encoding HTTPS header in requests sent to an LoginRadius server
8+
39
### Version 4.2.1
410
Released on **November 23, 2018**
511
##### Enhancements

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Use the following dependency in your project:
2727
<dependency>
2828
<groupId>com.loginradius.sdk</groupId>
2929
<artifactId>java-sdk</artifactId>
30-
<version>4.2.1</version>
30+
<version>4.2.2</version>
3131
</dependency>
3232
3333
```
@@ -37,7 +37,7 @@ the latest version and download the jar files.
3737

3838
## Documentation
3939

40-
[Getting Started](https://docs.loginradius.com/api/v2/sdk-libraries/java-library) - Everything you need to begin using this SDK.
40+
[Getting Started](https://www.loginradius.com/docs/api/v2/deployment/sdk-libraries/java-library) - Everything you need to begin using this SDK.
4141

4242

4343

demo/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<dependency>
4343
<groupId>com.loginradius.sdk</groupId>
4444
<artifactId>java-sdk</artifactId>
45-
<version>4.2.1</version>
45+
<version>4.2.2</version>
4646
</dependency>
4747
</dependencies>
4848

sdk/LoginRadius-JavaSDK/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.loginradius.sdk</groupId>
88
<artifactId>java-sdk</artifactId>
9-
<version>4.2.1</version>
9+
<version>4.2.2</version>
1010
<description>LoginRadius Java SDK</description>
1111
<url>https://github.com/LoginRadius/java-sdk</url>
1212

sdk/LoginRadius-JavaSDK/src/main/java/com/loginradius/sdk/util/RestRequest.java

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import java.util.Locale;
2727
import java.util.Map;
2828
import java.util.TimeZone;
29+
import java.util.zip.GZIPInputStream;
30+
2931
import javax.crypto.Mac;
3032
import javax.crypto.spec.SecretKeySpec;
3133

@@ -68,7 +70,7 @@ public RestResponse get(String serviceUrl, Map<String, String> params) {
6870
con.setReadTimeout(150000);
6971
con.setRequestProperty("Content-Type", "application/json");
7072
con.setRequestProperty("charset", "utf-8");
71-
73+
con.setRequestProperty("Accept-Encoding", "gzip");
7274
if (authorization != "") {
7375
con.setRequestProperty("Authorization", "Bearer " + authorization);
7476
}
@@ -81,9 +83,18 @@ public RestResponse get(String serviceUrl, Map<String, String> params) {
8183
con.setRequestProperty("X-LoginRadius-ApiSecret", apiSecret);
8284
}
8385
con.setDoOutput(true);
84-
85-
BufferedReader br = new BufferedReader(new InputStreamReader(
86-
con.getResponseCode() / 100 == 2 ? con.getInputStream() : con.getErrorStream()));
86+
87+
BufferedReader br;
88+
if ("gzip".equals(con.getContentEncoding())) {
89+
br = new BufferedReader(new InputStreamReader(
90+
con.getResponseCode() / 100 == 2 ? new GZIPInputStream(con.getInputStream()) : con.getErrorStream()));
91+
92+
}
93+
else {
94+
br = new BufferedReader(new InputStreamReader(
95+
con.getResponseCode() / 100 == 2 ? con.getInputStream() : con.getErrorStream()));
96+
97+
}
8798
String output;
8899
while ((output = br.readLine()) != null) {
89100
response.setResponse(output);
@@ -119,7 +130,7 @@ public RestResponse post(String serviceUrl, Map<String, String> getParams, Strin
119130
sott = getParams.get("sott");
120131
getParams.remove("sott");
121132
}
122-
if (getParams.containsKey("access_token")) {
133+
if (getParams.containsKey("access_token") && serviceUrl.contains("/auth")) {
123134
authorization = getParams.get("access_token");
124135
getParams.remove("access_token");
125136

@@ -139,7 +150,7 @@ public RestResponse post(String serviceUrl, Map<String, String> getParams, Strin
139150
con.setReadTimeout(150000);
140151
con.setRequestProperty("Content-Type", "application/json");
141152
con.setRequestProperty("charset", "utf-8");
142-
153+
con.setRequestProperty("Accept-Encoding", "gzip");
143154
if (sott != "") {
144155
con.setRequestProperty("X-LoginRadius-Sott", sott);
145156
}
@@ -168,8 +179,17 @@ public RestResponse post(String serviceUrl, Map<String, String> getParams, Strin
168179
body.flush();
169180
body.close();
170181

171-
BufferedReader br = new BufferedReader(new InputStreamReader(
172-
con.getResponseCode() / 100 == 2 ? con.getInputStream() : con.getErrorStream()));
182+
BufferedReader br;
183+
if ("gzip".equals(con.getContentEncoding())) {
184+
br = new BufferedReader(new InputStreamReader(
185+
con.getResponseCode() / 100 == 2 ? new GZIPInputStream(con.getInputStream()) : con.getErrorStream()));
186+
187+
}
188+
else {
189+
br = new BufferedReader(new InputStreamReader(
190+
con.getResponseCode() / 100 == 2 ? con.getInputStream() : con.getErrorStream()));
191+
192+
}
173193
String output;
174194
while ((output = br.readLine()) != null) {
175195
response.setResponse(output);
@@ -202,7 +222,7 @@ public RestResponse post(String serviceUrl, Map<String, String> getParams, Strin
202222

203223
public RestResponse put(String serviceUrl, Map<String, String> getParams, String payload) {
204224

205-
if (getParams.containsKey("access_token")) {
225+
if (getParams.containsKey("access_token") && serviceUrl.contains("/auth")) {
206226
authorization = getParams.get("access_token");
207227
getParams.remove("access_token");
208228
}
@@ -221,6 +241,7 @@ public RestResponse put(String serviceUrl, Map<String, String> getParams, String
221241
con.setReadTimeout(150000);
222242
con.setRequestProperty("Content-Type", "application/json");
223243
con.setRequestProperty("charset", "utf-8");
244+
con.setRequestProperty("Accept-Encoding", "gzip");
224245
con.setDoOutput(true);
225246
if (authorization != "") {
226247
con.setRequestProperty("Authorization", "Bearer " + authorization);
@@ -244,8 +265,17 @@ public RestResponse put(String serviceUrl, Map<String, String> getParams, String
244265
body.flush();
245266
body.close();
246267

247-
BufferedReader br = new BufferedReader(new InputStreamReader(
248-
con.getResponseCode() / 100 == 2 ? con.getInputStream() : con.getErrorStream()));
268+
BufferedReader br;
269+
if ("gzip".equals(con.getContentEncoding())) {
270+
br = new BufferedReader(new InputStreamReader(
271+
con.getResponseCode() / 100 == 2 ? new GZIPInputStream(con.getInputStream()) : con.getErrorStream()));
272+
273+
}
274+
else {
275+
br = new BufferedReader(new InputStreamReader(
276+
con.getResponseCode() / 100 == 2 ? con.getInputStream() : con.getErrorStream()));
277+
278+
}
249279
String output;
250280
while ((output = br.readLine()) != null) {
251281
response.setResponse(output);
@@ -279,7 +309,7 @@ public RestResponse put(String serviceUrl, Map<String, String> getParams, String
279309

280310
public RestResponse delete(String serviceUrl, Map<String, String> getParams, String payload) {
281311

282-
if (getParams.containsKey("access_token")) {
312+
if (getParams.containsKey("access_token") && serviceUrl.contains("/auth")) {
283313
authorization = getParams.get("access_token");
284314
getParams.remove("access_token");
285315
}
@@ -298,6 +328,7 @@ public RestResponse delete(String serviceUrl, Map<String, String> getParams, Str
298328
con.setReadTimeout(150000);
299329
con.setRequestProperty("Content-Type", "application/json");
300330
con.setRequestProperty("charset", "utf-8");
331+
con.setRequestProperty("Accept-Encoding", "gzip");
301332
con.setDoOutput(true);
302333
if (authorization != "") {
303334
con.setRequestProperty("Authorization", "Bearer " + authorization);
@@ -321,9 +352,18 @@ public RestResponse delete(String serviceUrl, Map<String, String> getParams, Str
321352
body.write(payload);
322353
body.flush();
323354
body.close();
324-
325-
BufferedReader br = new BufferedReader(new InputStreamReader(
326-
con.getResponseCode() / 100 == 2 ? con.getInputStream() : con.getErrorStream()));
355+
356+
BufferedReader br;
357+
if ("gzip".equals(con.getContentEncoding())) {
358+
br = new BufferedReader(new InputStreamReader(
359+
con.getResponseCode() / 100 == 2 ? new GZIPInputStream(con.getInputStream()) : con.getErrorStream()));
360+
361+
}
362+
else {
363+
br = new BufferedReader(new InputStreamReader(
364+
con.getResponseCode() / 100 == 2 ? con.getInputStream() : con.getErrorStream()));
365+
366+
}
327367
String output;
328368
while ((output = br.readLine()) != null) {
329369
response.setResponse(output);

0 commit comments

Comments
 (0)