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 2007/09/02 19:03:08 UTC

svn commit: r572035 - /webservices/muse/trunk/modules/muse-platform-mini/src/org/apache/muse/core/platform/mini/MiniIsolationLayer.java

Author: danj
Date: Sun Sep  2 10:03:08 2007
New Revision: 572035

URL: http://svn.apache.org/viewvc?rev=572035&view=rev
Log:
Applying patch for MUSE-261 - thanks Kevin!

Modified:
    webservices/muse/trunk/modules/muse-platform-mini/src/org/apache/muse/core/platform/mini/MiniIsolationLayer.java

Modified: webservices/muse/trunk/modules/muse-platform-mini/src/org/apache/muse/core/platform/mini/MiniIsolationLayer.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-platform-mini/src/org/apache/muse/core/platform/mini/MiniIsolationLayer.java?rev=572035&r1=572034&r2=572035&view=diff
==============================================================================
--- webservices/muse/trunk/modules/muse-platform-mini/src/org/apache/muse/core/platform/mini/MiniIsolationLayer.java (original)
+++ webservices/muse/trunk/modules/muse-platform-mini/src/org/apache/muse/core/platform/mini/MiniIsolationLayer.java Sun Sep  2 10:03:08 2007
@@ -1,198 +1,200 @@
-/* 
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.muse.core.platform.mini;
-
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-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.util.xml.XmlUtils;
-import org.apache.muse.ws.addressing.MessageHeaders;
-import org.apache.muse.ws.addressing.soap.SoapConstants;
-import org.apache.muse.ws.addressing.soap.SoapFault;
-import org.apache.muse.ws.addressing.soap.SoapUtils;
-
-/**
- * 
- * @author Dan Jemiolo (danjemiolo)
- *  
- */
-
-public class MiniIsolationLayer extends AbstractIsolationLayer
-{
-    private ServletContext _initialContext = null;
-    
-    private HttpServletRequest _initialRequest = null;
-    
-    public MiniIsolationLayer(HttpServletRequest initialRequest, ServletContext initialContext)
-    {
-        _initialRequest = initialRequest;
-        _initialContext = initialContext;
-    }
-    
-    private Element createBody(Document doc, Element contents)
-    {
-        //
-        // add the result (valid or fault) to the SOAP body...
-        //
-        Element body = XmlUtils.createElement(doc, SoapConstants.BODY_QNAME);
-        contents = (Element)doc.importNode(contents, true);
-        body.appendChild(contents);
-        return body;
-    }
-    
-    protected Document createEnvelope(MessageHeaders wsa, Element contents)
-    {
-        Document doc = XmlUtils.createDocument();
-        Element env = createEnvelope(doc, wsa, contents);
-        doc.appendChild(env);
-        return doc;
-    }
-    
-    private Element createEnvelope(Document doc, MessageHeaders wsa, Element contents)
-    {
-        Element soap = XmlUtils.createElement(doc, SoapConstants.ENVELOPE_QNAME);
-        Element headers = createHeaders(doc, wsa);
-        Element body = createBody(doc, contents);
-        
-        soap.appendChild(headers);
-        soap.appendChild(body);
-        
-        return soap;
-    }
-    
-    protected Environment createEnvironment()
-    {
-        return new MiniEnvironment(getInitialRequest(), getInitialContext());
-    }
-    
-    private Element createHeaders(Document doc, MessageHeaders wsa)
-    {
-        Element headers = XmlUtils.createElement(doc, SoapConstants.HEADER_QNAME);
-        
-        //
-        // no WS-A headers to return - probably an invalid SOAP request
-        //
-        if (wsa == null)
-            return headers;
-        
-        //
-        // import all of the headers into the response envelope...
-        //        
-        Element wsaXML = wsa.toXML();
-        Element[] children = XmlUtils.getAllElements(wsaXML);
-
-        for (int n = 0; n < children.length; ++n)
-        {
-            Node next = doc.importNode(children[n], true);
-            headers.appendChild(next);
-        }
-        
-        return headers;
-    }
-    
-    protected ServletContext getInitialContext()
-    {
-        return _initialContext;
-    }
-    
-    protected HttpServletRequest getInitialRequest()
-    {
-        return _initialRequest;
-    }
-
-    public Document handleRequest(Document request)
-    {
-        Element soap = XmlUtils.getFirstElement(request);
-        Element header = XmlUtils.getElement(soap, SoapConstants.HEADER_QNAME);
-        Element body = XmlUtils.getElement(soap, SoapConstants.BODY_QNAME);
-
-        if (header == null)
-            throw new RuntimeException("Invalid SOAP envelope: no header element.");        
-
-        if (body == null)
-            throw new RuntimeException("Invalid SOAP envelope: no body element.");
-
-        Element requestData = XmlUtils.getFirstElement(body);
-        
-        ResourceRouter router = getRouter();
-        Environment env = router.getEnvironment();
-
-        MessageHeaders addressing = null;
-
-        try
-        {
-            //
-            // WS-A info provides resource context for this request
-            //
-            addressing = new MessageHeaders(header);
-            env.addAddressingContext(addressing);
-        }
-
-        catch (SoapFault error)
-        {
-            //
-            // log error and return fault - we can't go any farther
-            //
-            LoggingUtils.logError(router.getLog(), error);
-            return createEnvelope(null, error.toXML());
-        }
-        
-        if (!hasFailedToInitialize())
-            LoggingUtils.logMessage(router.getLog(), request, true);
-
-        //
-        // actually perform the operation with the given parameters
-        //
-        Element result = router.invoke(requestData);
-        
-        MessageHeaders replyAddressing = null;
-
-        //
-        // send back fault headers on exception
-        //
-        if (SoapUtils.isFault(result))
-            replyAddressing = addressing.createFaultHeaders();
-
-        else
-            replyAddressing = addressing.createReplyHeaders();
-
-        //
-        // DONE - must be sure to remove the request context, or 
-        // we'll have a memory leak
-        //
-        env.removeAddressingContext();
-
-        Document response = createEnvelope(replyAddressing, result);
-
-        if (!hasFailedToInitialize())
-            LoggingUtils.logMessage(router.getLog(), response, false);
-
-        return response;
-    }
-}
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.muse.core.platform.mini;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+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.util.xml.XmlUtils;
+import org.apache.muse.ws.addressing.MessageHeaders;
+import org.apache.muse.ws.addressing.soap.SoapConstants;
+import org.apache.muse.ws.addressing.soap.SoapFault;
+import org.apache.muse.ws.addressing.soap.SoapUtils;
+
+/**
+ * 
+ * @author Dan Jemiolo (danjemiolo)
+ *  
+ */
+
+public class MiniIsolationLayer extends AbstractIsolationLayer
+{
+    private ServletContext _initialContext = null;
+    
+    private HttpServletRequest _initialRequest = null;
+    
+    public MiniIsolationLayer(HttpServletRequest initialRequest, ServletContext initialContext)
+    {
+        _initialRequest = initialRequest;
+        _initialContext = initialContext;
+    }
+    
+    private Element createBody(Document doc, Element contents)
+    {
+        //
+        // add the result (valid or fault) to the SOAP body...
+        //
+        Element body = XmlUtils.createElement(doc, SoapConstants.BODY_QNAME);
+
+        if (contents != null) 
+            body.appendChild(contents);
+        
+        return body;
+    }
+    
+    protected Document createEnvelope(MessageHeaders wsa, Element contents)
+    {
+        Document doc = XmlUtils.createDocument();
+        Element env = createEnvelope(doc, wsa, contents);
+        doc.appendChild(env);
+        return doc;
+    }
+    
+    private Element createEnvelope(Document doc, MessageHeaders wsa, Element contents)
+    {
+        Element soap = XmlUtils.createElement(doc, SoapConstants.ENVELOPE_QNAME);
+        Element headers = createHeaders(doc, wsa);
+        Element body = createBody(doc, contents);
+        
+        soap.appendChild(headers);
+        soap.appendChild(body);
+        
+        return soap;
+    }
+    
+    protected Environment createEnvironment()
+    {
+        return new MiniEnvironment(getInitialRequest(), getInitialContext());
+    }
+    
+    private Element createHeaders(Document doc, MessageHeaders wsa)
+    {
+        Element headers = XmlUtils.createElement(doc, SoapConstants.HEADER_QNAME);
+        
+        //
+        // no WS-A headers to return - probably an invalid SOAP request
+        //
+        if (wsa == null)
+            return headers;
+        
+        //
+        // import all of the headers into the response envelope...
+        //        
+        Element wsaXML = wsa.toXML();
+        Element[] children = XmlUtils.getAllElements(wsaXML);
+
+        for (int n = 0; n < children.length; ++n)
+        {
+            Node next = doc.importNode(children[n], true);
+            headers.appendChild(next);
+        }
+        
+        return headers;
+    }
+    
+    protected ServletContext getInitialContext()
+    {
+        return _initialContext;
+    }
+    
+    protected HttpServletRequest getInitialRequest()
+    {
+        return _initialRequest;
+    }
+
+    public Document handleRequest(Document request)
+    {
+        Element soap = XmlUtils.getFirstElement(request);
+        Element header = XmlUtils.getElement(soap, SoapConstants.HEADER_QNAME);
+        Element body = XmlUtils.getElement(soap, SoapConstants.BODY_QNAME);
+
+        if (header == null)
+            throw new RuntimeException("Invalid SOAP envelope: no header element.");        
+
+        if (body == null)
+            throw new RuntimeException("Invalid SOAP envelope: no body element.");
+
+        Element requestData = XmlUtils.getFirstElement(body);
+        
+        ResourceRouter router = getRouter();
+        Environment env = router.getEnvironment();
+
+        MessageHeaders addressing = null;
+
+        try
+        {
+            //
+            // WS-A info provides resource context for this request
+            //
+            addressing = new MessageHeaders(header);
+            env.addAddressingContext(addressing);
+        }
+
+        catch (SoapFault error)
+        {
+            //
+            // log error and return fault - we can't go any farther
+            //
+            LoggingUtils.logError(router.getLog(), error);
+            return createEnvelope(null, error.toXML());
+        }
+        
+        if (!hasFailedToInitialize())
+            LoggingUtils.logMessage(router.getLog(), request, true);
+
+        //
+        // actually perform the operation with the given parameters
+        //
+        Element result = router.invoke(requestData);
+        
+        MessageHeaders replyAddressing = null;
+
+        //
+        // send back fault headers on exception
+        //
+        if (result != null && SoapUtils.isFault(result))
+            replyAddressing = addressing.createFaultHeaders();
+
+        else
+            replyAddressing = addressing.createReplyHeaders();
+
+        //
+        // DONE - must be sure to remove the request context, or 
+        // we'll have a memory leak
+        //
+        env.removeAddressingContext();
+
+        Document response = createEnvelope(replyAddressing, result);
+
+        if (!hasFailedToInitialize())
+            LoggingUtils.logMessage(router.getLog(), response, false);
+
+        return response;
+    }
+}



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