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/24 05:09:17 UTC

svn commit: r371797 - /webservices/axis/trunk/java/src/org/apache/axis/server/AxisServer.java

Author: dug
Date: Mon Jan 23 20:09:15 2006
New Revision: 371797

URL: http://svn.apache.org/viewcvs?rev=371797&view=rev
Log:
Add server side of WSA support.
Still needs a little bit of cleanup but it does work.
Again, samples, tests and docs next...

Modified:
    webservices/axis/trunk/java/src/org/apache/axis/server/AxisServer.java

Modified: webservices/axis/trunk/java/src/org/apache/axis/server/AxisServer.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/src/org/apache/axis/server/AxisServer.java?rev=371797&r1=371796&r2=371797&view=diff
==============================================================================
--- webservices/axis/trunk/java/src/org/apache/axis/server/AxisServer.java (original)
+++ webservices/axis/trunk/java/src/org/apache/axis/server/AxisServer.java Mon Jan 23 20:09:15 2006
@@ -1,12 +1,12 @@
 /*
  * Copyright 2001-2004 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,19 +25,25 @@
 import org.apache.axis.Message;
 import org.apache.axis.MessageContext;
 import org.apache.axis.SimpleTargetedChain;
-import org.apache.axis.message.SOAPEnvelope;
 import org.apache.axis.soap.SOAPConstants;
 import org.apache.axis.client.AxisClient;
 import org.apache.axis.components.logger.LogFactory;
 import org.apache.axis.configuration.EngineConfigurationFactoryFinder;
+import org.apache.axis.message.SOAPEnvelope;
 import org.apache.axis.utils.ClassUtils;
 import org.apache.axis.utils.Messages;
 import org.apache.commons.logging.Log;
+import org.apache.axis.message.SOAPEnvelope;
+import org.apache.axis.message.SOAPBodyElement;
+import org.apache.axis.message.SOAPHeaderElement;
+import org.apache.axis.wsa.MIHeader;
+import org.apache.axis.wsa.WSAHandler;
 
 import java.util.Map;
+import java.lang.reflect.Method ;
+
 /**
  *
- * @author Doug Davis (dug@us.ibm.com)
  * @author Glen Daniels (gdaniels@allaire.com)
  */
 public class AxisServer extends AxisEngine
@@ -48,7 +54,8 @@
         LogFactory.getLog("org.apache.axis.TIME");
 
     private static AxisServerFactory factory = null;
-    
+    private long   t0=0, t1=0, t2=0, t3=0, t4=0, t5=0;
+
     public static AxisServer getServer(Map environment) throws AxisFault
     {
         if (factory == null) {
@@ -124,13 +131,154 @@
         return clientEngine;
     }
 
+    public void invokeInboundTransport(MessageContext msgContext) 
+      throws Exception
+    {
+      /* Process the Transport Specific Request Chain */
+      /**********************************************/
+      String              hName          = msgContext.getTransportName();
+      Handler             h              = null ;
+      SimpleTargetedChain transportChain = null ;
+
+      if (log.isDebugEnabled()) {
+        log.debug(Messages.getMessage("transport01","AxisServer.invoke",hName));
+        t1=System.currentTimeMillis();
+      }
+      
+      if ( hName != null && (h = getTransport( hName )) != null ) {
+        if (h instanceof SimpleTargetedChain) {
+          transportChain = (SimpleTargetedChain)h;
+          h = transportChain.getRequestHandler();
+          if (h != null)
+            h.invoke(msgContext);
+        }
+      }
+      // Run security
+      // Add call to securityCode.Verify();  // dug
+    }
+
+    public void invokeOutboundTransport(MessageContext msgContext)
+      throws Exception
+    {
+      String              hName          = msgContext.getTransportName();
+      Handler             h              = null ;
+      SimpleTargetedChain transportChain = null ;
+
+      // Run security
+      // Add call to securityCode.protect(); // dug
+
+      /* Process the Transport Specific Response Chain */
+      /***********************************************/
+      if ( hName != null && (h = getTransport( hName )) != null ) {
+        if (h instanceof SimpleTargetedChain) {
+          transportChain = (SimpleTargetedChain)h;
+          h = transportChain.getResponseHandler();
+          if (h != null) {
+            // add call to RM code to add piggy-backed headers
+            // RMCode.addRMHeaders(); // Dug
+            h.invoke(msgContext);
+          }
+        }
+      }
+    }
+
+    public void invokeService(MessageContext msgContext) throws Exception {
+      Handler h = null ;
+
+      if ( tlog.isDebugEnabled() ) 
+        t2=System.currentTimeMillis();
+
+      try {
+        // Run WSA logic
+        WSAHandler.invoke( msgContext );
+
+        MIHeader mih = MIHeader.fromCurrentMessage();
+
+        if ( mih != null ) {
+          // See if it needs to be rerouted
+          // Dug - not yet // (new WSXHandler()).invoke( msgContext );
+        }
+
+        /* Process the Global Request Chain */
+        /**********************************/
+        if ((h = getGlobalRequest()) != null ) {
+          h.invoke(msgContext);
+        }
+  
+        /**
+         * At this point, the service should have been set by someone
+         * (either the originator of the MessageContext, or one of the
+         * transport or global Handlers).  If it hasn't been set, we
+         * fault.
+         */
+        h = msgContext.getService();
+        if (h == null) {
+          // It's possible that we haven't yet parsed the
+          // message at this point.  This is a kludge to
+          // make sure we have.  There probably wants to be
+          // some kind of declarative "parse point" on the handler
+          // chain instead....
+          Message rm = msgContext.getRequestMessage();
+          rm.getSOAPEnvelope().getFirstBody();
+                      
+          h = msgContext.getService();
+          if (h == null)
+            throw new AxisFault("Server.NoService",
+                                Messages.getMessage("noService05",
+                                "" + msgContext.getTargetService()),
+                                null, null );
+        }
+        if ( tlog.isDebugEnabled() ) 
+          t3=System.currentTimeMillis();
+  
+        SOAPEnvelope env = msgContext.getRequestMessage().getSOAPEnvelope();
+  
+        // Only invoke the service is there's a body - sort of a hack
+        if ( env.getFirstBody() != null ) {
+          initSOAPConstants(msgContext);
+          h.invoke(msgContext);
+        }
+
+        // WSA logic is run first
+        WSAHandler.invoke( msgContext );
+
+        if ( tlog.isDebugEnabled() ) 
+          t4=System.currentTimeMillis();
+  
+        /* Process the Global Response Chain */
+        /***********************************/
+        if ((h = getGlobalResponse()) != null)
+          h.invoke(msgContext);
+      }
+      catch(Exception exp) {
+        // If WSA isn't turned on then just rethrow it
+        // Dug - fix this, it should not do this we need to make this
+        // work even when WSA is turned on
+        if ( MIHeader.fromRequest() == null ) throw exp ;
+
+        if ( !(exp instanceof AxisFault) )
+          exp = AxisFault.makeFault( exp );
+
+        msgContext.setPastPivot( true );
+        msgContext.setResponseMessage( new Message(exp) );
+
+        // WSA stuff
+        WSAHandler.fixAction( msgContext );
+        WSAHandler.invoke( msgContext );
+
+        /* Process the Global Response Chain */
+        /***********************************/
+        if ((h = getGlobalResponse()) != null)
+          h.invoke(msgContext);
+      }
+    }
+
     /**
      * Main routine of the AXIS server.  In short we locate the appropriate
      * handler for the desired service and invoke() it.
      */
     public void invoke(MessageContext msgContext) throws AxisFault {
-        long t0=0, t1=0, t2=0, t3=0, t4=0, t5=0;
-        if( tlog.isDebugEnabled() ) {
+        if ( tlog.isDebugEnabled() ) {
             t0=System.currentTimeMillis();
         }
         
@@ -167,16 +315,23 @@
                         h = null ;
                     }
                 }
-                if( tlog.isDebugEnabled() ) {
+                if ( tlog.isDebugEnabled() ) {
                     t1=System.currentTimeMillis();
                 }
-                if ( h != null )
+                if ( h != null ) {
+                  try {
                     h.invoke(msgContext);
+                  }
+                  catch(Exception exp ) {
+                    exp.printStackTrace();
+                    throw exp ;
+                  }
+                }
                 else
                     throw new AxisFault( "Server.error",
                                          Messages.getMessage("noHandler00", hName),
                                          null, null );
-                if( tlog.isDebugEnabled() ) {
+                if ( tlog.isDebugEnabled() ) {
                     t2=System.currentTimeMillis();
                     tlog.debug( "AxisServer.invoke " + hName + " invoke=" +
                                 ( t2-t1 ) + " pre=" + (t1-t0 ));
@@ -220,90 +375,22 @@
 
                 */
 
-                /* Process the Transport Specific Request Chain */
-                /**********************************************/
-                hName = msgContext.getTransportName();
-                SimpleTargetedChain transportChain = null;
-
-                if (log.isDebugEnabled())
-                    log.debug(Messages.getMessage("transport01", "AxisServer.invoke", hName));
-
-                if( tlog.isDebugEnabled() ) {
-                    t1=System.currentTimeMillis();
-                }
-                if ( hName != null && (h = getTransport( hName )) != null ) {
-                    if (h instanceof SimpleTargetedChain) {
-                        transportChain = (SimpleTargetedChain)h;
-                        h = transportChain.getRequestHandler();
-                        if (h != null)
-                            h.invoke(msgContext);
-                    }
-                }
-
-                if( tlog.isDebugEnabled() ) {
-                    t2=System.currentTimeMillis();
-                }
-                /* Process the Global Request Chain */
-                /**********************************/
-                if ((h = getGlobalRequest()) != null ) {
-                    h.invoke(msgContext);
-                }
-
-                /**
-                 * At this point, the service should have been set by someone
-                 * (either the originator of the MessageContext, or one of the
-                 * transport or global Handlers).  If it hasn't been set, we
-                 * fault.
-                 */
-                h = msgContext.getService();
-                if (h == null) {
-                    // It's possible that we haven't yet parsed the
-                    // message at this point.  This is a kludge to
-                    // make sure we have.  There probably wants to be
-                    // some kind of declarative "parse point" on the handler
-                    // chain instead....
-                    Message rm = msgContext.getRequestMessage();
-                    rm.getSOAPEnvelope().getFirstBody();
-                    
-                    h = msgContext.getService();
-                    if (h == null)
-                        throw new AxisFault("Server.NoService",
-                                            Messages.getMessage("noService05",
-                                                                 "" + msgContext.getTargetService()),
-                                            null, null );
-                }
-                if( tlog.isDebugEnabled() ) {
-                    t3=System.currentTimeMillis();
-                }
+                invokeInboundTransport(msgContext);
                 
-                initSOAPConstants(msgContext);
-                try {
-                    h.invoke(msgContext);
-                } catch (AxisFault ae) {
-                    if ((h = getGlobalRequest()) != null ) {
-                        h.onFault(msgContext);
-                    }
-                    throw ae;
-                }
+                invokeService(msgContext);
+                msgContext.setPastPivot( true );
+                
+                /*
+                if ( msgContext.getIsOneWay() )
+                  msgContext.setResponseMessage( null );
+                */
 
-                if( tlog.isDebugEnabled() ) {
-                    t4=System.currentTimeMillis();
-                }
+                // Send async response if needed
+                WSAHandler.sendResponse( msgContext );
 
-                /* Process the Global Response Chain */
-                /***********************************/
-                if ((h = getGlobalResponse()) != null)
-                    h.invoke(msgContext);
+                invokeOutboundTransport(msgContext);
 
-                /* Process the Transport Specific Response Chain */
-                /***********************************************/
-                if (transportChain != null) {
-                    h = transportChain.getResponseHandler();
-                    if (h != null)
-                        h.invoke(msgContext);
-                }
-                
-                if( tlog.isDebugEnabled() ) {
+                if ( tlog.isDebugEnabled() ) {
                     t5=System.currentTimeMillis();
                     tlog.debug( "AxisServer.invoke2 " +
                                 " preTr=" +
@@ -337,7 +424,7 @@
      * Extract ans store soap constants info from the envelope
      * @param msgContext
      * @throws AxisFault
-     */ 
+     */
     private void initSOAPConstants(MessageContext msgContext) throws AxisFault {
         Message msg = msgContext.getRequestMessage();
         if (msg == null)
@@ -466,9 +553,9 @@
                     // make sure we have.  There probably wants to be
                     // some kind of declarative "parse point" on the handler
                     // chain instead....
-                    Message rm = msgContext.getRequestMessage();
-                    if (rm != null) {
-                        rm.getSOAPEnvelope().getFirstBody();
+                    Message msg = msgContext.getRequestMessage();
+                    if (msg != null) {
+                        msg.getSOAPEnvelope().getFirstBody();
                         h = msgContext.getService();
                     }
                     if (h == null) {