public void setProxySettings ( Proxy proxy ) { if ( proxy == null || proxy . getProxyType ( ) == Proxy . ProxyType . UNSPECIFIED ) { return ; } switch ( proxy . getProxyType ( ) ) { case MANUAL : List < String > noProxyHosts = new ArrayList <> ( ) ; String noProxy = proxy . getNoProxy ( ) ; if ( noProxy != null && ! noProxy . isEmpty ( ) ) { String [ ] hosts = noProxy . split ( "," ) ; for ( String host : hosts ) { if ( host . trim ( ) . length ( ) > 0 ) { noProxyHosts . add ( host . trim ( ) ) ; } } } String httpProxy = proxy . getHttpProxy ( ) ; if ( httpProxy != null && ! httpProxy . isEmpty ( ) ) { String host = httpProxy ; int port = 0 ; int index = httpProxy . indexOf ( ":" ) ; if ( index != - 1 ) { host = httpProxy . substring ( 0 , index ) ; port = Integer . parseInt ( httpProxy . substring ( index + 1 ) ) ; } setHTTPProxy ( host , port , noProxyHosts ) ; } String socksProxy = proxy . getSocksProxy ( ) ; if ( socksProxy != null && ! socksProxy . isEmpty ( ) ) { String host = socksProxy ; int port = 0 ; int index = socksProxy . indexOf ( ":" ) ; if ( index != - 1 ) { host = socksProxy . substring ( 0 , index ) ; port = Integer . parseInt ( socksProxy . substring ( index + 1 ) ) ; } setSocksProxy ( host , port , noProxyHosts ) ; } // sslProxy is not supported/implemented // ftpProxy is not supported/implemented break ; case PAC : String pac = proxy . getProxyAutoconfigUrl ( ) ; if ( pac != null && ! pac . isEmpty ( ) ) { setAutoProxy ( pac ) ; } break ; default : break ; } }
Set proxy for WebClient using Proxy .