{
out = response.getWriter();
}
// The conduit to pass on reverse ajax scripts
ScriptConduit conduit = new CallScriptConduit(out);
// Setup a debugging prefix
if (out instanceof DebuggingPrintWriter)
{
DebuggingPrintWriter dpw = (DebuggingPrintWriter) out;
dpw.setPrefix("out(" + conduit.hashCode() + "): ");
}
// Send the script prefix (if any)
sendOutboundScriptPrefix(out, replies.getCalls().getInstanceId(), replies.getCalls().getBatchId());
out.println(ProtocolConstants.SCRIPT_CALL_INSERT);
scriptSession.writeScripts(conduit);
out.println(ProtocolConstants.SCRIPT_CALL_REPLY);
String batchId = replies.getCalls().getBatchId();
for (int i = 0; i < replies.getReplyCount(); i++)
{
Reply reply = replies.getReply(i);
String callId = reply.getCallId();
try
{
// The existence of a throwable indicates that something went wrong
if (reply.getThrowable() != null)
{
Throwable ex = reply.getThrowable();
ScriptBuffer script = EnginePrivate.getRemoteHandleExceptionScript(batchId, callId, ex);
conduit.addScript(script);
// TODO: Are there any reasons why we should be logging here (and in the ConversionException handler)
//log.warn("--Erroring: batchId[" + batchId + "] message[" + ex.toString() + ']'), ex;
}
else
{
Object data = reply.getReply();
ScriptBuffer script = EnginePrivate.getRemoteHandleCallbackScript(batchId, callId, data);
conduit.addScript(script);
}
}
catch (IOException ex)
{
// We're a bit stuck we died half way through writing so