// Log input/output for debug level
AmfTrace debugTrace = isDebug ? new AmfTrace() : null;
// Create an empty ActionMessage object to hold our response
context.setResponseMessage(new ActionMessage());
SerializationContext sc = SerializationContext.getSerializationContext();
try
{
// Deserialize the input stream into an "ActionMessage" object.
MessageDeserializer deserializer = sc.newMessageDeserializer();
// Set up the deserialization context
InputStream in = FlexContext.getHttpRequest().getInputStream();
deserializer.initialize(sc, in, debugTrace);
// record the length of the input stream for performance metrics
int reqLen = FlexContext.getHttpRequest().getContentLength();
context.setDeserializedBytes(reqLen);
// set up the incoming MPI info if it is enabled
if(context.isMPIenabled())
{
MessagePerformanceInfo mpi = new MessagePerformanceInfo();
mpi.recordMessageSizes = context.isRecordMessageSizes();
mpi.recordMessageTimes = context.isRecordMessageTimes();
if(context.isRecordMessageTimes())
mpi.receiveTime = System.currentTimeMillis();
if(context.isRecordMessageSizes())
mpi.messageSize =reqLen;
context.setMPII(mpi);
}
ActionMessage m = new ActionMessage();
context.setRequestMessage(m);
deserializer.readMessage(m, context);
success = true;
}
catch (EOFException eof)
{
context.setStatus(MessageIOConstants.STATUS_NOTAMF);
}
catch (IOException exc)
{
if (isDebug)
logger.debug("IOException reading message - client closed socket before sending the message?");
throw exc;
}
catch (Throwable t)
{
deserializationError(context, t);
}
finally
{
// Use the same ActionMessage version for the response
ActionMessage respMsg = context.getResponseMessage();
respMsg.setVersion(context.getVersion());
if (isDebug)
logger.debug(debugTrace.toString());
}
try
{
if (success)
{
next.invoke(context);
}
}
catch (Throwable t)
{
unhandledError(context, t);
}
finally
{
// serialize output
if (context.getStatus() != MessageIOConstants.STATUS_NOTAMF)
{
ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
ActionMessage respMesg = context.getResponseMessage();
if (isDebug)
{
debugTrace = new AmfTrace();
}
try
{
// overhead calculation is only necessary when MPI is enabled
long serializationOverhead=0;
if(context.isRecordMessageTimes())
{
// set server send time
context.getMPIO().sendTime = System.currentTimeMillis();
if(context.isRecordMessageSizes())
serializationOverhead = System.currentTimeMillis();
}
MessageSerializer serializer = sc.newMessageSerializer();
serializer.initialize(sc, outBuffer, debugTrace);
serializer.writeMessage(respMesg);
// keep track of serializes bytes for performance metrics
context.setSerializedBytes(outBuffer.size());
// serialized message again after adding info if mpio with sizing is enabled
if(context.isRecordMessageSizes())
{
try
{
context.getMPIO().messageSize = outBuffer.size();
// reset server send time
if(context.isRecordMessageTimes())
{
serializationOverhead = System.currentTimeMillis() - serializationOverhead;
context.getMPIO().addToOverhead(serializationOverhead);
context.getMPIO().sendTime = System.currentTimeMillis();
}
// reserialize the message now that info has been added
outBuffer = new ByteArrayOutputStream();
respMesg = context.getResponseMessage();
serializer = sc.newMessageSerializer();
serializer.initialize(sc, outBuffer, debugTrace);
serializer.writeMessage(respMesg);
}
catch(Exception e)
{