JBoss.orgCommunity Documentation

Chapter 4. Using the JBoss Communications JAIN SLEE REST Client Enabler

4.1. The Child's SbbLocalObject Interface
4.2. Creating And Retrieving The Child Sbb
4.3. Creating Requests for REST Resources

In the last chapter we integrated the Enabler in the JAIN SLEE Service's Sbb, the Parent Sbb, in this chapter it is explained how to use the Enabler's Sbb, the Child Sbb.

The JBoss Communications JAIN SLEE REST Client Enabler Sbb, the Child Sbb, implements the org.mobicents.slee.enabler.rest.client.RESTClientEnablerChildSbbLocalObject, which extends the org.mobicents.slee.SbbLocalObjectExt and org.mobicents.slee.enabler.rest.client.RESTClientEnablerChild interfaces, the latter declares the methods which can be used to interact with the REST Web Service:



package org.mobicents.slee.enabler.rest.client;
public interface RESTClientEnablerChild {
    public void execute(RESTClientEnablerRequest request) throws Exception;
}
        
        

The Child Relation in the Parent Sbb Abstract Class is used to create and retrieve the Child Sbb:



    RESTClientEnablerChild sbb = null;
    // creation
    try {
        sbb = (RESTClientEnablerChild) getRESTClientEnablerChildRelation().create(childName);                
    }
    catch (Exception e) {
      tracer.severe("Failed to create child sbb", e);      
    }
    // retrieval
    try {
        sbb = (RESTClientEnablerChild) getRESTClientEnablerChildRelation().get(childName);                
    }
    catch (Exception e) {
      tracer.severe("Failed to retrieve child sbb", e);      
    }
        

Requests are instances of org.mobicents.slee.enabler.rest.client.RESTClientEnablerRequest, which include all the mandatory and optional data, needed by the Enabler to send the HTTP messages to the REST Web Services.

The only mandatory data is the request type (the HTTP message method name) and the REST Web Service URI, but the application using the enabler may also include a SignPost OAuthConsumer object, to sign the request according to OAuth protocol, additional headers and/or content to include in the HTTP message, and content. The following Java code examples the creation of a POST request to update status in the Twitter network:



    String uri = "http://api.twitter.com/1/statuses/update.json?status="
            + URLEncoder.encode(
                            "Hello Twitter!", "UTF-8");
    CommonsHttpOAuthConsumer consumer = 
        new CommonsHttpOAuthConsumer(twitterConsumerKey,
        twitterConsumerSecret);
    consumer.setTokenWithSecret(twitterAccessToken,twitterAccessTokenKey);
    RESTClientEnablerRequest request = new RESTClientEnablerRequest(
        RESTClientEnablerRequest.Type.POST, uri)
        .setOAuthConsumer(consumer);