com.adventnet.adaptors.http
Class HttpConnector

java.lang.Object
  extended by com.adventnet.adaptors.AbstractAdaptor
      extended by com.adventnet.adaptors.http.HttpConnector
All Implemented Interfaces:
Adaptor, java.io.Serializable, java.lang.Runnable, javax.management.DynamicMBean, javax.management.MBeanRegistration, javax.management.NotificationBroadcaster

public class HttpConnector
extends AbstractAdaptor
implements javax.management.DynamicMBean, javax.management.MBeanRegistration, java.lang.Runnable

This class acts as a Connector for HTTP access to mbeans in Multi-Protocol.

It itself acts as a mbean for exposing the http properties. This class extends the AbstractAdaptor which provides the implementation of ServiceInfo interface and acts as the http-server.

The port number of the service can be specified in the ObjectName with key-value pair as, port=8050(by default)

For example, to start the web-server at 8200, you can specify the following object name:

  • DefaultDomain

    See Also:
    Serialized Form

    Nested Class Summary
     
    Nested classes/interfaces inherited from class com.adventnet.adaptors.AbstractAdaptor
    AbstractAdaptor.ProcessNotification
     
    Field Summary
    static HttpAuthTable httpAuth
               
    (package private) static java.lang.String parentDir
               
     
    Fields inherited from class com.adventnet.adaptors.AbstractAdaptor
    notifications, port, processnotification, state
     
    Constructor Summary
    HttpConnector()
              The NoArg constructor used to initialize the HttpAdaptor in forming the MBeanInfo and getting the reference of the MBeanServer using the MBeanServerFactory.findMBeanServer(null) method.
    HttpConnector(int portNum)
               
    HttpConnector(java.lang.Integer portNum)
               
    HttpConnector(java.lang.Integer portNum, javax.management.MBeanServer MBServer)
              This constructor used to initialize the HttpAdaptor in forming the MBeanInfo and getting the reference of the MBeanServer using the input parameter portNum and MBServer.
     
    Method Summary
     void addHttpServerInterface(HttpServerInterface httpServerInterface)
              Adds HttpServerInterface for controlling WebServer.
    static boolean authenticate(com.adventnet.agent.security.UserContext userContext)
              Deprecated
     void bind()
              Must be used to bind to a naming service or to bind to a ServerSocket
     void destroyAdaptor()
              Kills the adaptor and releases all its resources
     void enableAuthentication(boolean authFlag)
              enables the authentication feature of the adaptor.
     void enableAuthorisation(boolean authFlag)
              enables the authorisation feature of the adaptor.
     javax.management.ObjectName getAdaptorObjectName()
              Returns the ObjectName of this adaptor with which it has been registered with the MBeanServer.
     java.lang.String getAdaptorVersion()
              Gets the version of the adaptor.
     java.lang.Object getAttribute(java.lang.String attribute)
              Gets the value of a specific attribute of this MBean.
     javax.management.AttributeList getAttributes(java.lang.String[] attributes)
              Gets the value of a all attributes of this MBean.
     javax.management.MBeanInfo getMBeanInfo()
              This method discovers the attributes and operations this MBean exposes for management.
    static javax.management.MBeanServer getMBeanServer()
               
     java.lang.String getObjectName()
              Returns the ObjectName of this adaptor with which it has been registered with the MBeanServer.
    static java.lang.String getParentDirectory()
              Gets the parent directory for this adaptor
     java.lang.String getProtocol()
              Gets the protocol supported by this adaptor.
     void instantiateAdaptor()
              Must be implemented by the adaptor and should be used to instantiate itsefl
     java.lang.Object invoke(java.lang.String actionName, java.lang.Object[] params, java.lang.String[] signature)
              Invokes an action on this MBean.
    static boolean isAuthenticated()
              Deprecated
    static boolean isAuthorised()
              Deprecated
     void postDeregister()
              Allows this MBean to perform any operations needed after having been de-registered in the MBeanServer.
     void postRegister(java.lang.Boolean registrationDone)
              Allows this MBean to perform any operations needed after having been registered in the MBeanServer or after the registration has failed.
     void preDeregister()
              Allows this MBean to perform any operations it needs before being de-registered by the MBeanServer.
     javax.management.ObjectName preRegister(javax.management.MBeanServer server, javax.management.ObjectName name)
              This method is an implementation of MBeanRegistration interface.
     void processClientRequests()
               
     void registerAuthentication()
               
     void restartHttpServer()
              Restarts the WebServer.
     void run()
              Getter for MBean server.
     void setAttribute(javax.management.Attribute attribute)
              Sets the value of a specific attribute of this MBean.
     javax.management.AttributeList setAttributes(javax.management.AttributeList attributes)
              Sets the values of several attributes of this MBean.
    static void setParentDir(java.lang.String dirName)
               
     void startHttpServer()
              Invoke the HTTP server in a thread.
     void startService()
              Allows the web-server to get started.
     void stopHttpServer()
              Method to stop the http server.
     void stopService()
              Allows the web-server to get stopped.
     void unbind()
              Must be used to unbind from a naming service or to relese a ServerSocket
     
    Methods inherited from class com.adventnet.adaptors.AbstractAdaptor
    addNotificationListener, changeState, getHost, getNotificationInfo, getPort, getState, getStateInString, handleNotification, isActive, isSecure, processNotification, removeNotificationListener, setPort
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    httpAuth

    public static HttpAuthTable httpAuth

    parentDir

    static java.lang.String parentDir
    Constructor Detail

    HttpConnector

    public HttpConnector()
    The NoArg constructor used to initialize the HttpAdaptor in forming the MBeanInfo and getting the reference of the MBeanServer using the MBeanServerFactory.findMBeanServer(null) method.


    HttpConnector

    public HttpConnector(int portNum)

    HttpConnector

    public HttpConnector(java.lang.Integer portNum)

    HttpConnector

    public HttpConnector(java.lang.Integer portNum,
                         javax.management.MBeanServer MBServer)
    This constructor used to initialize the HttpAdaptor in forming the MBeanInfo and getting the reference of the MBeanServer using the input parameter portNum and MBServer.

    Method Detail

    authenticate

    public static boolean authenticate(com.adventnet.agent.security.UserContext userContext)
    Deprecated


    isAuthenticated

    public static boolean isAuthenticated()
    Deprecated


    isAuthorised

    public static boolean isAuthorised()
    Deprecated


    getMBeanInfo

    public javax.management.MBeanInfo getMBeanInfo()
    This method discovers the attributes and operations this MBean exposes for management.

    Specified by:
    getMBeanInfo in interface javax.management.DynamicMBean
    Returns:
    An instance of MBeanInfo allowing to retrieve all attributes and operations of this MBean.

    getAttribute

    public java.lang.Object getAttribute(java.lang.String attribute)
                                  throws javax.management.AttributeNotFoundException,
                                         javax.management.MBeanException,
                                         javax.management.ReflectionException
    Gets the value of a specific attribute of this MBean.

    Specified by:
    getAttribute in interface javax.management.DynamicMBean
    Parameters:
    attribute - A String specifying the name of the attribute to be retrieved.
    Returns:
    The value of the retrieved attribute.
    Throws:
    javax.management.AttributeNotFoundException
    javax.management.MBeanException
    javax.management.ReflectionException

    getAttributes

    public javax.management.AttributeList getAttributes(java.lang.String[] attributes)
    Gets the value of a all attributes of this MBean.

    Specified by:
    getAttributes in interface javax.management.DynamicMBean
    Parameters:
    attributes - A list of attributes to be retrieved.
    Returns:
    The value of the retrieved attributes as attributeList.

    invoke

    public java.lang.Object invoke(java.lang.String actionName,
                                   java.lang.Object[] params,
                                   java.lang.String[] signature)
                            throws javax.management.MBeanException,
                                   javax.management.ReflectionException
    Invokes an action on this MBean.

    Specified by:
    invoke in interface javax.management.DynamicMBean
    Parameters:
    actionName - The name of the action to be invoked.
    params - An array containing the parameters to be set when the action is invoked
    signature - An array containing the signature of the action. The class objects will be loaded using the same class loader as the one used for loading the MBean on which the action was invoked.
    Returns:
    The object returned by the action, which represents the result ofinvoking the action on the specified MBean.
    Throws:
    javax.management.MBeanException
    javax.management.ReflectionException

    setAttribute

    public void setAttribute(javax.management.Attribute attribute)
                      throws javax.management.AttributeNotFoundException,
                             javax.management.InvalidAttributeValueException,
                             javax.management.MBeanException,
                             javax.management.ReflectionException
    Sets the value of a specific attribute of this MBean.

    Specified by:
    setAttribute in interface javax.management.DynamicMBean
    Parameters:
    attribute - The identification of the attribute to be set and the value it is to be set to.
    Throws:
    javax.management.AttributeNotFoundException
    javax.management.InvalidAttributeValueException
    javax.management.MBeanException
    javax.management.ReflectionException

    setAttributes

    public javax.management.AttributeList setAttributes(javax.management.AttributeList attributes)
    Sets the values of several attributes of this MBean.

    Specified by:
    setAttributes in interface javax.management.DynamicMBean
    Parameters:
    attributes - A list of attributes: The identification of the attributes to be set and the values they are to be set to.
    Returns:
    The list of attributes that were set, with their new values.

    preRegister

    public javax.management.ObjectName preRegister(javax.management.MBeanServer server,
                                                   javax.management.ObjectName name)
                                            throws java.lang.Exception
    This method is an implementation of MBeanRegistration interface. Allows this MBean to perform any operations it needs before being registered in the MBeanServer. If the name of the MBean is not specified, the MBean can provide a name for its registration. If any exception is raised, the MBean will not be registered with the MBeanServer.

    This method is called by the MBeanServer before this mbean getting registered with the server. If the passed objectName is invalid, the returned objectName is taken as valid name to get registered with the server.

    The service gets actually started only inside this method at the specified port mentioned in the key "port". If the key "port" is absent, then the service(http - server) gets started at the default port 8050.

    Specified by:
    preRegister in interface javax.management.MBeanRegistration
    Overrides:
    preRegister in class AbstractAdaptor
    Parameters:
    server - The MBeanServer in which the MBean will be registered.
    name - The object name of the MBean.
    Returns:
    The name of the MBean registered.
    Throws:
    java.lang.Exception - This exception should be caught by the MBeanServer and re-thrown as an MBeanRegistrationException.

    postRegister

    public void postRegister(java.lang.Boolean registrationDone)
    Allows this MBean to perform any operations needed after having been registered in the MBeanServer or after the registration has failed.

    Specified by:
    postRegister in interface javax.management.MBeanRegistration
    Overrides:
    postRegister in class AbstractAdaptor
    Parameters:
    registrationDone - Indicates whether or not the MBean has been successfully registered in the MBeanServer. The value false means that either the registration phase has failed.

    preDeregister

    public void preDeregister()
                       throws java.lang.Exception
    Allows this MBean to perform any operations it needs before being de-registered by the MBeanServer.

    Specified by:
    preDeregister in interface javax.management.MBeanRegistration
    Overrides:
    preDeregister in class AbstractAdaptor
    Throws:
    java.langException - This exception should be caught by the MBeanServer and re-thrown as an MBeanRegistrationException.
    java.lang.Exception

    postDeregister

    public void postDeregister()
    Allows this MBean to perform any operations needed after having been de-registered in the MBeanServer.

    Specified by:
    postDeregister in interface javax.management.MBeanRegistration
    Overrides:
    postDeregister in class AbstractAdaptor

    startService

    public void startService()
                      throws java.lang.IllegalStateException,
                             java.lang.Exception
    Allows the web-server to get started.

    Specified by:
    startService in interface Adaptor
    Overrides:
    startService in class AbstractAdaptor
    Throws:
    java.lang.IllegalStateException - when the adaptor is in STARTED or STARTING state
    java.lang.Exception

    stopService

    public void stopService()
                     throws java.lang.IllegalStateException
    Allows the web-server to get stopped.

    Specified by:
    stopService in interface Adaptor
    Overrides:
    stopService in class AbstractAdaptor
    Throws:
    java.lang.IllegalStateException - when the adaptor is in STOPPED or STOPPING state

    enableAuthentication

    public void enableAuthentication(boolean authFlag)
    enables the authentication feature of the adaptor.

    Specified by:
    enableAuthentication in interface Adaptor
    Specified by:
    enableAuthentication in class AbstractAdaptor

    enableAuthorisation

    public void enableAuthorisation(boolean authFlag)
    enables the authorisation feature of the adaptor.

    Specified by:
    enableAuthorisation in interface Adaptor
    Specified by:
    enableAuthorisation in class AbstractAdaptor

    processClientRequests

    public void processClientRequests()

    instantiateAdaptor

    public void instantiateAdaptor()
                            throws java.lang.InstantiationException
    Description copied from class: AbstractAdaptor
    Must be implemented by the adaptor and should be used to instantiate itsefl

    Specified by:
    instantiateAdaptor in class AbstractAdaptor
    Throws:
    java.lang.InstantiationException

    bind

    public void bind()
    Description copied from class: AbstractAdaptor
    Must be used to bind to a naming service or to bind to a ServerSocket

    Specified by:
    bind in class AbstractAdaptor

    unbind

    public void unbind()
    Description copied from class: AbstractAdaptor
    Must be used to unbind from a naming service or to relese a ServerSocket

    Specified by:
    unbind in class AbstractAdaptor

    registerAuthentication

    public void registerAuthentication()

    destroyAdaptor

    public void destroyAdaptor()
    Description copied from class: AbstractAdaptor
    Kills the adaptor and releases all its resources

    Specified by:
    destroyAdaptor in class AbstractAdaptor

    getAdaptorObjectName

    public javax.management.ObjectName getAdaptorObjectName()
    Returns the ObjectName of this adaptor with which it has been registered with the MBeanServer.

    Specified by:
    getAdaptorObjectName in interface Adaptor
    Specified by:
    getAdaptorObjectName in class AbstractAdaptor
    Returns:
    the ObjectName

    getObjectName

    public java.lang.String getObjectName()
    Returns the ObjectName of this adaptor with which it has been registered with the MBeanServer.

    Returns:
    the ObjectName

    run

    public void run()
    Getter for MBean server.

    Specified by:
    run in interface java.lang.Runnable

    startHttpServer

    public void startHttpServer()
                         throws java.lang.Exception
    Invoke the HTTP server in a thread.

    Throws:
    java.lang.Exception

    stopHttpServer

    public void stopHttpServer()
    Method to stop the http server.


    restartHttpServer

    public void restartHttpServer()
    Restarts the WebServer.

    Since:
    AdventNet Agent Toolkit (Java Edition) 4.2 release.

    getAdaptorVersion

    public java.lang.String getAdaptorVersion()
    Gets the version of the adaptor.

    Specified by:
    getAdaptorVersion in interface Adaptor
    Overrides:
    getAdaptorVersion in class AbstractAdaptor

    getProtocol

    public java.lang.String getProtocol()
    Gets the protocol supported by this adaptor.

    Specified by:
    getProtocol in interface Adaptor
    Specified by:
    getProtocol in class AbstractAdaptor

    addHttpServerInterface

    public void addHttpServerInterface(HttpServerInterface httpServerInterface)
    Adds HttpServerInterface for controlling WebServer. Users can add their implementation of HttpServerInterface to plug-in other webserver.

    Parameters:
    httpServerInterface - The HttpServerInterface of the user.
    Since:
    AdventNet Agent Toolkit (Java Edition) 4.2 release.

    setParentDir

    public static void setParentDir(java.lang.String dirName)

    getParentDirectory

    public static java.lang.String getParentDirectory()
    Gets the parent directory for this adaptor

    Returns:
    The parent directory

    getMBeanServer

    public static javax.management.MBeanServer getMBeanServer()