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 du...@apache.org on 2006/01/08 03:59:14 UTC
svn commit: r366975 -
/webservices/axis/trunk/java/src/org/apache/axis/MessageContext.java
Author: dug
Date: Sat Jan 7 18:59:10 2006
New Revision: 366975
URL: http://svn.apache.org/viewcvs?rev=366975&view=rev
Log:
Add support to (de)serialize a messageContext.
Modified:
webservices/axis/trunk/java/src/org/apache/axis/MessageContext.java
Modified: webservices/axis/trunk/java/src/org/apache/axis/MessageContext.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/src/org/apache/axis/MessageContext.java?rev=366975&r1=366974&r2=366975&view=diff
==============================================================================
--- webservices/axis/trunk/java/src/org/apache/axis/MessageContext.java (original)
+++ webservices/axis/trunk/java/src/org/apache/axis/MessageContext.java Sat Jan 7 18:59:10 2006
@@ -26,6 +26,8 @@
import org.apache.axis.constants.Style;
import org.apache.axis.constants.Use;
import org.apache.axis.handlers.soap.SOAPService;
+import org.apache.axis.message.SOAPEnvelope;
+import org.apache.axis.message.SOAPHeaderElement;
import org.apache.axis.schema.SchemaVersion;
import org.apache.axis.session.Session;
import org.apache.axis.soap.SOAPConstants;
@@ -38,8 +40,14 @@
import javax.xml.rpc.Call;
import javax.xml.rpc.handler.soap.SOAPMessageContext;
import java.io.File;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
import java.util.ArrayList;
+import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Vector;
// fixme: fields are declared throughout this class, some at the top, and some
// near to where they are used. We should move all field declarations into a
@@ -373,6 +381,149 @@
}
}
}
+ }
+
+ public void toStream(ObjectOutputStream out) throws Exception {
+ Hashtable table = new Hashtable();
+
+ if ( requestMessage != null ) {
+ /* skip this for now
+ SOAPEnvelope env = requestMessage.getSOAPEnvelope();
+ if ( env != null ) {
+ Vector headers = env.getHeaders();
+ Vector muHdrs = new Vector();
+ for ( int i = 0 ; i < headers.size() ; i++ ) {
+ SOAPHeaderElement she = (SOAPHeaderElement) headers.get(i);
+ // if ( she.getMustUnderstand() && she.isProcessed() ) {
+ if ( she.isProcessed() ) {
+ // Ideally I'd like to just mark this as mU=0 instead of
+ // removing it but I couldn't get axis to do it
+ muHdrs.add( she.getQName() );
+ }
+ }
+ if ( muHdrs.size() > 0 )
+ table.put( "msg.reqMU", muHdrs );
+ }
+ */
+ table.put("msg.req", requestMessage.getSOAPPartAsString() );
+ }
+ if ( responseMessage != null ) {
+ /* Skip this for now
+ SOAPEnvelope env = responseMessage.getSOAPEnvelope();
+ if ( env != null ) {
+ Vector headers = env.getHeaders();
+ Vector muHdrs = new Vector();
+ for ( int i = 0 ; i < headers.size() ; i++ ) {
+ SOAPHeaderElement she = (SOAPHeaderElement) headers.get(i);
+ // if ( she.getMustUnderstand() && she.isProcessed() ) {
+ if ( she.isProcessed() ) {
+ // Ideally I'd like to just mark this as mU=0 instead of
+ // removing it but I couldn't get axis to do it
+ muHdrs.add( she.getQName() );
+ }
+ }
+ if ( muHdrs.size() > 0 )
+ table.put( "msg.resMU", muHdrs );
+ }
+ */
+ table.put("msg.res", responseMessage.getSOAPPartAsString() );
+ }
+ if ( targetService != null ) table.put("msg.svc", targetService );
+ if ( transportName != null ) table.put("msg.trn", transportName );
+ if ( maintainSession ) table.put("msg.mss", "true" );
+ if ( havePassedPivot ) table.put("msg.pvt", "true" );
+ table.put("msg.tim", new Integer(timeout) );
+ if ( highFidelity ) table.put( "msg.hig", "true" );
+ if ( username != null ) table.put( "msg.usr", username );
+ if ( password != null ) table.put( "msg.pwd", password );
+ if ( encodingStyle != null ) table.put( "msg.enc", encodingStyle );
+ if ( useSOAPAction ) table.put( "msg.usa", "true" );
+ if ( SOAPActionURI != null ) table.put( "msg.act", SOAPActionURI );
+
+ Iterator i = getPropertyNames();
+ while ( i.hasNext() ) {
+ String name = (String) i.next();
+ Object obj = bag.get(name);
+ if ( obj instanceof Serializable ) {
+ // First stop some liars!!
+ if ( obj instanceof org.apache.axis.client.Service ) continue ;
+ if ( obj instanceof org.apache.axis.message.RPCElement ) continue ;
+ if ( name.equals(org.apache.axis.transport.http
+ .HTTPConstants.MC_HTTP_SERVLET) ) continue ;
+
+ table.put( "__" + name, obj );
+ }
+ }
+ try {
+ out.writeObject( table );
+ } catch(Exception exp) {
+ System.err.println("Can't serialize MessageContext("+exp+")\n" +
+ "Current list of entries that were attempted:\n" );
+
+ Iterator ii = table.keySet().iterator();
+ while ( ii.hasNext() ) {
+ String key = (String) ii.next();
+ Object val = table.get(key);
+ System.err.println(" " + key + " : " + val.getClass() );
+ }
+ throw exp ;
+ }
+ }
+
+ public void fromStream(ObjectInputStream in) throws Exception {
+ Hashtable table = (Hashtable) in.readObject();
+ Enumeration enum = table.keys();
+ Object obj = null ;
+
+ if ( (obj = table.get("msg.req")) != null )
+ (requestMessage = new Message( obj, false )).setMessageContext(this);
+ if ( (obj = table.get("msg.res")) != null )
+ (responseMessage = new Message( obj, false )).setMessageContext(this);
+
+ transportName = (String) table.get("msg.trn");
+ maintainSession = "true".equals((String)table.get("msg.mss"));
+ havePassedPivot = "true".equals((String)table.get("msg.pvt"));
+ timeout = ((Integer)table.get("msg.tim")).intValue();
+ highFidelity = "true".equals((String)table.get("msg.hig"));
+ username = (String) table.get("msg.usr");
+ password = (String) table.get("msg.pwd");
+ encodingStyle = (String) table.get("msg.enc");
+ useSOAPAction = "true".equals((String)table.get("msg.usa"));
+ SOAPActionURI = (String) table.get("msg.act");
+
+ while ( enum.hasMoreElements() ) {
+ String name = (String) enum.nextElement();
+ if ( name.startsWith("__") )
+ bag.put( name.substring(2), table.get(name) );
+ }
+
+ /*
+ // Mark all processed headers as processed
+ if ( (obj = table.get("msg.reqMU")) != null ) {
+ Vector MUs = (Vector) obj ;
+ SOAPEnvelope env = requestMessage.getSOAPEnvelope();
+ for ( int i = 0 ; i < MUs.size() ; i++ ) {
+ QName qn = (QName) MUs.get(i);
+ enum = env.getHeadersByName(qn.getNamespaceURI(), qn.getLocalPart());
+ while (enum.hasMoreElements())
+ ((SOAPHeaderElement) enum.nextElement()).setProcessed(true);
+ }
+ }
+
+ if ( (obj = table.get("msg.resMU")) != null ) {
+ Vector MUs = (Vector) obj ;
+ SOAPEnvelope env = responseMessage.getSOAPEnvelope();
+ for ( int i = 0 ; i < MUs.size() ; i++ ) {
+ QName qn = (QName) MUs.get(i);
+ enum = env.getHeadersByName(qn.getNamespaceURI(), qn.getLocalPart());
+ while (enum.hasMoreElements())
+ ((SOAPHeaderElement) enum.nextElement()).setProcessed(true);
+ }
+ }
+ */
+
+ // Special because it will look up the service object
+ setTargetService( (String) table.get("msg.svc") );
}
/**