felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r870544 - in /websites/staging/felix/trunk/content: ./ documentation/subprojects/apache-felix-script-console-plugin.html documentation/subprojects/script-console-1.png
Date Mon, 22 Jul 2013 08:03:29 GMT
Author: buildbot
Date: Mon Jul 22 08:03:28 2013
New Revision: 870544

Staging update by buildbot for felix

(with props)
    websites/staging/felix/trunk/content/   (props changed)

Propchange: websites/staging/felix/trunk/content/
--- cms:source-revision (original)
+++ cms:source-revision Mon Jul 22 08:03:28 2013
@@ -1 +1 @@

Added: websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-script-console-plugin.html
--- websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-script-console-plugin.html
+++ websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-script-console-plugin.html
Mon Jul 22 08:03:28 2013
@@ -0,0 +1,206 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+    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.
+  <head>
+    <title>Apache Felix - Apache Felix Script Console Plugin</title>
+    <link rel="icon" href="/res/favicon.ico">
+    <link rel="stylesheet" href="/res/site.css" type="text/css" media="all">
+    <link rel="stylesheet" href="/res/codehilite.css" type="text/css" media="all">
+    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
+  </head>
+  <body>
+    <div class="title">
+      <div class="logo">
+        <a href="http://felix.apache.org/">
+          <img border="0" alt="Apache Felix" src="/res/logo.png">
+        </a>
+      </div>
+      <div class="header">
+        <a href="http://www.apache.org/">
+          <img border="0" alt="Apache" src="/res/apache.png">
+        </a>
+      </div>
+    </div>
+    <div class="menu"> 
+      <p><a href="/news.html">news</a>  <br />
+<a href="/license.html">license</a>  <br />
+<a href="/downloads.cgi">downloads</a>  <br />
+<a href="/documentation.html">documentation</a>  <br />
+<a href="/mailinglists.html">mailing lists</a>  <br />
+<a href="/documentation/community/contributing.html">contributing</a>  <br
+<a href="/sitemap.html">site map</a>  <br />
+<a href="http://www.apache.org/">asf</a>  <br />
+<a href="http://www.apache.org/security/">security</a>  <br />
+<a href="http://www.apache.org/foundation/sponsorship.html">sponsorship</a> 
<br />
+<a href="http://www.apache.org/foundation/thanks.html">sponsors</a>    </p>
+    src="http://www.apache.org/ads/button.html"
+    style="border-width:0; float: left"
+    frameborder="0"
+    scrolling="no"
+    width="135"
+    height="135">
+    </div>
+    <div class="main">
+      <div class="breadcrump" style="font-size: 80%;">
+        <a href="/">Home</a>&nbsp;&raquo&nbsp;<a href="/documentation.html">Documentation</a>&nbsp;&raquo&nbsp;<a
href="/documentation/subprojects.html">Apache Felix Subproject Documentation</a>
+      </div>
+      <h1>Apache Felix Script Console Plugin</h1>
+      <div class="note">
+Work in progress as part of FELIX-4122
+<p>Script Console is a Felix web console plugin which allows evaluation of scripts
within the OSGi container. It provides following
+<li>Support evaluation of script in any  e.g. Groovy, JavaScript, Ruby etc. You would
need to ensure that relevant language bundle is deployed</li>
+<li>Code editor with syntax highlighting support based on <a href="http://codemirror.net/">CodeMirror</a>
Javascript library</li>
+<li>Hot key support</li>
+<li>Execute remote testcase via evaluating test scripts</li>
+<p>A collection of useful scripts is maintained in <a href="https://gist.github.com/3748614">this
+<h3 id="installation">Installation</h3>
+<p>Untill the bundle is released you would need to build it and deploy</p>
+<h3 id="usage">Usage</h3>
+<p>After installing it you would see a new tab "Script Console" in <a href="http://localhost:4502/system/console">Felix
Web Console</a>.
+The plugin screen provides a textarea to author script code. One can select the language
via the given dropdown. The generated
+output is shown in pane below.</p>
+<p>The script exposes following variables
+<em> <code>request</code> - Current HttpServletRequest instance
+</em> <code>response</code> - Current HttpServletResponse instance
+<em> <code>reader</code> - Direct access to the Reader of the request -
same as request.getReader(). Use it for reading the data of an HTTP request body.
+</em> <code>out</code> - Direct access to the PrintWriter of the response
- same as response.getWriter(). Use it for writing to the HTTP response body.
+<em> <code>osgi</code> -  Provides convenience methods for scripts, mainly
osgi.getService(foo.bar.Service.class) to retrieve OSGi services available in
+   OSGi Container (Class notation depending on scripting language).
+</em> <code>bundleContext</code> - OSGi BundleContext instance for the
script console plugin bundle. Can be used to access the OSGi runtime</p>
+<p>So simplest script that can work is</p>
+<div class="codehilite"><pre><span class="n">out</span><span class="o">.</span><span
class="na">println</span> <span class="o">(</span><span class="s2">&quot;Hello
world!!&quot;</span><span class="o">);</span>
+<p>To access a service use <code>osgi.getService</code></p>
+<div class="codehilite"><pre><span class="kt">def</span> <span
class="n">httpService</span> <span class="o">=</span> <span class="n">osgi</span><span
class="o">.</span><span class="na">getService</span><span class="o">(</span><span
class="n">org</span><span class="o">.</span><span class="na">osgi</span><span
class="o">.</span><span class="na">service</span><span class="o">.</span><span
class="na">http</span><span class="o">.</span><span class="na">HttpService</span><span
class="o">.</span><span class="na">class</span><span class="o">)</span>
+<p>To access a service satisfying OSGi filter</p>
+<div class="codehilite"><pre><span class="kt">def</span> <span
class="n">eventPlugin</span> <span class="o">=</span> <span class="n">osgi</span><span
class="o">.</span><span class="na">getServices</span><span class="o">(</span><span
class="n">javax</span><span class="o">.</span><span class="na">servlet</span><span
class="o">.</span><span class="na">Servlet</span><span class="o">.</span><span
class="na">class</span><span class="o">,</span><span class="s1">&#39;(felix.webconsole.label=events)&#39;</span><span
class="o">)[</span><span class="mi">0</span><span class="o">]</span>
+<p>Following hotkeys work
+<em> Ctrl+F9 - Execute the script
+</em> Ctrl+q - Clear the output</p>
+<p>To try out Groovy scripts just install the <a href="http://repo1.maven.org/maven2/org/codehaus/groovy/groovy-all/1.8.6/groovy-all-1.8.6.jar">Groovy
+<h3 id="http-api">HTTP API</h3>
+<p>The plugin can also be invoked by making POST request. It supports following parameters</p>
+<li><code>code</code>- Script content. Can be norm form data or a multi
part content</li>
+<li><code>lang</code> - Language extension.<ul>
+<li>Groovy - groovy</li>
+<li>JavaScript - esp</li>
+<p>If any exception occurs while evaluating the script then it would return the exception
message with status set to 500. Scripts can control what output they want to emit.</p>
+<h3 id="screenshots">Screenshots</h3>
+<p><img src="script-console-1.png"></p>
+<h3 id="sample-scripts">Sample Scripts</h3>
+<p>Following are some sample scripts in Groovy. Note the scripts might be depending
on implementation details to access the
+relevant data structures</p>
+<p>Script to find out servlets which are registered problematically with Felix HTTP
+import org.osgi.service.http.HttpService
+import org.osgi.framework.FrameworkUtil
+import org.osgi.framework.Bundle</p>
+<p>def httpService = osgi.getService(HttpService.class)
+httpService.handlerRegistry.aliasMap.each{alias,servlet -&gt;
+    Bundle bnd = FrameworkUtil.getBundle(servlet.class)
+    println "$alias : ${servlet.class.name} ($bnd.symbolicName)"
+<p>Script to load a class which is not exported and then invoke some static method
on that class</p>
+<p>At times you need to access some private class to see the runtime state.</p>
+<div class="codehilite"><pre><span class="kn">import</span> <span
+<span class="kn">import</span> <span class="nn">org.osgi.framework.BundleContext</span>
+<span class="c1">//Script to load a class which is not exported and then invoke some
static method on that class</span>
+<span class="c1">//Name of the class</span>
+<span class="kt">def</span> <span class="n">className</span> <span
class="o">=</span> <span class="s2">&quot;org.apache.sling.engine.impl.SlingMainServlet&quot;</span>
+<span class="kt">def</span> <span class="n">resPath</span> <span
class="o">=</span> <span class="n">className</span><span class="o">.</span><span
class="na">replaceAll</span><span class="o">(</span><span class="s1">&#39;.&#39;</span><span
class="o">,</span><span class="s1">&#39;/&#39;</span><span
class="o">)+</span><span class="s2">&quot;.class&quot;</span>
+<span class="kt">def</span> <span class="n">bundles</span> <span
class="o">=</span> <span class="n">bundleContext</span><span class="o">.</span><span
class="na">getBundles</span><span class="o">().</span><span class="na">findAll</span><span
class="o">{</span><span class="n">Bundle</span> <span class="n">b</span>
<span class="o">-&gt;</span>
+    <span class="n">b</span><span class="o">.</span><span class="na">getEntry</span><span
class="o">(</span><span class="n">resPath</span><span class="o">)</span>
<span class="o">!=</span> <span class="kc">null</span>
+<span class="o">}</span>
+<span class="k">if</span><span class="o">(!</span><span class="n">bundles</span><span
+   <span class="n">println</span> <span class="s2">&quot;No bundle
found for class $className&quot;</span>
+   <span class="k">return</span>
+<span class="o">}</span>
+<span class="kt">def</span> <span class="n">b</span> <span class="o">=</span>
<span class="n">bundles</span><span class="o">.</span><span class="na">asList</span><span
class="o">().</span><span class="na">first</span><span class="o">()</span>
+<span class="kt">def</span> <span class="n">clazz</span> <span
class="o">=</span> <span class="n">b</span><span class="o">.</span><span
class="na">loadClass</span><span class="o">(</span><span class="n">className</span><span
+<span class="c1">//Invoke some static method</span>
+<span class="kt">def</span> <span class="n">result</span> <span
class="o">=</span> <span class="n">clazz</span><span class="o">.</span><span
class="na">metaClass</span><span class="o">.</span><span class="na">invokeStaticMethod</span><span
class="o">(</span><span class="n">clazz</span><span class="o">,</span>
<span class="s1">&#39;foo&#39;</span><span class="o">,</span>
 <span class="n">arg1</span><span class="o">)</span>
+<span class="n">println</span> <span class="n">result</span>
+<p>Script to find out which bundle embeds a given class</p>
+import org.osgi.framework.Bundle
+import org.osgi.framework.BundleContext</p>
+<p>//Name of the class
+def className = "org.apache.sling.engine.impl.SlingMainServlet"</p>
+<p>def resPath = className.replaceAll('.','/')+".class"
+def bundles = bundleContext.getBundles().findAll{Bundle b -&gt;
+    b.getEntry(resPath) != null
+<p>println "Following bundles have the class"
+    println it
+      <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;">
+        Rev. 1505617 by chetanm on Mon, 22 Jul 2013 08:03:10 +0000
+      </div>
+      <div class="trademarkFooter"> 
+        Apache Felix, Felix, Apache, the Apache feather logo, and the Apache Felix project
+        logo are trademarks of The Apache Software Foundation. All other marks mentioned
+        may be trademarks or registered trademarks of their respective owners.
+      </div>
+    </div>
+  </body>

Added: websites/staging/felix/trunk/content/documentation/subprojects/script-console-1.png
Binary file - no diff available.

Propchange: websites/staging/felix/trunk/content/documentation/subprojects/script-console-1.png
    svn:mime-type = image/png

View raw message