ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1571697 - in /ace/trunk: org.apache.ace.gogo.servlet/ org.apache.ace.gogo.servlet/.settings/ org.apache.ace.gogo.servlet/src/ org.apache.ace.gogo.servlet/src/org/ org.apache.ace.gogo.servlet/src/org/apache/ org.apache.ace.gogo.servlet/src/...
Date Tue, 25 Feb 2014 13:57:00 GMT
Author: marrs
Date: Tue Feb 25 13:56:59 2014
New Revision: 1571697

URL: http://svn.apache.org/r1571697
Log:
ACE-460 Applied the patch. Thanks Herko.

Added:
    ace/trunk/org.apache.ace.gogo.servlet/
    ace/trunk/org.apache.ace.gogo.servlet/.classpath
    ace/trunk/org.apache.ace.gogo.servlet/.gitignore
    ace/trunk/org.apache.ace.gogo.servlet/.project
    ace/trunk/org.apache.ace.gogo.servlet/.settings/
    ace/trunk/org.apache.ace.gogo.servlet/.settings/org.eclipse.jdt.core.prefs
    ace/trunk/org.apache.ace.gogo.servlet/bnd.bnd
    ace/trunk/org.apache.ace.gogo.servlet/build.xml
    ace/trunk/org.apache.ace.gogo.servlet/src/
    ace/trunk/org.apache.ace.gogo.servlet/src/org/
    ace/trunk/org.apache.ace.gogo.servlet/src/org/apache/
    ace/trunk/org.apache.ace.gogo.servlet/src/org/apache/ace/
    ace/trunk/org.apache.ace.gogo.servlet/src/org/apache/ace/gogo/
    ace/trunk/org.apache.ace.gogo.servlet/src/org/apache/ace/gogo/servlet/
    ace/trunk/org.apache.ace.gogo.servlet/src/org/apache/ace/gogo/servlet/Activator.java
    ace/trunk/org.apache.ace.gogo.servlet/src/org/apache/ace/gogo/servlet/ScriptServlet.java
    ace/trunk/org.apache.ace.gogo.servlet/test/
    ace/trunk/run-client/conf/org.apache.ace.gogo.servlet.cfg
    ace/trunk/run-server-allinone/conf/org.apache.ace.gogo.servlet.cfg

Added: ace/trunk/org.apache.ace.gogo.servlet/.classpath
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.gogo.servlet/.classpath?rev=1571697&view=auto
==============================================================================
--- ace/trunk/org.apache.ace.gogo.servlet/.classpath (added)
+++ ace/trunk/org.apache.ace.gogo.servlet/.classpath Tue Feb 25 13:56:59 2014
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" output="bin" path="src"/>
+	<classpathentry kind="src" output="bin_test" path="test"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

Added: ace/trunk/org.apache.ace.gogo.servlet/.gitignore
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.gogo.servlet/.gitignore?rev=1571697&view=auto
==============================================================================
--- ace/trunk/org.apache.ace.gogo.servlet/.gitignore (added)
+++ ace/trunk/org.apache.ace.gogo.servlet/.gitignore Tue Feb 25 13:56:59 2014
@@ -0,0 +1,3 @@
+/bin/
+/bin_test/
+/generated/

Added: ace/trunk/org.apache.ace.gogo.servlet/.project
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.gogo.servlet/.project?rev=1571697&view=auto
==============================================================================
--- ace/trunk/org.apache.ace.gogo.servlet/.project (added)
+++ ace/trunk/org.apache.ace.gogo.servlet/.project Tue Feb 25 13:56:59 2014
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.apache.ace.gogo.servlet</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>bndtools.core.bndbuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>bndtools.core.bndnature</nature>
+	</natures>
+</projectDescription>

Added: ace/trunk/org.apache.ace.gogo.servlet/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.gogo.servlet/.settings/org.eclipse.jdt.core.prefs?rev=1571697&view=auto
==============================================================================
--- ace/trunk/org.apache.ace.gogo.servlet/.settings/org.eclipse.jdt.core.prefs (added)
+++ ace/trunk/org.apache.ace.gogo.servlet/.settings/org.eclipse.jdt.core.prefs Tue Feb 25
13:56:59 2014
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6

Added: ace/trunk/org.apache.ace.gogo.servlet/bnd.bnd
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.gogo.servlet/bnd.bnd?rev=1571697&view=auto
==============================================================================
--- ace/trunk/org.apache.ace.gogo.servlet/bnd.bnd (added)
+++ ace/trunk/org.apache.ace.gogo.servlet/bnd.bnd Tue Feb 25 13:56:59 2014
@@ -0,0 +1,9 @@
+-buildpath: osgi.core,\
+	osgi.cmpn,\
+	org.apache.felix.dependencymanager,\
+	javax.servlet,\
+	org.apache.ace.gogo;version=latest,\
+	org.apache.felix.gogo.runtime,\
+	org.apache.commons.io
+Bundle-Activator: org.apache.ace.gogo.servlet.Activator
+Private-Package: org.apache.ace.gogo.servlet
\ No newline at end of file

Added: ace/trunk/org.apache.ace.gogo.servlet/build.xml
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.gogo.servlet/build.xml?rev=1571697&view=auto
==============================================================================
--- ace/trunk/org.apache.ace.gogo.servlet/build.xml (added)
+++ ace/trunk/org.apache.ace.gogo.servlet/build.xml Tue Feb 25 13:56:59 2014
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="project" default="build">
+
+	<!-- -->
+
+	<import file="../cnf/build.xml" />
+</project>

Added: ace/trunk/org.apache.ace.gogo.servlet/src/org/apache/ace/gogo/servlet/Activator.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.gogo.servlet/src/org/apache/ace/gogo/servlet/Activator.java?rev=1571697&view=auto
==============================================================================
--- ace/trunk/org.apache.ace.gogo.servlet/src/org/apache/ace/gogo/servlet/Activator.java (added)
+++ ace/trunk/org.apache.ace.gogo.servlet/src/org/apache/ace/gogo/servlet/Activator.java Tue
Feb 25 13:56:59 2014
@@ -0,0 +1,48 @@
+/*
+ * 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.ace.gogo.servlet;
+
+import javax.servlet.Servlet;
+
+import org.apache.felix.dm.DependencyActivatorBase;
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.service.command.CommandProcessor;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.log.LogService;
+
+public class Activator extends DependencyActivatorBase {
+
+    private static final String SCRIPT_SERVLET_PID = "org.apache.ace.gogo.servlet";
+
+    @Override
+    public void init(BundleContext context, DependencyManager manager) throws Exception {
+        manager.add(createComponent()
+            .setInterface(Servlet.class.getName(), null)
+            .setImplementation(ScriptServlet.class)
+            .add(createConfigurationDependency().setPropagate(true).setPid(SCRIPT_SERVLET_PID))
+            .add(createServiceDependency().setService(CommandProcessor.class).setRequired(true))
+            .add(createServiceDependency().setService(LogService.class).setRequired(false))
+        );
+    }
+
+    @Override
+    public void destroy(BundleContext context, DependencyManager manager) throws Exception
{
+        // nothing to do here for now
+    }
+}

Added: ace/trunk/org.apache.ace.gogo.servlet/src/org/apache/ace/gogo/servlet/ScriptServlet.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.gogo.servlet/src/org/apache/ace/gogo/servlet/ScriptServlet.java?rev=1571697&view=auto
==============================================================================
--- ace/trunk/org.apache.ace.gogo.servlet/src/org/apache/ace/gogo/servlet/ScriptServlet.java
(added)
+++ ace/trunk/org.apache.ace.gogo.servlet/src/org/apache/ace/gogo/servlet/ScriptServlet.java
Tue Feb 25 13:56:59 2014
@@ -0,0 +1,110 @@
+/*
+ * 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.ace.gogo.servlet;
+
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Map;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.felix.service.command.CommandProcessor;
+import org.apache.felix.service.command.CommandSession;
+import org.osgi.service.log.LogService;
+
+/**
+ * Servlet that can execute a Gogo script provided by the caller. Note that this is a generic
service that is not
+ * actually specific to ACE, it will accept any Gogo script.
+ * 
+ * Requests to this servlet must include a "script" parameter that contains a valid Gogo
script.
+ * 
+ * Note that commands used in the script must be deployed before the script is executed.
+ * 
+ * Motivation: provide the ability to script client calls to an ACE server for various automation
purposes.
+ */
+public class ScriptServlet extends HttpServlet {
+    private static final long serialVersionUID = -7838800050936438994L;
+    private static final String SCRIPT_KEY = "script";
+    private volatile LogService m_logger;
+    private volatile CommandProcessor m_processor;
+
+    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
IOException {
+        @SuppressWarnings("unchecked")
+        Dictionary<String, String> scriptDefinition = toDictionary(req.getParameterMap());
+        respondToScriptRequest(resp, scriptDefinition);
+    }
+
+    @Override
+    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
IOException {
+        String script = IOUtils.toString(req.getInputStream(), "UTF-8");
+        req.getInputStream();
+        Dictionary<String, String> scriptDefinition = new Hashtable<String, String>();
+        scriptDefinition.put(SCRIPT_KEY, script);
+        respondToScriptRequest(resp, scriptDefinition);
+    }
+
+    private void respondToScriptRequest(HttpServletResponse resp, Dictionary<String, String>
scriptDefinition) throws IOException {
+        try {
+            executeScript(scriptDefinition);
+        }
+        catch (Exception e) {
+            m_logger.log(LogService.LOG_ERROR, "Unable to execute Gogo script.", e);
+            resp.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
+        }
+    };
+
+    private void executeScript(Dictionary<String, String> scriptDefinition) throws
Exception {
+        String script = scriptDefinition.get(SCRIPT_KEY);
+        if (script == null) {
+            throw new IllegalArgumentException("Script definition *must* define at least
a 'script' property!");
+        }
+
+        CommandSession session = m_processor.createSession(System.in, System.out, System.err);
+        try {
+            Object scriptResult = session.execute(script);
+            m_logger.log(LogService.LOG_DEBUG, "Script output:\n" + scriptResult);
+        }
+        finally {
+            session.close();
+        }
+    }
+
+    private Dictionary<String, String> toDictionary(Map<String, ?> map) {
+        Dictionary<String, String> result = new Hashtable<String, String>();
+        for (Map.Entry<String, ?> entry : map.entrySet()) {
+            result.put(entry.getKey(), toString(entry.getValue()));
+        }
+        return result;
+    }
+
+    private String toString(Object value) {
+        if (value != null) {
+            if (!(value instanceof String)) {
+                m_logger.log(LogService.LOG_DEBUG, "Using String value for non-String object:
" + value);
+            }
+            return value.toString();
+        }
+        return null;
+    }
+}

Added: ace/trunk/run-client/conf/org.apache.ace.gogo.servlet.cfg
URL: http://svn.apache.org/viewvc/ace/trunk/run-client/conf/org.apache.ace.gogo.servlet.cfg?rev=1571697&view=auto
==============================================================================
--- ace/trunk/run-client/conf/org.apache.ace.gogo.servlet.cfg (added)
+++ ace/trunk/run-client/conf/org.apache.ace.gogo.servlet.cfg Tue Feb 25 13:56:59 2014
@@ -0,0 +1,3 @@
+org.apache.ace.server.servlet.endpoint=/gogo
+
+

Added: ace/trunk/run-server-allinone/conf/org.apache.ace.gogo.servlet.cfg
URL: http://svn.apache.org/viewvc/ace/trunk/run-server-allinone/conf/org.apache.ace.gogo.servlet.cfg?rev=1571697&view=auto
==============================================================================
--- ace/trunk/run-server-allinone/conf/org.apache.ace.gogo.servlet.cfg (added)
+++ ace/trunk/run-server-allinone/conf/org.apache.ace.gogo.servlet.cfg Tue Feb 25 13:56:59
2014
@@ -0,0 +1,3 @@
+org.apache.ace.server.servlet.endpoint=/gogo
+
+



Mime
View raw message