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:32:43 UTC
svn commit: r484756 - in /webservices/muse/trunk/modules/muse-platform-mini:
./ src/ src/org/ src/org/apache/ src/org/apache/muse/
src/org/apache/muse/core/ src/org/apache/muse/core/platform/
src/org/apache/muse/core/platform/mini/
Author: danj
Date: Fri Dec 8 12:32:42 2006
New Revision: 484756
URL: http://svn.apache.org/viewvc?view=rev&rev=484756
Log:
Support for constrained devices via Mini SOAP Engine - fix for MUSE-129
Added:
webservices/muse/trunk/modules/muse-platform-mini/
webservices/muse/trunk/modules/muse-platform-mini/pom.xml
webservices/muse/trunk/modules/muse-platform-mini/src/
webservices/muse/trunk/modules/muse-platform-mini/src/org/
webservices/muse/trunk/modules/muse-platform-mini/src/org/apache/
webservices/muse/trunk/modules/muse-platform-mini/src/org/apache/muse/
webservices/muse/trunk/modules/muse-platform-mini/src/org/apache/muse/core/
webservices/muse/trunk/modules/muse-platform-mini/src/org/apache/muse/core/platform/
webservices/muse/trunk/modules/muse-platform-mini/src/org/apache/muse/core/platform/mini/
webservices/muse/trunk/modules/muse-platform-mini/src/org/apache/muse/core/platform/mini/MiniEnvironment.java
webservices/muse/trunk/modules/muse-platform-mini/src/org/apache/muse/core/platform/mini/MiniIsolationLayer.java
webservices/muse/trunk/modules/muse-platform-mini/src/org/apache/muse/core/platform/mini/MiniServlet.java
Added: webservices/muse/trunk/modules/muse-platform-mini/pom.xml
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-platform-mini/pom.xml?view=auto&rev=484756
==============================================================================
--- webservices/muse/trunk/modules/muse-platform-mini/pom.xml (added)
+++ webservices/muse/trunk/modules/muse-platform-mini/pom.xml Fri Dec 8 12:32:42 2006
@@ -0,0 +1,41 @@
+<?xml version="1.0"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>muse-platform-mini</artifactId>
+ <parent>
+ <groupId>muse</groupId>
+ <artifactId>build-all</artifactId>
+ <version>2.1.0-SNAPSHOT</version>
+ </parent>
+ <packaging>jar</packaging>
+ <version>2.1.0-SNAPSHOT</version>
+ <name>Apache Muse - Simple Servlet Deployment</name>
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>muse</groupId>
+ <artifactId>muse-util</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>muse</groupId>
+ <artifactId>muse-util-qname</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>muse</groupId>
+ <artifactId>muse-util-xml</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>muse</groupId>
+ <artifactId>muse-wsa-soap</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>muse</groupId>
+ <artifactId>muse-core</artifactId>
+ </dependency>
+ </dependencies>
+</project>
Added: webservices/muse/trunk/modules/muse-platform-mini/src/org/apache/muse/core/platform/mini/MiniEnvironment.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-platform-mini/src/org/apache/muse/core/platform/mini/MiniEnvironment.java?view=auto&rev=484756
==============================================================================
--- webservices/muse/trunk/modules/muse-platform-mini/src/org/apache/muse/core/platform/mini/MiniEnvironment.java (added)
+++ webservices/muse/trunk/modules/muse-platform-mini/src/org/apache/muse/core/platform/mini/MiniEnvironment.java Fri Dec 8 12:32:42 2006
@@ -0,0 +1,57 @@
+/*=============================================================================*
+ * Copyright 2006 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *=============================================================================*/
+
+package org.apache.muse.core.platform.mini;
+
+import java.io.File;
+import java.net.URI;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.muse.core.AbstractEnvironment;
+import org.apache.muse.ws.addressing.EndpointReference;
+
+/**
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public class MiniEnvironment extends AbstractEnvironment
+{
+ private File _realDirectory = null;
+
+ public MiniEnvironment(HttpServletRequest httpRequest, ServletContext servletContext)
+ {
+ String realPath = servletContext.getRealPath("/WEB-INF/classes");
+ _realDirectory = new File(realPath);
+
+ setDefaultURI(httpRequest.getRequestURL().toString());
+ }
+
+ public EndpointReference getDeploymentEPR()
+ {
+ String defaultString = getDefaultURI();
+ URI defaultURI = URI.create(defaultString);
+ return new EndpointReference(defaultURI);
+ }
+
+ public File getRealDirectory()
+ {
+ return _realDirectory;
+ }
+}
Added: 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?view=auto&rev=484756
==============================================================================
--- webservices/muse/trunk/modules/muse-platform-mini/src/org/apache/muse/core/platform/mini/MiniIsolationLayer.java (added)
+++ webservices/muse/trunk/modules/muse-platform-mini/src/org/apache/muse/core/platform/mini/MiniIsolationLayer.java Fri Dec 8 12:32:42 2006
@@ -0,0 +1,160 @@
+// ========================================================================
+//
+// Licensed Materials - Property of IBM
+//
+// PRODUCT_NO
+//
+// (c) Copyright IBM Corp. 2005. All Rights Reserved.
+//
+// US Government Users Restricted Rights - Use, duplication or
+// disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
+//
+// =========================================================================
+
+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.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;
+ }
+
+ protected Environment createEnvironment()
+ {
+ return new MiniEnvironment(getInitialRequest(), getInitialContext());
+ }
+
+ 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 (Throwable error)
+ {
+ LoggingUtils.logError(router.getLog(), error);
+ }
+
+ if (!hasFailedToInitialize())
+ LoggingUtils.logMessage(router.getLog(), request, true);
+
+ //
+ // actually perform the operation with the given parameters
+ //
+ Element result = router.invoke(requestData);
+
+ //
+ // the standard response wsa:Action name is Action + "Response"
+ //
+ 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();
+
+ //
+ // import all of the headers into the response envelope...
+ //
+ Element replyXML = replyAddressing.toXML();
+ Element[] children = XmlUtils.getAllElements(replyXML);
+
+ Document response = XmlUtils.createDocument();
+
+ soap = XmlUtils.createElement(response, SoapConstants.ENVELOPE_QNAME);
+ response.appendChild(soap);
+
+ header = XmlUtils.createElement(response, SoapConstants.HEADER_QNAME);
+ soap.appendChild(header);
+
+ for (int n = 0; n < children.length; ++n)
+ {
+ Node next = response.importNode(children[n], true);
+ header.appendChild(next);
+ }
+
+ //
+ // add the result (valid or fault) to the SOAP body...
+ //
+ body = XmlUtils.createElement(response, SoapConstants.BODY_QNAME);
+ soap.appendChild(body);
+
+ result = (Element)response.importNode(result, true);
+ body.appendChild(result);
+
+ if (!hasFailedToInitialize())
+ LoggingUtils.logMessage(router.getLog(), response, false);
+
+ return response;
+ }
+}
Added: webservices/muse/trunk/modules/muse-platform-mini/src/org/apache/muse/core/platform/mini/MiniServlet.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-platform-mini/src/org/apache/muse/core/platform/mini/MiniServlet.java?view=auto&rev=484756
==============================================================================
--- webservices/muse/trunk/modules/muse-platform-mini/src/org/apache/muse/core/platform/mini/MiniServlet.java (added)
+++ webservices/muse/trunk/modules/muse-platform-mini/src/org/apache/muse/core/platform/mini/MiniServlet.java Fri Dec 8 12:32:42 2006
@@ -0,0 +1,73 @@
+
+package org.apache.muse.core.platform.mini;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+import org.apache.muse.util.xml.XmlUtils;
+
+/**
+ *
+ * @author Dan Jemiolo (danjemiolo)
+ *
+ */
+
+public class MiniServlet extends HttpServlet
+{
+ private static final long serialVersionUID = 685701350365490390L;
+
+ //
+ // the touchpoint runtime that handles all resource management
+ //
+ private MiniIsolationLayer _isolationLayer = null;
+
+ private MiniIsolationLayer createIsolationLayer(HttpServletRequest request, ServletContext context)
+ {
+ MiniIsolationLayer isolationLayer = new MiniIsolationLayer(request, context);
+ isolationLayer.initialize();
+ return isolationLayer;
+ }
+
+ /**
+ *
+ * POST handles all SOAP requests. The HTTP POST data is converted into
+ * a SOAP envelope and processed by MiniIsolationLayer.
+ *
+ */
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws IOException
+ {
+ if (_isolationLayer == null)
+ _isolationLayer = createIsolationLayer(request, getServletContext());
+
+ InputStream input = request.getInputStream();
+ Document soapRequest = null;
+
+ try
+ {
+ soapRequest = XmlUtils.createDocument(input);
+ }
+
+ catch (SAXException error)
+ {
+ throw new IOException(error.getMessage());
+ }
+
+ Document soapResponse = _isolationLayer.handleRequest(soapRequest);
+
+ response.setContentType("text/xml");
+
+ PrintWriter writer = response.getWriter();
+ writer.write(XmlUtils.toString(soapResponse));
+ writer.flush();
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: muse-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-commits-help@ws.apache.org