*/
public static MessageContext cloneMessageContext(MessageContext synCtx) throws AxisFault {
// creates the new MessageContext and clone the internal axis2 MessageContext
// inside the synapse message context and place that in the new one
MessageContext newCtx = synCtx.getEnvironment().createMessageContext();
Axis2MessageContext axis2MC = (Axis2MessageContext) newCtx;
axis2MC.setAxis2MessageContext(
cloneAxis2MessageContext(((Axis2MessageContext) synCtx).getAxis2MessageContext()));
newCtx.setConfiguration(synCtx.getConfiguration());
newCtx.setEnvironment(synCtx.getEnvironment());
newCtx.setContextEntries(synCtx.getContextEntries());
// set the parent correlation details to the cloned MC -
// for the use of aggregation like tasks
newCtx.setProperty(EIPConstants.AGGREGATE_CORRELATION, synCtx.getMessageID());
// copying the core parameters of the synapse MC
newCtx.setTo(synCtx.getTo());
newCtx.setReplyTo(synCtx.getReplyTo());
newCtx.setSoapAction(synCtx.getSoapAction());
newCtx.setWSAAction(synCtx.getWSAAction());
newCtx.setResponse(synCtx.isResponse());
// copy all the synapse level properties to the newCtx
for (Object o : synCtx.getPropertyKeySet()) {
// If there are non String keyed properties neglect them rather than trow exception
if (o instanceof String) {
newCtx.setProperty((String) o, synCtx.getProperty((String) o));
}
}
// Make deep copy of fault stack so that parent will not be lost it's fault stack
Stack<FaultHandler> faultStack = synCtx.getFaultStack();
if (!faultStack.isEmpty()) {
List<FaultHandler> newFaultStack = new ArrayList<FaultHandler>();
newFaultStack.addAll(faultStack);
for (FaultHandler faultHandler : newFaultStack) {
if (faultHandler != null) {
newCtx.pushFaultHandler(faultHandler);
}
}
}
if (log.isDebugEnabled()) {
log.info("Parent's Fault Stack : " + faultStack
+ " : Child's Fault Stack :" + newCtx.getFaultStack());
}
return newCtx;
}