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 TftpServerResourceAdaptorType
, its vendor is org.mobicents
and its version is 1.0
.
The Resource Adaptor Type defines one activity object, net.java.slee.resource.tftp.TransferActivity
.
The TransferActivity
represents a TFTP transfer. It is created on reception of a TFTP requests, and ends on end-of-file, closure of the datastream, or by an SBB invoking sendError()
on the TransferActivity
Object. The activity object interface is defined as follows:
package net.java.slee.resource.tftp;
public interface TransferActivity {
public String getTransferId();
public InputStream getInputStream() throws IOException;
public OutputStream getOutputStream() throws IOException;
public void receiveFile(String filename) throws FileNotFoundException, IOException;
public void receiveFile(File file) throws FileNotFoundException, IOException;
public void sendFile(String filename) throws FileNotFoundException, IOException;
public void sendFile(File file) throws FileNotFoundException, IOException;
public void sendError(int errorCode, String reason);
}
getTransferId()
method:Retrieves the ID of the transfer.
getInputStream()
method:Retrieves the data stream of the TFTP write request.
getOutputStream()
method:Retrieves the data stream of the TFTP read request.
receiveFile(...)
methods:Stores the data of the TFTP write request in the given file.
sendFile(...)
methods:Sends the content of the given file to the TFTP client that initiated the TFTP read request.
sendError(int, String)
methods:Sends an error to the TFTP client that initiated the TFTP read request.
The Events fired by TFTP Server Resource Adaptor represent an incoming TFTP Request. The table below lists the Resource Adaptor Type event types.
Table 2.1. Events fired on the TransferActivity:
Name | Vendor | Version | Event Class | Description |
---|---|---|---|---|
net.java.slee. resource.tftp.events. incoming.request.READ | net.java.slee | 1.0 | net.java.slee. resource.tftp.events. RequestEvent | An incoming READ TFTP request. |
net.java.slee. resource.tftp.events. incoming.request.WRITE | net.java.slee | 1.0 | net.java.slee. resource.tftp.events. RequestEvent | An incoming WRITE TFTP request. |
net.java.slee. resource.tftp.events. incoming.request.DATA | net.java.slee | 1.0 | net.java.slee. resource.tftp.events. RequestEvent | An incoming TFTP DATA block. |
net.java.slee. resource.tftp.events. incoming.request.ACK | net.java. slee | 1.0 | net.java.slee. resource.tftp.events. RequestEvent | An incoming TFTP ACK . |
net.java.slee. resource.tftp.events. incoming.request.ERROR | net.java.slee | 1.0 | net.java.slee. resource.tftp.events. RequestEvent | An incoming TFTP ERROR block. |
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.tftp.events.RequestEvent
. It's interface is as follows:
package net.java.slee.resource.tftp.events;
import org.apache.commons.net.tftp.TFTPPacket;
public interface RequestEvent {
public TFTPPacket getRequest();
public String getTypeDescr();
public String getId();
}
getRequest()
method:Retrieves the TFTP request packet which is associated with the event.
getTypeDescr()
method:Retrieves the type description associated with the request.
getId()
method:Retrieves unique event ID.
The Resource Adaptor's Activity Context Interface Factory is of type net.java.slee.resource.tftp.TftpServerActivityContextInterfaceFactory
, 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.tftp;
import javax.slee.ActivityContextInterface;
import javax.slee.FactoryException;
import javax.slee.UnrecognizedActivityException;
public interface TftpServerActivityContextInterfaceFactory {
public ActivityContextInterface getActivityContextInterface(
TransferActivity activity) throws NullPointerException,
UnrecognizedActivityException, FactoryException;
}
The following code shows how to use the Resource Adaptor Type for common functionalities
The following code handles a TFTP WRITE request:
import net.java.slee.resource.tftp.TransferActivity;
import net.java.slee.resource.tftp.events.RequestEvent;
import org.apache.commons.net.tftp.TFTPWriteRequestPacket;
import org.apache.commons.net.tftp.TFTPRequestPacket;
public void onWrite(RequestEvent event, ActivityContextInterface aci) {
TFTPWriteRequestPacket req = (TFTPWriteRequestPacket) event.getRequest();
if (isSpecialRequest(req) {
doSpecialThings(req);
} else {
// just receive data and create the requested file
TransferActivity activity = (TransferActivity) aci.getActivity();
try {
activity.receiveFile(req.getFilename());
} catch (FileNotFoundException e) {
activity.sendError(TFTPErrorPacket.FILE_NOT_FOUND, e.getMessage());
return;
} catch (Exception e) {
activity.sendError(TFTPErrorPacket.UNDEFINED, e.getMessage());
return;
}
}
}
private boolean isSpecialRequest(TFTPRequestPacket packet) {
// inspect packet and decide whether it needs special treatment
return false;
}
private void doSpecialThings(TFTPRequestPacket packet) {
// actually do the special things that need to be done.
...;
}
The following code handles a TFTP READ request:
import net.java.slee.resource.tftp.TransferActivity;
import net.java.slee.resource.tftp.events.RequestEvent;
import org.apache.commons.net.tftp.TFTPReadRequestPacket;
import org.apache.commons.net.tftp.TFTPRequestPacket;
// CMP fields
public abstract void setSuspendedEventCmp(EventContext ctxt);
public abstract EventContext getSuspendedEventCmp();
public void onRead(RequestEvent event, ActivityContextInterface aci,
EventContext ctxt) {
TFTPReadRequestPacket req = (TFTPReadRequestPacket) event.getRequest();
if (isSpecialRequest(req) {
doSpecialThings(req);
} else {
// just send the requested file
TransferActivity activity = (TransferActivity) aci.getActivity();
try {
activity.sendFile(req.getFilename());
} catch (FileNotFoundException e) {
activity.sendError(TFTPErrorPacket.FILE_NOT_FOUND, e.getMessage());
return;
} catch (Exception e) {
activity.sendError(TFTPErrorPacket.UNDEFINED, e.getMessage());
return;
}
}
}
private boolean isSpecialRequest(TFTPRequestPacket packet) {
// inspect packet and decide whether it needs special treatment
return false;
}
private void doSpecialThings(TFTPRequestPacket packet, EventContext ctxt) {
// actually do the special things that need to be done & suspend.
...;
setSuspendedEventCmp(ctxt);
ctxt.suspendDelivery();
}
public void onSomeOtherRelatedEvent(RelatedEvent event, ActivityContextInterface aci) {
try {
OutputStream os = getRequestActivity().getOutputStream();
os.write("whatever data needs to be written".getBytes());
os.flush(); os.close();
getSuspendedEventCmp().resumeDelivery();
} catch (Exception e) {
}
}
private TransferActivity getRequestActivity() {
for (ActivityContextInterface aci : sbbContext.getActivities())
if (aci.getActivity() instanceof TransferActivity)
return (TransferActivity) aci.getActivity();
return null;
}