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 HttpServletResourceAdaptorType
, its vendor is org.mobicents
and its version is 1.0
.
The Resource Adaptor Type defines two activity objects, the types net.java.slee.resource.http.HttpServletRequestActivity
and net.java.slee.resource.http.HttpSessionActivity
.
The HttpServletRequestActivity
represents a specific incoming request. It is created by the Resource Adaptor when processing the incoming event, unless the request is received with an HttpSession
. The activity ending is done by the Resource Adaptor once the related request event is unreferenced inside the SLEE Container. The activity object interface is defined as follows:
package net.java.slee.resource.http;
public interface HttpServletRequestActivity {
/**
* Method to fetch the Request ID for this request.
*
* @return
*/
public Object getRequestID();
}
getRequestID()
method:Retrieves the Request's ID.
The HttpSessionActivity
represents an HttpSession
. It is created on demand by an SBB, through the RA SBB Interface, and ends on timeout, managed by the underlying HTTP Servlet framework, or by an SBB, invoking the invalidate()
on the related HttpSession
Object. The activity object interface is defined as follows:
package net.java.slee.resource.http;
public interface HttpSessionActivity {
public String getSessionId();
}
getSessionId()
method:Retrieves the Session's ID.
The Events fired by HTTP Servlet Resource Adaptor represent an incoming HTTP Request, and for each HTTP Request a different event type is used for each activity type. The table below lists the Resource Adaptor Type event types.
Table 2.1. Events fired on the HttpServletRequestActivity:
Name | Vendor | Version | Event Class | Description |
---|---|---|---|---|
net.java. slee.resource. http.events. incoming.request. HEAD | net.java.slee | 1.0 | net.java. slee.resource. http.events. HttpServletRequestEvent | An incoming HEAD HTTP request. |
net.java. slee.resource. http.events. incoming.request. GET | net.java.slee | 1.0 | net.java. slee.resource. http.events. HttpServletRequestEvent | An incoming GET HTTP request. |
net.java. slee.resource. http.events. incoming.request. POST | net.java.slee | 1.0 | net.java. slee.resource. http.events. HttpServletRequestEvent | An incoming POST HTTP request. |
net.java. slee.resource. http.events. incoming.request. PUT | net.java.slee | 1.0 | net.java. slee.resource. http.events. HttpServletRequestEvent | An incoming PUT HTTP request. |
net.java. slee.resource. http.events. incoming.request. DELETE | net.java.slee | 1.0 | net.java. slee.resource. http.events. HttpServletRequestEvent | An incoming DELETE HTTP request. |
net.java. slee.resource. http.events. incoming.request. OPTIONS | net.java.slee | 1.0 | net.java. slee.resource. http.events. HttpServletRequestEvent | An incoming OPTIONS HTTP request. |
net.java. slee.resource. http.events. incoming.request. TRACE | net.java.slee | 1.0 | net.java. slee.resource. http.events. HttpServletRequestEvent | An incoming TRACE HTTP request. |
Spaces where introduced in Name
and Event Class
column values, to correctly render the table. Please remove them when using copy/paste.
Table 2.2. Events fired on the HttpSessionActivity:
Name | Vendor | Version | Event Class | Description |
---|---|---|---|---|
net.java. slee.resource. http.events. incoming.session. HEAD | net.java.slee | 1.0 | net.java. slee.resource. http.events. HttpServletRequestEvent | An incoming HEAD HTTP request. |
net.java. slee.resource. http.events. incoming.session. GET | net.java.slee | 1.0 | net.java. slee.resource. http.events. HttpServletRequestEvent | An incoming GET HTTP request. |
net.java. slee.resource. http.events. incoming.session. POST | net.java.slee | 1.0 | net.java. slee.resource. http.events. HttpServletRequestEvent | An incoming POST HTTP request. |
net.java. slee.resource. http.events. incoming.session. PUT | net.java. slee | 1.0 | net.java. slee.resource. http.events. HttpServletRequestEvent | An incoming PUT HTTP request. |
net.java. slee.resource. http.events. incoming.session. DELETE | net.java.slee | 1.0 | net.java. slee.resource. http.events. HttpServletRequestEvent | An incoming DELETE HTTP request. |
net.java. slee.resource. http.events. incoming.session. OPTIONS | net.java.slee | 1.0 | net.java. slee.resource. http.events. HttpServletRequestEvent | An incoming OPTIONS HTTP request. |
net.java. slee.resource. http.events. incoming.session. TRACE | net.java.slee | 1.0 | net.java. slee.resource. http.events. HttpServletRequestEvent | An incoming TRACE HTTP request. |
Spaces where introduced in Name
and Event Class
column values, to correctly render the table. Please remove them when using copy/paste.
All event types use the same type net.java.slee.resource.http.events.HttpServletRequestEvent
. It's interface is as follows:
package net.java.slee.resource.http.events;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public interface HttpServletRequestEvent {
public HttpServletRequest getRequest();
public HttpServletResponse getResponse();
public String getId();
}
getRequest()
method:Retrieves the HttpServletRequest which is associated with the event.
getResponse()
method:Retrieves the HttpServletResponse which is associated with the request, which can be used to reply to the incoming request.
getId()
method:Retrieves unique event ID.
The Resource Adaptor's Activity Context Interface Factory is of type net.java.slee.resource.http.HttpServletRaActivityContextInterfaceFactory
, 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.slee.resource.http;
import javax.slee.ActivityContextInterface;
import javax.slee.FactoryException;
import javax.slee.UnrecognizedActivityException;
public interface HttpServletRaActivityContextInterfaceFactory {
public ActivityContextInterface getActivityContextInterface(
HttpSessionActivity activity) throws NullPointerException,
UnrecognizedActivityException, FactoryException;
public ActivityContextInterface getActivityContextInterface(
HttpServletRequestActivity activity) throws NullPointerException,
UnrecognizedActivityException, FactoryException;
}
The HTTP Servlet Resource Adaptor interface, of type net.java.slee.resource.http.HttpServletRaSbbInterface
, which an SBB uses to create HtppSessionActivity instances, is defined as follows:
package net.java.slee.resource.http;
import javax.servlet.http.HttpSession;
import javax.slee.SLEEException;
import javax.slee.resource.ActivityAlreadyExistsException;
import javax.slee.resource.StartActivityException;
public interface HttpServletRaSbbInterface {
public HttpSessionActivity getHttpSessionActivity(HttpSession httpSession)
throws NullPointerException, IllegalArgumentException, IllegalStateException,
ActivityAlreadyExistsException, StartActivityException,
SLEEException;
}
getHttpSessionActivity(HttpSession)
method:Retrieves an HttpSessionActivity
for the specified HttpSession
. If the activity does not exist a new one is created.
The HTTP Servlet
does imposes some restrictions on the usage of the
HTTP Servlet
API java objects:
getAttribute(String)
method of the
HttpSession
object, retrieved from a request:
The
_ENTRY_POINT
attribute is reserved for internal usage, if such parameter value
is
used a SecurityException is thrown.
getValue(String)
method of the
HttpSession
object, retrieved from a request:
The
_ENTRY_POINT
attribute is reserved for internal usage, if such parameter value
is
used a SecurityException is thrown.
putValue(String,Object)
method of the
HttpSession
object, retrieved from a request:
The
_ENTRY_POINT
attribute is reserved for internal usage, if such value is used on
the first parameter a SecurityException is thrown.
removeAttribute(String)
method of the
HttpSession
object, retrieved from a request:
The
_ENTRY_POINT
attribute is reserved for internal usage, if such parameter value
is
used a SecurityException is thrown.
removeValue(String)
method of the
HttpSession
object, retrieved from a request:
The
_ENTRY_POINT
attribute is reserved for internal usage, if such parameter value
is
used a SecurityException is thrown.
setAttribute(String,Object)
method of the
HttpSession
object, retrieved from a request:
The
_ENTRY_POINT
attribute is reserved for internal usage, if such value is used on
the first parameter a SecurityException is thrown.
The following code examples shows how to use the Resource Adaptor Type for common functionalities
The following code examples the handling of an HTTP GET request:
public void onGet(HttpServletRequestEvent event,
ActivityContextInterface aci) {
// detach from HttpServletRequestActivity
aci.detach(sbbContext.getSbbLocalObject());
HttpServletResponse response = event.getResponse();
try {
PrintWriter w = response.getWriter();
w.print("onGet OK! Served by SBB = " + getSbbId());
w.flush();
response.flushBuffer();
log
.info("HttpServletRAExampleSbb: GET Request received and OK! response sent.");
} catch (Exception e) {
log.error(e);
}
}
The following code examples the handling of an HTTP PUT request, and the creation of an HttpSessionActivity:
public void onPut(HttpServletRequestEvent event,
ActivityContextInterface aci) {
SbbLocalObject sbbLocalObject = sbbContext.getSbbLocalObject();
// detach from HttpServletRequestActivity
aci.detach(sbbLocalObject);
try {
// here we will setup a session activity before sending the response back
if (httpServletRaSbbInterface == null) {
Context myEnv = (Context) new InitialContext().lookup("java:comp/env");
httpServletRaSbbInterface = (HttpServletRaSbbInterface) myEnv.lookup(
"slee/resources/mobicents/httpservlet/sbbrainterface");
httpServletRaActivityContextInterfaceFactory =
(HttpServletRaActivityContextInterfaceFactory) myEnv.lookup(
"slee/resources/mobicents/httpservlet/acifactory");
}
HttpSession httpSession = event.getRequest().getSession();
HttpSessionActivity httpSessionActivity = httpServletRaSbbInterface
.getHttpSessionActivity(httpSession);
ActivityContextInterface httpSessionActivityContextInterface =
httpServletRaActivityContextInterfaceFactory
.getActivityContextInterface(httpSessionActivity);
httpSessionActivityContextInterface.attach(sbbLocalObject);
HttpServletResponse response = event.getResponse();
PrintWriter w = response.getWriter();
w.print("onPut OK! Served by SBB = " + getSbbId());
w.flush();
response.flushBuffer();
log.info("HttpServletRAExampleSbb: PUT Request received and OK! response sent.");
} catch (Exception e) {
log.error(e);
}
}