You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by na...@apache.org on 2007/01/11 05:04:33 UTC

svn commit: r495106 [3/10] - in /webservices/axis2/trunk/java/modules: integration/ integration/test/org/apache/axis2/engine/ integration/test/org/apache/axis2/mtom/ kernel/src/org/apache/axis2/addressing/ kernel/src/org/apache/axis2/client/ kernel/src...

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java?view=diff&rev=495106&r1=495105&r2=495106
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java Wed Jan 10 20:04:31 2007
@@ -18,33 +18,103 @@
 
 import org.apache.axiom.attachments.Attachments;
 import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.impl.MTOMConstants;
+import org.apache.axiom.om.impl.builder.StAXBuilder;
+import org.apache.axiom.om.util.StAXUtils;
 import org.apache.axiom.om.util.UUIDGenerator;
 import org.apache.axiom.soap.SOAP11Constants;
 import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.axiom.soap.SOAPConstants;
 import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.addressing.RelatesTo;
 import org.apache.axis2.client.Options;
-import org.apache.axis2.description.*;
+import org.apache.axis2.description.AxisMessage;
+import org.apache.axis2.description.AxisModule;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.AxisServiceGroup;
+import org.apache.axis2.description.HandlerDescription;
+import org.apache.axis2.description.ModuleConfiguration;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.description.TransportInDescription;
+import org.apache.axis2.description.TransportOutDescription;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.engine.Handler;
+import org.apache.axis2.engine.Phase;
+import org.apache.axis2.handlers.AbstractHandler;
+import org.apache.axis2.util.Builder;
+import org.apache.axis2.util.ObjectStateUtils;
+import org.apache.axis2.util.MetaDataEntry;
+import org.apache.axis2.util.SelfManagedDataHolder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.neethi.Policy;
 
 import javax.activation.DataHandler;
 import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutput;
+import java.io.ObjectOutputStream;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
 
 /**
  * MessageContext holds service specific state information.
  */
-public class MessageContext extends AbstractContext {
+public class MessageContext extends AbstractContext implements Externalizable {
+
+    /*
+     * setup for logging
+     */
+    private static final Log log = LogFactory.getLog(MessageContext.class);
+
+    private static final String myClassName = "MessageContext";
+
+    /**
+     * @serial The serialization version ID tracks the version of the class.
+     * If a class definition changes, then the serialization/externalization
+     * of the class is affected. If a change to the class is made which is
+     * not compatible with the serialization/externalization of the class,
+     * then the serialization version ID should be updated.
+     * Refer to the "serialVer" utility to compute a serialization
+     * version ID.
+     */
+    private static final long serialVersionUID = -7753637088257391858L;
+
+    /**
+     * @serial Tracks the revision level of a class to identify changes to the 
+     * class definition that are compatible to serialization/externalization.
+     * If a class definition changes, then the serialization/externalization
+     * of the class is affected. 
+     * Refer to the writeExternal() and readExternal() methods.
+     */
+    // supported revision levels, add a new level to manage compatible changes
+    private static final int REVISION_1 = 1;
+    // current revision level of this object
+    private static final int revisionID = REVISION_1;
+
+
 
     /**
      * A place to store the current MessageContext
@@ -59,6 +129,10 @@
         currentMessageContext.set(ctx);
     }
 
+
+    /**
+     * @serial Options on the message
+     */
     protected Options options;
 
     public final static int IN_FLOW = 1;
@@ -70,8 +144,16 @@
     public static final String REMOTE_ADDR = "REMOTE_ADDR";
 
     public static final String TRANSPORT_HEADERS = "TRANSPORT_HEADERS";
+    
 
-    public Attachments attachments;
+    /**
+     * message attachments
+     * NOTE: Serialization of message attachments is handled as part of the
+     *       overall message serialization.  If this needs to change, then
+     *       investigate having the Attachment class implement the 
+     *       java.io.Externalizable interface.
+     */
+    public transient Attachments attachments;
 
     /**
      * Field TRANSPORT_OUT
@@ -111,8 +193,10 @@
      */
     public static final String DEFAULT_CHAR_SET_ENCODING = UTF_8;
 
-    // to keep a ref to figure out which path your are in the execution (send or
-    // receive)
+    /**
+     * @serial The direction flow in use to figure out which path the message is in
+     * (send or receive)
+     */
     public int FLOW = IN_FLOW;
 
     /**
@@ -129,104 +213,305 @@
      * Callback.onError(...).
      */
     public static final String DISABLE_ASYNC_CALLBACK_ON_TRANSPORT_ERROR = "disableTransmissionErrorCallback";
-
+    
     /**
-     * Field processingFault
+     * @serial processingFault
      */
     private boolean processingFault;
 
+    /**
+     * @serial paused
+     */
     private boolean paused;
 
+    /**
+     * @serial outputWritten
+     */
     public boolean outputWritten;
 
     /**
-     * Field newThreadRequired
+     * @serial newThreadRequired
      */
     private boolean newThreadRequired;
 
+    /**
+     * @serial isSOAP11
+     */
     private boolean isSOAP11 = true;
 
     /**
-     * The chain of Handlers/Phases for processing this message
+     * @serial The chain of Handlers/Phases for processing this message
      */
     private ArrayList executionChain = new ArrayList();
 
+    /**
+     * @serial The chain of executed Handlers/Phases from inbound processing
+     */
     private LinkedList inboundExecutedPhases = new LinkedList();
+
+    /**
+     * @serial The chain of executed Handlers/Phases from outbound processing
+     */
     private LinkedList outboundExecutedPhases = new LinkedList();
 
-    // Are we doing REST now?
+    /**
+     * @serial Flag to indicate if we are doing REST
+     */
     private boolean doingREST;
 
-    // Are we doing MTOM now?
+    /**
+     * @serial Flag to indicate if we are doing MTOM
+     */
     private boolean doingMTOM;
-
-    // Are we doing SwA now?
+    
+    /**
+     * @serial Flag to indicate if we are doing SWA
+     */
     private boolean doingSwA;
 
+    /**
+     * AxisMessage associated with this message context
+     */
     private transient AxisMessage axisMessage;
 
+    /**
+     * AxisOperation associated with this message context
+     */
     private transient AxisOperation axisOperation;
 
+    /**
+     * AxisService
+     */
     private transient AxisService axisService;
 
+    /**
+     * AxisServiceGroup
+     * <P>
+     * Note the service group can be set independently of the service
+     * so the service might not match up with this serviceGroup
+     */
     private transient AxisServiceGroup axisServiceGroup;
 
-    private ConfigurationContext configurationContext;
+    /**
+     * ConfigurationContext
+     */
+    private transient ConfigurationContext configurationContext;
 
     /**
-     * Index into the execution chain of the currently executing handler
+     * @serial Index into the executuion chain of the currently executing handler
      */
     private int currentHandlerIndex;
 
     /**
-     * Index into the current Phase of the currently executing handler (if any)
+     * @serial Index into the current Phase of the currently executing handler (if any)
      */
     private int currentPhaseIndex;
 
     /**
-     * Field service
+     * @serial SOAP envelope
      */
+    private SOAPEnvelope envelope;
 
     /**
-     * Field envelope
+     * @serial OperationContext
      */
-    private SOAPEnvelope envelope;
-
     private OperationContext operationContext;
 
     /**
-     * Field responseWritten
+     * @serial responseWritten
      */
     private boolean responseWritten;
 
     /**
-     * Field serverSide
+     * @serial serverSide
      */
     private boolean serverSide;
 
+    /**
+     * @serial ServiceContext
+     */
     private ServiceContext serviceContext;
 
+    /**
+     * @serial service context ID
+     */
     private String serviceContextID;
 
+    /**
+     * @serial service group context
+     */
     private ServiceGroupContext serviceGroupContext;
 
     /**
-     * This will hold a key to retrieve the correct ServiceGroupContext.
+     * @serial Holds a key to retrieve the correct ServiceGroupContext.
      */
     private String serviceGroupContextId;
 
     /**
-     * Field sessionContext
+     * @serial sessionContext
      */
     private SessionContext sessionContext;
 
+
+    /**
+     * transport out description
+     */
     private transient TransportOutDescription transportOut;
+
+    /**
+     * transport in description
+     */
     private transient TransportInDescription transportIn;
 
+
+    /**
+     * @serial incoming transport name
+     */
     //The value will be set by the transport receiver and there will be validation for the transport
     //at the dispatch phase (its post condition)
     private String incomingTransportName;
 
+
+    /*
+     * SelfManagedData will hold message-specific data set by handlers 
+     * Note that this list is not explicitly saved by the MessageContext, but
+     * rather through the SelfManagedDataManager interface implemented by handlers
+     */
+    private transient LinkedHashMap selfManagedDataMap = null;
+    
+
+    //-------------------------------------------------------------------------
+    // MetaData for data to be restored in activate() after readExternal()
+    //-------------------------------------------------------------------------
+    
+    /**
+     * Indicates whether the message context has been reconstituted
+     * and needs to have its object references reconciled
+     */
+    private transient boolean needsToBeReconciled = false;
+
+    /**
+     * selfManagedDataHandlerCount is a count of the number of handlers
+     * that actually saved data during serialization
+     */
+    private transient int selfManagedDataHandlerCount = 0;
+    
+    /**
+     * SelfManagedData cannot be restored until the configurationContext
+     * is available, so we have to hold the data from readExternal until
+     * activate is called.
+     */
+    private transient ArrayList selfManagedDataListHolder = null;
+
+    /**
+     * The ordered list of metadata for handlers/phases 
+     * used during re-constitution of the message context
+     */
+    private transient ArrayList metaExecutionChain = null;
+    
+    /**
+     * The ordered list of metadata for inbound executed phases 
+     * used during re-constitution of the message context
+     */
+    private transient LinkedList metaInboundExecuted = null;
+    
+    /**
+     * The ordered list of metadata for outbound executed phases 
+     * used during re-constitution of the message context
+     */
+    private transient LinkedList metaOutboundExecuted = null;
+    
+    /**
+     * Index into the executuion chain of the currently executing handler
+     */
+    private transient int metaHandlerIndex = 0;
+
+    /**
+     * Index into the current Phase of the currently executing handler (if any)
+     */
+    private transient int metaPhaseIndex = 0;
+
+    /**
+     * The AxisOperation metadata will be used during
+     * activate to match up with an existing object
+     */
+    private transient MetaDataEntry metaAxisOperation = null;
+    
+    /**
+     * The AxisService metadata will be used during
+     * activate to match up with an existing object
+     */
+    private transient MetaDataEntry metaAxisService = null;
+    
+    /**
+     * The AxisServiceGroup metadata will be used during
+     * activate to match up with an existing object
+     */
+    private transient MetaDataEntry metaAxisServiceGroup = null;
+    
+    /**
+     * The OperationContext metadata will be used during
+     * activate to finish restoring the object
+     */
+    private transient OperationContext metaOperationContext = null;
+    
+    /**
+     * The ServiceContext metadata will be used during
+     * activate to finish restoring the object, if needed
+     */
+    private transient ServiceContext metaServiceContext = null;
+    
+    /**
+     * The ServiceGroupContext metadata will be used during
+     * activate to finish restoring the object, if needed
+     */
+    private transient ServiceGroupContext metaServiceGroupContext = null;
+    
+    /**
+     * The TransportOutDescription metadata will be used during
+     * activate to match up with an existing object
+     */
+    private transient MetaDataEntry metaTransportOut = null;
+    
+    /**
+     * The TransportInDescription metadata will be used during
+     * activate to match up with an existing object
+     */
+    private transient MetaDataEntry metaTransportIn = null;
+    
+    /**
+     * The AxisMessage metadata will be used during
+     * activate to match up with an existing object
+     */
+    private transient MetaDataEntry metaAxisMessage = null;
+    
+    /**
+     * Indicates whether this message context has an 
+     * AxisMessage object associated with it that needs to 
+     * be reconciled
+     */
+    private transient boolean reconcileAxisMessage = false;
+    
+    /**
+     * Indicates whether the inbound executed phase list
+     * was reset before the restored list has been reconciled
+     */
+    private transient boolean inboundReset = false;
+    
+    /**
+     * Indicates whether the outbound executed phase list
+     * was reset before the restored list has been reconciled
+     */
+    private transient boolean outboundReset = false;
+    
+    //----------------------------------------------------------------
+    // end MetaData section
+    //----------------------------------------------------------------
+
+
+    /**
+     * Constructor
+     */
     public MessageContext() {
         super(null);
         options = new Options();
@@ -240,18 +525,51 @@
     }
 
     public AxisOperation getAxisOperation() {
+        if (needsToBeReconciled) {
+            if (log.isWarnEnabled()) {
+                log.warn(myClassName+":getAxisOperation(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+            }
+            //System.out.println(myClassName+":getAxisOperation(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+        }
+
         return axisOperation;
     }
 
     public AxisService getAxisService() {
+        if (needsToBeReconciled) {
+            if (log.isWarnEnabled()) {
+                log.warn(myClassName+":getAxisService(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+            }
+            //System.out.println(myClassName+":getAxisService(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+        }
+
         return axisService;
     }
 
+    /*
+     * <P>
+     * Note the service group can be set independently of the service
+     * so the service might not match up with this serviceGroup
+    */
     public AxisServiceGroup getAxisServiceGroup() {
+        if (needsToBeReconciled) {
+            if (log.isWarnEnabled()) {
+                log.warn(myClassName+":getAxisServiceGroup(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+            }
+            //System.out.println(myClassName+":getAxisServiceGroup(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+        }
+
         return axisServiceGroup;
     }
 
     public ConfigurationContext getConfigurationContext() {
+        if (needsToBeReconciled) {
+            if (log.isWarnEnabled()) {
+                log.warn(myClassName+":getConfigurationContext(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+            }
+            //System.out.println(myClassName+":getConfigurationContext(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+        }
+
         return configurationContext;
     }
 
@@ -271,9 +589,16 @@
     }
 
     public ArrayList getExecutionChain() {
+        if (needsToBeReconciled) {
+            if (log.isWarnEnabled()) {
+                log.warn(myClassName+":getExecutionChain(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+            }
+            //System.out.println(myClassName+":getExecutionChain(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+        }
+
         return executionChain;
     }
-    
+
     /**
      * Add a Phase to the collection of executed phases for the inbound path.
      * Phases will be inserted in a LIFO data structure.
@@ -281,9 +606,13 @@
      */
     public void addInboundExecutedPhase(Handler phase)
     {
-      inboundExecutedPhases.addFirst(phase); 
+        if (inboundExecutedPhases == null)
+        {
+            inboundExecutedPhases = new LinkedList();
+        }
+        inboundExecutedPhases.addFirst(phase); 
     }
-        
+    
     /**
      * Remove the first Phase in the collection of executed phases for the
      * inbound path.
@@ -302,9 +631,20 @@
      */
     public Iterator getInboundExecutedPhases()
     {
-      return inboundExecutedPhases.iterator();
+        if (needsToBeReconciled) {
+            if (log.isWarnEnabled()) {
+                log.warn(myClassName+":getInboundExecutedPhases(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+            }
+            //System.out.println(myClassName+":getInboundExecutedPhases(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+        }
+
+        if (inboundExecutedPhases == null)
+        {
+            inboundExecutedPhases = new LinkedList();
+        }
+        return inboundExecutedPhases.iterator();
     }
-          
+      
     /**
      * Reset the list of executed inbound phases.
      * This is needed because the OutInAxisOperation currently invokes
@@ -313,9 +653,10 @@
      */
     public void resetInboundExecutedPhases()
     {
-      inboundExecutedPhases = new LinkedList();
+        inboundReset = true;
+        inboundExecutedPhases = new LinkedList();
     }
-        
+    
     /**
      * Add a Phase to the collection of executed phases for the outbound path.
      * Phases will be inserted in a LIFO data structure.
@@ -323,9 +664,13 @@
      */
     public void addOutboundExecutedPhase(Handler phase)
     {
-      outboundExecutedPhases.addFirst(phase); 
+        if (outboundExecutedPhases == null)
+        {
+            outboundExecutedPhases = new LinkedList();
+        }
+        outboundExecutedPhases.addFirst(phase); 
     }
-        
+    
     /**
      * Remove the first Phase in the collection of executed phases for the
      * outbound path.
@@ -344,9 +689,20 @@
      */
     public Iterator getOutboundExecutedPhases()
     {
-      return outboundExecutedPhases.iterator();
+        if (needsToBeReconciled) {
+            if (log.isWarnEnabled()) {
+                log.warn(myClassName+":getOutboundExecutedPhases(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+            }
+            //System.out.println(myClassName+":getOutboundExecutedPhases(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+        }
+
+        if (outboundExecutedPhases == null)
+        {
+            outboundExecutedPhases = new LinkedList();
+        }
+        return outboundExecutedPhases.iterator();
     }
-        
+    
     /**
      * Reset the list of executed outbound phases.
      * This is needed because the OutInAxisOperation currently invokes
@@ -355,9 +711,10 @@
      */
     public void resetOutboundExecutedPhases()
     {
-      outboundExecutedPhases = new LinkedList();
+        outboundReset = true;
+        outboundExecutedPhases = new LinkedList();
     }
-    
+      
     /**
      * @return Returns EndpointReference.
      */
@@ -510,6 +867,13 @@
     }
 
     public OperationContext getOperationContext() {
+        if (needsToBeReconciled) {
+            if (log.isWarnEnabled()) {
+                log.warn(myClassName+":getOperationContext(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+            }
+            //System.out.println(myClassName+":getOperationContext(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+        }
+
         return operationContext;
     }
 
@@ -570,6 +934,13 @@
      * @return the value of the property, or null if the property is not found
      */
     public Object getProperty(String name) {
+        if (needsToBeReconciled) {
+            if (log.isWarnEnabled()) {
+                log.warn(myClassName+":getProperty(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+            }
+            //System.out.println(myClassName+":getProperty(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+        }
+
         // search in my own options
         Object obj = options.getProperty(name);
         if (obj != null) {
@@ -663,6 +1034,13 @@
      * @return Returns ServiceContext.
      */
     public ServiceContext getServiceContext() {
+        if (needsToBeReconciled) {
+            if (log.isWarnEnabled()) {
+                log.warn(myClassName+":getServiceContext(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+            }
+            //System.out.println(myClassName+":getServiceContext(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+        }
+
         return serviceContext;
     }
 
@@ -674,6 +1052,13 @@
     }
 
     public ServiceGroupContext getServiceGroupContext() {
+        if (needsToBeReconciled) {
+            if (log.isWarnEnabled()) {
+                log.warn(myClassName+":getServiceGroupContext(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+            }
+            //System.out.println(myClassName+":getServiceGroupContext(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+        }
+
         return serviceGroupContext;
     }
 
@@ -711,6 +1096,13 @@
      * @return Returns TransportInDescription.
      */
     public TransportInDescription getTransportIn() {
+        if (needsToBeReconciled) {
+            if (log.isWarnEnabled()) {
+                log.warn(myClassName+":getTransportIn(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+            }
+            //System.out.println(myClassName+":getTransportIn(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+        }
+
         return transportIn;
     }
 
@@ -718,6 +1110,13 @@
      * @return Returns TransportOutDescription.
      */
     public TransportOutDescription getTransportOut() {
+        if (needsToBeReconciled) {
+            if (log.isWarnEnabled()) {
+                log.warn(myClassName+":getTransportOut(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+            }
+            //System.out.println(myClassName+":getTransportOut(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+        }
+
         return transportOut;
     }
 
@@ -738,7 +1137,7 @@
     public boolean isDoingREST() {
         return doingREST;
     }
-
+    
     /**
      * @return Returns boolean.
      */
@@ -797,6 +1196,13 @@
     }
 
     public AxisMessage getAxisMessage() {
+        if (reconcileAxisMessage) {
+            if (log.isWarnEnabled()) {
+                log.warn(myClassName+":getAxisMessage(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+            }
+            //System.out.println(myClassName+":getAxisMessage(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+        }
+
         return axisMessage;
     }
 
@@ -810,13 +1216,20 @@
 
     public void setAxisService(AxisService axisService) {
         this.axisService = axisService;
-        this.axisServiceGroup = (AxisServiceGroup) this.axisService.getParent();
+        if (this.axisService != null)
+        	this.axisServiceGroup = (AxisServiceGroup)this.axisService.getParent();
+        else
+        	this.axisServiceGroup = null;
     }
 
+    /*
+     * note setAxisServiceGroup() does not verify that the service is associated with the service group!
+     */
     public void setAxisServiceGroup(AxisServiceGroup axisServiceGroup) {
-        if (axisServiceGroup != null) {
-            this.axisServiceGroup = axisServiceGroup;
-        }
+        // need to set the axis service group object to null when necessary
+        // for example, when extracting the message context object from 
+        // the object graph
+        this.axisServiceGroup = axisServiceGroup;
     }
 
     /**
@@ -847,7 +1260,7 @@
     public void setDoingREST(boolean b) {
         doingREST = b;
     }
-
+    
     /**
      * @param b
      */
@@ -861,17 +1274,19 @@
     public void setEnvelope(SOAPEnvelope envelope) throws AxisFault {
         this.envelope = envelope;
 
-        String soapNamespaceURI = envelope.getNamespace().getNamespaceURI();
+        if (this.envelope != null) {
+            String soapNamespaceURI = envelope.getNamespace().getNamespaceURI();
 
-        if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI
-                .equals(soapNamespaceURI)) {
-            isSOAP11 = false;
-        } else if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI
-                .equals(soapNamespaceURI)) {
-            isSOAP11 = true;
-        } else {
-            throw new AxisFault(
-                    "Unknown SOAP Version. Current Axis handles only SOAP 1.1 and SOAP 1.2 messages");
+            if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI
+                    .equals(soapNamespaceURI)) {
+                isSOAP11 = false;
+            } else if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI
+                    .equals(soapNamespaceURI)) {
+                isSOAP11 = true;
+            } else {
+                throw new AxisFault(
+                        "Unknown SOAP Version. Current Axis handles only SOAP 1.1 and SOAP 1.2 messages");
+            }
         }
     }
 
@@ -918,18 +1333,20 @@
     }
 
     /**
-     * @param context
+     * @param context The OperationContext
      */
     public void setOperationContext(OperationContext context) {
+        // allow setting the fields to null
+        // useful when extracting the messge context from the object graph
         operationContext = context;
 
-        if ((serviceContext != null) && (operationContext.getParent() == null)) {
-            operationContext.setParent(serviceContext);
-        }
-
         this.setParent(operationContext);
 
         if (operationContext != null) {
+            if ((serviceContext != null) && (operationContext.getParent() == null)) {
+                operationContext.setParent(serviceContext);
+            }
+
             this.setAxisOperation(operationContext.getAxisOperation());
         }
     }
@@ -980,21 +1397,29 @@
      * @param context
      */
     public void setServiceContext(ServiceContext context) {
+
+        // allow the service context to be set to null
+        // this allows the message context object to be extraced from
+        // the object graph
+
         serviceContext = context;
-        if ((operationContext != null)
-                && (operationContext.getParent() != null)) {
-            operationContext.setParent(context);
-        }
-        // setting configcontext using configuration context in service context
-        if (configurationContext == null) {
-            // setting configcontext
-            configurationContext = context.getConfigurationContext();
-        }
-        if (serviceGroupContext == null) {
-            // setting service group context
-            serviceGroupContext = context.getServiceGroupContext();
+
+        if (serviceContext != null) {
+            if ((operationContext != null)
+                    && (operationContext.getParent() != null)) {
+                operationContext.setParent(context);
+            }
+            // setting configcontext using configuration context in service context
+            if (configurationContext == null) {
+                // setting configcontext
+                configurationContext = context.getConfigurationContext();
+            }
+            if (serviceGroupContext == null) {
+                // setting service group context
+                serviceGroupContext = context.getServiceGroupContext();
+            }
+            this.setAxisService(context.getAxisService());
         }
-        this.setAxisService(context.getAxisService());
     }
 
     /**
@@ -1007,8 +1432,16 @@
     }
 
     public void setServiceGroupContext(ServiceGroupContext serviceGroupContext) {
+        // allow the service group context to be set to null
+        // this allows the message context object to be extraced from
+        // the object graph
+
         this.serviceGroupContext = serviceGroupContext;
-        this.axisServiceGroup = serviceGroupContext.getDescription();
+
+        if (this.serviceGroupContext != null)
+        {
+            this.axisServiceGroup = serviceGroupContext.getDescription();
+        }
     }
 
     public void setServiceGroupContextId(String serviceGroupContextId) {
@@ -1044,7 +1477,7 @@
     }
 
     /**
-     * Method getExecutionChain
+     * setWSAAction
      */
     public void setWSAAction(String actionURI) {
         options.setAction(actionURI);
@@ -1064,6 +1497,13 @@
     }
 
     public Options getOptions() {
+        if (needsToBeReconciled) {
+            if (log.isWarnEnabled()) {
+                log.warn(myClassName+":getOptions(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+            }
+            //System.out.println(myClassName+":getOptions(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+        }
+
         return options;
     }
 
@@ -1093,6 +1533,13 @@
 
 
     public Policy getEffectivePolicy() {
+        if (needsToBeReconciled) {
+            if (log.isWarnEnabled()) {
+                log.warn(myClassName+":getEffectivePolicy(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+            }
+            //System.out.println(myClassName+":getEffectivePolicy(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+        }
+
         if (axisMessage != null) {
             return axisMessage.getPolicyInclude().getEffectivePolicy();
         }
@@ -1107,6 +1554,13 @@
 
 
     public boolean isEngaged(QName moduleName) {
+        if (needsToBeReconciled) {
+            if (log.isWarnEnabled()) {
+                log.warn(myClassName+":isEngaged(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+            }
+            //System.out.println(myClassName+":isEngaged(): ****WARNING**** MessageContext.activate(configurationContext) needs to be invoked.");
+        }
+
         boolean enegage;
         if (configurationContext != null) {
             AxisConfiguration axisConfig = configurationContext.getAxisConfiguration();
@@ -1198,5 +1652,3306 @@
             attachments = new Attachments();
         }
         return attachments.getDataHandler(contentID);
+    }
+
+
+    
+    /* ===============================================================
+     * SelfManagedData Section
+     * ===============================================================
+     */
+    
+    /*
+     * character to delimit strings
+     */
+    private static final String selfManagedDataDelimiter = "*";
+    
+
+    /**
+     * Set up a unique key in the form of
+     * <OL>
+     * <LI>the class name for the class that owns the key
+     * <LI>delimitor
+     * <LI>the key as a string
+     * <LI>delimitor
+     * <LI>the key's hash code as a string
+     * </OL>
+     * 
+     * @param clazz  The class that owns the supplied key
+     * @param key    The key
+     * 
+     * @return A string key
+     */
+    private String generateSelfManagedDataKey(Class clazz, Object key) 
+    {
+    	return clazz.getName()+selfManagedDataDelimiter+key.toString()+selfManagedDataDelimiter+Integer.toString(key.hashCode());
+    }
+    
+    /**
+     * Get the class name from the key generated by generateSelfManagedDataKey()
+     * 
+     * @param key    The key
+     * 
+     * @return The class name
+     */
+    private String getClassNameFromSelfManagedDataKey(String key) 
+    {
+    	StringTokenizer tokenizer = new StringTokenizer(key, selfManagedDataDelimiter);
+    	return tokenizer.nextToken();
+    }
+    
+    /**
+     * Add a key-value pair of self managed data to the set associated with 
+     * this message context.  
+     * <P>
+     * This is primarily intended to allow handlers to manage their own 
+     * message-specific data when the message context is saved/restored.
+     * 
+     * @param clazz   The class of the caller that owns the key-value pair
+     * @param key     The key for this data object
+     * @param value   The data object 
+     */
+    public void setSelfManagedData(Class clazz, Object key, Object value)
+    {
+    	if (selfManagedDataMap == null)
+        {
+    		selfManagedDataMap = new LinkedHashMap();
+    	}
+
+    	// make sure we have a unique key and a delimiter so we can
+    	// get the classname and hashcode for serialization/deserialization
+    	selfManagedDataMap.put(generateSelfManagedDataKey(clazz, key), value);
+    }
+    
+    /**
+     * Retrieve a value of self managed data previously saved with the specified key.
+     * 
+     * @param clazz  The class of the caller that owns the key-value pair
+     * @param key    The key for the data
+     *
+     * @return The data object associated with the key, or NULL if not found
+     */
+    public Object getSelfManagedData(Class clazz, Object key)
+    {
+    	if (selfManagedDataMap != null)
+        {
+    		return selfManagedDataMap.get(generateSelfManagedDataKey(clazz, key));
+        }
+    	return null;
+    }
+    
+    /**
+     * Check to see if the key for the self managed data is available
+     *
+     * @param clazz  The class of the caller that owns the key-value pair
+     * @param key    The key to look for 
+     *
+     * @return TRUE if the key exists, FALSE otherwise
+     */
+    public boolean containsSelfManagedDataKey(Class clazz, Object key)
+    {
+    	if (selfManagedDataMap != null)
+        {
+    		return selfManagedDataMap.containsKey(generateSelfManagedDataKey(clazz, key));
+        }
+    	return false;
+    }
+    
+    /**
+     * Removes the mapping of the specified key if the specified key 
+     * has been set for self managed data
+     * 
+     * @param clazz   The class of the caller that owns the key-value pair
+     * @param key     The key of the object to be removed 
+     */
+    public void removeSelfManagedData(Class clazz, Object key) 
+    {
+    	if (selfManagedDataMap != null)
+        {
+    		selfManagedDataMap.remove(generateSelfManagedDataKey(clazz, key));
+        }
+    }
+    
+    /**
+     * Flatten the phase list into a list of just unique handler instances
+     *
+     * @param list   the list of handlers
+     * @param map    users should pass null as this is just a holder for the recursion
+     *
+     * @return a list of unigue object instances
+     */
+    private ArrayList flattenPhaseListToHandlers(ArrayList list, LinkedHashMap map)
+    {
+    	
+    	if (map == null)
+        {
+    		map = new LinkedHashMap();
+        }
+    	
+        Iterator it = list.iterator();
+		while (it.hasNext())
+        {
+			Handler handler = (Handler)it.next();
+
+            String key = null;
+            if (handler != null)
+            {
+                key = handler.getClass().getName() +"@"+ handler.hashCode();
+            }
+
+			if (handler instanceof Phase)
+            {
+                // add its handlers to the list
+				flattenHandlerList(((Phase)handler).getHandlers(), map);
+            }
+			else
+            {
+                // if the same object is already in the list,
+                // then it won't be in the list multiple times
+				map.put(key, handler);
+            }
+		}
+		
+        if (log.isTraceEnabled())
+        {
+            Iterator it2 = map.keySet().iterator();
+            while (it2.hasNext())
+            {
+                Object key = it2.next();
+                Handler value = (Handler) map.get(key);
+                String name = value.getName();
+                log.trace(myClassName+":flattenPhaseListToHandlers():  key ["+(String)key+"]    handler name ["+name+"]");
+                //System.out.println(myClassName+":flattenPhaseListToHandlers():  key ["+(String)key+"]    handler name ["+name+"]");
+            }
+        }
+
+
+		return new ArrayList(map.values());
+    }
+
+
+    /**
+     * Flatten the handler list into just unique handler instances
+     * including phase instances.
+     *
+     * @param list   the list of handlers/phases
+     * @param map    users should pass null as this is just a holder for the recursion
+     *
+     * @return a list of unigue object instances
+     */
+    private ArrayList flattenHandlerList(ArrayList list, LinkedHashMap map)
+    {
+    	
+    	if (map == null)
+        {
+    		map = new LinkedHashMap();
+        }
+    	
+        Iterator it = list.iterator();
+		while( it.hasNext() )
+        {
+			Handler handler = (Handler)it.next();
+
+            String key = null;
+            if (handler != null)
+            {
+                key = handler.getClass().getName() +"@"+ handler.hashCode();
+            }
+
+			if (handler instanceof Phase)
+            {
+                // put the phase in the list
+				map.put(key, handler);
+
+                // add its handlers to the list
+				flattenHandlerList(((Phase)handler).getHandlers(), map);
+            }
+			else
+            {
+                // if the same object is already in the list,
+                // then it won't be in the list multiple times
+				map.put(key, handler);
+            }
+		}
+		
+		return new ArrayList(map.values());
+    }
+
+
+    /**
+     * Calls the serializeSelfManagedData() method of each handler that 
+     * implements the <bold>SelfManagedDataManager</bold> interface.
+     * Handlers for this message context are identified via the 
+     * executionChain list.
+     *
+     * @param out The output stream
+	 * 
+	 */
+    private void serializeSelfManagedData(ObjectOutput out) 
+    {
+        if (log.isTraceEnabled())
+        {
+            log.trace(myClassName+":serializeSelfManagedData(): BEGIN");
+        }
+        //System.out.println(myClassName+":serializeSelfManagedData(): BEGIN");
+
+
+        selfManagedDataHandlerCount = 0;
+
+        try
+        {
+            if ((selfManagedDataMap == null)
+                || (executionChain == null)
+                || (selfManagedDataMap.size() == 0)
+                || (executionChain.size() == 0))
+            {
+                out.writeBoolean(ObjectStateUtils.EMPTY_OBJECT);
+
+                if (log.isTraceEnabled())
+                {
+                    log.trace(myClassName+":serializeSelfManagedData(): No data : END");
+                }
+                //System.out.println(myClassName+":serializeSelfManagedData(): No data : END");
+
+                return;
+            }
+
+            // let's create a temporary list with the handlers
+            ArrayList flatExecChain = flattenPhaseListToHandlers(executionChain, null);
+
+            //System.out.println(myClassName+":serializeSelfManagedData():  number of handlers to check ["+flatExecChain.size()+"]");
+
+            //ArrayList selfManagedDataHolderList = serializeSelfManagedDataHelper(flatExecChain.iterator(), new ArrayList()); 
+            ArrayList selfManagedDataHolderList = serializeSelfManagedDataHelper(flatExecChain);
+
+            if (selfManagedDataHolderList.size() == 0)
+            {
+                out.writeBoolean(ObjectStateUtils.EMPTY_OBJECT);
+
+                if (log.isTraceEnabled())
+                {
+                    log.trace(myClassName+":serializeSelfManagedData(): No data : END");
+                }
+                //System.out.println(myClassName+":serializeSelfManagedData(): No data : END");
+
+                return;
+            }
+
+            out.writeBoolean(ObjectStateUtils.ACTIVE_OBJECT);
+
+            // SelfManagedData can be binary so won't be able to treat it as a 
+            // string - need to treat it as a byte []
+
+            // how many handlers actually 
+            // returned serialized SelfManagedData
+            out.writeInt(selfManagedDataHolderList.size()); 
+
+            for (int i = 0; i < selfManagedDataHolderList.size(); i++)
+            {
+                out.writeObject(selfManagedDataHolderList.get(i));
+            }
+
+        }
+        catch (IOException e)
+        {
+            if (log.isTraceEnabled())
+            {
+                log.trace("MessageContext:serializeSelfManagedData(): Exception ["+e.getClass().getName()+"]  description ["+e.getMessage()+"]"); 
+
+                e.printStackTrace();
+            }
+            //System.out.println("MessageContext:serializeSelfManagedData(): Exception ["+e.getClass().getName()+"]  description ["+e.getMessage()+"]"); 
+
+        }
+
+        if (log.isTraceEnabled())
+        {
+            log.trace(myClassName+":serializeSelfManagedData(): END");
+        }
+        //System.out.println(myClassName+":serializeSelfManagedData(): END");
+    }
+    
+
+    /**
+	 * This is the helper method to do the recursion for serializeSelfManagedData()
+     *
+     * @param it                         The Iterator
+     * @param selfManagedDataHolderList  The array list
+	 * 
+	 * @return ArrayList
+	 */
+    //private ArrayList serializeSelfManagedDataHelper(ArrayList handlers, ArrayList selfManagedDataHolderList)
+    private ArrayList serializeSelfManagedDataHelper(ArrayList handlers)
+    {
+        //System.out.println("MessageContext:serializeSelfManagedDataHelper():  number of handlers ["+handlers.size()+"]");
+
+        ArrayList selfManagedDataHolderList = new ArrayList();
+        Iterator it = handlers.iterator();
+
+    	try 
+        {
+    		while (it.hasNext())
+            {
+    			Handler handler = (Handler)it.next();
+                
+    			//if (handler instanceof Phase)
+                //{
+    			//	selfManagedDataHolderList = serializeSelfManagedDataHelper(((Phase)handler).getHandlers().iterator(), selfManagedDataHolderList);
+                //}
+    			//else if (SelfManagedDataManager.class.isAssignableFrom(handler.getClass()))
+                if (SelfManagedDataManager.class.isAssignableFrom(handler.getClass()))
+                {
+                    // only call the handler's serializeSelfManagedData if it implements SelfManagedDataManager
+
+                    if (log.isTraceEnabled())
+                    {
+                        log.trace("MessageContext:serializeSelfManagedDataHelper(): calling handler  ["+handler.getClass().getName()+"]  name ["+handler.getName().toString()+"]   serializeSelfManagedData method");
+                    }
+                    //System.out.println("MessageContext:serializeSelfManagedDataHelper(): calling handler  ["+handler.getClass().getName()+"]  name ["+handler.getName().toString()+"]   serializeSelfManagedData method");
+
+
+            		ByteArrayOutputStream baos_fromHandler = ((SelfManagedDataManager)handler).serializeSelfManagedData(this);
+
+            		if (baos_fromHandler != null)
+                    {
+            			baos_fromHandler.close();
+
+            			try
+                        {
+            				SelfManagedDataHolder selfManagedDataHolder = new SelfManagedDataHolder(handler.getClass().getName(), handler.getName().toString(), baos_fromHandler.toByteArray());
+            				selfManagedDataHolderList.add(selfManagedDataHolder);
+            				selfManagedDataHandlerCount++;
+                        }
+            			catch (Exception exc)
+                        {
+            				log.warn("MessageContext:serializeSelfManagedData(): exception ["+exc.getClass().getName()+"]["+exc.getMessage()+"]  in setting up SelfManagedDataHolder object for ["+handler.getClass().getName()+" / "+handler.getName().toString()+"] ");
+
+            				//System.out.println("MessageContext:serializeSelfManagedData(): exception ["+exc.getClass().getName()+"]["+exc.getMessage()+"]  in setting up SelfManagedDataHolder object for ["+handler.getClass().getName()+" / "+handler.getName().toString()+"] ");
+
+            				exc.printStackTrace();
+
+            			}
+            		}
+            	}
+    		}
+
+    		return selfManagedDataHolderList;
+        }
+        catch (Exception ex)
+        {
+        	log.warn("MessageContext:serializeSelfManagedData(): exception ["+ex.getClass().getName()+"]["+ex.getMessage()+"]");
+
+        	//System.out.println("MessageContext:serializeSelfManagedData(): exception ["+ex.getClass().getName()+"]["+ex.getMessage()+"]");
+
+            ex.printStackTrace();
+
+            return null;
+        }
+        
+    }
+    
+    /**
+     * During deserialization, the executionChain will be
+     * re-constituted before the SelfManagedData is restored.
+     * This means the handler instances are already available.
+     * This method lets us find the handler instance from the
+     * executionChain so we can call each one's
+     * deserializeSelfManagedData method.
+     * 
+     * @param it             The iterator from the executionChain object
+     * @param classname      The class name
+     * @param qNameAsString  The QName in string form 
+     *                  
+     * @return SelfManagedDataManager handler
+     */
+    private SelfManagedDataManager deserialize_getHandlerFromExecutionChain(Iterator it, String classname, String qNameAsString)
+    {
+    	SelfManagedDataManager handler_toreturn = null;
+
+    	try 
+        {
+    		while ((it.hasNext()) && (handler_toreturn == null)) 
+            {
+    			Handler handler = (Handler)it.next();
+
+    			if (handler instanceof Phase)
+                {
+    				handler_toreturn = deserialize_getHandlerFromExecutionChain(((Phase)handler).getHandlers().iterator(), classname, qNameAsString);
+    			}
+    			else if ((handler.getClass().getName().equals(classname))
+    					&& (handler.getName().toString().equals(qNameAsString)))
+                {
+    				handler_toreturn = (SelfManagedDataManager)handler;
+    			}
+    		}
+    		return handler_toreturn;
+        }
+    	catch (ClassCastException e) 
+        {
+    		// Doesn't seem likely to happen, but just in case...
+    		// A handler classname in the executionChain matched up with our parameter
+    		// classname, but the existing class in the executionChain is a different
+    		// implementation than the one we saved during serializeSelfManagedData.
+    		// NOTE: the exception gets absorbed!
+
+        	log.warn("MessageContext:deserialize_getHandlerFromExecutionChain(): ClassCastException thrown: " + e.getMessage());
+
+        	//System.out.println("MessageContext:deserialize_getHandlerFromExecutionChain(): ClassCastException thrown: " + e.getMessage());
+
+            e.printStackTrace();
+
+            return null;
+    	}
+    }
+    
+
+    /*
+     * We don't need to create new instances of the handlers
+     * since the executionChain is rebuilt after readExternal().
+     * We just have to find them in the executionChain and
+     * call each handler's deserializeSelfManagedData method.
+     */
+    private void deserializeSelfManagedData() throws IOException
+    {
+    	try 
+        {
+    		for (int i = 0; (selfManagedDataListHolder != null) && (i < selfManagedDataListHolder.size()); i++)
+            {
+    			SelfManagedDataHolder selfManagedDataHolder = (SelfManagedDataHolder)selfManagedDataListHolder.get(i);
+
+    			String classname = selfManagedDataHolder.getClassname();
+    			String qNameAsString = selfManagedDataHolder.getId();
+
+    			SelfManagedDataManager handler = deserialize_getHandlerFromExecutionChain(executionChain.iterator(), classname, qNameAsString);
+
+    			if (handler == null)
+                {
+    				log.warn(myClassName+":deserializeSelfManagedData():  ["+classname+"]  was not found in the executionChain associated with the message context.");
+
+    				//System.out.println(myClassName+":deserializeSelfManagedData():  ["+classname+"]  was not found in the executionChain associated with the message context.");
+
+    				throw new IOException("The class ["+classname+"] was not found in the executionChain associated with the message context.");
+    			}
+
+    			ByteArrayInputStream handlerData = new ByteArrayInputStream(selfManagedDataHolder.getData());
+
+    			// the handler implementing SelfManagedDataManager is responsible for repopulating
+    			// the SelfManagedData in the MessageContext (this)
+
+                if (log.isTraceEnabled())
+                {
+                    log.trace(myClassName+":deserializeSelfManagedData(): calling handler ["+classname+"] ["+qNameAsString+"]  deserializeSelfManagedData method");
+                }
+    			//System.out.println(myClassName+":deserializeSelfManagedData(): calling handler ["+classname+"] ["+qNameAsString+"]  deserializeSelfManagedData method");
+
+    			handler.deserializeSelfManagedData(handlerData, this);
+    			handler.restoreTransientData(this);
+    		}
+        }
+    	catch (IOException ioe)
+        {
+        	log.warn(myClassName+":deserializeSelfManagedData(): IOException thrown: " + ioe.getMessage());
+
+        	//System.out.println(myClassName+":deserializeSelfManagedData(): IOException thrown: " + ioe.getMessage());
+
+            ioe.printStackTrace();
+
+    		throw ioe;
+    	}
+    	
+    }
+
+
+
+    /* ===============================================================
+     * Externalizable support 
+     * ===============================================================
+     */
+    
+
+    /**
+     * Save the contents of this MessageContext instance.
+     * <p>
+     * NOTE: Transient fields and static fields are not saved.
+     *       Also, objects that represent "static" data are
+     *       not saved, except for enough information to be
+     *       able to find matching objects when the message
+     *       context is re-constituted.
+     *
+     * @param out    The stream to write the object contents to
+     * 
+     * @exception IOException
+     */
+    public void writeExternal(ObjectOutput out) throws IOException
+    {
+        if (log.isTraceEnabled())
+        {
+            log.trace(myClassName+":writeExternal():  BEGIN  ");
+        }
+        //System.out.println(myClassName+":writeExternal():  BEGIN  ");
+
+
+        //---------------------------------------------------------
+        // in order to handle future changes to the message 
+        // context definition, be sure to maintain the 
+        // object level identifiers
+        //---------------------------------------------------------
+        // serialization version ID
+        out.writeLong(serialVersionUID);
+
+        // revision ID
+        out.writeInt(revisionID);
+
+        //---------------------------------------------------------
+        // various simple fields
+        //---------------------------------------------------------
+
+        // the type of execution flow for the message context
+        out.writeInt(FLOW);
+
+        // various flags
+        out.writeBoolean(processingFault);
+        out.writeBoolean(paused);
+        out.writeBoolean(outputWritten);
+        out.writeBoolean(newThreadRequired);
+        out.writeBoolean(isSOAP11);
+        out.writeBoolean(doingREST);
+        out.writeBoolean(doingMTOM);
+        out.writeBoolean(doingSwA);
+        out.writeBoolean(responseWritten);
+        out.writeBoolean(serverSide);
+
+        out.writeLong(getLastTouchedTime());
+
+        boolean persistWithOptimizedMTOM = (getProperty(MTOMConstants.ATTACHMENTS) != null);
+        out.writeBoolean(persistWithOptimizedMTOM);
+        
+        //---------------------------------------------------------
+        // message
+        //---------------------------------------------------------
+
+        // Just in case anything else is added here, notice that in the case
+        // of MTOM, something is written to the stream in middle of the envelope
+        // serialization logic below
+
+        // make sure message attachments are handled
+
+        if (envelope != null)
+        {
+            String msgClass = envelope.getClass().getName();
+
+            ByteArrayOutputStream msgBuffer = new ByteArrayOutputStream();
+
+            try 
+            {
+                // use a non-destructive method on the soap message
+
+                // We don't need to write to a separate byte array
+                // unless we want to log the message
+                ByteArrayOutputStream msgData = new ByteArrayOutputStream();
+
+                OMOutputFormat outputFormat = new OMOutputFormat();
+
+                outputFormat.setSOAP11(isSOAP11);
+
+                if (persistWithOptimizedMTOM)
+                {
+                    outputFormat.setDoOptimize(true);
+
+                    //Notice that we're writing this next bit out to the
+                    //serialized stream and not the baos
+                    out.writeUTF(outputFormat.getContentType());
+                }
+
+                // this will be expensive because it builds the OM tree
+                envelope.serialize(msgData, outputFormat);
+                
+                msgBuffer.write(msgData.toByteArray() ,0, msgData.size());
+
+                if (log.isTraceEnabled())
+                {
+                    log.trace(myClassName+":writeExternal(): msg data ["+msgData+"]");
+                }
+
+                //System.out.println(myClassName+":writeExternal(): msg data ["+msgData+"]");
+
+            }
+            catch (Exception e) 
+            {
+                log.warn(myClassName+":writeExternal(): can not serialize the SOAP message ***Exception***  ["+e.getClass().getName()+" : "+e.getMessage()+"]");
+
+                //System.out.println(myClassName+":writeExternal(): can not serialize the SOAP message ***Exception***  ["+e.getClass().getName()+" : "+e.getMessage()+"]");
+            }
+
+            //---------------------------------------------
+            // get the character encoding for the message
+            //---------------------------------------------
+            String charSetEnc = (String) getProperty(MessageContext.CHARACTER_SET_ENCODING); 
+
+            if (charSetEnc == null) 
+            {
+                OperationContext opContext = getOperationContext();
+                if (opContext != null)
+                {
+                    charSetEnc = (String) opContext.getProperty(MessageContext.CHARACTER_SET_ENCODING);
+                }
+            }
+
+            if (charSetEnc == null)
+            {
+                charSetEnc = MessageContext.DEFAULT_CHAR_SET_ENCODING;
+            }
+
+            //---------------------------------------------
+            // get the soap namespace uri
+            //---------------------------------------------
+            String namespaceURI = envelope.getNamespace().getName();
+
+
+            // write out the following information, IN ORDER:
+            //           the class name
+            //           the active or empty flag
+            //           the data length
+            //           the data   
+            out.writeUTF(msgClass);
+
+            int msgSize = msgBuffer.size();
+
+            if (msgSize != 0)
+            {
+                out.writeBoolean(ObjectStateUtils.ACTIVE_OBJECT);
+                out.writeUTF(charSetEnc);
+                out.writeUTF(namespaceURI);
+                out.writeInt(msgSize);
+                out.write(msgBuffer.toByteArray());
+
+                if (log.isTraceEnabled())
+                {
+                    log.trace(myClassName+":writeExternal(): msg  charSetEnc=["+charSetEnc+"]  namespaceURI=["+namespaceURI+"]  msgSize=["+msgSize+"]");
+                }
+                //System.out.println(myClassName+":writeExternal(): msg  charSetEnc=["+charSetEnc+"]  namespaceURI=["+namespaceURI+"]  msgSize=["+msgSize+"]");
+            }
+            else
+            {
+                // the envelope is null
+                out.writeBoolean(ObjectStateUtils.EMPTY_OBJECT);
+
+                if (log.isTraceEnabled())
+                {
+                    log.trace(myClassName+":writeExternal(): msg  is Empty");
+                }
+                //System.out.println(myClassName+":writeExternal(): msg  is Empty");
+            }
+
+            // close out internal stream
+            msgBuffer.close();
+        }
+        else
+        {
+            // the envelope is null
+            out.writeUTF("MessageContext.envelope");
+            out.writeBoolean(ObjectStateUtils.EMPTY_OBJECT);
+
+            if (log.isTraceEnabled())
+            {
+                log.trace(myClassName+":writeExternal(): msg  is Empty");
+            }
+            //System.out.println(myClassName+":writeExternal(): msg  is Empty");
+        }
+
+
+        //---------------------------------------------------------
+        // ArrayList executionChain 
+        //     handler and phase related data 
+        //---------------------------------------------------------
+        // The strategy is to save some metadata about each
+        // member of the list and the order of the list.
+        // Then when the message context is re-constituted,
+        // try to match up with phases and handlers on the 
+        // engine.
+        //    
+        // Non-null list:
+        //    UTF          - description string
+        //    boolean      - active flag
+        //    int          - current handler index
+        //    int          - current phase index
+        //    int          - expected number of entries in the list
+        //    objects      - MetaDataEntry object per list entry
+        //                        last entry will be empty MetaDataEntry
+        //                        with MetaDataEntry.LAST_ENTRY marker
+        //    int          - adjusted number of entries in the list
+        //                        includes the last empty entry
+        //    
+        // Empty list:
+        //    UTF          - description string
+        //    boolean      - empty flag
+        //---------------------------------------------------------
+        String execChainDesc = "Messagecontext.executionChain";
+
+        int listSize = 0;
+
+        if (executionChain != null)
+        {
+            listSize = executionChain.size();
+        }
+
+        if (listSize > 0)
+        {
+            // start writing data to the output stream
+            out.writeUTF(execChainDesc);
+            out.writeBoolean(ObjectStateUtils.ACTIVE_OBJECT);
+            out.writeInt(currentHandlerIndex);
+            out.writeInt(currentPhaseIndex);
+            out.writeInt(listSize);
+
+            // put the metadata on each member of the list into a buffer
+
+            // match the current index with the actual saved list
+            int executionChainEntry = 0;
+            int nextIndex = 0;
+
+            Iterator i = executionChain.iterator();
+
+            while (i.hasNext())
+            {
+                Object obj = i.next();
+                String objClass = obj.getClass().getName();
+                int objClassLength = objClass.length();
+
+                // start the meta data entry for this object
+                MetaDataEntry mdEntry = new MetaDataEntry();
+                mdEntry.setClassName(objClass);
+
+                // get the correct object-specific name
+                String qnameAsString = null;
+
+                if (obj instanceof Phase)
+                {
+                    Phase phaseObj = (Phase)obj;
+                    qnameAsString = phaseObj.getName().toString();
+
+                    // add the list of handlers to the meta data
+                    setupPhaseList(phaseObj, mdEntry);
+                }
+                else if (obj instanceof Handler)
+                {
+                    Handler handlerObj = (Handler)obj;
+                    qnameAsString = handlerObj.getName().toString();
+                }
+                else
+                {
+                    // TODO: will there be any other kinds of objects in the execution Chain?
+                    qnameAsString = "NULL";
+                }
+
+                mdEntry.setQName(qnameAsString);
+
+
+                // update the index for the entry in the chain
+                executionChainEntry++;
+
+                if (log.isTraceEnabled())
+                {
+                    log.trace(myClassName+":writeExternal(): ***BEFORE OBJ WRITE*** executionChain entry class ["+objClass+"] qname ["+qnameAsString+"]");
+                }
+                //System.out.println(myClassName+":writeExternal(): ***BEFORE OBJ WRITE*** executionChain entry class ["+objClass+"] qname ["+qnameAsString+"]");
+
+                ObjectStateUtils.writeObject(out, mdEntry, "Messagecontext.executionChain:entry class ["+objClass+"] qname ["+qnameAsString+"]");
+
+                // update the index so that the index 
+                // now indicates the next entry that
+                // will be attempted
+                nextIndex++;
+
+                if (log.isTraceEnabled())
+                {
+                    log.trace(myClassName+":writeExternal(): ***AFTER OBJ WRITE*** executionChain entry class ["+objClass+"] qname ["+qnameAsString+"]");
+                }
+                //System.out.println(myClassName+":writeExternal(): ***AFTER OBJ WRITE*** executionChain entry class ["+objClass+"] qname ["+qnameAsString+"]");
+
+            } // end while entries in execution chain
+
+            // done with the entries in the execution chain
+            // add the end-of-list marker
+            MetaDataEntry lastEntry = new MetaDataEntry();
+            lastEntry.setClassName(MetaDataEntry.END_OF_LIST);
+
+            ObjectStateUtils.writeObject(out, lastEntry, "Messagecontext.executionChain:  last entry ");
+            nextIndex++;
+
+            // nextIndex also gives us the number of entries 
+            // that were actually saved as opposed to the 
+            // number of entries in the executionChain
+            out.writeInt(nextIndex);         
+
+        }
+        else
+        {
+            // general case: handle "null" or "empty"
+
+            out.writeUTF(execChainDesc);
+            out.writeBoolean(ObjectStateUtils.EMPTY_OBJECT);
+
+            if (log.isTraceEnabled())
+            {
+                log.trace(myClassName+":writeExternal(): executionChain is NULL");
+            }
+            //System.out.println(myClassName+":writeExternal(): executionChain is NULL");
+
+        }
+
+
+        //---------------------------------------------------------
+        // LinkedList inboundExecutedPhases 
+        //---------------------------------------------------------
+        // The strategy is to save some metadata about each
+        // member of the list and the order of the list.
+        // Then when the message context is re-constituted,
+        // try to match up with phases and handlers on the 
+        // engine.
+        //    
+        // Non-null list:
+        //    UTF          - description string
+        //    boolean      - active flag
+        //    int          - expected number of entries in the list
+        //    objects      - MetaDataEntry object per list entry
+        //                        last entry will be empty MetaDataEntry
+        //                        with MetaDataEntry.LAST_ENTRY marker
+        //    int          - adjusted number of entries in the list
+        //                        includes the last empty entry
+        //    
+        // Empty list:
+        //    UTF          - description string
+        //    boolean      - empty flag
+        //---------------------------------------------------------
+        String inExecListDesc = "Messagecontext.inboundExecutedPhases";
+
+        int inExecListSize = 0;
+
+        if (inboundExecutedPhases != null)
+        {
+            inExecListSize = inboundExecutedPhases.size();
+        }
+
+        if (inExecListSize > 0)
+        {
+            // start writing data to the output stream
+            out.writeUTF(inExecListDesc);
+            out.writeBoolean(ObjectStateUtils.ACTIVE_OBJECT);
+            out.writeInt(inExecListSize);
+
+            // put the metadata on each member of the list into a buffer
+
+            int inExecNextIndex = 0;
+
+            Iterator inIterator = inboundExecutedPhases.iterator();
+
+            while (inIterator.hasNext())
+            {
+                Object inObj = inIterator.next();
+                String inObjClass = inObj.getClass().getName();
+                int inObjClassLength = inObjClass.length();
+
+                // start the meta data entry for this object
+                MetaDataEntry inMdEntry = new MetaDataEntry();
+                inMdEntry.setClassName(inObjClass);
+
+                // get the correct object-specific name
+                String inQnameAsString = null;
+
+                if (inObj instanceof Phase)
+                {
+                    Phase inPhaseObj = (Phase)inObj;
+                    inQnameAsString = inPhaseObj.getName().toString();
+
+                    // add the list of handlers to the meta data
+                    setupPhaseList(inPhaseObj, inMdEntry);
+                }
+                else if (inObj instanceof Handler)
+                {
+                    Handler inHandlerObj = (Handler)inObj;
+                    inQnameAsString = inHandlerObj.getName().toString();
+                }
+                else
+                {
+                    // TODO: will there be any other kinds of objects in the list
+                    inQnameAsString = "NULL";
+                }
+
+                inMdEntry.setQName(inQnameAsString);
+
+
+                if (log.isTraceEnabled())
+                {
+                    log.trace(myClassName+":writeExternal(): ***BEFORE Inbound Executed List OBJ WRITE*** inboundExecutedPhases entry class ["+inObjClass+"] qname ["+inQnameAsString+"]");
+                }
+                //System.out.println(myClassName+":writeExternal(): ***BEFORE Inbound Executed List OBJ WRITE*** inboundExecutedPhases entry class ["+inObjClass+"] qname ["+inQnameAsString+"]");
+
+                ObjectStateUtils.writeObject(out, inMdEntry, "Messagecontext.inboundExecutedPhases:entry class ["+inObjClass+"] qname ["+inQnameAsString+"]");
+
+                // update the index so that the index 
+                // now indicates the next entry that
+                // will be attempted
+                inExecNextIndex++;
+
+                if (log.isTraceEnabled())
+                {
+                    log.trace(myClassName+":writeExternal(): ***AFTER Inbound Executed List OBJ WRITE*** inboundExecutedPhases entry class ["+inObjClass+"] qname ["+inQnameAsString+"]");
+                }
+                //System.out.println(myClassName+":writeExternal(): ***AFTER Inbound Executed List OBJ WRITE*** inboundExecutedPhases entry class ["+inObjClass+"] qname ["+inQnameAsString+"]");
+
+            } // end while entries in execution chain
+
+            // done with the entries in the execution chain
+            // add the end-of-list marker
+            MetaDataEntry inLastEntry = new MetaDataEntry();
+            inLastEntry.setClassName(MetaDataEntry.END_OF_LIST);
+
+            ObjectStateUtils.writeObject(out, inLastEntry, "Messagecontext.inboundExecutedPhases:  last entry ");
+            inExecNextIndex++;
+
+            // inExecNextIndex also gives us the number of entries 
+            // that were actually saved as opposed to the 
+            // number of entries in the inboundExecutedPhases
+            out.writeInt(inExecNextIndex);         
+
+        }
+        else
+        {
+            // general case: handle "null" or "empty"
+
+            out.writeUTF(inExecListDesc);
+            out.writeBoolean(ObjectStateUtils.EMPTY_OBJECT);
+
+            if (log.isTraceEnabled())
+            {
+                log.trace(myClassName+":writeExternal(): inboundExecutedPhases is NULL");
+            }
+            //System.out.println(myClassName+":writeExternal(): inboundExecutedPhases is NULL");
+
+        }
+
+
+        //---------------------------------------------------------
+        // LinkedList outboundExecutedPhases 
+        //---------------------------------------------------------
+        // The strategy is to save some metadata about each
+        // member of the list and the order of the list.
+        // Then when the message context is re-constituted,
+        // try to match up with phases and handlers on the 
+        // engine.
+        //    
+        // Non-null list:
+        //    UTF          - description string
+        //    boolean      - active flag
+        //    int          - expected number of entries in the list
+        //    objects      - MetaDataEntry object per list entry
+        //                        last entry will be empty MetaDataEntry
+        //                        with MetaDataEntry.LAST_ENTRY marker
+        //    int          - adjusted number of entries in the list
+        //                        includes the last empty entry
+        //    
+        // Empty list:
+        //    UTF          - description string
+        //    boolean      - empty flag
+        //---------------------------------------------------------
+        String outExecListDesc = "Messagecontext.outboundExecutedPhases";
+
+        int outExecListSize = 0;
+
+        if (outboundExecutedPhases != null)
+        {
+            outExecListSize = outboundExecutedPhases.size();
+        }
+
+        if (outExecListSize > 0)
+        {
+            // start writing data to the output stream
+            out.writeUTF(outExecListDesc);
+            out.writeBoolean(ObjectStateUtils.ACTIVE_OBJECT);
+            out.writeInt(outExecListSize);
+
+            // put the metadata on each member of the list into a buffer
+
+            int outExecNextIndex = 0;
+
+            Iterator outIterator = outboundExecutedPhases.iterator();
+
+            while (outIterator.hasNext())
+            {
+                Object outObj = outIterator.next();
+                String outObjClass = outObj.getClass().getName();
+                int outObjClassLength = outObjClass.length();
+
+                // start the meta data entry for this object
+                MetaDataEntry outMdEntry = new MetaDataEntry();
+                outMdEntry.setClassName(outObjClass);
+
+                // get the correct object-specific name
+                String outQnameAsString = null;
+
+                if (outObj instanceof Phase)
+                {
+                    Phase outPhaseObj = (Phase)outObj;
+                    outQnameAsString = outPhaseObj.getName().toString();
+
+                    // add the list of handlers to the meta data
+                    setupPhaseList(outPhaseObj, outMdEntry);
+                }
+                else if (outObj instanceof Handler)
+                {
+                    Handler outHandlerObj = (Handler)outObj;
+                    outQnameAsString = outHandlerObj.getName().toString();
+                }
+                else
+                {
+                    // TODO: will there be any other kinds of objects in the list
+                    outQnameAsString = "NULL";
+                }
+
+                outMdEntry.setQName(outQnameAsString);
+
+                if (log.isTraceEnabled())
+                {
+                    log.trace(myClassName+":writeExternal(): ***BEFORE Outbound Executed List OBJ WRITE*** outboundExecutedPhases entry class ["+outObjClass+"] qname ["+outQnameAsString+"]");
+                }
+                //System.out.println(myClassName+":writeExternal(): ***BEFORE Outbound Executed List OBJ WRITE*** outboundExecutedPhases entry class ["+outObjClass+"] qname ["+outQnameAsString+"]");
+
+                ObjectStateUtils.writeObject(out, outMdEntry, "Messagecontext.outboundExecutedPhases:entry class ["+outObjClass+"] qname ["+outQnameAsString+"]");
+
+                // update the index so that the index 
+                // now indicates the next entry that
+                // will be attempted
+                outExecNextIndex++;
+
+                if (log.isTraceEnabled())
+                {
+                    log.trace(myClassName+":writeExternal(): ***AFTER Outbound Executed List OBJ WRITE*** outboundExecutedPhases entry class ["+outObjClass+"] qname ["+outQnameAsString+"]");
+                }
+                //System.out.println(myClassName+":writeExternal(): ***AFTER Outbound Executed List OBJ WRITE*** outboundExecutedPhases entry class ["+outObjClass+"] qname ["+outQnameAsString+"]");
+
+            } // end while entries 
+
+            // done with the entries 
+            // add the end-of-list marker
+            MetaDataEntry outLastEntry = new MetaDataEntry();
+            outLastEntry.setClassName(MetaDataEntry.END_OF_LIST);
+
+            ObjectStateUtils.writeObject(out, outLastEntry, "Messagecontext.outboundExecutedPhases:  last entry ");
+            outExecNextIndex++;
+
+            // outExecNextIndex also gives us the number of entries 
+            // that were actually saved as opposed to the 
+            // number of entries in the outboundExecutedPhases
+            out.writeInt(outExecNextIndex);         
+
+        }
+        else
+        {
+            // general case: handle "null" or "empty"
+
+            out.writeUTF(outExecListDesc);
+            out.writeBoolean(ObjectStateUtils.EMPTY_OBJECT);
+
+            if (log.isTraceEnabled())
+            {
+                log.trace(myClassName+":writeExternal(): outboundExecutedPhases is NULL");
+            }
+            //System.out.println(myClassName+":writeExternal(): outboundExecutedPhases is NULL");
+
+        }
+
+
+        //---------------------------------------------------------
+        // options
+        //---------------------------------------------------------
+        // before saving the Options, make sure there is a message ID
+        String tmpID = getMessageID();
+        if (tmpID == null)
+        {
+            // get an id to use when restoring this object
+            tmpID = org.apache.axis2.util.UUIDGenerator.getUUID();
+            setMessageID(tmpID);
+        }
+
+        if (log.isInfoEnabled())
+        {
+            log.info(myClassName+":writeExternal():   message ID ["+tmpID+"]");
+        }
+        //System.out.println(myClassName+":writeExternal():   message ID ["+tmpID+"]");
+
+        ObjectStateUtils.writeObject(out, options, "MessageContext.options");
+
+
+        //---------------------------------------------------------
+        // operation
+        //---------------------------------------------------------
+        // axis operation 
+        //---------------------------------------------------------
+        String axisOpMarker = "MessageContext.axisOperation";
+        ObjectStateUtils.writeString(out, axisOpMarker, axisOpMarker);
+
+        if (axisOperation == null)
+        {
+        	out.writeBoolean(ObjectStateUtils.EMPTY_OBJECT);
+        }
+        else
+        {
+            // TODO: may need to include the meta data for the axis service that is 
+            //       the parent of the axis operation
+
+        	out.writeBoolean(ObjectStateUtils.ACTIVE_OBJECT);
+
+            // make sure the axis operation has a name associated with it
+            QName aoTmpQName = axisOperation.getName();
+
+            if (aoTmpQName == null)
+            {
+                aoTmpQName = new QName(ObjectStateUtils.EMPTY_MARKER);
+                axisOperation.setName(aoTmpQName);
+            }
+
+        	metaAxisOperation = new MetaDataEntry(axisOperation.getClass().getName(), axisOperation.getName().toString());
+        	ObjectStateUtils.writeObject(out, metaAxisOperation, "MessageContext.metaAxisOperation");
+        }
+
+        //---------------------------------------------------------
+        // operation context
+        //---------------------------------------------------------
+        // The OperationContext has pointers to MessageContext objects.
+        // In order to avoid having multiple copies of the object graph
+        // being saved at different points in the serialization,
+        // it is important to isolate this message context object.
+        if (operationContext != null)
+        {
+            operationContext.isolateMessageContext(this);
+        }
+
+        // NOTE: expect this to be the parent of the message context
+        ObjectStateUtils.writeObject(out, operationContext, "MessageContext.operationContext" );
+
+
+        //---------------------------------------------------------
+        // service
+        //---------------------------------------------------------
+        // axis service
+        //-------------------------
+        // this is expected to be the parent of the axis operation object
+        String axisServMarker = "MessageContext.axisService";
+        ObjectStateUtils.writeString(out, axisServMarker, axisServMarker);
+
+        if (axisService == null)
+        {
+        	out.writeBoolean(ObjectStateUtils.EMPTY_OBJECT);
+        }
+        else
+        {
+        	out.writeBoolean(ObjectStateUtils.ACTIVE_OBJECT);
+        	metaAxisService = new MetaDataEntry(axisService.getClass().getName(), axisService.getName().toString());
+        	ObjectStateUtils.writeObject(out, metaAxisService, "MessageContext.metaAxisService");
+        }
+        
+
+        //-------------------------
+        // serviceContextID string
+        //-------------------------
+        ObjectStateUtils.writeString(out, serviceContextID, "MessageContext.serviceContextID");
+
+
+        //-------------------------
+        // serviceContext
+        //-------------------------
+        // is this the same as the parent of the OperationContext?
+        boolean isParent = false;
+
+        if (operationContext != null)
+        {
+            ServiceContext opctxParent = operationContext.getServiceContext();
+
+            if (serviceContext != null)
+            {
+                if (serviceContext.equals(opctxParent))
+                {
+                    // the ServiceContext is the parent of the OperationContext
+                    isParent = true;
+                }
+            }
+        }
+
+        String servCtxMarker = "MessageContext.serviceContext";
+        ObjectStateUtils.writeString(out, servCtxMarker, servCtxMarker);
+
+        if (serviceContext == null)
+        {
+        	out.writeBoolean(ObjectStateUtils.EMPTY_OBJECT);
+        }
+        else
+        {
+        	out.writeBoolean(ObjectStateUtils.ACTIVE_OBJECT);
+            out.writeBoolean(isParent);
+
+            // only write out the object if it is not the parent
+            if (!isParent)
+            {
+                ObjectStateUtils.writeObject(out, serviceContext, "MessageContext.serviceContext");
+            }
+        }
+
+
+        //---------------------------------------------------------
+        // axisServiceGroup
+        //---------------------------------------------------------
+
+        String axisServGrpMarker = "MessageContext.axisServiceGroup";
+        ObjectStateUtils.writeString(out, axisServGrpMarker, axisServGrpMarker);
+
+        if (axisServiceGroup == null)
+        {
+        	out.writeBoolean(ObjectStateUtils.EMPTY_OBJECT);
+        }
+        else
+        {
+        	out.writeBoolean(ObjectStateUtils.ACTIVE_OBJECT);
+        	metaAxisServiceGroup = new MetaDataEntry(axisServiceGroup.getClass().getName(), axisServiceGroup.getServiceGroupName());
+        	ObjectStateUtils.writeObject(out, metaAxisServiceGroup, "MessageContext.metaAxisServiceGroup");
+        }
+        
+        //-----------------------------
+        // serviceGroupContextId string
+        //-----------------------------
+        ObjectStateUtils.writeString(out, serviceGroupContextId, "MessageContext.serviceGroupContextId");
+
+        
+        //-------------------------
+        // serviceGroupContext
+        //-------------------------
+
+        // is this the same as the parent of the ServiceContext?
+        isParent = false;
+
+        if (serviceContext != null)
+        {
+            ServiceGroupContext srvgrpctxParent = (ServiceGroupContext) serviceContext.getParent();
+
+            if (serviceGroupContext != null)
+            {
+                if (serviceGroupContext.equals(srvgrpctxParent))
+                {
+                    // the ServiceGroupContext is the parent of the ServiceContext
+                    isParent = true;
+                }
+            }
+        }
+
+        String servGrpCtxMarker = "MessageContext.serviceGroupContext";
+        ObjectStateUtils.writeString(out, servGrpCtxMarker, servGrpCtxMarker);
+
+        if (serviceGroupContext == null)
+        {
+        	out.writeBoolean(ObjectStateUtils.EMPTY_OBJECT);
+        }
+        else
+        {
+        	out.writeBoolean(ObjectStateUtils.ACTIVE_OBJECT);
+            out.writeBoolean(isParent);
+
+            // only write out the object if it is not the parent
+            if (!isParent)
+            {
+                ObjectStateUtils.writeObject(out, serviceGroupContext, "MessageContext.serviceGroupContext");
+            }
+        }
+
+
+
+        //---------------------------------------------------------
+        // axis message
+        //---------------------------------------------------------
+        String axisMsgMarker = "MessageContext.axisMessage";
+        ObjectStateUtils.writeString(out, axisMsgMarker, axisMsgMarker);
+
+        if (axisMessage == null)
+        {
+        	out.writeBoolean(ObjectStateUtils.EMPTY_OBJECT);
+        }
+        else
+        {
+            // This AxisMessage is expected to belong to the AxisOperation
+            // that has already been recorded for this MessageContext.
+            // If an AxisMessage associated with this Messagecontext is
+            // associated with a different AxisOperation, then more 
+            // meta information would need to be saved
+
+        	out.writeBoolean(ObjectStateUtils.ACTIVE_OBJECT);
+
+            // make sure the axis message has a name associated with it
+            String amTmpName = axisMessage.getName();
+
+            if (amTmpName == null)
+            {
+                amTmpName = new String(ObjectStateUtils.EMPTY_MARKER);
+                axisMessage.setName(amTmpName);
+            }
+
+            // get the element name if there is one
+            QName amTmpElementQName = axisMessage.getElementQName();
+            String amTmpElemQNameString = null;
+
+            if (amTmpElementQName != null)
+            {
+                amTmpElemQNameString = amTmpElementQName.toString();
+            }
+
+        	metaAxisMessage = new MetaDataEntry(axisMessage.getClass().getName(), axisMessage.getName(), amTmpElemQNameString);
+
+        	ObjectStateUtils.writeObject(out, metaAxisMessage, "MessageContext.metaAxisMessage");
+        }
+
+        //---------------------------------------------------------
+        // configuration context
+        //---------------------------------------------------------
+
+        // NOTE: Currently, there does not seem to be any 
+        //       runtime data important to this message context
+        //       in the configuration context.
+        //       if so, then need to save that runtime data and reconcile
+        //       it with the configuration context on the system when
+        //       this message context object is restored
+
+
+
+        //---------------------------------------------------------
+        // session context
+        //---------------------------------------------------------
+        ObjectStateUtils.writeObject(out, sessionContext, "MessageContext.sessionContext" );
+        
+
+        //---------------------------------------------------------
+        // transport
+        //---------------------------------------------------------
+
+        //------------------------------
+        // incomingTransportName string
+        //------------------------------
+        ObjectStateUtils.writeString(out, incomingTransportName, "MessageContext.incomingTransportName");
+
+        // TransportInDescription transportIn
+        if (transportIn != null)
+        {
+            metaTransportIn = new MetaDataEntry(null, transportIn.getName().toString());
+        }
+        else
+        {
+            metaTransportIn = null;
+        }
+        ObjectStateUtils.writeObject(out, metaTransportIn, "MessageContext.transportIn");
+
+
+        // TransportOutDescription transportOut
+        if (transportOut != null)
+        {
+            metaTransportOut = new MetaDataEntry(null, transportOut.getName().toString());
+        }
+        else
+        {
+            metaTransportOut = null;
+        }
+        ObjectStateUtils.writeObject(out, metaTransportOut, "MessageContext.transportOut");
+
+
+
+        //---------------------------------------------------------
+        // properties
+        //---------------------------------------------------------
+        Map tmpMap = getProperties();
+
+        HashMap tmpHashMap = null;
+
+        if ((tmpMap != null) && (tmpMap.isEmpty()==false))
+        {
+            tmpHashMap = new HashMap(tmpMap);
+        }
+
+        ObjectStateUtils.writeHashMap(out, tmpHashMap, "MessageContext.properties");
+
+
+        //---------------------------------------------------------
+        // special data
+        //---------------------------------------------------------
+
+        String selfManagedDataMarker = "MessageContext.selfManagedData";
+        ObjectStateUtils.writeString(out, selfManagedDataMarker, selfManagedDataMarker);
+
+        // save the data, which the handlers themselves will serialize
+        //ByteArrayOutputStream baos_fromSelfManagedData = serializeSelfManagedData();
+        serializeSelfManagedData(out);
+
+
+
+        //---------------------------------------------------------
+        // done
+        //---------------------------------------------------------
+
+        if (log.isTraceEnabled())
+        {
+            log.trace(myClassName+":writeExternal():  END  ");
+        }
+        //System.out.println(myClassName+":writeExternal():  END  ");
+
+    }
+
+
+
+
+    /**
+     * Restore the contents of the MessageContext that was 
+     * previously saved. 
+     * <p> 
+     * NOTE: The field data must read back in the same order and type
+     * as it was written.  Some data will need to be validated when 
+     * resurrected.
+     *
+     * @param in    The stream to read the object contents from 
+     * 
+     * @exception IOException
+     * @exception ClassNotFoundException
+     */
+    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+    {
+        // set the flag to indicate that the message context is being
+        // reconstituted and will need to have certain object references 
+        // to be reconciled with the current engine setup
+        needsToBeReconciled = true;
+
+        // trace point
+        if (log.isTraceEnabled())
+        {

[... 1830 lines stripped ...]


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org