@Test public void testGetProxy_HttpProxy() throws Exception { final RemoteRepository repo = new RemoteRepository.Builder( "test", "default", "http: final URL url = new URL( repo.getUrl() ); final InetSocketAddress addr = InetSocketAddress.createUnresolved( "proxy", 8080 ); java.net.ProxySelector.setDefault( new AbstractProxySelector() { @Override public List<java.net.Proxy> select( URI uri ) { if ( repo.getHost().equalsIgnoreCase( uri.getHost() ) ) { return Arrays.asList( new java.net.Proxy( java.net.Proxy.Type.HTTP, addr ) ); } return Collections.emptyList(); } } ); Authenticator.setDefault( new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { if ( Authenticator.RequestorType.PROXY.equals( getRequestorType() ) && addr.getHostName().equals( getRequestingHost() ) && addr.getPort() == getRequestingPort() && url.equals( getRequestingURL() ) ) { return new PasswordAuthentication( "proxyuser", "proxypass".toCharArray() ); } return super.getPasswordAuthentication(); } } ); Proxy proxy = selector.getProxy( repo ); assertNotNull( proxy ); assertEquals( addr.getHostName(), proxy.getHost() ); assertEquals( addr.getPort(), proxy.getPort() ); assertEquals( Proxy.TYPE_HTTP, proxy.getType() ); RemoteRepository repo2 = new RemoteRepository.Builder( repo ).setProxy( proxy ).build(); Authentication auth = proxy.getAuthentication(); assertNotNull( auth ); AuthenticationContext authCtx = AuthenticationContext.forProxy( new DefaultRepositorySystemSession(), repo2 ); assertEquals( "proxyuser", authCtx.get( AuthenticationContext.USERNAME ) ); assertEquals( "proxypass", authCtx.get( AuthenticationContext.PASSWORD ) ); }
public Proxy getProxy( RemoteRepository repository ) { List<java.net.Proxy> proxies = null; try { URI uri = new URI( repository.getUrl() ).parseServerAuthority(); proxies = java.net.ProxySelector.getDefault().select( uri ); } catch ( Exception e ) { } if ( proxies != null ) { for ( java.net.Proxy proxy : proxies ) { if ( java.net.Proxy.Type.DIRECT.equals( proxy.type() ) ) { break; } if ( java.net.Proxy.Type.HTTP.equals( proxy.type() ) && isValid( proxy.address() ) ) { InetSocketAddress addr = (InetSocketAddress) proxy.address(); return new Proxy( Proxy.TYPE_HTTP, addr.getHostName(), addr.getPort(), JreProxyAuthentication.INSTANCE ); } } } return null; }
JreProxySelector implements ProxySelector { public Proxy getProxy( RemoteRepository repository ) { List<java.net.Proxy> proxies = null; try { URI uri = new URI( repository.getUrl() ).parseServerAuthority(); proxies = java.net.ProxySelector.getDefault().select( uri ); } catch ( Exception e ) { } if ( proxies != null ) { for ( java.net.Proxy proxy : proxies ) { if ( java.net.Proxy.Type.DIRECT.equals( proxy.type() ) ) { break; } if ( java.net.Proxy.Type.HTTP.equals( proxy.type() ) && isValid( proxy.address() ) ) { InetSocketAddress addr = (InetSocketAddress) proxy.address(); return new Proxy( Proxy.TYPE_HTTP, addr.getHostName(), addr.getPort(), JreProxyAuthentication.INSTANCE ); } } } return null; } }
JreProxySelector implements ProxySelector { public Proxy getProxy( RemoteRepository repository ) { List<java.net.Proxy> proxies = null; try { URI uri = new URI( repository.getUrl() ).parseServerAuthority(); proxies = java.net.ProxySelector.getDefault().select( uri ); } catch ( Exception e ) { } if ( proxies != null ) { for ( java.net.Proxy proxy : proxies ) { if ( java.net.Proxy.Type.DIRECT.equals( proxy.type() ) ) { break; } if ( java.net.Proxy.Type.HTTP.equals( proxy.type() ) && isValid( proxy.address() ) ) { InetSocketAddress addr = (InetSocketAddress) proxy.address(); return new Proxy( Proxy.TYPE_HTTP, addr.getHostName(), addr.getPort(), JreProxyAuthentication.INSTANCE ); } } } return null; } JreProxySelector(); }
JreProxySelector implements ProxySelector { public Proxy getProxy( RemoteRepository repository ) { List<java.net.Proxy> proxies = null; try { URI uri = new URI( repository.getUrl() ).parseServerAuthority(); proxies = java.net.ProxySelector.getDefault().select( uri ); } catch ( Exception e ) { } if ( proxies != null ) { for ( java.net.Proxy proxy : proxies ) { if ( java.net.Proxy.Type.DIRECT.equals( proxy.type() ) ) { break; } if ( java.net.Proxy.Type.HTTP.equals( proxy.type() ) && isValid( proxy.address() ) ) { InetSocketAddress addr = (InetSocketAddress) proxy.address(); return new Proxy( Proxy.TYPE_HTTP, addr.getHostName(), addr.getPort(), JreProxyAuthentication.INSTANCE ); } } } return null; } JreProxySelector(); Proxy getProxy( RemoteRepository repository ); }
JreProxySelector implements ProxySelector { public Proxy getProxy( RemoteRepository repository ) { List<java.net.Proxy> proxies = null; try { URI uri = new URI( repository.getUrl() ).parseServerAuthority(); proxies = java.net.ProxySelector.getDefault().select( uri ); } catch ( Exception e ) { } if ( proxies != null ) { for ( java.net.Proxy proxy : proxies ) { if ( java.net.Proxy.Type.DIRECT.equals( proxy.type() ) ) { break; } if ( java.net.Proxy.Type.HTTP.equals( proxy.type() ) && isValid( proxy.address() ) ) { InetSocketAddress addr = (InetSocketAddress) proxy.address(); return new Proxy( Proxy.TYPE_HTTP, addr.getHostName(), addr.getPort(), JreProxyAuthentication.INSTANCE ); } } } return null; } JreProxySelector(); Proxy getProxy( RemoteRepository repository );  }