private static URL getURLAndSetAuthorization ( final String pURL , final Properties pProperties ) throws MalformedURLException { String url = pURL ; // Split user/password away from url String userPass = null ; String protocolPrefix = HTTP ; int httpIdx = url . indexOf ( HTTPS ) ; if ( httpIdx >= 0 ) { protocolPrefix = HTTPS ; url = url . substring ( httpIdx + HTTPS . length ( ) ) ; } else { httpIdx = url . indexOf ( HTTP ) ; if ( httpIdx >= 0 ) { url = url . substring ( httpIdx + HTTP . length ( ) ) ; } } // Get authorization part int atIdx = url . indexOf ( "@" ) ; if ( atIdx >= 0 ) { userPass = url . substring ( 0 , atIdx ) ; url = url . substring ( atIdx + 1 ) ; } // Set authorization if user/password is present if ( userPass != null ) { // System.out.println("Setting password ("+ userPass + ")!"); pProperties . setProperty ( "Authorization" , "Basic " + BASE64 . encode ( userPass . getBytes ( ) ) ) ; } // Return URL return new URL ( protocolPrefix + url ) ; }
Registers the password from the URL string and returns the URL object .