@@ -82,9 +82,12 @@ public class StoreAccessTokenProvider implements AuthorizationProvider {
8282 private static final String LOGOUT_SERVICE = "/logout" ;
8383
8484 /*
85- * Default timeout when sending http request to server
85+ * Default timeout when sending http request to server if not specified
86+ * by a request timeout. This is fairly long because it is usually
87+ * performed in an async fashion from a timer task and not in the
88+ * request path
8689 */
87- private static final int HTTP_TIMEOUT_MS = 30000 ;
90+ private static final int HTTP_TIMEOUT_MS = 20000 ;
8891
8992 /*
9093 * Authentication string which contain the Bearer prefix and login token's
@@ -220,7 +223,7 @@ public StoreAccessTokenProvider(String userName,
220223 *
221224 * Bootstrap login using the provided credentials
222225 */
223- public synchronized void bootstrapLogin () {
226+ public synchronized void bootstrapLogin (Request request ) {
224227
225228 /* re-check the authString in case of a race */
226229 if (!isSecure || isClosed || authString .get () != null ) {
@@ -236,11 +239,16 @@ public synchronized void bootstrapLogin() {
236239 encodeToString ((
237240 userName + ":" + String .valueOf (password )).getBytes ());
238241
242+ /*
243+ * Use the request timeout for this operation if available
244+ */
245+ int timeoutMs = (request != null ?
246+ request .getTimeoutInternal () : 0 );
239247 /*
240248 * Send request to server for login token
241249 */
242250 HttpResponse response = sendRequest (BASIC_PREFIX + encoded ,
243- LOGIN_SERVICE );
251+ LOGIN_SERVICE , timeoutMs );
244252
245253 /*
246254 * login fail
@@ -294,7 +302,7 @@ public String getAuthorizationString(Request request) {
294302 * the login token and generate the auth string.
295303 */
296304 if (authString .get () == null ) {
297- bootstrapLogin ();
305+ bootstrapLogin (request );
298306 }
299307 return authString .get ();
300308 }
@@ -330,7 +338,7 @@ public synchronized void close() {
330338 */
331339 try {
332340 final HttpResponse response =
333- sendRequest (authString .get (), LOGOUT_SERVICE );
341+ sendRequest (authString .get (), LOGOUT_SERVICE , 0 );
334342 if (response .getStatusCode () != HttpResponseStatus .OK .code ()) {
335343 if (logger != null ) {
336344 logger .info ("Failed to logout user " + userName +
@@ -497,7 +505,8 @@ private String parseJsonResult(String jsonResult) {
497505 * authentication information.
498506 */
499507 private HttpResponse sendRequest (String authHeader ,
500- String serviceName ) throws Exception {
508+ String serviceName ,
509+ int timeoutMs ) throws Exception {
501510 HttpClient client = null ;
502511 try {
503512 final HttpHeaders headers = new DefaultHttpHeaders ();
@@ -509,11 +518,14 @@ private HttpResponse sendRequest(String authHeader,
509518 sslHandshakeTimeoutMs ,
510519 serviceName ,
511520 logger );
521+ if (timeoutMs == 0 ) {
522+ timeoutMs = HTTP_TIMEOUT_MS ;
523+ }
512524 return HttpRequestUtil .doGetRequest (
513525 client ,
514526 NoSQLHandleConfig .createURL (endpoint , basePath + serviceName )
515527 .toString (),
516- headers , HTTP_TIMEOUT_MS , logger );
528+ headers , timeoutMs , logger );
517529 } finally {
518530 if (client != null ) {
519531 client .shutdown ();
@@ -560,7 +572,8 @@ public void run() {
560572 try {
561573 final String oldAuth = authString .get ();
562574 HttpResponse response = sendRequest (oldAuth ,
563- RENEW_SERVICE );
575+ RENEW_SERVICE ,
576+ 0 );
564577 final String token = parseJsonResult (response .getOutput ());
565578 if (response .getStatusCode () != HttpResponseStatus .OK .code ()) {
566579 throw new InvalidAuthorizationException (token );
0 commit comments