else if (data.getClass().isArray())
{
data = Array.get(data, 0);
}
Message inMessage;
if (data instanceof Message)
{
inMessage = (Message)data;
}
else
{
throw new MessageException("Request was not of type flex.messaging.messages.Message");
}
Object outMessage = null;
String replyMethodName = MessageIOConstants.STATUS_METHOD;
try
{
// Lookup or create the correct FlexClient.
endpoint.setupFlexClient(inMessage);
// Assign a clientId if necessary.
// We don't need to assign clientIds to general poll requests.
if (inMessage.getClientId() == null &&
(!(inMessage instanceof CommandMessage) || ((CommandMessage)inMessage).getOperation() != CommandMessage.POLL_OPERATION))
{
Object clientId = UUIDUtils.createUUID();
inMessage.setClientId(clientId);
}
// Messages received via the AMF channel can be batched (by NetConnection on the client) and
// we must not put the handler thread into a poll-wait state if a poll command message is followed by
// or preceeded by other messages in the batch; the request-response loop must complete without waiting.
// If the poll command is the only message in the batch it's ok to wait.
// If it isn't ok to wait, tag the poll message with a header that short-circuits any potential poll-wait.
if (inMessage instanceof CommandMessage)
{
CommandMessage command = (CommandMessage)inMessage;
if ((command.getOperation() == CommandMessage.POLL_OPERATION) && (context.getRequestMessage().getBodyCount() != 1))
command.setHeader(CommandMessage.SUPPRESS_POLL_WAIT_HEADER, Boolean.TRUE);
}
// If MPI is enabled update the MPI metrics on the object referred to by the context
// and the messages
if (context.isMPIenabled())
MessagePerformanceUtils.setupMPII(context, inMessage);
// Service the message.
outMessage = endpoint.serviceMessage(inMessage);
// if processing of the message resulted in an error, set up context and reply method accordingly
if (outMessage instanceof ErrorMessage)
{
context.setStatus(MessageIOConstants.STATUS_ERR);
replyMethodName = MessageIOConstants.STATUS_METHOD;
}
else
{
replyMethodName = MessageIOConstants.RESULT_METHOD;
}
}
catch (MessageException e)
{
context.setStatus(MessageIOConstants.STATUS_ERR);
replyMethodName = MessageIOConstants.STATUS_METHOD;
outMessage = e.createErrorMessage();
((ErrorMessage)outMessage).setCorrelationId(inMessage.getMessageId());
((ErrorMessage)outMessage).setDestination(inMessage.getDestination());
((ErrorMessage)outMessage).setClientId(inMessage.getClientId());
e.logAtHingePoint(inMessage, (ErrorMessage)outMessage, null /* Use default message intros */);
}
catch (Throwable t)
{
// Handle any uncaught failures. The normal exception path on the server
// is to throw MessageExceptions which are handled in the catch block above,
// so if that was skipped we have an overlooked or serious problem.
context.setStatus(MessageIOConstants.STATUS_ERR);
replyMethodName = MessageIOConstants.STATUS_METHOD;
String lmeMessage = t.getMessage();
if (lmeMessage == null)
lmeMessage = t.getClass().getName();
MessageException lme = new MessageException();
lme.setMessage(UNHANDLED_ERROR, new Object[] {lmeMessage});
outMessage = lme.createErrorMessage();
((ErrorMessage)outMessage).setCorrelationId(inMessage.getMessageId());
((ErrorMessage)outMessage).setDestination(inMessage.getDestination());
((ErrorMessage)outMessage).setClientId(inMessage.getClientId());
if (Log.isError())
{
Log.getLogger(LOG_CATEGORY).error("Unhandled error when processing a message: " +
t.toString() + StringUtils.NEWLINE +