org.apache.commons.httpclient.protocol

Class 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 );
 
Authors:
Michael Becke
Jeff Dever
Mike Bowler
Since:
2.0

Constructor Summary

Protocol(String scheme, ProtocolSocketFactory factory, int defaultPort)
Constructs a new Protocol.
Protocol(String scheme, SecureProtocolSocketFactory factory, int defaultPort)
Deprecated. Use the constructor that uses ProtocolSocketFactory, this version of the constructor is only kept for backwards API compatibility.

Method Summary

boolean
equals(Object obj)
Return true if the specified object equals this object.
int
getDefaultPort()
Returns the defaultPort.
static Protocol
getProtocol(String id)
Gets the protocol with the given ID.
String
getScheme()
Returns the scheme.
ProtocolSocketFactory
getSocketFactory()
Returns the socketFactory.
int
hashCode()
Return a hash code for this object
boolean
isSecure()
Returns true if this protocol is secure
static void
registerProtocol(String id, Protocol protocol)
Registers a new protocol with the given identifier.
int
resolvePort(int port)
Resolves the correct port for this protocol.
String
toString()
Return a string representation of this object.
static void
unregisterProtocol(String id)
Unregisters the protocol with the given ID.

Constructor Details

Protocol

public Protocol(String scheme,
                ProtocolSocketFactory factory,
                int defaultPort)
Constructs a new Protocol. Whether the created protocol is secure depends on the class of factory.
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(String scheme,
                SecureProtocolSocketFactory factory,
                int defaultPort)

Deprecated. Use the constructor that uses ProtocolSocketFactory, this version of the constructor is only kept for backwards API compatibility.

Constructs a new Protocol. Whether the created protocol is secure depends on the class of factory.
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 Details

equals

public boolean equals(Object obj)
Return true if the specified object equals this object.
Parameters:
obj - The object to compare against.
Returns:
true if the objects are equal.

getDefaultPort

public int getDefaultPort()
Returns the defaultPort.
Returns:
int

getProtocol

public static Protocol getProtocol(String id)
            throws IllegalStateException
Gets the protocol with the given ID.
Parameters:
id - the protocol ID
Returns:
Protocol a protocol

getScheme

public String getScheme()
Returns the scheme.
Returns:
The scheme

getSocketFactory

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

hashCode

public int hashCode()
Return a hash code for this object
Returns:
The hash code.

isSecure

public boolean isSecure()
Returns true if this protocol is secure
Returns:
true if this protocol is secure

registerProtocol

public static void registerProtocol(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

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 String toString()
Return a string representation of this object.
Returns:
a string representation of this object.

unregisterProtocol

public static void unregisterProtocol(String id)
Unregisters the protocol with the given ID.
Parameters:
id - the ID of the protocol to remove

Copyright (c) 1999-2005 - Apache Software Foundation