25 Using the Web Presence API

This chapter describes how to use and configure the Oracle Communications Instant Messaging Server Web Presence API.

About the Instant Messaging Server Web Presence API

Users of instant messaging are typically able to see a contact list showing whether individual contacts are available. Instant messaging users who are not contacts typically do not receive such presence information. Instant Messaging Server provides a Web Presence API that allows a Web application to obtain presence information from Instant Messaging Server and display it to users, independent of whether they are contacts. An example of where this is useful is an enterprise application that provides an employee listing with information such as employee name, department, title, location, and phone number. If the application provides availability information, it may help a user who looks up an employee to decide whether to make a phone call, send an email, or look for someone else to contact.

For a Web application to obtain presence information from Instant Messaging Server, it needs to use the new Web Presence API and the Web Presence API must be configured to allow use by the Web application. In addition, any Instant Messaging server that the Web Presence API communicates with must be configured to recognize the Web Presence API (see "Configuring an Instant Messaging Server to Recognize the Web Presence API").

Web Presence API for Requesting Presence Information

When a user's instant messaging application starts and contacts Instant Messaging Server, it sends presence information about the user. A web application can then obtain this information from Instant Messaging Server by making an HTTP GET or HTTP POST request that uses the Web Presence API. The request can be for the availability of a single user or of multiple users.

web.xml File for the Web Presence API

A template deployment descriptor (web.xml) file for the Web Presence API is provided at the following location:

InstantMessaging_home/lib/presenceapi-web.xml.template

You can edit the file to add any custom servlets you have developed for handing requests to the Web Presence API.

HTTP GET Requests for Presence Information

GET requests for presence information have different formats when they are sent to an individual user or to multiple users. In both cases, by default, the response to a request for presence information is returned in a JSON object (see "JSON Response to Requests for Presence Information").

GET Requests for Presence Information on an Individual User

To send a GET request for presence information on an individual user, send the request to /presence/jid_or_email_address as in the following example:

GET /presence/node@domain.com/resource

By default, the request returns a JSON object containing the presence information (see "JSON Response to Requests for Presence Information").

GET Requests for Presence Information on Multiple Users

To send a GET request for presence information on more than one user, send a request in the following format:

GET /presence?request={JSON object}

where the JSON object has the following format:

[{"presence":{"type":"probe","to":"node@domain/resource"}},{"presence":{"type":"probe","to":"node1@domain1/resource2"}},{"presence":{"type":"probe","to":"node2@domain/resource3"}}]

In the request (see RFC 3921, XMPP: Instant Messaging and Presence):

  • type is a parameter for the type of presence request.

  • to is a parameter for the user's JID or email address.

  • node@domain/resource is the user's JID or email address.

For more information, see RFC 3921, XMPP: Instant Messaging and Presence at:

http://www.ietf.org/rfc/rfc3921.txt

By default, the request returns a JSON object containing the presence information (see "JSON Response to Requests for Presence Information").

HTTP POST Requests for Presence Information

A POST request for presence information has the following format:

POST /presence
request:JSON object

where the JSON object contains one or more presence requests, as in the following example:

POST /presence
request:[{"presence":{"type":"probe","to":"node@domain/resource"}},{"presence":{"type":"probe","to":"node1@domain1/resource2"}},{"presence":{"type":"probe","to":"node2@domain/resource3"}}]

In the example:

  • type is a parameter for the type of presence request.

  • probe is a request for a contact's current presence information.

  • to is a parameter for the user's JID or email address.

  • node@domain/resource is the user's JID or email address.

For more information, see RFC 3921, XMPP: Instant Messaging and Presence:

http://www.ietf.org/rfc/rfc3921.txt

By default, the request returns a JSON object containing the presence information (see "JSON Response to Requests for Presence Information").

JSON Response to Requests for Presence Information

By default, requests for presence information return an HTTP response whose payload is a JSON object that contains the parameters of an XMPP presence stanza. The following example shows a JSON object with presence information on three users:

{"response":[{"presence":{"show":"dnd","from":"node@domain/resource "}},{"presence":{"show":"away","status":"temporarily unavailable ","from":"node1@domain/resource"}},{"presence":{"from":"node2@domain/resource"}}]}

where:

  • show is a parameter for showing a user's availability.

  • dnd (Do Not Disturb) means the user is busy.

  • from is a parameter for the JID or email address of the user sending the presence information.

  • node@domain/resource is the JID or email address of the user.

  • status is a parameter for a description of the user's availability status.

  • temporarily unavailable is the user's availability status.

Configuring the Instant Messaging Server Web Presence API

For a Web application to obtain and display presence information, you must configure properties in the Web Presence API's configuration file. A template for the configuration file is installed in: InstantMessaging_home/lib. There is no required name or location for the configuration file.

Table 25-1 lists Web Presence API configuration properties.

Table 25-1 Web Presence API Configuration Properties

Property Default Value Description

presenceapi.idtype

jid

Specifies whether HTTP requests for presence information contain a JID (idtype is jid) or an email address (idtype is email).

presenceapi.wait_time

10

The maximum length of time, in seconds, that the presence component waits to receive a response from an Instant Messaging server that contains presence information for an individual user. If no response is received within the time limit, the presence component returns a presence type of none as the user's availability.

presenceapi.log4j.config

None

The location of the configuration file that Instant Messaging Server uses for Apache-log4j logging.

See "Managing Logging for Instant Messaging Server" for information on Instant Messaging Server logging.

For information on Apache-log4j logging, see the Apache website at:

http://logging.apache.org

At installation, a presenceapi_log4j.conf.template template file to use as the basis for a log4j configuration file is installed in InstantMessaging_home/config. Use the template file to create a log4j configuration file. There is no required name or location for the configuration file.

presenceapi.config

None

A space-separated list of identifiers for the Instant-Messaging-Server deployments that the presence component can communicate with. Each identifier will be used as a prefix to presence-API configuration properties for the deployment. For example, given the identifier list ImDeploy1 ImDeploy2, there will be separate sets of ImDeploy1.property properties and ImDeploy2.property properties. Each deployment in the list of identifiers must be separately configured to recognize communications from the Web Presence API (see "Configuring an Instant Messaging Server to Recognize the Web Presence API").

identifier.presencepolicy

open

Specifies the way to interpret the list of JID or email domains in the identifier.domains property, one of the following:

  • open (the default value): The Server supports presence requests for users in all domains except those listed in identifier.domains.

  • closed: The Server supports presence requests for users only in the domains listed in identifier.domains.

identifier.domains

None

A space separated list of JID or email domains:

  • If the presenceapi.idtype property is set to jid, list JID domains; if presenceapi.idtype is set to email, list email domains.

  • If the identifier.presencepolicy property is set to open, a list of domains that are not supported and for which presence information will not be retrieved.

  • If the identifier.presencepolicy property is set to closed, a list of domains that are supported and for which presence information is retrieved.

identifier.hosts

None

A space-separated list of Instant Messaging servers and their ports (hostname:port) that make up the deployment identified by identifier.

identifier.componentjid

None

The JID that the Web Presence API uses in establishing a connection with the Instant Messaging server specified by identifier. When you configure Instant Messaging Server, you must enter this JID to identify the Web Presence API to the Server (see "Configuring an Instant Messaging Server to Recognize the Web Presence API"). It is recommended that the same JID be used with each Instant Messaging server the Web Presence API communicates with.

identifier.password

None

The password that the presence component uses in establishing a connection with Instant Messaging Server specified by identifier. When you configure Instant Messaging Server, you will need to enter this JID to identify the Web Presence API to the Server (see "Configuring an Instant Messaging Server to Recognize the Web Presence API"). It is recommended that the same password be used with each Instant Messaging server. To generate an encrypted password, use the Instant Messaging Server "passwordtool Command Reference".

presenceapi.component. password.cipher.delegate

None

If you want to use an encrypted password, this property is required with a value of com.sun.im.tools.passwordtool.Crypto.

presenceapi.component. password.cipher

None

If you want to use an encrypted password, this property is required with a value of com.sun.im.tools.passwordtool.CommsClientCipher.

presenceapi.cache_size

10000

The size in MB of the logging cache. If cache_size is set to -1, the size of the logging cache is unlimited.

presenceapi.log_timeout

30

The time interval in minutes for statistics logging. To enable, uncomment the line.


Configuring an Instant Messaging Server to Recognize the Web Presence API

The Web Presence API is an XMPP component that communicates with Instant Messaging Server. The Web Presence API must be configured to communicate with the Instant Messaging Server, and Instant Messaging Server must be configured to receive communications from an XMPP component. This requires using the imconfutil command to add the Web Presence API as a component of the Instant Messaging Server, as in the following example:

imconfutil -c InstantMessaging_home/config/iim.conf.xml add-component id=presenceapi jid=presenceapi.example.com password=drowp broadcastpresence=true

where:

  • jid must be set to the same value as the Web Presence API's ImServer1.componentjid property.

  • password must be set to the same value as the Web Presence API's ImServer1.password property.

  • broadcast must be set to true to allow Instant Messaging Server to send presence information to the Web Presence API.

After adding the Web Presence API as a component to Instant Messaging Server, restart the server:

imadmin refresh server

Configuring and Testing the Web Presence API

This section provides steps for configuring and trying out the Web Presence API before you have done more extensive application development. The steps cover:

  • Configuring and deploying the Web Presence API on a local machine.

  • Configuring Instant Messaging Server for the Web Presence API and restarting the Server.

  • Logging a user in to Instant Messaging Server through an XMPP client.

  • Sending a GET request for the user's presence to Instant Messaging Server and viewing the response.

To configure and test the functionality of the Web Presence API:

  1. Use the iwadmin command to create a ZIP file for the Web Presence API that you can move to another machine or keep locally:

    iwadmin generatezip presenceapi -c /local/presenceAPI/config/presenceapi.conf -d /tmp/presenceapi.zip
    

    where:

    • The -c parameter specifies the future location of the configuration file for the Web Presence API, once the ZIP file is unzipped.

    • The -d parameter specifies a destination directory and file name for the ZIP file. The directory must exist before you generate the ZIP file.

    • The ZIP file contains:

      • A deployable WAR file for the Web Presence API

      • A template file (presenceapi.conf.template) to use for creating a Web Presence API configuration file.

      • A template file, presenceapi_log4j.conf.template, for configuring a log4j log file.

      • The Instant Messaging Server password tool. See "passwordtool Command Reference" for more information.

  2. Extract the contents of the ZIP file to the directory that you want to use as your Web Presence API configuration directory, for example, /local/presenceAPI.

    unzip /tmp/presenceapi.zip -d /local/presenceAPI
    
  3. To create a configuration file for the Web Presence API, copy the configuration file template, presenceapi.conf.template, to presenceapi.conf.

  4. In presenceapi.conf, edit the following lines according to the instructions below them.

    presenceapi.config=default
    
    default.presencepolicy=open
    
    default.domains=DOMAINS_LIST
    
    default.hosts=HOSTS_LIST
    
    default.componentjid=COMPONENT_JID
    
    default.password=ENCRYPTED_COMPONENT_PASSWORD
    
    presenceapi.log4j.config=LOG4J_CONFIG_FILE
    
    # Comment out the following options if you are not using an encrypted password.
    
    presenceapi.component.password.cipher.delegate=DELEGATE_CLASS
    
    presenceapi.component.password.cipher=CIPHER_CLASS
    

    For information about the configuration properties above, see Table 25-1.

    1. Leave the first two entries, presenceapi.config=default and default.presencepolicy=open as they are.

      The first property identifies a deployment of Instant Messaging servers as default.

      The second property sets the deployment to provide presence information for contacts in all domains, except for domains that are listed with the default.domains property.

    2. Delete default.domains=DOMAINS_LIST. There is no need to restrict the domains open to presence requests in this example.

    3. Set default.hosts to a space-separated list of the Instant Messaging servers and their ports (hostname:port) that make up the default deployment. For example:

      default.hosts=ImServer1.example.com:5269 ImServer2.example.com:5269
      
    4. Set default.componentjid to the JID of the Web Presence API in its Web server. The same JID must be entered when you use the command to configure Instant Messaging Server at a later step. Example:

      default.componentjid=presenceapi.example.com
      
    5. Set default.password to the password you want to use in connecting to Instant Messaging Server. The same password must be entered when you use the command to configure Instant Messaging Server at a later step. Example:

      default.password=asdfjkl;
      
    6. Set presenceapi.log4j.config to the absolute path of the log4j configuration file. For example:

      set presenceapi.log4j.config=/local/presenceAPI/config/presenceapi_log4j.conf
      
  5. Deploy the Web Presence API WAR file.

    • GlassFish Server: Use the asadmin command to deploy the Web Presence API WAR file (you will need Administrator privileges), for example:

      asadmin deploy /local/presenceAPI/presenceapi.war
      
    • Oracle WebLogic Server: use WebLogic console to deploy the Web Presence API WAR file.

  6. Use the imconfutil command to add the Web Presence API as an XMPP Web component to the Instant Messaging server identified as ImServer1:

    imconfutil -c InstantMessaging_home/config/iim.conf.xml add-component id=presenceapi jid=presenceapi.example.com password=asdfjkl; broadcastpresence=true
    

    where:

    • jid must be set to the same value as the Web Presence API's ImServer1.componentjid property.

    • password must be set to the same value as the Web Presence API's ImServer1.password property.

    • broadcast must be set to true to allow Instant Messaging Server to send presence information to the Web Presence API.

  7. Restart Instant Messaging Server using the imadmin command. This is necessary because of the configuration changes you made to the Server.

    imadmin refresh server
    
  8. In preparation for the next step, sending a request for presence information, get the JID of a user that is logged-in to Instant Messaging Server through an XMPP client. If you have an instant messaging account on an XMPP client that uses the Instant Messaging Server, and your XMPP client is running, you can use your own JID.

  9. Send a GET or POST request for presence information to the Web Presence API, using the JID from the previous step.

    • You can send a GET request manually by entering it directly in the address bar of a browser and pressing Return. The following is an example of such a request. Note the / that follows the JID. Without it, the JID is interpreted as a file name and the request fails.

      http://imhost@pythia.com:8080/presenceapi/presence/wxyz@example.com/
      

      If the request is successful, a JSON object with presence information is displayed in the browser, as in the following example:

      {"response":[{"presence":{"from":"wxyz@example.com/1379305740520"}}]}
      
    • You can send the request from a JavaScript, in which case the response is returned to the script as a JSON object.

  10. Verify that the response received is what was expected.