blob: 28332f6796838a5bb9c6bfa05ece0c24217773a2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
package org.openslx.network;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.SocketAddress;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
public class StaticProxySelector extends ProxySelector
{
private static Logger log = Logger.getLogger( StaticProxySelector.class );
private final Proxy proxy;
public StaticProxySelector( Proxy proxy )
{
this.proxy = proxy;
}
@Override
public void connectFailed( URI uri, SocketAddress sa, IOException ioe )
{
// Just one fix proxy. So no code is necessary here for deactivating proxy.
}
@Override
public List<Proxy> select( URI uri )
{
List<Proxy> proxyList = new ArrayList<Proxy>();
String host = uri.getHost();
log.info( "Host: " + host );
// If host equals localhost return empty list.
if ( ! ( host.startsWith( "127." ) ) && ! ( host.equals( "localhost" ) ) ) {
// log.info("host.startsWith(127.): " + host.startsWith( "127." ));
// log.info( "host.equals(localhost): " + host.equals("localhost"));
log.info( "Adding proxy to proxyList" );
proxyList.add( this.proxy );
}
// log.info( "proxyList: " + proxyList.toString() );
return proxyList;
}
}
|