Skip to content

Commit

Permalink
resolve swift test 401 error code
Browse files Browse the repository at this point in the history
  • Loading branch information
yllions committed Oct 10, 2014
1 parent e11e9b9 commit 36c20b0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.http.*;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.util.EntityUtils;

import com.intel.cosbench.client.http.HttpClientUtil;
Expand Down Expand Up @@ -83,5 +84,23 @@ public void login() throws IOException, SwiftAuthClientException {
EntityUtils.consume(response.getEntity());
}
}

public boolean check() {
HttpResponse response;
if(storageURL == null || authToken == null)
return false;
try {
HttpHead method = new HttpHead(storageURL);
method.setHeader(X_AUTH_TOKEN, authToken);
response = client.execute(method);

if ((response.getStatusLine().getStatusCode() >= HttpStatus.SC_OK) &&
(response.getStatusLine().getStatusCode() < (HttpStatus.SC_OK + 100)))
return true;
} catch (IOException e) {
}
return false;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static synchronized void loadSwiftTokenCache(SwiftAuthClient client, Swif
}

public static SwiftTokenCache getSwiftTokenCache(SwiftAuthClient client) {
if(latestTokenCache.getVersion()==0)
if(latestTokenCache.getVersion()==0 || ! client.check())
loadSwiftTokenCache(client,latestTokenCache);
return latestTokenCache;
}
Expand Down

0 comments on commit 36c20b0

Please sign in to comment.