message = t.getMessage();
if (message == null)
message = t.toString();
}
methodResult = new MessageException(message, t).createErrorMessage();
}
if (context.isLegacy())
{
if (methodResult instanceof ErrorMessage)
{
ErrorMessage error = (ErrorMessage)methodResult;
ASObject aso = new ASObject();
aso.put("message", error.faultString);
aso.put("code", error.faultCode);
aso.put("details", error.faultDetail);
aso.put("rootCause", error.rootCause);
methodResult = aso;
}
else if (methodResult instanceof Message)
{
methodResult = ((Message)methodResult).getBody();
}
}
else
{
Object data = context.getRequestMessageBody().getData();
if (data instanceof List)
{
data = ((List)data).get(0);
}
else if (data.getClass().isArray())
{
data = Array.get(data, 0);
}
Message inMessage;
if (data instanceof Message)
{
inMessage = (Message)data;
if (inMessage.getClientId() != null)
{
((ErrorMessage)methodResult).setClientId(inMessage.getClientId().toString());
}
if (inMessage.getMessageId() != null)
{
((ErrorMessage)methodResult).setCorrelationId(inMessage.getMessageId());
((ErrorMessage)methodResult).setDestination(inMessage.getDestination());
}
}
}
responseBody.setData(methodResult);
responseBody.setReplyMethod(MessageIOConstants.STATUS_METHOD);
}
if (Log.isError())
logger.error("Exception occurred during serialization: " + ExceptionUtil.toString(t));
// serialize the error messages
SerializationContext sc = SerializationContext.getSerializationContext();
MessageSerializer serializer = sc.newMessageSerializer();
ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
AmfTrace debugTrace = isDebug ? new AmfTrace() : null;
serializer.initialize(sc, outBuffer, debugTrace);
try
{
serializer.writeMessage(context.getResponseMessage());
context.setResponseOutput(outBuffer);
}
catch (IOException e)
{
//Error serializing response
MessageException ex = new MessageException();
ex.setMessage(RESPONSE_ERROR);
ex.setRootCause(e);
throw ex;
}
}