private void updateRegionCache ( String bucketName ) throws InvalidBucketNameException , NoSuchAlgorithmException , InsufficientDataException , IOException , InvalidKeyException , NoResponseException , XmlPullParserException , ErrorResponseException , InternalException { if ( bucketName != null && this . accessKey != null && this . secretKey != null && ! BucketRegionCache . INSTANCE . exists ( bucketName ) ) { Map < String , String > queryParamMap = new HashMap <> ( ) ; queryParamMap . put ( "location" , null ) ; HttpResponse response = execute ( Method . GET , US_EAST_1 , bucketName , "/" , null , queryParamMap , null , 0 ) ; // existing XmlEntity does not work, so fallback to regular parsing. XmlPullParser xpp = xmlPullParserFactory . newPullParser ( ) ; String location = null ; try ( ResponseBody body = response . body ( ) ) { xpp . setInput ( body . charStream ( ) ) ; while ( xpp . getEventType ( ) != XmlPullParser . END_DOCUMENT ) { if ( xpp . getEventType ( ) == XmlPullParser . START_TAG && "LocationConstraint" . equals ( xpp . getName ( ) ) ) { xpp . next ( ) ; location = getText ( xpp ) ; break ; } xpp . next ( ) ; } } String region ; if ( location == null ) { region = US_EAST_1 ; } else { // eu-west-1 can be sometimes 'EU'. if ( "EU" . equals ( location ) ) { region = "eu-west-1" ; } else { region = location ; } } // Add the new location. BucketRegionCache . INSTANCE . set ( bucketName , region ) ; } }
Updates Region cache for given bucket .