11/** 
2-  * © Copyright IBM Corporation 2020. All Rights Reserved. 
2+  * © Copyright IBM Corporation 2020, 2024 . All Rights Reserved. 
33 * 
44 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 
55 * the License. You may obtain a copy of the License at 
2828import  okhttp3 .Cookie ;
2929import  okhttp3 .Headers ;
3030import  okhttp3 .HttpUrl ;
31- import  okhttp3 .OkHttpClient ;
3231import  okhttp3 .Response ;
3332
3433import  java .io .IOException ;
@@ -55,7 +54,6 @@ public class CouchDbSessionAuthenticator
5554    private  HttpUrl  sessionUrl  = null ;
5655    private  HttpConfigOptions  options  = null ;
5756    private  Headers  headers  = null ;
58-     private  OkHttpClient  sessionAuthClient  = null ;
5957
6058    /** 
6159     * Get a new Authenticator instance for the supplied service URL and credentials that provides 
@@ -166,27 +164,28 @@ public CouchDbSessionToken requestToken() {
166164            }
167165        }
168166
169-         try  {
170-             // Build the client if we need to 
171-             if  (sessionAuthClient  == null ) {
172-                 sessionAuthClient  = HttpClientSingleton 
173-                         .getInstance ()
174-                         .configureClient (options )
175-                         .newBuilder ()
176-                         .cookieJar (cookieJar )
177-                         .build ();
178-             }
179-             try  (Response  response  = sessionAuthClient .newCall (postSessionbuilder .build ()).execute ()) {
180-                 if  (response .isSuccessful ()) {
181-                     List <Cookie > cookies  = Cookie .parseAll (sessionUrl , response .headers ());
182-                     for  (Cookie  cookie  : cookies ) {
183-                         if  ("AuthSession" .equals (cookie .name ())) {
184-                             return  new  CouchDbSessionToken (cookie .expiresAt ());
185-                         }
167+         // Build the client if we need to 
168+         if  (getClient () == null ) {
169+             setClient (
170+                 HttpClientSingleton 
171+                 .getInstance ()
172+                 .configureClient (options )
173+                 .newBuilder ()
174+                 .cookieJar (cookieJar )
175+                 .build ()
176+             );
177+         }
178+ 
179+         try  (Response  response  = getClient ().newCall (postSessionbuilder .build ()).execute ()) {
180+             if  (response .isSuccessful ()) {
181+                 List <Cookie > cookies  = Cookie .parseAll (sessionUrl , response .headers ());
182+                 for  (Cookie  cookie  : cookies ) {
183+                     if  ("AuthSession" .equals (cookie .name ())) {
184+                         return  new  CouchDbSessionToken (cookie .expiresAt ());
186185                    }
187186                }
188-                 throw  new  ServiceResponseException (response .code (), response );
189187            }
188+             throw  new  ServiceResponseException (response .code (), response );
190189        } catch  (RuntimeException  | IOException  t ) {
191190            return  new  CouchDbSessionToken (t );
192191        }
0 commit comments