if (log.isDebugEnabled()) {
log.debug("Received HTTP onRequest: {} self contained = {}", request, request.isSelfContained());
}
// Queue up a task to process the request
runner.enqueueTask(new ScriptTask()
{
@Override
public void execute(Context cx, Scriptable scope)
{
RequestAdapter reqAdapter =
(RequestAdapter)cx.newObject(ServerContainer.this, RequestAdapter.CLASS_NAME);
reqAdapter.init(request);
ResponseAdapter respAdapter =
(ResponseAdapter)cx.newObject(ServerContainer.this, ResponseAdapter.CLASS_NAME);
respAdapter.init(response, ServerContainer.this);
Scriptable socketInfo = makeSocketInfo(cx, request);
Scriptable socketObj = (Scriptable)makeSocket.call(cx, makeSocket, null,
new Object[] { socketInfo });
Scriptable requestObj = (Scriptable)makeRequest.call(cx, makeRequest, null,
new Object[] { reqAdapter, socketObj });
Scriptable responseObj = (Scriptable)makeResponse.call(cx, makeResponse, null,
new Object[] { respAdapter, socketObj, timeoutOpts });
request.setScriptObject(requestObj);
response.setScriptObject(responseObj);
onHeaders.call(cx, onHeaders, ServerContainer.this, new Object[] { requestObj, responseObj });
}
});
if (request.isSelfContained()) {
final ByteBuffer requestData =
(request.hasData() ? request.getData() : null);
// Queue up another task for the data. Noderunner guarantees that this will run after
// the previous task. However, do this in a separate tick because it's highly likely that
// the revious request to call "onHeaders" will register more event handlers
runner.enqueueTask(new ScriptTask()
{
@Override
public void execute(Context cx, Scriptable scope)
{
callOnData(cx, scope, request, requestData);
}
});
runner.enqueueTask(new ScriptTask()
{
@Override
public void execute(Context cx, Scriptable scope)
{
callOnComplete(cx, request);