org.apache.commons.httpclient.protocol
Class Protocol

java.lang.Object
  |
  +--org.apache.commons.httpclient.protocol.Protocol

public class Protocol
extends java.lang.Object

A class to encapsulate the specifics of a protocol. This class class also provides the ability to customize the set and characteristics of the protocols used.

One use case for modifying the default set of protocols would be to set a custom SSL socket factory. This would look something like the following:

 
 Protocol myHTTPS = new Protocol( "https", new MySSLSocketFactory(), 443 );
 
 Protocol.registerProtocol( "https", myHTTPS );
 

Since:
2.0
Author:
Michael Becke, Jeff Dever

Constructor Summary
Protocol(java.lang.String scheme, ProtocolSocketFactory factory, int defaultPort)
          Constructs a new Protocol.
Protocol(java.lang.String scheme, SecureProtocolSocketFactory factory, int defaultPort)
          Constructs a new Protocol.
 
Method Summary
 boolean equals(java.lang.Object obj)
           
 int getDefaultPort()
          Returns the defaultPort.
static Protocol getProtocol(java.lang.String id)
          Gets the protocol with the given ID.
 java.lang.String getScheme()
          Returns the scheme.
 ProtocolSocketFactory getSocketFactory()
          Returns the socketFactory.
 int hashCode()
           
 boolean isSecure()
          Returns the secure.
static void registerProtocol(java.lang.String id, Protocol protocol)
          Registers a new protocol with the given identifier.
 int resolvePort(int port)
          Resolves the correct port for this protocol.
 java.lang.String toString()
           
static void unregisterProtocol(java.lang.String id)
          Unregisters the protocol with the given ID.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Protocol

public Protocol(java.lang.String scheme,
                ProtocolSocketFactory factory,
                int defaultPort)
Constructs a new Protocol. The created protcol is insecure.

Parameters:
scheme - the scheme (e.g. http, https)
factory - the factory for creating sockets for communication using this protocol
defaultPort - the port this protocol defaults to

Protocol

public Protocol(java.lang.String scheme,
                SecureProtocolSocketFactory factory,
                int defaultPort)
Constructs a new Protocol. The created protcol is secure.

Parameters:
scheme - the scheme (e.g. http, https)
factory - the factory for creating sockets for communication using this protocol
defaultPort - the port this protocol defaults to
Method Detail

registerProtocol

public static void registerProtocol(java.lang.String id,
                                    Protocol protocol)
Registers a new protocol with the given identifier. If a protocol with the given ID already exists it will be overridden. This ID is the same one used to retrieve the protocol from getProtocol(String).

Parameters:
id - the identifier for this protocol
protocol - the protocol to register
See Also:
getProtocol(String)

unregisterProtocol

public static void unregisterProtocol(java.lang.String id)
Unregisters the protocol with the given ID.

Parameters:
id - the ID of the protocol to remove

getProtocol

public static Protocol getProtocol(java.lang.String id)
Gets the protocol with the given ID.

Parameters:
id - the protocol ID
Returns:
Protocol a protocol
Throws:
java.lang.IllegalStateException - if a protocol with the ID cannot be found

getDefaultPort

public int getDefaultPort()
Returns the defaultPort.

Returns:
int

getSocketFactory

public ProtocolSocketFactory getSocketFactory()
Returns the socketFactory. If secure the factory is a SecureProtocolSocketFactory.

Returns:
SocketFactory

getScheme

public java.lang.String getScheme()
Returns the scheme.

Returns:
String

isSecure

public boolean isSecure()
Returns the secure.

Returns:
boolean

resolvePort

public int resolvePort(int port)
Resolves the correct port for this protocol. Returns the given port if valid or the default port otherwise.

Parameters:
port - the port to be resolved
Returns:
the given port or the defaultPort

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()


Copyright © 2001-2003 Apache Software Foundation. All Rights Reserved.