WARNING: This server provides a static reference view of the NetKernel documentation. Links to dynamic content do not work. For the best experience we recommend you install NetKernel and view the documentation in the live system .

JabberEndpoint

Endpoint
Name:JabberEndpoint
Description:Jabber XMPP symmetric peer transport/accessor
Id:JabberEndpoint
Category:accessor prototype

JabberEndpoint is an accessor that must be instantiated from a prototype. You must instantiate the prototype in your module to create an accessor that can receive requests.

Parameters

The JabberEndpoint prototype has the following initialisation parameters:

NameRulesTypingDefaultDescription
configMandatoryIdentifier or XML(none)
XML configuration resource
idOptionalStringnull
An identifier for created logical endpoint, if omitted a unique auto-generated value it will be used.
privateOptionalBooleanfalse
If included this parameter will mark the endpoint as private and it will not be exposed outside module.

Here is an auto-generated example of how to instantiate an instance of JabberEndpoint:

<accessor>
  <prototype>JabberEndpoint</prototype>
  <config>XML configuration resource</config>
</accessor>
Import Requirements

To use JabberEndpoint accessor prototype you must import the module urn:org:netkernel:mod:jabber:

<import>
  <uri>urn:org:netkernel:mod:jabber</uri>
</import>

JabberEndpoint is a symmetric XMPP peer. It implements both a NetKernel transport to receive messages and and accessor to send messages. When configured it will listen for messages from a XMPP server and can also initiate conversations by sending messages. As a peer-to-peer endpoint, receiving and sending messages may occur completely independently.

Configuration

The JabberEndpoint must be provided with a config parameter. This has the form...

<config>
  <server>XMPP-Server-Name</server>
  <user>User-Account-Name</user>
  <password>User-Account-Password</password>
  <port>5222</port>
  <tls>true</tls>
  < !-- enable both server and client -->
  <enabled>true</enabled>
</config>

  • tls encrypted connection mode is optional.
  • port is optional and will default to 5222
  • enabled is optional and will default to true

Receiving Messages

When the endpoint is commissioned it will listen for messages for the configured user@server identity. When a message is received the endpoint issues a SOURCE request into the host address space. The request has the following form...

Resource Identifier Syntax

jabber:message
+ to @ [ configured user identity ]
+ from @ [ sender's identity ]
+ message @ [ the received message ]

The message argument is of type org.jivesoftware.smack.packet.Message

A handler of the jabber:message request may source the message argument and call getBody() to receive the message body as a String.

Replying to a received message

When the JabberEndpoint issues a jabber:message request into the host address space it also dynamically constructs a transient space which implements the resource jabber:reply. The transient space is inserted into the request scope superstack and is accessible in the context of the message request.

A message handler can reply directly to the sender of the message by SINK ing either a java.lang.String or org.jivesoftware.smack.packet.Message to jabber:reply

For example:

context.sink("jabber:reply", "Message received - thanks very much");

Sending Messages

The JabberEndpoint implements the active:jabberSend accessor with syntax...

Resource Identifier Syntax

active:jabberSend
+ to @ [ recipients identity ]
+ message @ [ the message to send ]

Message may be either java.lang.String or org.jivesoftware.smack.packet.Message

Note: the JabberEndpoint must be instantiated and connected to the XMPP server for it to be able to send messages.

Examples

Sending

The following code fragment shows how to send a message...

//Send a message with active:jabberSend
req=context.createRequest("active:jabberSend");
req.addArgument("to", "someone@jabber.org");
req.addArgumentByValue("message", "Hello XMPP World");
context.issueRequest(req);

Receiving

The following mapper endpoint declaration shows how you might use the mapper to route received messages to a handler script...

<mapper>
  <config>
    <endpoint>
      <grammar>
        <active>
          <identifier>jabber:message</identifier>
          <argument name="to" />
          <argument name="from" />
          <argument name="message" />
        </active>
      </grammar>
      <request>
        <identifier>active:groovy</identifier>
        <argument name="operator">res:/myJabberMessageHandler.gy</argument>
        <argument name="to">arg:to</argument>
        <argument name="from">arg:from</argument>
        <argument name="message">arg:message</argument>
      </request>
    </endpoint>
  </config>
  <space>....space containing script and groovy runtime import....</space>
</mapper>