@@ -48,6 +48,11 @@ public API(String baseUrl) {
48
48
this .retry = true ;
49
49
}
50
50
51
+ private boolean authenticate () {
52
+ return authenticate (this .ClientKey , this .ClientSecret );
53
+ }
54
+
55
+
51
56
public boolean authenticate (String username , String password ) {
52
57
this .ClientKey = username ;
53
58
this .ClientSecret = password ;
@@ -97,7 +102,7 @@ public <T extends BaseData> T navigate(Class<T> tClass, Link l, HashMap<String,
97
102
98
103
if (l .getRel ().equals ("authenticate" )) {
99
104
HashMap <String , String > headers = new HashMap <String , String >();
100
- String authorization = "Basic " + Base64 .encodeBase64String ((ClientKey + ":" + ClientSecret ).getBytes ());
105
+ String authorization = "Basic " + Base64 .encodeBase64String ((this . ClientKey + ":" + this . ClientSecret ).getBytes ());
101
106
headers .put ("authorization" , authorization );
102
107
result = sendRequestWithAddedHeaders (Verb .POST , this .baseUrl + l .getUri (), tClass , null , headers );
103
108
return (T ) result ;
@@ -226,7 +231,7 @@ private <T extends BaseData> T sendRequest(Verb verb, String url, Class<T> tClas
226
231
osw .close ();
227
232
}
228
233
}
229
- else if (verb == verb .POST && object == null ) {
234
+ else if (verb == Verb .POST && object == null ) {
230
235
connection .addRequestProperty ("Content-Length" , "0" );
231
236
OutputStreamWriter osw = new OutputStreamWriter (connection .getOutputStream ());
232
237
osw .write ("" );
@@ -247,8 +252,9 @@ else if (verb == verb.POST && object == null) {
247
252
if (connection .getResponseCode () == HttpURLConnection .HTTP_UNAUTHORIZED ) {
248
253
System .out .println ("Authentication expired " + connection .getResponseMessage ());
249
254
if (retry && this .tokenData != null ) {
255
+ this .tokenData = null ;
250
256
retry = false ;
251
- if ( authenticate (this . ClientKey , this . ClientSecret ) ) {
257
+ if ( authenticate () ) {
252
258
System .out .println ("Authenticated again" );
253
259
return sendRequest (verb , url , tClass , object );
254
260
}
@@ -297,7 +303,6 @@ else if (connection.getResponseCode() >= HttpURLConnection.HTTP_INTERNAL_ERROR )
297
303
String abba = null ;
298
304
if ((abba = connection .getHeaderField ("ETag" )) != null ) {
299
305
sb .insert (sb .lastIndexOf ("}" ), ",\" VersionNumber\" :" + abba + "" );
300
-
301
306
}
302
307
303
308
result = sb .toString ();
@@ -361,7 +366,8 @@ private <T extends BaseData> T sendRequestWithAddedHeaders(Verb verb, String url
361
366
System .out .println ("Authentication expired: " + connection .getResponseMessage ());
362
367
if ( retry && this .tokenData != null ) {
363
368
retry = false ;
364
- if ( authenticate (this .ClientKey , this .ClientSecret ) ) {
369
+ this .tokenData = null ;
370
+ if ( authenticate () ) {
365
371
System .out .println ("Authenticated again" );
366
372
return sendRequestWithAddedHeaders (verb , url , tClass , object , headers );
367
373
}
0 commit comments