JBoss.orgCommunity Documentation
The Resource Adaptor Type is the interface which defines the contract between the RA implementations, the SLEE container, and the Applications running in it.
The name of the RA Type is XMPPResourceAdaptorType
, its vendor is org.mobicents
and its version is 2.0
.
The single activity object for XMPP Resource Adaptor is the org.mobicents.slee.resource.xmpp.XmppConnection
interface. The activity represents a connection to an XMPP Server, of client or component type, where a sequence of incoming XMPP messages - the events - occur.
The XmppConnection activity starts when an SBB requests a new connection to be created, through the RA SBB Interface, and it ends when an SBB uses the same interface to request the closing of the connection. The activity also gives access to the underlying connection on the SMACK API, through the method named getConnection()
. With that object the SBB is able to completely interact with the resource.
For further information about the SMACK
API refer to its website at http://www.igniterealtime.org/projects/smack/.
The Events fired by XMPP Resource Adaptor represent an incoming message, received in a specific XmppConnection
activity. The table below lists the Resource Adaptor Type event types.
Table 2.1. Events fired on the XmppConnection Activity
Name | Vendor | Version | Event Class | Description |
---|---|---|---|---|
org.jivesoftware. smack.packet. Message | org.jivesoftware. smack | 1.0 | org.jivesoftware. smack.packet. Message | An incoming MESSAGE XMPP stanza. |
org.jivesoftware. smack.packet. Presence | org.jivesoftware. smack | 1.0 | org. jivesoftware. smack.packet. Presence | An incoming PRESENCE XMPP stanza. |
org.jivesoftware. smackx.packet. DiscoverInfo | org.jivesoftware. smack | 1.0 | org.jivesoftware. smackx.packet. DiscoverInfo | An incoming IQ XMPP stanza related to a discovery of information about an XMPP Entity. |
org.jivesoftware. smackx.packet. DiscoverItems | org.jivesoftware. smack | 1.0 | org.jivesoftware. smackx.packet. DiscoverItems | An incoming IQ XMPP stanza related to a discovery of the items associated with an XMPP Entity. |
org.jivesoftware. smack.packet. IQ | org.jivesoftware. smack | 1.0 | org.jivesoftware. smack.packet. IQ | An incoming and generic IQ XMPP stanza. |
org.jivesoftware. smackx.packet. IQBasedAvatar | org.jivesoftware. smack | 1.0 | org.jivesoftware. smackx.packet. IQBasedAvatar | An incoming IQ XMPP stanza related to the IQ-Based Avatars XMPP extension. |
org.jivesoftware. smack.packet. Registration | org.jivesoftware. smack | 1.0 | org.jivesoftware. smack.packet. Registration | An incoming IQ XMPP stanza, represents a registration packet. An empty GET query will cause the server to return information about it's registration support. SET queries can be used to create accounts or update existing account information. |
Spaces where introduced in Name
, Vendor
and Event Class
column values, to correctly render the table. Please remove them when using copy/paste.
More details for each event type may be obtained on the javadocs of each event type class.
The Resource Adaptor's Activity Context Interface Factory is of type org.mobicents.slee.resource.xmpp.XmppActivityContextInterfaceFactory
. It allows the SBB to retrieve the ActivityContextInterface
related with a specific XmppConnection
activity object. The interface is defined as follows:
package org.mobicents.slee.resource.xmpp;
import javax.slee.ActivityContextInterface;
import javax.slee.FactoryException;
import javax.slee.UnrecognizedActivityException;
public interface XmppActivityContextInterfaceFactory {
public ActivityContextInterface getActivityContextInterface(
XmppConnection connection) throws NullPointerException,
UnrecognizedActivityException, FactoryException;
}
The XMPP Resource Adaptor interface, of type org.mobicents.slee.resource.xmpp.XmppResourceAdaptorSbbInterface
, is used by an SBB to interact with XMPP resources. It is defined as follows:
package org.mobicents.slee.resource.xmpp;
import java.util.Collection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Packet;
public interface XmppResourceAdaptorSbbInterface {
public XmppConnection getXmppConnection(String connectionId);
public void sendPacket(String connectionID, Packet packet);
public XmppConnection connectClient(String connectionID, String serverHost,
int serverPort, String serviceName, String username,
String password, String resource, Collection packetFilters)
throws XMPPException;
public XmppConnection connectComponent(String connectionID,
String serverHost, int serverPort, String serviceName,
String componentName, String componentSecret,
Collection packetFilters) throws XMPPException;
public void disconnect(String connectionID);
}
getXmppConnection(String)
method:Retrieves the XMPP connection with the specified id.
sendPacket(String,Packet)
method:Sends the specified XMPP packet using the specified connection Id.
connectClient(String, String, int, String, String, String, String, Collection)
method:Creates and retrieves a new XMPP client connection to the XMPP server using the given service name on the given host and port and authenticates the client using the given username, password and resource. This connection will be identified with the specified connection Id. The XmppConnection
returned is a new Activity in SLEE.
connectComponent(String, String, int, String, String, String, Collection)
method:Creates and retrieves a new XMPP component connection to the XMPP server using the given service name on the given host and port and authenticates the component using the given component name and secret. The XmppConnection
returned is a new Activity in SLEE.
disconnect(String)
method:Disconnects the XMPP connection with the specified Id, terminating the activity and its related ActivityContextInterface
.
The XMPP does not imposes any kind of restriction on the usage of the SMACK
API java objects.
The following code examples shows how to use the Resource Adaptor Type for common functionalities
The following code examples the creation of a client XMPP connection and attachment to the related activity context. The xmppSbbInterface
object is the RA SBB Interface, while the object xmppActivityContextInterfaceFactory
is the RA Activity Context Interface Factory, both obtained through the SBB JNDI environment.
try {
XmppConnection connection = xmppSbbInterface.connectClient(
connectionID, serviceHost, servicePort, serviceName,
username, password, resource, Arrays
.asList(packetsToListen));
xmppActivityContextInterfaceFactory.getActivityContextInterface(
connection).attach(sbbContext.getSbbLocalObject());
} catch (XMPPException e) {
tracer.severe("Connection to server failed!",e);
}
The following code examples the sending of a XMPP message, through the RA SBB Interface:
String connectionID = getXmppConnectionID();
String targetXmppUser = getTargetXmppUser();
Message msg = new Message(targetXmppUser, Message.Type.CHAT);
msg.setBody("Hello");
xmppSbbInterface.sendPacket(connectionID, msg);