JBoss.orgCommunity Documentation
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 1.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 void executeMethod(HttpMethod httpMethod);
}
getSessionId()
method:
Retrieves the activity unique Id.
getEndOnReceivingResponse()
method:
Returns true if this Activity is set to end as soon as the Response is received
executeMethod(HttpMethod)
method:
Executes an
HttpMethod
, i.e., sends an HTTP request, created through the RA SBB
Interface.
endActivity()
method:
Ends the activity and its related Activity Context.
There is a single event fired by HTTP Client Resource Adaptor, which represents a response to a request, received in a specific HttpClientActivity
instance.
Table 2.1. Events fired on the HttpClientActivity
Name | Vendor | Version | Event Class | Description |
---|---|---|---|---|
net.java. client.slee. resource.http. event. ResponseEvent | net.java. client.slee | 1.0 | net.java. client.slee. resource.http. event. ResponseEvent | A response event to an asynchronous HTTP request. |
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 send synchronous requests, 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 HttpClientActivity createHttpClientActivity() throws StartActivityException;
public HttpClientActivity createHttpClientActivity(
boolean endOnReceivingResponse) throws StartActivityException;
public HttpMethod createHttpMethod(HttpMethodName methodName, String uri);
public Response executeMethod(HttpMethod method) throws HttpException, IOException;
public HttpClientParams getParams();
public HttpState getState();
public void setParams(HttpClientParams params);
public void setState(HttpState state);
}
createHttpClientActivity()
method:
Creates a new
HttpClientActivity
instance which has to be ended by the SBB, that is, it won't end
once the HTTP Request response is received.
createHttpClientActivity(boolean)
method:
Creates a new
HttpClientActivity
instance. If the parameter is true then the activity will end once
the HTTP Request response is received, if false then the SBB needs
to end the activity through its endActivity() method.
createHttpMethod(HttpMethodName, String)
method:
Creates an HttpMethod instance, which request will be sent to the specified URI.
executeMethod(HttpMethod)
method:
Sends the HttpMethod's request synchronously, blocking till a response is received.
getParams()
method:
Retrieves the HTTP protocol parameters associated with the HttpClient.
getState()
method:
Retrieves the HTTP state associated with the HttpClient.
setParams(HttpClientParams)
method:
Sets the HTTP protocol parameters for the HttpClient.
setState(HttpState)
method:
Sets the HTTP state for the HttpClient.
The HTTP Client Resource Adaptor Type does not defines any restriction on the usage of its interfaces.
The following code examples shows how to use the Resource Adaptor Type for common functionalities
The following code examples the usage of the RA's SBB Interface to send synchronous HTTP requests:
HttpMethod httpMethod = raSbbInterface.createHttpMethod(
HttpMethodName.GET, syndFeed.getLink());
try {
Response response = raSbbInterface.executeMethod(httpMethod);
} catch (Throwable e) {
tracer.severe("Error while sending request",e);
}
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:
HttpMethod httpMethod = raSbbInterface.createHttpMethod(
HttpMethodName.GET, syndFeed.getLink());
try {
HttpClientActivity clientActivity = raSbbInterface
.createHttpClientActivity(true);
ActivityContextInterface clientAci = httpClientAci
.getActivityContextInterface(clientActivity);
clientAci.attach(sbbContext.getSbbLocalObject());
clientActivity.executeMethod(httpMethod);
} catch (Throwable e) {
tracer.severe("Error while creating HttpClientActivity",e);
}