public static String getKey ( KeyRequest keyRequest , String envTag ) throws ClientException { final Http2Client client = Http2Client . getInstance ( ) ; final CountDownLatch latch = new CountDownLatch ( 1 ) ; final ClientConnection connection ; try { if ( keyRequest . getServerUrl ( ) != null ) { connection = client . connect ( new URI ( keyRequest . getServerUrl ( ) ) , Http2Client . WORKER , Http2Client . SSL , Http2Client . BUFFER_POOL , keyRequest . enableHttp2 ? OptionMap . create ( UndertowOptions . ENABLE_HTTP2 , true ) : OptionMap . EMPTY ) . get ( ) ; } else if ( keyRequest . getServiceId ( ) != null ) { Cluster cluster = SingletonServiceFactory . getBean ( Cluster . class ) ; String url = cluster . serviceToUrl ( "https" , keyRequest . getServiceId ( ) , envTag , null ) ; connection = client . connect ( new URI ( url ) , Http2Client . WORKER , Http2Client . SSL , Http2Client . BUFFER_POOL , keyRequest . enableHttp2 ? OptionMap . create ( UndertowOptions . ENABLE_HTTP2 , true ) : OptionMap . EMPTY ) . get ( ) ; } else { // both server_url and serviceId are empty in the config. logger . error ( "Error: both server_url and serviceId are not configured in client.yml for " + keyRequest . getClass ( ) ) ; throw new ClientException ( "both server_url and serviceId are not configured in client.yml for " + keyRequest . getClass ( ) ) ; } } catch ( Exception e ) { throw new ClientException ( e ) ; } final AtomicReference < ClientResponse > reference = new AtomicReference <> ( ) ; try { ClientRequest request = new ClientRequest ( ) . setPath ( keyRequest . getUri ( ) ) . setMethod ( Methods . GET ) ; if ( keyRequest . getClientId ( ) != null ) { request . getRequestHeaders ( ) . put ( Headers . AUTHORIZATION , getBasicAuthHeader ( keyRequest . getClientId ( ) , keyRequest . getClientSecret ( ) ) ) ; } request . getRequestHeaders ( ) . put ( Headers . HOST , "localhost" ) ; adjustNoChunkedEncoding ( request , "" ) ; connection . sendRequest ( request , client . createClientCallback ( reference , latch ) ) ; latch . await ( ) ; } catch ( Exception e ) { logger . error ( "Exception: " , e ) ; throw new ClientException ( e ) ; } finally { IoUtils . safeClose ( connection ) ; } return reference . get ( ) . getAttachment ( Http2Client . RESPONSE_BODY ) ; }
Get the certificate from key distribution service of OAuth 2 . 0 provider with the kid .