public static URL buildUrl ( String scheme , String host , int port , String path , Map < String , String > parameters ) throws MalformedURLException { checkSchemeAndPort ( scheme , port ) ; StringBuilder buffer = new StringBuilder ( ) ; if ( ! host . startsWith ( scheme + "://" ) ) { buffer . append ( scheme ) . append ( "://" ) ; } buffer . append ( host ) ; if ( port > 0 ) { buffer . append ( ' ' ) ; buffer . append ( port ) ; } if ( path == null ) { path = "/" ; } buffer . append ( path ) ; if ( ! parameters . isEmpty ( ) ) { buffer . append ( ' ' ) ; } int size = parameters . size ( ) ; for ( Map . Entry < String , String > entry : parameters . entrySet ( ) ) { buffer . append ( entry . getKey ( ) ) ; buffer . append ( ' ' ) ; Object value = entry . getValue ( ) ; if ( value != null ) { String string = value . toString ( ) ; try { string = URLEncoder . encode ( string , UTF8 ) ; } catch ( UnsupportedEncodingException e ) { // Should never happen, but just in case } buffer . append ( string ) ; } if ( -- size != 0 ) { buffer . append ( ' ' ) ; } } /* * RequestContext requestContext = RequestContext.getRequestContext(); Auth auth = requestContext.getAuth(); if (auth != null && * !ignoreMethod(getMethod(parameters))) { buffer.append("&api_sig="); buffer.append(AuthUtilities.getSignature(sharedSecret, parameters)); } */ return new URL ( buffer . toString ( ) ) ; }
Build a request URL using a given scheme .