You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-commits@ws.apache.org by da...@apache.org on 2006/12/08 21:16:07 UTC

svn commit: r484732 - in /webservices/muse/trunk/modules/muse-platform-axis2/src/org/apache/muse/core/platform/axis2: AxisEnvironment.java AxisIsolationLayer.java ResponseActionHandler.java

Author: danj
Date: Fri Dec  8 12:16:05 2006
New Revision: 484732

URL: http://svn.apache.org/viewvc?view=rev&rev=484732
Log:
Fixes for MUSE-138, MUSE-140, and MUSE-141 - file loading issues and new 
initialization schema for Axis2 1.1 Final.

Modified:
    webservices/muse/trunk/modules/muse-platform-axis2/src/org/apache/muse/core/platform/axis2/AxisEnvironment.java
    webservices/muse/trunk/modules/muse-platform-axis2/src/org/apache/muse/core/platform/axis2/AxisIsolationLayer.java
    webservices/muse/trunk/modules/muse-platform-axis2/src/org/apache/muse/core/platform/axis2/ResponseActionHandler.java

Modified: webservices/muse/trunk/modules/muse-platform-axis2/src/org/apache/muse/core/platform/axis2/AxisEnvironment.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-platform-axis2/src/org/apache/muse/core/platform/axis2/AxisEnvironment.java?view=diff&rev=484732&r1=484731&r2=484732
==============================================================================
--- webservices/muse/trunk/modules/muse-platform-axis2/src/org/apache/muse/core/platform/axis2/AxisEnvironment.java (original)
+++ webservices/muse/trunk/modules/muse-platform-axis2/src/org/apache/muse/core/platform/axis2/AxisEnvironment.java Fri Dec  8 12:16:05 2006
@@ -17,30 +17,22 @@
 package org.apache.muse.core.platform.axis2;
 
 import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
 import java.net.URI;
-import java.net.URL;
 import java.util.Iterator;
 import java.util.Map;
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 
-import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
+import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.soap.SOAPHeader;
-import org.apache.axis2.AxisFault;
 import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.context.OperationContext;
-import org.apache.axis2.wsdl.WSDLConstants;
 
 import org.apache.muse.core.AbstractEnvironment;
 import org.apache.muse.util.xml.XmlUtils;
@@ -61,10 +53,11 @@
 
 public class AxisEnvironment extends AbstractEnvironment
 {
+    private static final String _CLASSES = "classes";
     
     //
     // The service installation directory (NOT the WAR file directory). This 
-    // is found at $WAR_INSTALL_DIR/WEB-INF/services/muse
+    // is found at $WAR_INSTALL_DIR/WEB-INF/classes
     //
     private File _realDirectory = null;
     
@@ -75,9 +68,10 @@
      * adoption of something like JSR-261 or some WS-A project in Apache Commons.
      *
      */
-    public static MessageHeaders convertContext(OperationContext opContext)
+    public static MessageHeaders convertContext()
     {
-        SOAPHeader axiom = getInputMessageContext(opContext).getEnvelope().getHeader();
+        MessageContext context = MessageContext.getCurrentMessageContext();
+        SOAPHeader axiom = context.getEnvelope().getHeader();
         Element dom = convertToDOM(axiom);
         
         try
@@ -152,62 +146,40 @@
      */
     public static Element convertToDOM(OMElement axiom)
     {
-        try
-        {
-            ByteArrayOutputStream output = new ByteArrayOutputStream();
-            axiom.serialize(output);
-            
-            byte[] bytes = output.toByteArray();
-            ByteArrayInputStream input = new ByteArrayInputStream(bytes);
-            
-            Document doc = XmlUtils.createDocument(input);
-            return XmlUtils.getFirstElement(doc);
-        }
+        Element dom = XmlUtils.createElement(axiom.getQName());
+
+        String text = axiom.getText();
+
+        if (text != null && text.length() > 0)
+            XmlUtils.setElementText(dom, axiom.getText());
+
+        Iterator i = axiom.getAllAttributes();
         
-        catch (Throwable error)
-        {
-            throw new RuntimeException(error.getMessage(), error);
-        }
-    }
-    
-    /**
-     * 
-     * @param opContext
-     * 
-     * @return The Axis2 MessageContext for the request.
-     *
-     */
-    public static MessageContext getInputMessageContext(OperationContext opContext)
-    {
-        try
+        while (i.hasNext())
         {
-            return opContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+            OMAttribute attr = (OMAttribute)i.next();
+            QName qname = attr.getQName();
+            String value = attr.getAttributeValue();
+            dom.setAttributeNS(qname.getNamespaceURI(), qname.getLocalPart(), value);
         }
+
+        i = axiom.getAllDeclaredNamespaces();
         
-        catch (AxisFault error)
-        {
-            throw new RuntimeException(error.getMessage(), error);
-        }
-    }
-    
-    /**
-     * 
-     * @param opContext
-     * 
-     * @return The Axis2 MessageContext for the response.
-     *
-     */
-    public static MessageContext getOutputMessageContext(OperationContext opContext)
-    {
-        try
+        while (i.hasNext())
         {
-            return opContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
+            OMNamespace ns = (OMNamespace)i.next();
+            XmlUtils.setNamespaceAttribute(dom, ns.getPrefix(), ns.getNamespaceURI());
         }
-        
-        catch (AxisFault error)
+
+        i = axiom.getChildElements();
+
+        while (i.hasNext())
         {
-            throw new RuntimeException(error.getMessage(), error);
+            Element child = convertToDOM((OMElement)i.next());
+            dom.appendChild(child);
         }
+
+        return dom;
     }
     
     /**
@@ -216,56 +188,27 @@
      * the application is installed on the file system so that it can read 
      * local files when it needs to.
      *
-     * @param opContext
-     *
      */
-    public AxisEnvironment(OperationContext opContext)
+    public AxisEnvironment()
     {
-        MessageHeaders wsa = convertContext(opContext);        
+        MessageHeaders wsa = convertContext();        
         addAddressingContext(wsa);
         
-        MessageContext message = getInputMessageContext(opContext);
+        MessageContext context = MessageContext.getCurrentMessageContext();
         
         //
         // where are we? this is the path of the service installation, 
-        // not of the Axis2 WAR
-        //
-        String realDirPath = message.getAxisService().getFileName().getFile();
-        _realDirectory = new File(realDirPath);
+        // not of the Axis2 WAR, so we need to go up two levels to 
+        // WEB-INF/classes
+        //        
+        String axisServicePath = context.getAxisService().getFileName().getFile();
+        File axisServiceDir = new File(axisServicePath);
+        File webInfDir = axisServiceDir.getParentFile().getParentFile();
+        _realDirectory = new File(webInfDir, _CLASSES);
         
-        String address = message.getTo().getAddress();
+        String address = context.getTo().getAddress();
         setDefaultURI(getDeploymentURI(address));
     }
-    
-    public URL getDataResource(String path) 
-    {
-		File file = new File(_realDirectory, path);
-        
-		try 
-        {
-			return file.toURL();
-		}
-        
-		catch (MalformedURLException error) 
-        {
-			throw new RuntimeException(error);
-		}
-	}
-    
-    public InputStream getDataResourceStream(String path) 
-    {
-		File file = new File(getRealDirectory(), path);
-        
-		try
-        {
-            return new FileInputStream(file);
-        }
-        
-        catch (FileNotFoundException error)
-        {
-            throw new RuntimeException(error.getMessage(), error);
-        }
-	}
     
     public EndpointReference getDeploymentEPR()
     {

Modified: webservices/muse/trunk/modules/muse-platform-axis2/src/org/apache/muse/core/platform/axis2/AxisIsolationLayer.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-platform-axis2/src/org/apache/muse/core/platform/axis2/AxisIsolationLayer.java?view=diff&rev=484732&r1=484731&r2=484732
==============================================================================
--- webservices/muse/trunk/modules/muse-platform-axis2/src/org/apache/muse/core/platform/axis2/AxisIsolationLayer.java (original)
+++ webservices/muse/trunk/modules/muse-platform-axis2/src/org/apache/muse/core/platform/axis2/AxisIsolationLayer.java Fri Dec  8 12:16:05 2006
@@ -22,10 +22,11 @@
 
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.soap.SOAPEnvelope;
-import org.apache.axis2.context.OperationContext;
+import org.apache.axis2.context.MessageContext;
 
 import org.apache.muse.core.Environment;
 import org.apache.muse.core.platform.AbstractIsolationLayer;
+import org.apache.muse.core.routing.ResourceRouter;
 import org.apache.muse.util.LoggingUtils;
 import org.apache.muse.ws.addressing.MessageHeaders;
 
@@ -43,24 +44,9 @@
 
 public class AxisIsolationLayer extends AbstractIsolationLayer
 {
-    //
-    // the context provided for the very first request - we need 
-    // to save this in order to do initialization tasks (then it 
-    // can be nullified). Axis2 services don't have methods similar 
-    // to JAX-RPC ServiceLifecycle init() and destroy() so we have 
-    // to grab the value in setOperationContext() and then kick off 
-    // initialization tasks from there. oy.
-    //
-    private static OperationContext _initialOpContext = null;
-    
     protected Environment createEnvironment()
     {
-        return new AxisEnvironment(getInitialContext());
-    }
-    
-    protected OperationContext getInitialContext()
-    {
-        return _initialOpContext;
+        return new AxisEnvironment();
     }
     
     /**
@@ -79,110 +65,78 @@
      */
     public final OMElement handleRequest(OMElement request)
     {
-        AxisEnvironment env = (AxisEnvironment)getRouter().getEnvironment();
-        
-        Element soapBody = null;
-        
         //
-        // handle empty SOAP bodies
+        // is this the first time this is being called? initialize!
         //
-        if (request != null)
-            soapBody = env.convertToDOM(request);
+        if (!hasBeenInitialized())
+            initialize();
         
         Element soapResponse = null;
         
         //
-        // if the initialization failed, there will be a fault 
-        // waiting to be serialized/sent back
+        // for all requests, we need to save the addressing headers so that 
+        // we can access the SOAP envelope in handleRequest()
         //
         if (hasFailedToInitialize())
             soapResponse = getCauseOfFailure().toXML();
         
-        //
-        // otherwise, proceed as normal with routing
-        //
         else
-            soapResponse = getRouter().invoke(soapBody);
-        
-        //
-        // all done - don't forget to clean up the context or 
-        // we'll have a memory leak
-        //
-        env.removeAddressingContext();
-        
+            soapResponse = invoke(request);
+
         //
         // be sure to handle empty SOAP body in the response
         //
         if (soapResponse == null)
             return null;
-        
-        return env.convertToAxiom(soapResponse);
-    }
 
-    protected void setInitialContext(OperationContext opContext)
-    {
-        _initialOpContext = opContext;
+        AxisEnvironment env = (AxisEnvironment)getRouter().getEnvironment();
+        return env.convertToAxiom(soapResponse);
     }
     
-    /**
-     * 
-     * Because Axis2 doesn't use JAX-RPC ServiceLifecycle methods (or 
-     * something similar), we use this as our initialization routine. 
-     * This method is called via reflection for any Axis2 service that 
-     * implements it. When this method is called, we first check to see 
-     * if Muse has bee initialized - if not, we kick off initialization. 
-     * We then proceed with normal request handling.
-     * <br/><br/>
-     * This method also logs the incoming SOAP message if the Muse logging 
-     * level is set to FINE. 
-     *
-     * @param opContext
-     *
-     */
-    public void setOperationContext(OperationContext opContext)
+    public Element invoke(OMElement request)
     {
+        ResourceRouter router = getRouter();
+        AxisEnvironment env = (AxisEnvironment)router.getEnvironment();
+        
         //
-        // is this the first time this is being called? initialize!
+        // log incoming SOAP envelope
         //
-        if (!hasBeenInitialized())
+        // NOTE: This is kind of hack-ish, but we check to see if the 
+        //       current log level is 'FINE' before we try and log the 
+        //       message. We don't actually have to do this - the JDK 
+        //       logging API fine() will do this for us - but because 
+        //       we have to translate from Axiom to DOM once already, 
+        //       I don't want to do it twice unless the tracing is being 
+        //       used. If SOAP-level tracing is on, it's likely that this 
+        //       is not being used in a production system, so we can afford 
+        //       the performance hit of an extra conversion.
+        //
+        if (router.getLog().getLevel() == Level.FINE)
         {
-            setInitialContext(opContext);
-            
-            initialize();
-            
-            setInitialContext(null);
+            SOAPEnvelope soap = MessageContext.getCurrentMessageContext().getEnvelope();
+            Element soapAsDOM = env.convertToDOM(soap);
+            LoggingUtils.logMessage(router.getLog(), soapAsDOM, true);
         }
         
+        MessageHeaders wsa = env.convertContext();        
+        env.addAddressingContext(wsa);
+        
+        Element soapBody = null;
+        
         //
-        // for all requests, we need to save the addressing headers so that 
-        // we can access the SOAP envelope in handleRequest()
+        // handle empty SOAP bodies
         //
-        if (!hasFailedToInitialize())
-        {
-            AxisEnvironment env = (AxisEnvironment)getRouter().getEnvironment();
-            MessageHeaders wsa = env.convertContext(opContext);
-            env.addAddressingContext(wsa);
-            
-            //
-            // log incoming SOAP envelope now so we don't have to store 
-            // it for handleRequest().
-            //
-            // NOTE: This is kind of hack-ish, but we check to see if the 
-            //       current log level is 'FINE' before we try and log the 
-            //       message. We don't actually have to do this - the JDK 
-            //       logging API fine() will do this for us - but because 
-            //       we have to translate from Axiom to DOM once already, 
-            //       I don't want to do it twice unless the tracing is being 
-            //       used. If SOAP-level tracing is on, it's likely that this 
-            //       is not being used in a production system, so we can afford 
-            //       the performance hit of an extra conversion.
-            //
-            if (getRouter().getLog().getLevel() == Level.FINE)
-            {
-                SOAPEnvelope soap = env.getInputMessageContext(opContext).getEnvelope();
-                Element soapAsDOM = env.convertToDOM(soap);
-                LoggingUtils.logMessage(getRouter().getLog(), soapAsDOM, true);
-            }
-        }
+        if (request != null)
+            soapBody = env.convertToDOM(request);
+    
+        Element soapResponse = getRouter().invoke(soapBody);
+        
+        //
+        // all done - don't forget to clean up the context or 
+        // we'll have a memory leak
+        //
+        env.removeAddressingContext();
+        
+        return soapResponse;        
     }
 }

Modified: webservices/muse/trunk/modules/muse-platform-axis2/src/org/apache/muse/core/platform/axis2/ResponseActionHandler.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-platform-axis2/src/org/apache/muse/core/platform/axis2/ResponseActionHandler.java?view=diff&rev=484732&r1=484731&r2=484732
==============================================================================
--- webservices/muse/trunk/modules/muse-platform-axis2/src/org/apache/muse/core/platform/axis2/ResponseActionHandler.java (original)
+++ webservices/muse/trunk/modules/muse-platform-axis2/src/org/apache/muse/core/platform/axis2/ResponseActionHandler.java Fri Dec  8 12:16:05 2006
@@ -60,11 +60,12 @@
 
         else
             realResponseAction = currentResponseAction + RESPONSE;
-        
+
         msgContext.setWSAAction(realResponseAction);
+
     }
 
-    public void invoke(MessageContext msgContext)
+    public InvocationResponse invoke(MessageContext msgContext)
     {
         SOAPBody soapBody = msgContext.getEnvelope().getBody();
         
@@ -77,5 +78,7 @@
         
     	else
     		handleResponse(msgContext);
+        
+        return InvocationResponse.CONTINUE;
     }
 }



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