hamsam.net
Class ProxyInfo

java.lang.Object
  |
  +--hamsam.net.ProxyInfo

public class ProxyInfo
extends java.lang.Object

Defines the type of connections to be used for each protocol. An object that implements this interface is used by Hamsam library to determine what type of connections are to be used for each protocol.


Field Summary
static int DIRECT
          Connection type indicating a direct connection to the Internet.
static int HTTP
          Connection type indicating a connection through HTTP proxy to the Internet.
static int SOCKS4
          Connection type indicating a connection through Socks Version 4 proxy to the Internet.
static int SOCKS5
          Connection type indicating a connection through Socks Version 5 proxy to the Internet.
 
Constructor Summary
ProxyInfo()
          Construct a proxy information object indicating direct connection to the Internet.
ProxyInfo(int type, java.lang.String serverName, int serverPort)
          Construct a proxy information object indicating the type of proxy to be used, the proxy server's host name, and proxy server's listening port number.
 
Method Summary
 Connection getConnection(java.lang.String hostname, int port)
          Creates a connection through the proxy set in this ProxyInfo object.
 java.lang.String getPassword()
          Returns the password to be used for proxy authentication.
 int getProxyType()
          Returns the type of proxy to be used as indicated by this object.
 java.lang.String getServerName()
          Returns the host name of the proxy server to be used.
 int getServerPort()
          Returns the TCP/IP port at which the proxy server is listening.
 java.lang.String getUsername()
          Returns the username to be used for proxy authentication.
 void setPassword(java.lang.String password)
          Set the password to be used for proxy authentication.
 void setUsername(java.lang.String username)
          Set the username to be used for proxy authentication.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIRECT

public static final int DIRECT
Connection type indicating a direct connection to the Internet.

See Also:
Constant Field Values

SOCKS4

public static final int SOCKS4
Connection type indicating a connection through Socks Version 4 proxy to the Internet.

See Also:
Constant Field Values

SOCKS5

public static final int SOCKS5
Connection type indicating a connection through Socks Version 5 proxy to the Internet.

See Also:
Constant Field Values

HTTP

public static final int HTTP
Connection type indicating a connection through HTTP proxy to the Internet.

See Also:
Constant Field Values
Constructor Detail

ProxyInfo

public ProxyInfo()
Construct a proxy information object indicating direct connection to the Internet. This is to be used if you don't have any proxy servers.


ProxyInfo

public ProxyInfo(int type,
                 java.lang.String serverName,
                 int serverPort)
          throws IllegalArgumentException
Construct a proxy information object indicating the type of proxy to be used, the proxy server's host name, and proxy server's listening port number. This is to be used if you are connecting through Socks or HTTP proxy servers.

You may use SOCKS4, SOCKS5, or HTTP as the proxy types. If you specify the proxy type as DIRECT, an IllegalArgumentException will be thrown.

Parameters:
type - The proxy server type.
serverName - The host name of the proxy server.
serverPort - The TCP/IP port number in which the proxy is listening.
Throws:
IllegalArgumentException - If type is DIRECT.
Method Detail

setUsername

public void setUsername(java.lang.String username)
                 throws IllegalStateException
Set the username to be used for proxy authentication.

Socks version 5 and HTTP proxies optionally use authentication through a username-password mechanism. This method sets the username for such authentication.

If the proxy type is other than SOCKS5 or HTTP, this method throws an IllegalStateException.

Parameters:
username - The username to be used for proxy authentication.
Throws:
IllegalStateException - If the proxy type is neither Socks version 5 nor HTTP.

setPassword

public void setPassword(java.lang.String password)
                 throws IllegalStateException
Set the password to be used for proxy authentication.

Socks version 5 and HTTP proxies optionally use authentication through a username-password mechanism. This method sets the password for such authentication.

If the proxy type is other than SOCKS5 or HTTP, this method throws an IllegalStateException.

Parameters:
password - The password to be used for proxy authentication.
Throws:
IllegalStateException - If the proxy type is neither Socks version 5 nor HTTP.

getProxyType

public int getProxyType()
Returns the type of proxy to be used as indicated by this object.

This method returns the proxy type set at the time of constructing this object.

Returns:
The proxy type as indicated by this object.

getServerName

public java.lang.String getServerName()
Returns the host name of the proxy server to be used.

If this object specifies a direct connection to the Internet, this method will return null.

Returns:
The host name of the proxy server, or null if there is no proxy servers.

getServerPort

public int getServerPort()
Returns the TCP/IP port at which the proxy server is listening.

If there is no proxy server, this will return -1.

Returns:
The proxy server port, or -1 if there is no proxy.

getUsername

public java.lang.String getUsername()
                             throws IllegalStateException
Returns the username to be used for proxy authentication.

If the type of the proxy is neither Socks version 5 nor HTTP, an IllegalStateException will be thrown.

Returns:
The username for proxy authentication, or null if the proxy does not require authentication.
Throws:
IllegalStateException - If the proxy type is neither Socks version 5 nor HTTP.

getPassword

public java.lang.String getPassword()
                             throws IllegalStateException
Returns the password to be used for proxy authentication.

If the type of the proxy is neither Socks version 5 nor HTTP, an IllegalStateException will be thrown.

Returns:
The password for proxy authentication, or null if the proxy does not require authentication.
Throws:
IllegalStateException - If the proxy type is neither Socks version 5 nor HTTP.

getConnection

public Connection getConnection(java.lang.String hostname,
                                int port)
                         throws java.net.UnknownHostException,
                                java.io.IOException,
                                IllegalStateException
Creates a connection through the proxy set in this ProxyInfo object.

Parameters:
hostname - the host to connect to.
port - the TCP/IP ports number to connect to.
Returns:
a newly created connection to the specified server at the specified port.
Throws:
java.net.UnknownHostException - if the proxy server or the host is unknown.
java.io.IOException - if an I/O error occured while connecting.
IllegalStateException - if this ProxyInfo is not initialized properly.