JBoss.orgCommunity Documentation

JBoss Communications JAIN SLEE SIP Wake Up Example User Guide


This manual uses several conventions to highlight certain words and phrases and draw attention to specific pieces of information.

In PDF and paper editions, this manual uses typefaces drawn from the Liberation Fonts set. The Liberation Fonts set is also used in HTML editions if the set is installed on your system. If not, alternative but equivalent typefaces are displayed. Note: Red Hat Enterprise Linux 5 and later includes the Liberation Fonts set by default.

Four typographic conventions are used to call attention to specific words and phrases. These conventions, and the circumstances they apply to, are as follows.

Mono-spaced Bold

Used to highlight system input, including shell commands, file names and paths. Also used to highlight key caps and key-combinations. For example:

The above includes a file name, a shell command and a key cap, all presented in Mono-spaced Bold and all distinguishable thanks to context.

Key-combinations can be distinguished from key caps by the hyphen connecting each part of a key-combination. For example:

The first sentence highlights the particular key cap to press. The second highlights two sets of three key caps, each set pressed simultaneously.

If source code is discussed, class names, methods, functions, variable names and returned values mentioned within a paragraph will be presented as above, in Mono-spaced Bold. For example:

Proportional Bold

This denotes words or phrases encountered on a system, including application names; dialogue box text; labelled buttons; check-box and radio button labels; menu titles and sub-menu titles. For example:

The above text includes application names; system-wide menu names and items; application-specific menu names; and buttons and text found within a GUI interface, all presented in Proportional Bold and all distinguishable by context.

Note the > shorthand used to indicate traversal through a menu and its sub-menus. This is to avoid the difficult-to-follow 'Select Mouse from the Preferences sub-menu in the System menu of the main menu bar' approach.

Mono-spaced Bold Italic or Proportional Bold Italic

Whether Mono-spaced Bold or Proportional Bold, the addition of Italics indicates replaceable or variable text. Italics denotes text you do not input literally or displayed text that changes depending on circumstance. For example:

Note the words in bold italics above username, domain.name, file-system, package, version and release. Each word is a placeholder, either for text you enter when issuing a command or for text displayed by the system.

Aside from standard usage for presenting the title of a work, italics denotes the first use of a new and important term. For example:

If you find a typographical error in this manual, or if you have thought of a way to make this manual better, we would love to hear from you! Please submit a report in the the Issue Tracker, against the product JBoss Communications JAIN SLEE SIP Wake Up Example, or contact the authors.

When submitting a bug report, be sure to mention the manual's identifier: JAIN_SLEE_SipWakeUp_EXAMPLE_User_Guide

If you have a suggestion for improving the documentation, try to be as specific as possible when describing it. If you have found an error, please include the section number and some of the surrounding text so we can find it easily.

This section provides instructions on how to obtain and build the SIP Wake Up Example from source code.

  1. Downloading the source code

    Use SVN to checkout a specific release source, the base URL is ?, then add the specific release version, lets consider 2.4.0.CR1.

    [usr]$ svn co ?/2.4.0.CR1 slee-example-sip-wake-up-2.4.0.CR1
  2. Building the source code

    Important

    Maven 2.0.9 (or higher) is used to build the release. Instructions for using Maven2, including install, can be found at http://maven.apache.org

    Use Maven to build the deployable unit binary.

    				    [usr]$ cd slee-example-sip-wake-up-2.4.0.CR1
    				    [usr]$ mvn install
    				    

    Once the process finishes you should have the deployable-unit jar file in the target directory, if JBoss Communications JAIN SLEE is installed and environment variable JBOSS_HOME is pointing to its underlying JBoss Enterprise Application Platform directory, then the deployable unit jar will also be deployed in the container.

    Important

    This procedure does not install the Example's dependencies

The example application is defined by a service descriptor, which refers the included root SBB. The root SBB uses the Location Service SBB (from SIP Services Example) as a child, to retrieve the SIP entities registered.

Important

To obtain the example's complete source code please refer to Section 2.2, “JBoss Communications JAIN SLEE SIP Wake Up Example Source Code”.

The SIP Wake Up Example's Root SBB is composed by the abstract class and the XML descriptor.

The class org.mobicents.slee.examples.wakeup.WakeupSbb includes all the service logic for the example.

The javax.slee.SbbObject's setSbbContext(SbbContext) is used by SBBs to store the SBB's context into a class field. The SBB should take the opportunity to also store objects, such as SLEE facilities, which are reused by all service logic entities, a.k.a. SbbEntities, and are stored in the JNDI environment.

The class fields and setSbbContext(SbbContext) method's and related code:



    // the Sbb's context
    private SbbContext sbbContext; 
    
    // the Sbb's single tracer
    private Tracer tracer = null; 
        
    // cached objects in Sbb's environment, lookups are expensive
    private SleeSipProvider sipProvider;
    private TimerFacility timerFacility;
    private NullActivityContextInterfaceFactory nullACIFactory;
    private NullActivityFactory nullActivityFactory;
    
    /*
     * (non-Javadoc)
     * 
     * @see javax.slee.Sbb#setSbbContext(javax.slee.SbbContext)
     */
    public void setSbbContext(SbbContext context) {
        // save the sbb context in a field
        this.sbbContext = context;
        // get the tracer if needed
        this.tracer = context.getTracer(WakeUpSbb.class.getSimpleName());
        // get jndi environment stuff
        try {
            final Context myEnv = (Context) new InitialContext();
            // slee facilities
            this.timerFacility = (TimerFacility) myEnv
                    .lookup(TimerFacility.JNDI_NAME);
            this.nullACIFactory = (NullActivityContextInterfaceFactory) myEnv
                    .lookup(NullActivityContextInterfaceFactory.JNDI_NAME);
            this.nullActivityFactory = (NullActivityFactory) myEnv
                    .lookup(NullActivityFactory.JNDI_NAME);
            // the sbb interface to interact with SIP resource adaptor
            this.sipProvider = (SleeSipProvider) myEnv
                    .lookup("java:comp/env/slee/resources/jainsip/1.2/provider");
        } catch (Exception e) {
            tracer.severe("Failed to set sbb context", e);
        }
    }
                
                

The SIP MESSAGE is the starting point of each instance of the service logic, its responsibility is:

The event handler code:



    /**
     * Event handler for the SIP MESSAGE from the UA
     * 
     * @param event
     * @param aci
     */
    public void onMessageEvent(javax.sip.RequestEvent event,
            ActivityContextInterface aci) {
        final Request request = event.getRequest();
        try {
            // message body should be *FIRST_TOKEN<timer value in
            // seconds>MIDDLE_TOKEN<msg to send back to UA>LAST_TOKEN*
            final String body = new String(request.getRawContent());
            final int firstTokenStart = body.indexOf(FIRST_TOKEN);
            final int timerDurationStart = firstTokenStart + FIRST_TOKEN_LENGTH;
            final int middleTokenStart = body.indexOf(MIDDLE_TOKEN,
                    timerDurationStart);
            final int bodyMessageStart = middleTokenStart + MIDDLE_TOKEN_LENGTH;
            final int lastTokenStart = body.indexOf(LAST_TOKEN,
                    bodyMessageStart);
            if (firstTokenStart > -1 && middleTokenStart > -1
                    && lastTokenStart > -1) {
                // extract the timer duration
                final int timerDuration = Integer.parseInt(body.substring(
                        timerDurationStart, middleTokenStart));
                // create a null AC and attach the sbb local object
                final ActivityContextInterface timerACI = this.nullACIFactory
                        .getActivityContextInterface(this.nullActivityFactory
                                .createNullActivity());
                timerACI.attach(sbbContext.getSbbLocalObject());
                // set the timer on the null AC, because the one from this event
                // will end as soon as we send back the 200 ok
                this.timerFacility.setTimer(timerACI, null, System
                        .currentTimeMillis()
                        + (timerDuration * 1000), new TimerOptions());
                // extract the body message
                final String bodyMessage = body.substring(bodyMessageStart,
                        lastTokenStart);
                // store it in a cmp field
                setBody(bodyMessage);
                // do the same for the call id
                setCallId((CallIdHeader) request.getHeader(CallIdHeader.NAME));
                // also store the sender's address, so we can send the wake up
                // message
                final FromHeader fromHeader = (FromHeader) request
                        .getHeader(FromHeader.NAME);
                if (tracer.isInfoEnabled()) {
                    tracer.info("Received a valid message from "
                            + fromHeader.getAddress()
                            + " requesting a reply containing '" + bodyMessage
                            + "' after " + timerDuration + "s");
                }
                setSender(fromHeader.getAddress());
                // finally reply to the SIP message request
                sendResponse(event, Response.OK);
            } else {
                // parsing failed
                tracer.warning("Invalid msg '" + body + "' received");
                sendResponse(event, Response.BAD_REQUEST);
            }
        } catch (Throwable e) {
            // oh oh something wrong happened
            tracer.severe("Exception while processing MESSAGE", e);
            try {
                sendResponse(event, Response.SERVER_INTERNAL_ERROR);
            } catch (Exception f) {
                tracer.severe("Exception while sending SERVER INTERNAL ERROR",
                        f);
            }
        }
    }
                
                

The JAIN SLEE TimerEvent handler is invoked when the duration requested by the SIP Message has passed, it is the final "piece" of the service instance logic, and its responsibility is:

The event handler code:



    /**
     * Event handler from the timer event, which signals that a message must be
     * sent back to the UA
     * 
     * @param event
     * @param aci
     */
    public void onTimerEvent(TimerEvent event, ActivityContextInterface aci) {
        // detaching so the null AC is claimed after the event handling
        aci.detach(sbbContext.getSbbLocalObject());
        // get data from cmp fields
        String body = getBody();
        CallIdHeader callId = getCallId();
        Address sender = getSender();
        try {
            // create headers needed to create a out-of-dialog request
            AddressFactory addressFactory = sipProvider.getAddressFactory();
            Address fromNameAddress = addressFactory
                    .createAddress("sip:wakeup@mobicents.org");
            fromNameAddress.setDisplayName("Wake Up Service");
            HeaderFactory headerFactory = sipProvider.getHeaderFactory();
            FromHeader fromHeader = headerFactory.createFromHeader(
                    fromNameAddress, null);
            List<ViaHeader> viaHeaders = new ArrayList<ViaHeader>(1);
            ListeningPoint listeningPoint = sipProvider.getListeningPoints()[0];
            ViaHeader viaHeader = sipProvider.getHeaderFactory()
                    .createViaHeader(listeningPoint.getIPAddress(),
                            listeningPoint.getPort(),
                            listeningPoint.getTransport(), null);
            viaHeaders.add(viaHeader);
            ContentTypeHeader contentTypeHeader = headerFactory
                    .createContentTypeHeader("text", "plain");
            CSeqHeader cSeqHeader = headerFactory.createCSeqHeader(2L,
                    Request.MESSAGE);
            MaxForwardsHeader maxForwardsHeader = headerFactory
                    .createMaxForwardsHeader(70);
            // create location service child sbb
            final LocationSbbLocalObject locationChildSbb = (LocationSbbLocalObject) 
                getLocationChildRelation().create();
            // get sender bindings and send a message to each
            MessageFactory messageFactory = sipProvider.getMessageFactory();
            for (RegistrationBinding registration : locationChildSbb
                    .getBindings(sender.getURI().toString()).values()) {
                try {
                    // create request uri
                    URI requestURI = addressFactory.createURI(registration
                            .getContactAddress());
                    // create to header
                    ToHeader toHeader = headerFactory.createToHeader(sender,
                            null);
                    // create request
                    Request request = messageFactory.createRequest(requestURI,
                            Request.MESSAGE, callId, cSeqHeader, fromHeader,
                            toHeader, viaHeaders, maxForwardsHeader,
                            contentTypeHeader, body);
                    // create client transaction and send request
                    ClientTransaction clientTransaction = sipProvider
                            .getNewClientTransaction(request);
                    clientTransaction.sendRequest();
                } catch (Throwable f) {
                    tracer.severe("Failed to create and send message", f);
                }
            }
        } catch (Throwable e) {
            tracer.severe("Failed to create message headers", e);
        }
    }
                
                

The Root SBB XML Descriptor has to be provided and match the abstract class code.

First relevant part is the declaration of the sbb-classes element, where the sbb class abstract name must be specified, along with the cmp fields and child relation.:



        <sbb-classes>
            <sbb-abstract-class>
                <sbb-abstract-class-name>org.mobicents.slee.examples.wakeup.WakeUpSbb</sbb-abstract-class-name>
                <cmp-field>
                    <cmp-field-name>body</cmp-field-name>
                </cmp-field>
                <cmp-field>
                    <cmp-field-name>callId</cmp-field-name>
                </cmp-field>
                <cmp-field>
                    <cmp-field-name>sender</cmp-field-name>
                </cmp-field>
                <get-child-relation-method>
                    <sbb-alias-ref>LocationSbb</sbb-alias-ref>
                    <get-child-relation-method-name>
                        getLocationChildRelation
                    </get-child-relation-method-name>
                    <default-priority>0</default-priority>
                </get-child-relation-method>
            </sbb-abstract-class>
        </sbb-classes>
            
            

Then the events handled by the SBB must be specified too:



        <event event-direction="Receive" initial-event="True">
            <event-name>MessageEvent</event-name>
            <event-type-ref>
                <event-type-name>javax.sip.message.Request.MESSAGE</event-type-name>
                <event-type-vendor>net.java.slee</event-type-vendor>
                <event-type-version>1.2</event-type-version>
            </event-type-ref>
            <initial-event-select variable="ActivityContext" />
        </event>

        <event event-direction="Receive" initial-event="False">
            <event-name>TimerEvent</event-name>
            <event-type-ref>
                <event-type-name>javax.slee.facilities.TimerEvent</event-type-name>
                <event-type-vendor>javax.slee</event-type-vendor>
                <event-type-version>1.0</event-type-version>
            </event-type-ref>
        </event>
            
            

Finally, the SIP11 Resource Adaptor must be specified also, otherwise SLEE won't put its SBB Interface in the SBB's JNDI Context:



        <resource-adaptor-type-binding>
            <resource-adaptor-type-ref>
                <resource-adaptor-type-name>
                    JAIN SIP
                </resource-adaptor-type-name>
                <resource-adaptor-type-vendor>
                    javax.sip
                </resource-adaptor-type-vendor>
                <resource-adaptor-type-version>
                    1.2
                </resource-adaptor-type-version>
            </resource-adaptor-type-ref>
            <activity-context-interface-factory-name>
                slee/resources/jainsip/1.2/acifactory
            </activity-context-interface-factory-name>
            <resource-adaptor-entity-binding>
                <resource-adaptor-object-name>
                    slee/resources/jainsip/1.2/provider
                </resource-adaptor-object-name>
                <resource-adaptor-entity-link>
                    SipRA
                </resource-adaptor-entity-link>
            </resource-adaptor-entity-binding>
        </resource-adaptor-type-binding>
            
            

Revision History
Revision 1.0Tue Dec 30 2009Eduardo Martins
Creation of the JBoss Communications JAIN SLEE SIP Wake Up Example User Guide.