// Write the initial response object so that the
// object stream is initialized
oos.writeObject(new Response());
boolean disconnect = false;
Command inputCommand = null;
Response response = null;
while (! disconnect)
{
task.getProject().log("Reading command object.",
Project.MSG_DEBUG);
inputCommand = (Command) ois.readObject();
task.getProject().log("Executing command object: " + inputCommand,
Project.MSG_DEBUG);
response = new Response();
try
{
cbl = new ConnectionBuildListener();
task.getProject().addBuildListener(cbl);
inputCommand.execute(task.getProject(),
inputCommand.getContentLength(),
is);
response.setSucceeded(true);
}
catch (Throwable t)
{
response.setSucceeded(false);
response.setThrowable(t);
}
finally
{
if (cbl != null)
task.getProject().removeBuildListener(cbl);
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLSerializer serial = new XMLSerializer();
OutputFormat fmt = new OutputFormat();
fmt.setOmitDocumentType(true);
fmt.setOmitXMLDeclaration(false);
serial.setOutputFormat(fmt);
serial.setOutputByteStream(baos);
serial.serialize(cbl.getDocument());
response.setResultsXml(baos.toString());
task.getProject().log("Executed command object: " + inputCommand,
Project.MSG_DEBUG);
task.getProject().log("Sending response: " + response,
Project.MSG_DEBUG);
response.setContentLength(inputCommand.getContentLength());
oos.writeObject(response);
if (inputCommand.getResponseContentLength() != 0)
{
Util.transferBytes(inputCommand.getReponseContentStream(),
inputCommand.getResponseContentLength(),
os,
true);
}
if (inputCommand instanceof DisconnectCommand)