26
26
import java .util .Locale ;
27
27
import java .util .Map ;
28
28
import java .util .TimeZone ;
29
+ import java .util .zip .GZIPInputStream ;
30
+
29
31
import javax .crypto .Mac ;
30
32
import javax .crypto .spec .SecretKeySpec ;
31
33
@@ -68,7 +70,7 @@ public RestResponse get(String serviceUrl, Map<String, String> params) {
68
70
con .setReadTimeout (150000 );
69
71
con .setRequestProperty ("Content-Type" , "application/json" );
70
72
con .setRequestProperty ("charset" , "utf-8" );
71
-
73
+ con . setRequestProperty ( "Accept-Encoding" , "gzip" );
72
74
if (authorization != "" ) {
73
75
con .setRequestProperty ("Authorization" , "Bearer " + authorization );
74
76
}
@@ -81,9 +83,18 @@ public RestResponse get(String serviceUrl, Map<String, String> params) {
81
83
con .setRequestProperty ("X-LoginRadius-ApiSecret" , apiSecret );
82
84
}
83
85
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
+ }
87
98
String output ;
88
99
while ((output = br .readLine ()) != null ) {
89
100
response .setResponse (output );
@@ -119,7 +130,7 @@ public RestResponse post(String serviceUrl, Map<String, String> getParams, Strin
119
130
sott = getParams .get ("sott" );
120
131
getParams .remove ("sott" );
121
132
}
122
- if (getParams .containsKey ("access_token" )) {
133
+ if (getParams .containsKey ("access_token" ) && serviceUrl . contains ( "/auth" ) ) {
123
134
authorization = getParams .get ("access_token" );
124
135
getParams .remove ("access_token" );
125
136
@@ -139,7 +150,7 @@ public RestResponse post(String serviceUrl, Map<String, String> getParams, Strin
139
150
con .setReadTimeout (150000 );
140
151
con .setRequestProperty ("Content-Type" , "application/json" );
141
152
con .setRequestProperty ("charset" , "utf-8" );
142
-
153
+ con . setRequestProperty ( "Accept-Encoding" , "gzip" );
143
154
if (sott != "" ) {
144
155
con .setRequestProperty ("X-LoginRadius-Sott" , sott );
145
156
}
@@ -168,8 +179,17 @@ public RestResponse post(String serviceUrl, Map<String, String> getParams, Strin
168
179
body .flush ();
169
180
body .close ();
170
181
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
+ }
173
193
String output ;
174
194
while ((output = br .readLine ()) != null ) {
175
195
response .setResponse (output );
@@ -202,7 +222,7 @@ public RestResponse post(String serviceUrl, Map<String, String> getParams, Strin
202
222
203
223
public RestResponse put (String serviceUrl , Map <String , String > getParams , String payload ) {
204
224
205
- if (getParams .containsKey ("access_token" )) {
225
+ if (getParams .containsKey ("access_token" ) && serviceUrl . contains ( "/auth" ) ) {
206
226
authorization = getParams .get ("access_token" );
207
227
getParams .remove ("access_token" );
208
228
}
@@ -221,6 +241,7 @@ public RestResponse put(String serviceUrl, Map<String, String> getParams, String
221
241
con .setReadTimeout (150000 );
222
242
con .setRequestProperty ("Content-Type" , "application/json" );
223
243
con .setRequestProperty ("charset" , "utf-8" );
244
+ con .setRequestProperty ("Accept-Encoding" , "gzip" );
224
245
con .setDoOutput (true );
225
246
if (authorization != "" ) {
226
247
con .setRequestProperty ("Authorization" , "Bearer " + authorization );
@@ -244,8 +265,17 @@ public RestResponse put(String serviceUrl, Map<String, String> getParams, String
244
265
body .flush ();
245
266
body .close ();
246
267
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
+ }
249
279
String output ;
250
280
while ((output = br .readLine ()) != null ) {
251
281
response .setResponse (output );
@@ -279,7 +309,7 @@ public RestResponse put(String serviceUrl, Map<String, String> getParams, String
279
309
280
310
public RestResponse delete (String serviceUrl , Map <String , String > getParams , String payload ) {
281
311
282
- if (getParams .containsKey ("access_token" )) {
312
+ if (getParams .containsKey ("access_token" ) && serviceUrl . contains ( "/auth" ) ) {
283
313
authorization = getParams .get ("access_token" );
284
314
getParams .remove ("access_token" );
285
315
}
@@ -298,6 +328,7 @@ public RestResponse delete(String serviceUrl, Map<String, String> getParams, Str
298
328
con .setReadTimeout (150000 );
299
329
con .setRequestProperty ("Content-Type" , "application/json" );
300
330
con .setRequestProperty ("charset" , "utf-8" );
331
+ con .setRequestProperty ("Accept-Encoding" , "gzip" );
301
332
con .setDoOutput (true );
302
333
if (authorization != "" ) {
303
334
con .setRequestProperty ("Authorization" , "Bearer " + authorization );
@@ -321,9 +352,18 @@ public RestResponse delete(String serviceUrl, Map<String, String> getParams, Str
321
352
body .write (payload );
322
353
body .flush ();
323
354
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
+ }
327
367
String output ;
328
368
while ((output = br .readLine ()) != null ) {
329
369
response .setResponse (output );
0 commit comments