HotJava
----------------------------
Jigsaw Client package
----------------------------
PICS Trust Mgt Kernel (PTMK)
----------------------------
Profile-0.9 Interpreter
To use Jigsaw Client package under HotJava, all you need to do is to change
java.protocol.handler.pkgs property to w3c.www.protocol
before launching HotJava.
The API is very simple: it takes in a Request (generally a URL) and
returns a Reply (the content of the URL). In general, this HTTP
Client API serves similar function as the standard java.net.URLConnect
class, but this API is much more robust and modular.
A typical loop inside the Jigsaw Client looks like the following:
| Request from Caller ^ Reply to Caller
\ / |
--------------------------------------
| HttpManager |
--------------------------------------
| Request ^
\ / |
------------------ Reply |
| IngoingFilters |---------------> |
------------------ |
| Request |
\ / |
------------------- |
| HttpConnection | |
------------------- |
| Request, Reply |
\ / |
------------------- Reply |
| OutgoingFilters |--------------> |
------------------- |
| |
-----------------------------
To be a valid instance of a Jigsaw filter, you need to implement three
methods: Initialization, ingoingFilter, and
outgoingFilter. In PTMKFilter, Initialization
defines the default interpreter and script to run, as well
as various callback. IngoingFilter sets the statement list,
invoke the interpreter and examine the returned statement list.
OutgoingFilter does nothing in this case.
Here are some pseudo-codes for class PTMKFilter .
Here are some pseudo-codes for Fetch Callback .
public class PTMKFilter implements PropRequestFilter {
public void initialize(HttpManager manager) {
// set default profile interpreter
// set default script (policy) for the interpreter
// set the fetch callback
// set the default ptmk_cb
// install as a global filter
this.manager = manager;
manager.setFilter(this);
manager.setAllowUserInteraction(true);
}
// the kernel
public Reply ingoingFilter(Request request) {
return null;
// generate the initial two statements and the statement list.
Statement userRequest = new Statement("USER",
"("+Request.getMethod()+" "+ Request.getURL()",
"http://actions-v1");
Statement userProfile = new Statement("application",
this.defaultScript,
"http://labels");
StatementList stmtList = new StatementList();
// put both statements in the statement list. UR and UP are the IDs
// of the statement in the statement list.
int UR = stmtList.add(userRequest);
int UP = stmtList.add(userProfile);
// provides pointer to the user request and the script for the
// interpreter
stmtList.ptrUserRequest = UR;
stmtList.ptrUserProfile = UP;
// invoke the interpreter
StatementList replyStmtList = this.defaultInterpreter.eval(stmtList);
// generateReply looks at the statement list, returns null
// if the request is granted, or returns a "sorry, viewing URL is
// not allowed" Reply if not.
return(generateReply(replyStmtList));
}
// do nothing
public Reply outgoingFilter(Request request, Reply reply)
throws HttpException
{
return(null);
}
}
public InputStream fetch_callback(String url) {
// Get the manager
HttpManager manager = HttpManager.getManager();
// exclude PTMKFilter
RequestFilter filter = getGlobalFilter(PTMKFilter);
manager.setFilter(null, *, filter);
// create the request
Request request = manager.createRequest();
request.setURL(new URL(args[0]));
request.setMethod("GET");
// run the request and return the reply
Reply reply = manager.runRequest(request);
return(reply.getInputStream());
}