JBoss.orgCommunity Documentation

Chapter 2. Resource Adaptor Type

2.1. Activities
2.2. Events
2.3. Activity Context Interface Factory
2.4. Resource Adaptor Interface
2.5. Restrictions
2.6. Sbb Code Examples
2.6.1. Synchronous Operations
2.6.2. Asynchronous Operations

The Resource Adaptor Type is the interface which defines the contract between the RA implementations, the SLEE container, and the Applications running in it.

The name of the RA Type is HttpClientResourceAdaptorType, its vendor is org.mobicents and its version is 4.0.

The single activity object for HTTP Client Resource Adaptor is the net.java.client.slee.resource.http.HttpClientActivity interface. Through the activity an SBB can send multiple HTTP requests, and receive the related responses asynchronously. Due to the nature of SLEE activities, this RA activity acts like a queue of requests, allowing the processing of their responses - the events- in a serialized way

An activity starts on demand by an SBB, through the RA SBB Interface, and it ends when the response is received, or when the SBB invokes its endActivity() method.

The HttpClientActivity interface is defined as follows:



        
package net.java.client.slee.resource.http;
import org.apache.commons.httpclient.HttpMethod;
public interface HttpClientActivity {
    public String getSessionId();
    public void endActivity();
    public boolean getEndOnReceivingResponse();
    
    public HttpContext getHttpContext();
    
    public void execute(HttpUriRequest request,
        Object requestApplicationData);
    
    public void execute(HttpHost target, 
        HttpRequest request, 
        Object requestApplicationData);
}
     

There is a single event fired by HTTP Client Resource Adaptor, which represents a response to a request, received in a specific HttpClientActivity instance.


Important

Spaces where introduced in Name, Vendor and Event Class column values, to correctly render the table. Please remove them when using copy/paste.

The response event class provides the result of sending an HTTP request, which can be response or exception, due to error.

The Resource Adaptor's Activity Context Interface Factory is of type net.java.client.slee.resource.http.HttpClientActivityContextInterfaceFactory, it allows the SBB to retrieve the ActivityContextInterface related with an existing Resource Adaptor activity object. The interface is defined as follows:



        
package net.java.client.slee.resource.http;
import javax.slee.ActivityContextInterface;
import javax.slee.FactoryException;
import javax.slee.UnrecognizedActivityException;
public interface HttpClientActivityContextInterfaceFactory {
    
    public ActivityContextInterface getActivityContextInterface(
            HttpClientActivity acivity) throws NullPointerException,
            UnrecognizedActivityException, FactoryException;    
}
     

The HTTP Client Resource Adaptor interface, of type net.java.client.slee.resource.http.HttpClientResourceAdaptorSbbInterface, which an SBB uses to create new HttpClientActivity instances or get access the managed HTTP Client, to send synchronous requests or change its parameters, its interface is defined as follows:



        
package net.java.client.slee.resource.http;
import java.io.IOException;
import javax.slee.resource.StartActivityException;
import net.java.client.slee.resource.http.event.Response;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.params.HttpClientParams;
public interface HttpClientResourceAdaptorSbbInterface {
    public HttpClient getHttpClient();
    public HttpClientActivity createHttpClientActivity(
            boolean endOnReceivingResponse, HttpContext context)
            throws StartActivityException;
    
}
    

The managed HTTP Client, which may be obtained from HTTP Client Resource Adaptor SBB Interface, throws a SecurityException if the application tries to access its ClientConnectionManager.

The following code examples shows how to use the Resource Adaptor Type for common functionalities

The following code examples the creation and usage of the HttpClientActivity to send an async HTTP GET requests the optimal way to use the RA, since it doesn't block the SLEE container event routing threads:



            
HttpGet request = new HttpGet(syndFeed.getLink());
try {
    HttpClientActivity clientActivity = raSbbInterface
            .createHttpClientActivity(true,null);
    ActivityContextInterface clientAci = httpClientAci
            .getActivityContextInterface(clientActivity);
    clientAci.attach(sbbContext.getSbbLocalObject());
    clientActivity.execute(request,syndFeed.getLink());
} catch (Throwable e) {
    tracer.severe("Error while creating HttpClientActivity",e);
}
        

And the following code examples the handling of the response event:



            
public void onResponseEvent(ResponseEvent event,
            ActivityContextInterface aci) {
    HttpResponse response = event.getHttpResponse();
    tracer.info("********** onResponseEvent **************");
    tracer.info("URI = " + event.getRequestApplicationData());
    tracer.info("Status Code = " + 
        response.getStatusLine().getStatusCode());
    try {
        tracer.info("Response Body = "
                + EntityUtils.toString(response.getEntity()));
    } catch (Exception e) {
        tracer.severe("Failed reading response body", e);
    }
    tracer.info("*****************************************");
}