Interface WebContext


public interface WebContext
Allows a Rest or WebSocket Service to communicate with NetSwitch.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Name used with ServletContext#getAttribute(String) to retrieve an instance of WebContext.
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    executeSQL(String poolName, SQLExecutor<T> executor)
    Allocates a connection from the specified pool and then executes the supplied SQL executor.
    Returns an unmodifiable map with all the properties of this WebContext.
    getProperty(String name, String defval)
    Returns the value of the property indexed by specified name.
    void
    sendMail(String sessionName, String subject, String text)
    Sends a mail message using the specified SMTP mail session.
    void
    Sends an multicast message built using the supplied name and data.
    sendRequest(String destination, Serializable data, int timeout)
    Sends a request message to a destination and then blocks waiting for the reply message for at most timeout milliseconds.
  • Field Details

  • Method Details

    • getProperties

      Map<String,String> getProperties()
      Returns an unmodifiable map with all the properties of this WebContext.
      Returns:
      an unmodifiable map with all the properties of this WebContext.
    • getProperty

      String getProperty(String name, String defval)
      Returns the value of the property indexed by specified name. If the property is not defined, it returns the supplied default value.
      Parameters:
      name - the name of the required property.
      defval - value returned if property is not defined (can be null).
      Returns:
      the value of the property or default value defval.
      Throws:
      NullPointerException - if name is null.
    • sendMail

      void sendMail(String sessionName, String subject, String text) throws Exception
      Sends a mail message using the specified SMTP mail session.
      Parameters:
      sessionName - the name of the mail session.
      subject - the subject of the mail message.
      text - the text of the mail message.
      Throws:
      NullPointerException - if an argument is null.
      Exception - if another error occurs.
    • sendMulticast

      void sendMulticast(String name, Serializable data) throws Exception
      Sends an multicast message built using the supplied name and data. The message will be dispatched to all client and/or server applications that have enabled the reception of multicast messages with the specified name.
      Parameters:
      name - the name of the multicast message.
      data - data to include in the multicast message (can be null).
      Throws:
      NullPointerException - if name is null.
      Exception - if another error occurs.
    • sendRequest

      Message sendRequest(String destination, Serializable data, int timeout) throws Exception
      Sends a request message to a destination and then blocks waiting for the reply message for at most timeout milliseconds. The value of destination must have the following format:
      [SwitchName:]ServerName[.ServiceName]
      where optional items are shown within "[" and "]" brackets, and the characters ":" and "." stand for themselves. If the optional SwitchName is not specified, the message is sent to the connected switch. ServerName is the name of a server, a listener or a connector. The optional ServiceName is the name of a service provided by the server, or the name of a channel of a listener. The following are examples of valid destinations:
       POS_DEVICE
       NETSWITCH.LOG_ERROR
       HUB:IMSER.ADD_CONTACT
      Argument timeout specifies the amount of time to wait for the synchronous reply message. If timeout is zero (0), the call waits forever for the reply message.
      Parameters:
      destination - the request destination switch:server.service.
      data - the data to include in the request message (can be null).
      timeout - the maximum time to wait for a reply (in milliseconds).
      Returns:
      the reply message returned from the switch server.
      Throws:
      NullPointerException - if destination is null.
      IllegalArgumentException - if timeout is negative.
      IllegalStateException - if already waiting for a reply message.
      SocketTimeoutException - if timeout expired while waiting for reply.
      Exception - if another error occurs.
    • executeSQL

      <T> T executeSQL(String poolName, SQLExecutor<T> executor) throws SQLException, Exception
      Allocates a connection from the specified pool and then executes the supplied SQL executor. If the SQL executor returns normally, the connection is committed. If the SQL executor throws an exception, the connection is rollback. In any event, the connection is returned to the pool.
      Type Parameters:
      T - the type of the value returned by the executor.
      Parameters:
      poolName - the name of the connection pool.
      executor - an SQL statement executor.
      Returns:
      the value returned by the executor.
      Throws:
      NullPointerException - if an argument is null.
      SQLException - if an SQL error occurs.
      Exception - if another error occurs.