public static RemoteNodeInformation getRemoteNodeInfo ( String hostName , int port , SessionId session ) { logger . entering ( new Object [ ] { hostName , port , session } ) ; RemoteNodeInformation node = null ; String errorMsg = "Failed to acquire remote webdriver node and port info. Root cause: " ; // go ahead and abort if this is a known grid where know we won't be able to extract the proxy info via the hub // api if ( Config . getBoolConfigProperty ( ConfigProperty . SELENIUM_USE_SAUCELAB_GRID ) ) { logger . exiting ( node ) ; return node ; } try { HttpHost host = new HttpHost ( hostName , port ) ; CloseableHttpClient client = HttpClientBuilder . create ( ) . build ( ) ; URL sessionURL = new URL ( "http://" + hostName + ":" + port + "/grid/api/testsession?session=" + session ) ; BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest ( "POST" , sessionURL . toExternalForm ( ) ) ; CloseableHttpResponse response = client . execute ( host , r ) ; JSONObject object = extractObject ( response ) ; URL myURL = new URL ( object . getString ( "proxyId" ) ) ; if ( ( myURL . getHost ( ) != null ) && ( myURL . getPort ( ) != - 1 ) ) { node = new RemoteNodeInformation ( myURL . getHost ( ) , myURL . getPort ( ) ) ; } } catch ( Exception e ) { logger . log ( Level . FINE , errorMsg , e ) ; // Just log the exception at finer level but dont throw any exceptions // because this is just value added information. } logger . exiting ( node ) ; return node ; }
For a given Session ID against a host on a particular port this method returns the remote webdriver node and the port to which the execution was redirected to by the hub .