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

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

public class TestForSmtpServer
extends Object
implements CapsdPlugin

This class is designed to be used by the capabilities daemon to test for the existance of an SMTP 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.7 $
Author:
Sowmya, Weaver, OpenNMS

Field Summary
private static String CAPABILITY_NAME
          The capability name for the plugin.
private static int DEFAULT_PORT
          The port on which the host is checked to see if it supports SMTP.
 
Constructor Summary
TestForSmtpServer()
          The default constructor for the 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 SMTP.
 boolean isProtocolSupported(InetAddress host, int port)
          Returns true if the host supports SMTP on the port specified.
 boolean isProtocolSupported(InetAddress host, int port, String capName)
          Returns true if the host supports SMTP on the specified port and the capability specified is 'isSMTP'
 boolean isProtocolSupported(InetAddress host, String capName)
          Returns true if the host supports the classes protocol.
private  boolean isServer(InetAddress host, int port)
          Test to see if the passed host-port pair is the endpoint for an SMTP server.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

DEFAULT_PORT

private static final int DEFAULT_PORT

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


CAPABILITY_NAME

private static final String CAPABILITY_NAME

The capability name for the plugin.

Constructor Detail

TestForSmtpServer

public TestForSmtpServer()

The default constructor for the object. There is currently no data to be initialized in the constructor. It is present for completeness.

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 SMTP 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 SMTP server. If there is an SMTP 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 on the host.
Returns:
True if server supports SMTP on the specified port, false otherwise

isProtocolSupported

public boolean isProtocolSupported(InetAddress host)

Returns true if the host supports SMTP.

Specified by:
isProtocolSupported in interface CapsdPlugin
Parameters:
host - The InetAddress which is to be checked for SMTP support
Returns:
True if the host supports SMTP, false otherwise

isProtocolSupported

public boolean isProtocolSupported(InetAddress host,
                                   int port)

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

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

isProtocolSupported

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

Returns true if the host supports the classes protocol. If the protocl passed to the method is not supported by this instance the an exception is thrown to the caller.

Specified by:
isProtocolSupported in interface CapsdPlugin
Parameters:
host - The InetAddress which is to be checked for SMTP support
capName - The capability whose suport is to be checked for
Returns:
True if the host supports SMTP, false otherwise
Throws:
UnsupportedProtocolException - Thrown if capability specified is not supported by this instance.

isProtocolSupported

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

Returns true if the host supports SMTP on the specified port and the capability specified is 'isSMTP'

Parameters:
host - The InetAddress which is to be checked for SMTP support
port - The port number to be used for the SMTP support
capName - The capability whose suport is to be checked for
Returns:
True if the host supports SMTP, false otherwise
Throws:
UnsupportedProtocolException - Thrown if capability specified is not supported by the instance.

getCapabilityName

public String getCapabilityName()

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

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