public void refresh ( ) { this . refreshLock . writeLock ( ) . lock ( ) ; if ( ! this . canRefresh ( ) ) { this . refreshLock . writeLock ( ) . unlock ( ) ; throw new IllegalStateException ( "The BoxAPIConnection cannot be refreshed because it doesn't have a " + "refresh token." ) ; } URL url = null ; try { url = new URL ( this . tokenURL ) ; } catch ( MalformedURLException e ) { this . refreshLock . writeLock ( ) . unlock ( ) ; assert false : "An invalid refresh URL indicates a bug in the SDK." ; throw new RuntimeException ( "An invalid refresh URL indicates a bug in the SDK." , e ) ; } String urlParameters = String . format ( "grant_type=refresh_token&refresh_token=%s&client_id=%s&client_secret=%s" , this . refreshToken , this . clientID , this . clientSecret ) ; BoxAPIRequest request = new BoxAPIRequest ( this , url , "POST" ) ; request . shouldAuthenticate ( false ) ; request . setBody ( urlParameters ) ; String json ; try { BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; json = response . getJSON ( ) ; } catch ( BoxAPIException e ) { this . notifyError ( e ) ; this . refreshLock . writeLock ( ) . unlock ( ) ; throw e ; } JsonObject jsonObject = JsonObject . readFrom ( json ) ; this . accessToken = jsonObject . get ( "access_token" ) . asString ( ) ; this . refreshToken = jsonObject . get ( "refresh_token" ) . asString ( ) ; this . lastRefresh = System . currentTimeMillis ( ) ; this . expires = jsonObject . get ( "expires_in" ) . asLong ( ) * 1000 ; this . notifyRefresh ( ) ; this . refreshLock . writeLock ( ) . unlock ( ) ; }
Refresh s this connection s access token using its refresh token .