org.jurvis.net
Class JvProxySelector

java.lang.Object
  extended by java.net.ProxySelector
      extended by org.jurvis.net.JvProxySelector

public class JvProxySelector
extends ProxySelector

Selects the proxy server to use, if any, when connecting to the network resource referenced by a URL. This class provides a ProxySelector facade to a JvProxyConfig.

Author:
Neil W. Weber

Field Summary
protected  JvProxyConfig proxyConfig
          The JvProxyConfig used to determine the proxies for a URI.
 
Constructor Summary
JvProxySelector(JvProxyConfig proxyConfig)
          Construct a new JvProxySelector that uses the specified JvProxyConfig to determine the proxies to use for a URI.
 
Method Summary
 void connectFailed(URI uri, SocketAddress sa, IOException ioe)
          Called to indicate that a connection could not be established to a proxy/socks server.
static void main(String[] args)
           
 List<Proxy> select(URI uri)
          Selects all the applicable proxies based on the protocol to access the resource with and a destination address to access the resource at.
protected  Proxy toProxy(JvProxyInfo proxyInfo)
          Returns a 1.5 Proxy object representing a proxy info.
 
Methods inherited from class java.net.ProxySelector
getDefault, setDefault
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

proxyConfig

protected JvProxyConfig proxyConfig
The JvProxyConfig used to determine the proxies for a URI.

Constructor Detail

JvProxySelector

public JvProxySelector(JvProxyConfig proxyConfig)
Construct a new JvProxySelector that uses the specified JvProxyConfig to determine the proxies to use for a URI.

Parameters:
proxyConfig - an internet proxy configuration
Method Detail

select

public List<Proxy> select(URI uri)
Selects all the applicable proxies based on the protocol to access the resource with and a destination address to access the resource at. The format of the URI is defined as follow:
  • http URI for http connections
  • https URI for https connections
  • ftp URI for ftp connections
  • socket://host:port
    for tcp client sockets connections
  • serversocket://address:port
    for tcp server sockets binding requests

Specified by:
select in class ProxySelector
Parameters:
uri - The URI that a connection is required to
Returns:
a List of Proxies. Each element in the the List is of type Proxy; when no proxy is available, the list will contain one element of type Proxy that represents a direct connection.

connectFailed

public void connectFailed(URI uri,
                          SocketAddress sa,
                          IOException ioe)
Called to indicate that a connection could not be established to a proxy/socks server. An implementation of this method can temporarily remove the proxies or reorder the sequence of proxies returned by select(String, String), using the address and they kind of IOException given.

Specified by:
connectFailed in class ProxySelector
Parameters:
uri - The URI that the proxy at sa failed to serve.
sa - The socket address of the proxy/SOCKS server
ioe - The I/O exception thrown when the connect failed.
Throws:
IllegalArgumentException - if either argument is null

toProxy

protected Proxy toProxy(JvProxyInfo proxyInfo)
Returns a 1.5 Proxy object representing a proxy info.

Parameters:
proxyInfo - the JvProxyInfo object to convert
Returns:
a Proxy representation of the object

main

public static void main(String[] args)
                 throws Exception
Throws:
Exception


Copyright © 1999-2004 Neil W. Weber. All Rights Reserved.