/**
* @see flex.messaging.endpoints.amf.SuspendableAMFFilter#doInboundFilter(ActionContext)
*/
protected void doInboundFilter(final ActionContext context) throws IOException
{
MessageBody requestBody = context.getRequestMessageBody();
context.setLegacy(true);
// Parameters are usually sent as an AMF Array.
Object data = requestBody.getData();
List newParams = null;
// Check whether we're a new Flex 2.0 Messaging request.
if (data != null)
{
if (data.getClass().isArray())
{
int paramLength = Array.getLength(data);
if (paramLength == 1)
{
Object obj = Array.get(data, 0);
if ((obj != null) && (obj instanceof Message))
{
context.setLegacy(false);
newParams = new ArrayList();
newParams.add(obj);
}
}
// It was not a Flex 2.0 Message, but we have an array, use its contents as our params.
if (newParams == null)
{
newParams = new ArrayList();
for (int i = 0; i < paramLength; i++)
{
try
{
newParams.add(Array.get(data, i));
}
catch (Throwable ignore)
{
// NOWARN
}
}
}
}
else if (data instanceof List)
{
List paramList = (List)data;
if (paramList.size() == 1)
{
Object obj = paramList.get(0);
if ((obj != null) && (obj instanceof Message))
{
context.setLegacy(false);
newParams = new ArrayList();
newParams.add(obj);
}
}
// It was not a Flex 2.0 Message, but we have a list, so use it as our params.
if (newParams == null)
{
newParams = (List)data;
}
}
}
// We still haven't found any lists of params, so create one with whatever data we have.
if (newParams == null)
{
newParams = new ArrayList();
newParams.add(data);
}
if (context.isLegacy())
{
newParams = legacyRequest(context, newParams);
}
requestBody.setData(newParams);
}