org.opennms.bb.dp.capsd.plugin
Class TestForHttpServer

java.lang.Object
  |
  +--org.opennms.bb.dp.capsd.plugin.TestForHttpServer
All Implemented Interfaces:
CapsdPlugin

public class TestForHttpServer
extends Object
implements CapsdPlugin

This class is designed to be used by the capabilities daemon to test for the existance of an HTTP server on remote interfaces. The class implements the CapsdPlugin interface that allows it to be used along with other plugins by the daemon.

Version:
$Revision: 1.6 $
Author:
Sowmya, Weaver, OpenNMS

Field Summary
private static String CAPABILITY_NAME
          The capability name for this class.
private static int[] DEFAULT_PORTS
          The port on which the host is checked to see if it supports HTTP.
 
Constructor Summary
TestForHttpServer()
          The default constructor for the test object.
 
Method Summary
 String getCapabilityName()
          Returns the capability name of the plugin poller.
private  String getLine(InputStream istream)
          Reads a single line at a time from the input stream.
 boolean isProtocolSupported(InetAddress host)
          Returns true if the host supports HTTP.
 boolean isProtocolSupported(InetAddress host, int port)
          Returns true if the host supports HTTP on the port specified.
 boolean isProtocolSupported(InetAddress host, int port, String capName)
          Returns true if the host supports HTTP on the port specified and the capability specified is 'isHttp'.
 boolean isProtocolSupported(InetAddress host, String capName)
          Returns true if the host supports HTTP and the capability specified is 'isHttp'.
private  boolean isServer(InetAddress host, int port)
          Test to see if the passed host-port pair is the endpoint for an HTTP server.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

DEFAULT_PORTS

private static final int[] DEFAULT_PORTS

The port on which the host is checked to see if it supports HTTP.


CAPABILITY_NAME

private static final String CAPABILITY_NAME

The capability name for this class.

Constructor Detail

TestForHttpServer

public TestForHttpServer()

The default constructor for the test object. Currently this constructor does nothing since there is no data to initialize in the class.

Method Detail

getLine

private String getLine(InputStream istream)
                throws IOException

Reads a single line at a time from the input stream. Each line is terminated by the sequence '\r\n'. For more information on the format of the line see the FTP RFC.

If the end of file condition is reached before the cariage-return line-feed sequence then the received buffer is returned, or a string of zero length.

NOTE: The \r\n sequence is stripped from the returned line.

Parameters:
istream - The input stream from which characters are to be read.
Returns:
A line of characters read off the input stream.
Throws:
java.lang.IOException - Thrown if an error occurs reading the data from the stream.

isServer

private boolean isServer(InetAddress host,
                         int port)

Test to see if the passed host-port pair is the endpoint for an HTTP server. If there is an HTTP server at that destination then a value of true is returned from the method. Otherwise a false value is returned to the caller.

Parameters:
host - The remote host to connect to.
port - The remote port to connect to.
Returns:
True if server supports HTTP on the specified port, false otherwise

isProtocolSupported

public boolean isProtocolSupported(InetAddress host)

Returns true if the host supports HTTP.

Specified by:
isProtocolSupported in interface CapsdPlugin
Parameters:
host - The InetAddress which is to be checked for HTTP support on all well known ports for http.
Returns:
True if the host supports HTTP, false otherwise

isProtocolSupported

public boolean isProtocolSupported(InetAddress host,
                                   int port)

Returns true if the host supports HTTP on the port specified.

Parameters:
host - The InetAddress which is to be checked for HTTP support.
port - The port on which the HTTP test is to be done.
Returns:
True if the host supports HTTP, false otherwise.

isProtocolSupported

public boolean isProtocolSupported(InetAddress host,
                                   String capName)
                            throws UnsupportedProtocolException

Returns true if the host supports HTTP and the capability specified is 'isHttp'.

Specified by:
isProtocolSupported in interface CapsdPlugin
Parameters:
host - The InetAddress which is to be checked for HTTP support.
capName - The capability whose suport is to be checked for.
Returns:
True if the host supports HTTP, false otherwise
Throws:
org.opennms.bb.db.capsd.plugin.UnsupportedProtocolException - Thrown if capability specified is not 'isHttp'

isProtocolSupported

public boolean isProtocolSupported(InetAddress host,
                                   int port,
                                   String capName)
                            throws UnsupportedProtocolException

Returns true if the host supports HTTP on the port specified and the capability specified is 'isHttp'.

Parameters:
host - The InetAddress which is to be checked for HTTP support.
port - The port number to be used for the HTTP support.
capName - The capability whose suport is to be checked for.
Returns:
true if the host supports HTTP, false otherwise
Throws:
org.opennms.bb.dp.capsd.pluing.UnsupportedProtocolException - Thrown if capability specified is not 'isHttp'.

getCapabilityName

public String getCapabilityName()

Returns the capability name of the plugin poller. In this instance it will be the string "isHTTP".

Specified by:
getCapabilityName in interface CapsdPlugin
Returns:
The capability name.