JBoss.orgCommunity Documentation
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.
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);
}
onResponse(RESTClientEnablerChildSbbLocalObject,
RESTClientEnablerResponse)
method:Callback from the Enabler providing the result of executing a REST request, which besides containing the executed REST request, also contains either the received HTTP Response, or the exception which was thrown when executing the request. It also provides the child sbb which was used to execute the request.
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>
The Sbb local object interface may be an interface which extends org.mobicents.slee.enabler.rest.client.RESTClientEnablerParentSbbLocalObject
, for instance one that extends multiple Enabler Parent Sbb local object interfaces.