JBoss.orgCommunity Documentation

Chapter 3. Integrating the JBoss Communications JAIN SLEE REST Client Enabler

3.1. The Parent's SbbLocalObject Interface
3.2. Handling HTTP Responses Provided by the Enabler
3.3. The Parent's Sbb Abstract Class
3.4. The Parent's Sbb XML Descriptor

This chapter explains how to setup a JAIN SLEE Service Sbb to use the Enabler.

In short terms, a Service's Sbb will define the Enabler's Sbb as a child, and to achieve that it will need to setup the XML Descriptor, Abstract Class and SbbLocalObject interface.

Important

The Service's Sbb will be referred as the Parent Sbb in the following sections.

The JBoss Communications JAIN SLEE REST Client Enabler Sbb provides asynchronous callbacks to the Parent's Sbb, and that can only be achieved if the Parent's SbbLocalObject extends a specific Java interface, deployed also by the Enabler. The Enabler uses the Parent's SbbLocalObject when a callback to the Parent's Sbb is needed.

The SbbLocalObject which must be used or extended by the Parent's Sbb is named org.mobicents.slee.enabler.rest.client.RESTClientEnablerParentSbbLocalObject, which extends the org.mobicents.slee.SbbLocalObjectExt and org.mobicents.slee.enabler.rest.client.RESTClientEnablerParent interfaces, the latter declares the callbacks which must be implemented in the Parent's Sbb Abstract Class:



package org.mobicents.slee.enabler.rest.client;
public interface RESTClientEnablerParent {
    public void onResponse(RESTClientEnablerChildSbbLocalObject child,
            RESTClientEnablerResponse response);
}
        
        

Please refer to the Apache HTTP Client 4.x Tutorial for detailed instructions on how to process the HTTP Response object, the code below is just a simple example of tracing the request information, the response status and content:



    @Override
    public void onResponse(RESTClientEnablerChildSbbLocalObject child,
            RESTClientEnablerResponse response) {
        String uri = response.getRequest().getUri();
        RESTClientEnablerRequest.Type type = response.getRequest().getType();
        HttpResponse httpResponse = response.getHttpResponse();
        if (httpResponse != null) {
            String content = null;
            if (httpResponse.getEntity() != null) {
                try {
                    content = EntityUtils.toString(httpResponse.getEntity());
                } catch (Exception e) {
                    tracer.severe("failed to convert response content to String", e);
                }
            }
            tracer.info("onResponse. Child '" + child + "', request type '"
                    + type + "', uri '" + uri + "', status '"
                    + httpResponse.getStatusLine().getStatusCode()
                    + "', response content '" + content + "'");
        } else {
            tracer.info("onResponse. Child '" + child + "', request type '"
                    + type + "', uri '" + uri + "', exception '"
                    + response.getExecutionException() + "'");
        }
    }
        
        

The Parent Sbb Abstract Class must implement the callbacks on it's SbbLocalObject, that is, must implement the org.mobicents.slee.enabler.rest.client.RESTClientEnablerParent interface discussed in last section.

The Enabler's Sbb is a Child Sbb, and JAIN SLEE 1.1 Child Relations requires an abstract method in the Sbb Abstract Class, to retrieve the org.mobicents.slee.ChildRelationExt object, which is used to create or access specific Child Sbbs. This method should be:



    public abstract ChildRelationExt getRESTClientEnablerChildRelation();
        
        

The Parent's Sbb must define a reference to the Enabler's Child Sbb, declare which is the method name to get the related ChildRelation object, and also ensure the SbbLocalObject interface is defined correctly.

A reference to the Enabler's Child Sbb is defined right after the Parent's Sbb Vendor ID element, using the following XML element:



        <sbb-ref>
            <sbb-name>RESTClientEnabler</sbb-name>
            <sbb-vendor>org.mobicents</sbb-vendor>
            <sbb-version>1.0</sbb-version>
            <sbb-alias>restClientChildSbb</sbb-alias>
        </sbb-ref>
        
        

The method name to get the Enabler's ChildRelation object must be defined after the CMP Fields (if any), this XML element links the sbb-alias previously defined with the abstract method declared in the Parent's Sbb Abstract Class:



        <get-child-relation-method>                 
            <sbb-alias-ref>restClientChildSbb</sbb-alias-ref>
            <get-child-relation-method-name>getRESTClientEnablerChildRelation</get-child-relation-method-name>
            <default-priority>0</default-priority>
        </get-child-relation-method>
        
        

Finally, after the sbb-abstract-class element the Parent's SbbLocalObject interface name is defined:



        <sbb-local-interface>
            <sbb-local-interface-name>org.mobicents.slee.enabler.rest.client.RESTClientEnablerParentSbbLocalObject</sbb-local-interface-name>
        </sbb-local-interface>