You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2017/09/06 13:24:25 UTC
svn commit: r1807480 [4/5] - in /sling/whiteboard/microsling: ./ src/
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/sling/ src/main/java/org/apache/sling/microsling/
src/main/java/org/apache/sling/micros...
Added: sling/whiteboard/microsling/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/microsling/src/main/webapp/WEB-INF/web.xml?rev=1807480&view=auto
==============================================================================
--- sling/whiteboard/microsling/src/main/webapp/WEB-INF/web.xml (added)
+++ sling/whiteboard/microsling/src/main/webapp/WEB-INF/web.xml Wed Sep 6 13:24:23 2017
@@ -0,0 +1,267 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+ -->
+
+<!DOCTYPE web-app PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd" >
+
+<web-app>
+ <display-name>Microsling Web Application</display-name>
+
+ <servlet>
+ <servlet-name>Logging</servlet-name>
+ <description>Configures the Log4J logging facility.</description>
+ <servlet-class>org.apache.jackrabbit.j2ee.LoggingServlet</servlet-class>
+
+ <init-param>
+ <param-name>log4j-config</param-name>
+ <param-value>/WEB-INF/log4j.xml</param-value>
+ <description>initial log4j configuration</description>
+ </init-param>
+
+ <load-on-startup>10</load-on-startup>
+ </servlet>
+
+ <servlet>
+ <servlet-name>JackrabbitRepository</servlet-name>
+ <description>
+ Creates a Jackrabbit repository (or opens it if already created) and makes it available as
+ a servlet context attribute.
+ </description>
+ <servlet-class>org.apache.jackrabbit.servlet.jackrabbit.JackrabbitRepositoryServlet</servlet-class>
+ <load-on-startup>20</load-on-startup>
+ </servlet>
+
+ <servlet>
+ <servlet-name>RepositoryAccess</servlet-name>
+ <description>
+ Used by the WebDAV servlet to access the repository
+ </description>
+ <servlet-class>org.apache.jackrabbit.j2ee.RepositoryAccessServlet</servlet-class>
+
+ <init-param>
+ <param-name>repository.context.attribute.name</param-name>
+ <param-value>javax.jcr.Repository</param-value>
+ </init-param>
+
+ <load-on-startup>40</load-on-startup>
+ </servlet>
+
+ <servlet>
+ <servlet-name>Webdav</servlet-name>
+ <description>Makes the repository available via WebDAV</description>
+ <servlet-class>org.apache.jackrabbit.j2ee.SimpleWebdavServlet</servlet-class>
+
+ <init-param>
+ <param-name>resource-path-prefix</param-name>
+ <param-value>/repository</param-value>
+ <description>defines the prefix for spooling resources out of the repository.</description>
+ </init-param>
+ <!--
+ <init-param>
+ <param-name>missing-auth-mapping</param-name>
+ <param-value>anonymous:anonymous</param-value>
+ <description>
+ Defines how a missing authorization header should be handled.
+ 1) If this init-param is missing, a 401 response is generated.
+ This is suiteable for clients (eg. webdav clients) for which
+ sending a proper authorization header is not possible if the
+ server never sent a 401.
+ 2) If this init-param is present with an empty value,
+ null-credentials are returned, thus forcing an null login
+ on the repository.
+ 3) If this init-param has a 'user:password' value, the respective
+ simple credentials are generated.
+ </description>
+ </init-param>
+ -->
+ <!--
+ Optional parameter to define the value of the 'WWW-Authenticate' header
+ -->
+ <!--
+ <init-param>
+ <param-name>authenticate-header</param-name>
+ <param-value>Basic realm="Jackrabbit Webdav Server"</param-value>
+ <description>
+ Defines the value of the 'WWW-Authenticate' header.
+ </description>
+ </init-param>
+ -->
+ <!--
+ Parameter used to configure behaviour of webdav resources such as:
+ - destinction between collections and non-collections
+ - resource filtering
+ -->
+ <init-param>
+ <param-name>resource-config</param-name>
+ <param-value>/WEB-INF/webdav-resource-config.xml</param-value>
+ <description>Defines various dav-resource configuration parameters.</description>
+ </init-param>
+ <load-on-startup>50</load-on-startup>
+ </servlet>
+
+ <servlet>
+ <servlet-name>Microsling</servlet-name>
+ <description>Microsling support servlet</description>
+ <servlet-class>org.apache.sling.microsling.servlet.MicroslingMainServlet</servlet-class>
+
+ <init-param>
+ <param-name>container-encoding</param-name>
+ <param-value>UTF-8</param-value>
+ </init-param>
+
+ <init-param>
+ <param-name>form-encoding</param-name>
+ <param-value>UTF-8</param-value>
+ </init-param>
+
+ <init-param>
+ <param-name>welcome-url</param-name>
+ <param-value>index.html</param-value>
+ <description>URL to redirect to when / is accessed</description>
+ </init-param>
+
+ <load-on-startup>999</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>Microsling</servlet-name>
+ <url-pattern>/microsling/*</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>Webdav</servlet-name>
+ <url-pattern>/repository/*</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>JackrabbitRepository</servlet-name>
+ <url-pattern>/repository-info</url-pattern>
+ </servlet-mapping>
+
+ <!-- ====================================================================== -->
+ <!-- M I M E T Y P E M A P P I N G -->
+ <!-- ====================================================================== -->
+ <mime-mapping>
+ <extension>doc</extension>
+ <mime-type>application/msword</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>bin</extension>
+ <mime-type>application/octet-stream</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>pdf</extension>
+ <mime-type>application/pdf</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>ai</extension>
+ <mime-type>application/postscript</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>eps</extension>
+ <mime-type>application/postscript</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>ps</extension>
+ <mime-type>application/postscript</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>rtf</extension>
+ <mime-type>application/rtf</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>mif</extension>
+ <mime-type>application/vnd.mif</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>ppt</extension>
+ <mime-type>application/vnd.ms-powerpoint</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>vcd</extension>
+ <mime-type>application/x-cdlink</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>js</extension>
+ <mime-type>application/x-javascript</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>mp3</extension>
+ <mime-type>audio/mpeg</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>ram</extension>
+ <mime-type>audio/x-pn-realaudio</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>rm</extension>
+ <mime-type>audio/x-pn-realaudio</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>ra</extension>
+ <mime-type>audio/x-realaudio</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>gif</extension>
+ <mime-type>image/gif</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>jpeg</extension>
+ <mime-type>image/jpeg</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>jpg</extension>
+ <mime-type>image/jpeg</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>png</extension>
+ <mime-type>image/png</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>tiff</extension>
+ <mime-type>image/tiff</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>tif</extension>
+ <mime-type>image/tiff</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>css</extension>
+ <mime-type>text/css</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>asc</extension>
+ <mime-type>text/plain</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>txt</extension>
+ <mime-type>text/plain</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>xml</extension>
+ <mime-type>text/xml</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>html</extension>
+ <mime-type>text/html</mime-type>
+ </mime-mapping>
+ <mime-mapping>
+ <extension>htm</extension>
+ <mime-type>text/html</mime-type>
+ </mime-mapping>
+</web-app>
Added: sling/whiteboard/microsling/src/main/webapp/WEB-INF/webdav-resource-config.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/microsling/src/main/webapp/WEB-INF/webdav-resource-config.xml?rev=1807480&view=auto
==============================================================================
--- sling/whiteboard/microsling/src/main/webapp/WEB-INF/webdav-resource-config.xml (added)
+++ sling/whiteboard/microsling/src/main/webapp/WEB-INF/webdav-resource-config.xml Wed Sep 6 13:24:23 2017
@@ -0,0 +1,162 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+ -->
+<!--
+<!DOCTYPE config [
+ <!ELEMENT config (iomanager , propertymanager, (collection | noncollection)? , filter?) >
+
+ <!ELEMENT iomanager (class, iohandler*) >
+ <!ELEMENT iohandler (class) >
+
+ <!ELEMENT propertymanager (class, propertyhandler*) >
+ <!ELEMENT propertyhandler (class) >
+
+ <!ELEMENT collection (nodetypes) >
+ <!ELEMENT noncollection (nodetypes) >
+
+ <!ELEMENT filter (class, namespaces?, nodetypes?) >
+
+ <!ELEMENT class >
+ <!ATTLIST class
+ name CDATA #REQUIRED
+ >
+ <!ELEMENT namespaces (prefix | uri)* >
+ <!ELEMENT prefix (CDATA) >
+ <!ELEMENT uri (CDATA) >
+
+ <!ELEMENT nodetypes (nodetype)* >
+ <!ELEMENT nodetype (CDATA) >
+]>
+-->
+
+<config>
+ <!--
+ Defines the IOManager implementation that is responsible for passing import/export
+ request to the individual IO-handlers.
+ -->
+ <iomanager>
+ <!-- class element defines the manager to be used. The specified class
+ must implement the IOManager interface.
+ Note, that the handlers are being added and called in the order
+ they appear in the configuration.
+ -->
+ <class name="org.apache.jackrabbit.server.io.IOManagerImpl" />
+ <iohandler>
+ <class name="org.apache.jackrabbit.server.io.ZipHandler" />
+ </iohandler>
+ <iohandler>
+ <class name="org.apache.jackrabbit.server.io.XmlHandler" />
+ </iohandler>
+ <iohandler>
+ <class name="org.apache.jackrabbit.server.io.DirListingExportHandler" />
+ </iohandler>
+ <iohandler>
+ <class name="org.apache.jackrabbit.server.io.DefaultHandler" />
+ </iohandler>
+ </iomanager>
+ <!--
+ Example config for iomanager that populates its list of handlers with
+ default values. Therefore the 'iohandler' elements are omited.
+ -->
+ <!--
+ <iomanager>
+ <class name="org.apache.jackrabbit.server.io.DefaultIOManager" />
+ </iomanager>
+ -->
+ <!--
+ Defines the PropertyManager implementation that is responsible for export
+ and import of resource properties.
+ -->
+ <propertymanager>
+ <!-- class element defines the manager to be used. The specified class
+ must implement the PropertyManager interface.
+ Note, that the handlers are being added and called in the order
+ they appear in the configuration.
+ -->
+ <class name="org.apache.jackrabbit.server.io.PropertyManagerImpl" />
+ <propertyhandler>
+ <class name="org.apache.jackrabbit.server.io.ZipHandler" />
+ </propertyhandler>
+ <propertyhandler>
+ <class name="org.apache.jackrabbit.server.io.XmlHandler" />
+ </propertyhandler>
+ <propertyhandler>
+ <class name="org.apache.jackrabbit.server.io.DirListingExportHandler" />
+ </propertyhandler>
+ <propertyhandler>
+ <class name="org.apache.jackrabbit.server.io.DefaultHandler" />
+ </propertyhandler>
+ </propertymanager>
+ <!--
+ Define nodetypes, that should never by displayed as 'collection'
+ -->
+ <noncollection>
+ <nodetypes>
+ <nodetype>nt:file</nodetype>
+ <nodetype>nt:resource</nodetype>
+ </nodetypes>
+ </noncollection>
+ <!--
+ Example: Defines nodetypes, that should always be displayed as 'collection'.
+ -->
+ <!--
+ <collection>
+ <nodetypes>
+ <nodetype>nt:folder</nodetype>
+ <nodetype>rep:root</nodetype>
+ </nodetypes>
+ </collection>
+ -->
+ <!--
+ Filter that allows to prevent certain items from being displayed.
+ Please note, that this has an effect on PROPFIND calls only and does not
+ provide limited access to those items matching any of the filters.
+
+ However specifying a filter may cause problems with PUT or MKCOL if the
+ resource to be created is being filtered out, thus resulting in inconsistent
+ responses (e.g. PUT followed by PROPFIND on parent).
+ -->
+ <filter>
+ <!-- class element defines the resource filter to be used. The specified class
+ must implement the ItemFilter interface -->
+ <class name="org.apache.jackrabbit.webdav.simple.DefaultItemFilter" />
+ <!-- Nodetype names to be used to filter child nodes.
+ A child node can be filtered if the declaring nodetype of its definition
+ is one of the nodetype names specified in the nodetypes Element.
+ E.g. defining 'rep:root' as filtered nodetype whould result in jcr:system
+ being hidden but no other child node of the root node, since those
+ are defined by the nodetype nt:unstructered.
+ -->
+ <!--
+ <nodetypes>
+ <nodetype>rep:root</nodetype>
+ </nodetypes>
+ -->
+ <!-- Namespace prefixes or uris. Items having a name that matches any of the
+ entries will be filtered.
+ -->
+ <namespaces>
+ <prefix>rep</prefix>
+ <prefix>jcr</prefix>
+ <!--
+ <uri>internal</uri>
+ <uri>http://www.jcp.org/jcr/1.0</uri>
+ -->
+ </namespaces>
+ </filter>
+</config>
+
Added: sling/whiteboard/microsling/src/main/webapp/content-creation-forms.html
URL: http://svn.apache.org/viewvc/sling/whiteboard/microsling/src/main/webapp/content-creation-forms.html?rev=1807480&view=auto
==============================================================================
--- sling/whiteboard/microsling/src/main/webapp/content-creation-forms.html (added)
+++ sling/whiteboard/microsling/src/main/webapp/content-creation-forms.html Wed Sep 6 13:24:23 2017
@@ -0,0 +1,60 @@
+<html>
+<head>
+ <title>microsling content creation forms</title>
+ <link rel="stylesheet" href="microsling.css"/>
+</head>
+<body>
+ <h1>microsling content creation forms</h1>
+
+ <div class="note">
+ <a href="../">back to homepage</a>
+ </div>
+
+ <p>
+ Use these forms to test the microsling request processing and rendering SlingServlets.
+ </p>
+
+ <div>
+ <form class="testbox" action="microsling/content/testing.sling" method="POST">
+ <input type="hidden" name="slingDisplayExtension" value="html"/>
+
+ <h1>SlingPostServlet content creation form</h1>
+ <p>
+ Submitting this form creates an <em>nt:unstructured</em> node under content/testing,
+ and displays it using an <em>html</em> extension.
+ </p>
+ <p>
+ See the <em>Velocity scripts</em> and <em>server-side Javascript</em> pages for how to
+ render the content using templates and scripts.
+ </p>
+ <p>
+ Title:
+ <br/>
+ <input name="title" type="text" size="40" value="Default title"/>
+ <br/>
+ Text:
+ <br/>
+ <input name="text" type="text" size="80" value="Default text of the test node"/>
+ <br/>
+ slingResourceType:
+ <span class="note">(leave this empty to use the JCR node type for script resolution)</span>
+ <br/>
+ <input name="slingResourceType" type="text" size="80" value="microsling/example"/>
+ <br/>
+ <input type="submit" value="Create and display node"/>
+ </p>
+ </form>
+ </div>
+
+ <div>
+ <form class="testbox" action="microsling/whatever" method="POST">
+ <h1>Non-Sling POST method form</h1>
+ <p>
+ Submitting this form should cause an error 501: <em>POST method is not supported by DefaultSlingServlet</em>.
+ </p>
+ <input type="submit"/>
+ </form>
+ </div>
+
+</body>
+</html>
\ No newline at end of file
Added: sling/whiteboard/microsling/src/main/webapp/freemarker-scripts.html
URL: http://svn.apache.org/viewvc/sling/whiteboard/microsling/src/main/webapp/freemarker-scripts.html?rev=1807480&view=auto
==============================================================================
--- sling/whiteboard/microsling/src/main/webapp/freemarker-scripts.html (added)
+++ sling/whiteboard/microsling/src/main/webapp/freemarker-scripts.html Wed Sep 6 13:24:23 2017
@@ -0,0 +1,38 @@
+<html>
+<head>
+ <title>microsling FreeMarker templates</title>
+ <link rel="stylesheet" href="microsling.css"/>
+</head>
+<body>
+ <h1>microsling FreeMarker templates</h1>
+
+ <div class="note">
+ <a href="../">back to homepage</a>
+ </div>
+ <p>
+ Scripts found by the <code>SlingScriptResolver</code> using the <code>.ftl</code> extension are executed by
+ the <code>FreemarkerScriptEngine</code>.
+ </p>
+ <p>
+ This works exactly like the <a href="velocity-scripts.html">Velocity templates</a>, except that
+ templates use the FreeMarker syntax.
+ </p>
+ <p>
+ Here's an example HTML template. See the <a href="http://freemarker.org">FreeMarker</a> website
+ more info about the syntax.
+ <pre><html>
+<body>
+<h1>This is generated from a FreeMarker template</h1>
+<p>
+ The current resource URI is <b>${resource.URI}</b>
+</p>
+
+<h2>${resource.getItem().getProperty("title").getString()}</h2>
+<p>
+ ${resource.getItem().getProperty("text").getString()}
+</p>
+
+</body></pre>
+ </p>
+</body>
+</html>
\ No newline at end of file
Added: sling/whiteboard/microsling/src/main/webapp/index.html
URL: http://svn.apache.org/viewvc/sling/whiteboard/microsling/src/main/webapp/index.html?rev=1807480&view=auto
==============================================================================
--- sling/whiteboard/microsling/src/main/webapp/index.html (added)
+++ sling/whiteboard/microsling/src/main/webapp/index.html Wed Sep 6 13:24:23 2017
@@ -0,0 +1,153 @@
+<html>
+<head>
+ <title>microsling homepage</title>
+ <link rel="stylesheet" href="microsling.css"/>
+</head>
+<body>
+ <h1>microsling homepage</h1>
+
+ <div style="color:red; font-weight:bold; font-size: 18pt">
+ The microsling code from the sling-whiteboard is OBSOLETE,
+ see the microsling-code module in the main Sling code
+ repository instead.
+ </div>
+
+ <p>
+ <em>Sling request processing, reduced to the max!</em>
+ </p>
+
+ <h2>Overview</h2>
+ <p>
+ The goal of microsling is to demonstrate the Sling HTTP
+ request processing in the simplest possible way, to help the
+ community converge on the goals and architecture of this
+ module.
+ </p>
+
+ <h2>microsling test links</h2>
+ <ul>
+ <li>
+ <a href="content-creation-forms.html">
+ Content creation forms
+ </a>: use this page to create content and test the rendering mechanisms.
+ </li>
+ <li>
+ <a href="velocity-scripts.html">
+ Velocity templates
+ </a>: explains how to use Velocity templates to render content.
+ </li>
+ <li>
+ <a href="server-side-javascript.html">
+ Server-side javascript and ESP templates
+ </a>: explains how to use server-side javascript and javascript-based ESP templates to process requests.
+ </li>
+ <li>
+ <a href="freemarker-scripts.html">
+ FreeMarker templates
+ </a>: explains how to use FreeMarker templates to render content.
+ </li>
+ </ul>
+
+ <h2>Show me the code</h2>
+ <p>
+ Here's a brief description of how microsling processes HTTP requests. Follow the links to the source code
+ for more details.
+ <ul>
+ <li>
+ The main <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java?view=markup">MicroSlingServlet</a>
+ handles HTTP requests. That's probably where you want to
+ start studying the code.
+ </li>
+ <li>
+ <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/RequestFilter.java?view=markup">RequestFilter</a>
+ objects process the incoming requests before passing them on to SlingServlet objects
+ which do the actual processing.
+ <ul>
+ <li>
+ The
+ <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/ResourceResolverFilter.java?view=markup">ResourceResolverFilter</a>
+ selects the <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/Resource.java?view=markup">Resource</a> (currently a JCR Node, OCM is not used yet) to process.
+ </li>
+ <li>
+ The <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/contenttype/ResponseContentTypeResolverFilter.java?view=markup">ResponseContentTypeResolverFilter</a>
+ computes the desired <em>Content-Type</em> for the response, so that rendering scripts or SlingServlets know what output format to generate.
+ </li>
+ </ul>
+ Other filters would include
+ Locale selection, client capabilities analysis, etc.
+
+ </li>
+ <li>
+ After applying the RequestFilters, the MicroSlingServlet selects a
+ <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/SlingServlet.java?view=markup">SlingServlet</a> to process the request.
+ The first SlingServlet where canProcess(...) returns true is used.
+ </li>
+ <li>
+ The <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/requestcontext/SlingRequestContext.java?view=markup">SlingRequestContext</a> is
+ stored as a request attribute, and gives access to Sling-specific objects (Resource, repository Session, etc.) used for request processing.
+ </li>
+ <li>
+ A few SlingServlet classes are implemented (source code <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/">here</a>):
+ <ul>
+ <li>
+ The SlingPostServlet allows Nodes to be created by POSTing to URLs ending
+ with ".sling".
+ </li>
+ <li>
+ The VelocityTemplatesServlet and RhinoJavascriptServlet execute server-side scripts in those
+ languages to process requests.
+ </li>
+ <li>
+ The DefaultSlingServlet is used when no other SlingServlet wants the request.
+ </li>
+ </ul>
+ </li>
+ <li>
+ The <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/SlingScriptResolver.java?view=markup">SlingScriptResolver</a>
+ is used by the scripting SlingServlet classes to locate scripts in the repository.
+ See comments in that class for how script paths are computed based on the Resource's resourceType and the
+ request method and extension.
+ </li>
+ <li>
+ Rendering scripts can generate various output formats, for example a Velocity script named "get.xml.vlt" will
+ cause a page with <em>Content-Type=text/xml</em> to be generated by the VelocityTemplatesServlet.
+ </li>
+ <li>
+ The microsling architecture allows
+ additional scripting engines (JSP, JRuby, BSF,...) to be plugged in easily - and this would
+ of course be much easier with OSGi.
+ </li>
+ <li>
+ We'll probably need a ResponseFilter interface at some point, but for now it's not needed. It could be useful
+ to apply "rendering standards" to the output, adding header/footers/glitter to HTML pages for example.
+ </li>
+ </ul>
+ <p>
+ If you have followed the links to source code in the above descriptions, you've seen most or all of the interesting
+ microsling source code. What's remaining are a few simple support classes.
+ </p>
+ </p>
+
+ <h2>No OSGi</h2>
+ <p>
+ To keep things simple, microsling does <em>not</em> use OSGi.
+ We will of course continue to use OSGi in the real Sling, and there are many
+ places in the code which say <em>TODO - use OSGi plugins here</em>. Keeping things
+ "static" for this example makes it easier to concentrate on the basics.
+ </p>
+
+ <h2>More test links</h2>
+ <p>
+ <ul>
+ <li>
+ <a href="repository-info">repository-info</a>, dumps the JCR repository
+ properties.
+ </li>
+ <li>
+ <a href="repository/default">WebDAV mount point</a>: use this URL to mount
+ the repository via WebDAV (login = admin/admin).
+ </li>
+ </ul>
+ </p>
+</body>
+</html>
Added: sling/whiteboard/microsling/src/main/webapp/microsling.css
URL: http://svn.apache.org/viewvc/sling/whiteboard/microsling/src/main/webapp/microsling.css?rev=1807480&view=auto
==============================================================================
--- sling/whiteboard/microsling/src/main/webapp/microsling.css (added)
+++ sling/whiteboard/microsling/src/main/webapp/microsling.css Wed Sep 6 13:24:23 2017
@@ -0,0 +1,58 @@
+body {
+ font-family: Verdana,Helvetica,Arial,sans-serif;
+}
+
+h1,h2,h3,h4 {
+ color:#869900;
+}
+
+h1 {
+ border-color:#999999;
+ border-style:solid solid dotted;
+ border-width:0px 0px 1px;
+ color:#869900;
+ font-size:x-large;
+ font-weight:900;
+ padding:20px 4px 4px 0px;
+}
+
+h2 {
+ font-size: large;
+ font-weight:900;
+}
+
+h3 {
+ font-weight:900;
+ font-size:100%;
+}
+
+.testbox {
+ border: solid gray 1px;
+ margin: 1em;
+ padding: 0.5em;
+}
+
+form h1 {
+ padding: 1px;
+ margin: 1px;
+ font-size: 100%;
+}
+
+p {
+ margin-bottom: 0.5em;
+}
+
+li {
+ margin-bottom: 0.2em;
+}
+
+pre {
+ font-size: 120%;
+ background-color: #FFFFCC;
+ border: solid #FF9900 1px;
+ padding: 0.5em;
+}
+
+.note {
+ font-size:80%;
+}
Added: sling/whiteboard/microsling/src/main/webapp/server-side-javascript.html
URL: http://svn.apache.org/viewvc/sling/whiteboard/microsling/src/main/webapp/server-side-javascript.html?rev=1807480&view=auto
==============================================================================
--- sling/whiteboard/microsling/src/main/webapp/server-side-javascript.html (added)
+++ sling/whiteboard/microsling/src/main/webapp/server-side-javascript.html Wed Sep 6 13:24:23 2017
@@ -0,0 +1,137 @@
+<html>
+<head>
+ <title>microsling server-side javascript and ESP templates</title>
+ <link rel="stylesheet" href="microsling.css"/>
+</head>
+<body>
+ <h1>microsling server-side javascript and ESP templates</h1>
+
+ <div class="note">
+ <a href="../">back to homepage</a>
+ </div>
+
+ <p>
+ Server-side javascript code and javascript-based ESP templates can be used by microsling to process requests.
+ The scripts are located by the
+ <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/SlingScriptResolver.java?view=markup">SlingScriptResolver</a>
+ , as for the <a href="velocity-scripts.html">Velocity templates</a> (see that
+ page for more details about how this resolution works).
+ </p>
+ <p>
+ Scripts can either:
+ <ul>
+ <li>
+ Have the <em>.esp</em> extension to use the microsling <em>ECMAscript Server Pages</em> syntax
+ described below.
+ </li>
+ <li>
+ Have the <em>.js</em> extension to use "raw" javascript.
+ </li>
+ </ul>
+ </p>
+ <p>
+ Server-side javascript support is implemented by the
+ <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/RhinoJavascriptServlet.java?revision=585096&view=markup">RhinoJavascriptServlet</a>.
+ </p>
+ <p>
+ To test this, remove or rename <a href="velocity-scripts.html">Velocity templates</a>
+ if you played with them before (Velocity has priority due to the order in which the SlingServlet classes
+ are setup), and store one of the scripts shown
+ below under <em>/sling/scripts/microsling/example/</em>, using the filenames shown in comments in the scripts below.
+ </p>
+ <p>
+ Content nodes created with the <a href="content-creation-forms.html">Content creation forms</a>
+ should then be displayed in HTML, with a layout defined by the example scripts.
+ </p>
+ <p>
+ As for the Velocity templates, other output formats can be generated, for example by renaming the ESP template
+ to <em>plain.esp</em> (as the Content-type for text is <em>text/plain</em>), modifying it to output plain text
+ and using a <em>.txt</em> extension in the request.
+ </p>
+
+ <h2>ECMAscript Server Pages (ESP)</h2>
+ <p>
+ <em>ECMAscript Server Pages</em> work much like JSP:
+ <ul>
+ <li>
+ A template mixes javascript code with litteral text that is copied to the output.
+ </li>
+ <li>
+ <em><% ... %></em> tags enclose code blocks.
+ </li>
+ <li>
+ <em><%= ... %></em> tags include the result of a javascript expression in the output.
+ </li>
+ <li>
+ Several standard objects are available in javascript to access microsling data
+ (TODO: document these objects - for now see the RhinoJavascriptServlet source code)
+ </li>
+ </ul>
+ </p>
+ <h3>ESP template example</h3>
+ <pre>
+<%-- microsling ESP template example, store this as html.esp --%>
+<html>
+<body>
+<p>This page is generated from an ESP template!</p>
+<h1><%= resource.getURI() %></h1>
+<%
+ for (var prop in resource.item) {
+ %>
+ <p>
+ <%= resource.item[prop] %>
+ </p>
+ <%
+ }
+%>
+</body>
+</html></pre>
+ <h2>Raw javascript</h2>
+ <p>
+ Raw javascript is probably more useful to handle the POST, PUT or DELETE methods.
+ </p>
+
+ <h3>Javascript example</h3>
+ <pre>
+// store this as html.js in the repository
+// TODO this is not very useful, rewrite this example
+out.println("<html><body>");
+out.println("<p>This page is generated from a rhino script</p>");
+out.println("<h1>" + resource.getURI() + "</h1>");
+out.println("<p>Title: " + resource.getItem().getProperty('title').getString() + "</p>");
+out.println("<p>Text: " + resource.getItem().getProperty('text').getString() + "</p>");
+out.println("</body></html>");</pre>
+ </p>
+ </div>
+
+ <h2>Directory listing example</h2>
+ <p>
+ Store the following template under
+ <code>sling/scripts/NODETYPES/nt/unstructured/html.esp</code> to render a simple
+ directory listing for <em>nt:unstructured</em> nodes which do not have a
+ <code>slingComponentId</code> property.
+ </p>
+ <pre>
+<%-- microsling ESP directory listing example -%>
+<html>
+<body>
+<p>This HTML directory listing is generated from an ESP template!</p>
+<h1><%= resource.uri %></h1>
+<ol>
+<%
+for (var prop in resource.item) {
+ if (resource.item[prop]["text"]) {
+ %><li><a href="/microsling<%= resource.item[prop] %>.html"><%= resource.item[prop] %></a></li><%
+ }
+}
+%>
+</ol>
+</body>
+</html></pre>
+ <p>
+ If you have created some content with the test form, and activated the above template,
+ <a href="microsling/content/testing.sling.html">microsling/content/testing.sling.html</a> should
+ display an HTML directory listing.
+ </p>
+</body>
+</html>
\ No newline at end of file
Added: sling/whiteboard/microsling/src/main/webapp/velocity-scripts.html
URL: http://svn.apache.org/viewvc/sling/whiteboard/microsling/src/main/webapp/velocity-scripts.html?rev=1807480&view=auto
==============================================================================
--- sling/whiteboard/microsling/src/main/webapp/velocity-scripts.html (added)
+++ sling/whiteboard/microsling/src/main/webapp/velocity-scripts.html Wed Sep 6 13:24:23 2017
@@ -0,0 +1,65 @@
+<html>
+<head>
+ <title>microsling Velocity templates</title>
+ <link rel="stylesheet" href="microsling.css"/>
+</head>
+<body>
+ <h1>microsling Velocity templates</h1>
+
+ <div class="note">
+ <a href="../">back to homepage</a>
+ </div>
+ <p>
+ When processing requests, the <em>VelocityTemplatesServlet</em> ask the <em>SlingScriptResolver</em>
+ for scripts with the <em>.vlt</em> extension.
+ </p>
+ <p>
+ If a script
+ is found, it used as a Velocity template to render the content.
+ </p>
+ <p>
+ To test this, try storing (via WebDAV, see mount point URL on the microsling homepage) the following script in your
+ repository under <em> /sling/scripts/microsling/example/html.vlt</em> .
+ Doing so will cause microsling to use that script
+ to render nodes having <em>slingResourceType=microsling/example</em>.
+ </p>
+ <p>
+ To try that rendering, use the <a href="content-creation-forms.html">content creation</a> page to create
+ and node and display it.
+ </p>
+ <p>
+ The name <em>html.vlt</em> indicates that this script is meant to process HTTP GET requests with
+ expect a <em>text/html</em> response.
+ </p>
+ <p>
+ For other HTTP methods the script would have the method name,
+ for example POST.vlt for a POST. But
+ GET is probably the only request method that makes sense to process with Velocity templates.
+ </p>
+ <p>
+ To generate XML instead, rename the script to <em>xml.vlt</em>, modify it to generate
+ the XML of your choice, and replace <em>.html</em> with <em>.xml</em> at the end of the request URL.
+ </p>
+ <p>
+ Here's the example HTML template. See the <a href="http://velocity.apache.org">Velocity website</a> for
+ more info about the syntax.
+ <pre><html>
+<body>
+<h1>This is generated from a Velocity template</h1>
+<p>
+ The current resource URI is <b>$resource.URI</b>
+</p>
+
+<h2>$resource.getItem().getProperty("title").getString()</h2>
+<p>
+ $resource.getItem().getProperty("text").getString()
+</p>
+
+</body>
+</html></pre> </p>
+ <p>
+ To deactivate the Velocity-based rendering of nodes, rename or delete the corresponding rendering
+ scripts.
+ </p>
+</body>
+</html>
\ No newline at end of file
Added: sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/CreateNodeTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/CreateNodeTest.java?rev=1807480&view=auto
==============================================================================
--- sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/CreateNodeTest.java (added)
+++ sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/CreateNodeTest.java Wed Sep 6 13:24:23 2017
@@ -0,0 +1,52 @@
+/*
+ * 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.sling.microsling.integration;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.httpclient.methods.GetMethod;
+
+/** Test creating a Node using the MicroslingIntegrationTestClient */
+public class CreateNodeTest extends MicroslingHttpTestBase {
+
+ public void testCreateNode() throws IOException {
+ final String url = HTTP_BASE_URL + TEST_PATH + ".sling";
+
+ // add some properties to the node
+ final Map<String,String> props = new HashMap<String,String>();
+ props.put("name1","value1");
+ props.put("name2","value2");
+
+ // POST and get URL of created node
+ String urlOfNewNode = null;
+ try {
+ urlOfNewNode = testClient.createNode(url, props);
+ } catch(IOException ioe) {
+ fail("createNode failed: " + ioe);
+ }
+
+ // get and check URL of created node
+ final GetMethod get = new GetMethod(urlOfNewNode);
+ final int status = httpClient.executeMethod(get);
+ assertEquals(urlOfNewNode + " must be accessible after createNode",200,status);
+ final String responseBodyStr = get.getResponseBodyAsString();
+ assertTrue(responseBodyStr.contains("value1"));
+ assertTrue(responseBodyStr.contains("value2"));
+ }
+}
\ No newline at end of file
Added: sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java?rev=1807480&view=auto
==============================================================================
--- sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java (added)
+++ sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java Wed Sep 6 13:24:23 2017
@@ -0,0 +1,52 @@
+/*
+ * 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.sling.microsling.integration;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/** Test uploading files to the microsling repository
+ * via WebDAV, as a first step towards testing the
+ * complete content creation and rendering scenario.
+ */
+public class FileUploadTest extends MicroslingHttpTestBase {
+
+ /** This only tests the WebDAV interface. We know it works, so
+ * we're mostly testing our test code here ;-)
+ */
+ public void testUploadAndDelete() throws IOException {
+ final String testFile = "/integration-test/testfile.txt";
+ final InputStream data = getClass().getResourceAsStream(testFile);
+ try {
+ assertNotNull("Local test file " + testFile + " must be found",data);
+
+ final String webdavUrl = WEBDAV_BASE_URL + "/FileUploadTest." + System.currentTimeMillis() + ".txt";
+
+ // Upload a file via WebDAV, verify, delete and verify
+ assertHttpStatus(webdavUrl, 404, "Resource " + webdavUrl + " must not exist before test");
+ int status = testClient.upload(webdavUrl, data);
+ assertEquals("upload must return status code 201",201,status);
+ assertHttpStatus(webdavUrl, 200, "Resource " + webdavUrl + " must exist after upload");
+ testClient.delete(webdavUrl);
+ assertHttpStatus(webdavUrl, 404, "Resource " + webdavUrl + " must not exist anymore after deleting");
+ } finally {
+ if(data!=null) {
+ data.close();
+ }
+ }
+ }
+}
Added: sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/HttpPingTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/HttpPingTest.java?rev=1807480&view=auto
==============================================================================
--- sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/HttpPingTest.java (added)
+++ sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/HttpPingTest.java Wed Sep 6 13:24:23 2017
@@ -0,0 +1,34 @@
+/*
+ * 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.sling.microsling.integration;
+
+
+/** Ping the microsling server to verify that our integration test
+ * setup is ok (SLING-82).
+ */
+public class HttpPingTest extends MicroslingHttpTestBase {
+ public void testWebServerRoot() throws Exception
+ {
+ assertHttpStatus(HTTP_BASE_URL + "/", 200);
+ }
+
+ public void test404() throws Exception
+ {
+ assertHttpStatus(HTTP_BASE_URL + "/someNonExistentUrl", 404);
+ }
+
+}
\ No newline at end of file
Added: sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java?rev=1807480&view=auto
==============================================================================
--- sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java (added)
+++ sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java Wed Sep 6 13:24:23 2017
@@ -0,0 +1,85 @@
+/*
+ * 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.sling.microsling.integration;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.sling.microsling.integration.helpers.MicroslingIntegrationTestClient;
+
+/** Base class for HTTP-based microsling integration tests */
+class MicroslingHttpTestBase extends TestCase {
+ public static final String HTTP_BASE_URL = System.getProperty("microsling.http.server.url");
+ public static final String WEBDAV_BASE_URL = System.getProperty("microsling.webdav.server.url");
+
+ /** base path for test files */
+ public static final String TEST_PATH = "/microsling-integration-tests";
+
+ public static final String CONTENT_TYPE_HTML = "text/html";
+ public static final String CONTENT_TYPE_XML = "text/xml";
+ public static final String CONTENT_TYPE_PLAIN = "text/plain";
+
+ protected MicroslingIntegrationTestClient testClient;
+ protected HttpClient httpClient;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // assume http and webdav are on the same host + port
+ URL url = null;
+ try {
+ url = new URL(HTTP_BASE_URL);
+ } catch(MalformedURLException mfe) {
+ // MalformedURLException doesn't tell us the URL by default
+ throw new IOException("MalformedURLException: " + HTTP_BASE_URL);
+ }
+
+ // setup HTTP client, with authentication (using default Jackrabbit credentials)
+ httpClient = new HttpClient();
+ httpClient.getParams().setAuthenticationPreemptive(true);
+ Credentials defaultcreds = new UsernamePasswordCredentials("admin", "admin");
+ httpClient.getState().setCredentials(new AuthScope(url.getHost(), url.getPort(), AuthScope.ANY_REALM), defaultcreds);
+
+ testClient = new MicroslingIntegrationTestClient(httpClient);
+ }
+
+ /** Verify that given URL returns expectedStatusCode
+ * @throws IOException */
+ protected void assertHttpStatus(String urlString, int expectedStatusCode, String assertMessage) throws IOException {
+ final int status = httpClient.executeMethod(new GetMethod(urlString));
+ if(assertMessage == null) {
+ assertEquals(expectedStatusCode, status);
+ } else {
+ assertEquals(assertMessage, expectedStatusCode, status);
+ }
+ }
+
+ /** Verify that given URL returns expectedStatusCode
+ * @throws IOException */
+ protected void assertHttpStatus(String urlString, int expectedStatusCode) throws IOException {
+ assertHttpStatus(urlString, expectedStatusCode, null);
+ }
+}
\ No newline at end of file
Added: sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MkdirTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MkdirTest.java?rev=1807480&view=auto
==============================================================================
--- sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MkdirTest.java (added)
+++ sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MkdirTest.java Wed Sep 6 13:24:23 2017
@@ -0,0 +1,62 @@
+/*
+ * 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.sling.microsling.integration;
+
+import java.io.IOException;
+
+/** Test the MicroslingIntegrationTestClient's mkdir functions */
+public class MkdirTest extends MicroslingHttpTestBase {
+
+ /** Try creating a directory via WebDAV */
+ public void testMkdir() throws IOException {
+ final String testDirUrl = WEBDAV_BASE_URL + TEST_PATH + System.currentTimeMillis();
+
+ assertHttpStatus(testDirUrl, 404, testDirUrl);
+
+ try {
+ testClient.mkdir(testDirUrl);
+ } catch(IOException ioe) {
+ fail(ioe.getMessage());
+ }
+
+ assertHttpStatus(testDirUrl, 200, testDirUrl);
+
+ try {
+ testClient.mkdir(testDirUrl);
+ } catch(IOException ioe) {
+ fail("mkdir must succeed on an existing directory, got IOException:" + ioe);
+ }
+
+ assertHttpStatus(testDirUrl, 200, testDirUrl);
+
+ testClient.delete(testDirUrl);
+ assertHttpStatus(testDirUrl, 404, testDirUrl + " must be gone after DELETE");
+ }
+
+ /** Try creating a deep directory structure */
+ public void testMkdirDeep() throws IOException {
+ final String path = TEST_PATH + "/mkdir-test-" + System.currentTimeMillis() + "/something";
+ final String url = WEBDAV_BASE_URL + path;
+ assertHttpStatus(url,404,url + " must not exist before test");
+ try {
+ testClient.mkdirs(WEBDAV_BASE_URL, path);
+ } catch(IOException ioe) {
+ fail("mkdirs failed:" + ioe);
+ }
+ assertHttpStatus(url,200,url + " must exist after test");
+ }
+}
Added: sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java?rev=1807480&view=auto
==============================================================================
--- sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java (added)
+++ sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java Wed Sep 6 13:24:23 2017
@@ -0,0 +1,117 @@
+/*
+ * 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.sling.microsling.integration;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/** Test creating a Node and rendering it using scripts in
+ * various supported languages, using nodetype-based
+ * script resolution
+ */
+public class NodetypeRenderingTest extends RenderingTestBase {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // set test values
+ testText = "This is a test " + System.currentTimeMillis();
+
+ // create the test node
+ final String url = HTTP_BASE_URL + TEST_PATH + ".sling";
+ final Map<String,String> props = new HashMap<String,String>();
+ props.put("text", testText);
+ displayUrl = testClient.createNode(url, props);
+
+ // the rendering script goes under /sling/scripts in the repository
+ scriptPath = "/sling/scripts/NODETYPES/nt/unstructured";
+ testClient.mkdirs(WEBDAV_BASE_URL, scriptPath);
+ }
+
+ public void testWithoutScript() throws IOException {
+ final String content = getContent(displayUrl + ".html", CONTENT_TYPE_PLAIN);
+ assertTrue("Content includes default servlet marker",content.contains("dumped by DefaultSlingServlet"));
+ }
+
+ public void testEspHtml() throws IOException {
+ final String toDelete = uploadTestScript("rendering-test.esp","html.esp");
+ try {
+ final String content = getContent(displayUrl + ".html", CONTENT_TYPE_HTML);
+ assertTrue("Content includes ESP marker",content.contains("ESP template"));
+ assertTrue("Content contains formatted test text",content.contains("<p>" + testText + "</p>"));
+ } finally {
+ testClient.delete(toDelete);
+ }
+ }
+
+ public void testEspXml() throws IOException {
+ final String toDelete = uploadTestScript("rendering-test.esp","xml.esp");
+ try {
+ final String content = getContent(displayUrl + ".xml", CONTENT_TYPE_XML);
+ assertTrue("Content includes ESP marker",content.contains("ESP template"));
+ assertTrue("Content contains formatted test text",content.contains("<p>" + testText + "</p>"));
+ } finally {
+ testClient.delete(toDelete);
+ }
+ }
+
+ public void testEspPlain() throws IOException {
+ final String toDelete = uploadTestScript("rendering-test.esp","plain.esp");
+ try {
+ final String content = getContent(displayUrl + ".txt", CONTENT_TYPE_PLAIN);
+ assertTrue("Content includes ESP marker",content.contains("ESP template"));
+ assertTrue("Content contains formatted test text",content.contains("<p>" + testText + "</p>"));
+ } finally {
+ testClient.delete(toDelete);
+ }
+ }
+
+ public void testVltHtml() throws IOException {
+ final String toDelete = uploadTestScript("rendering-test.vlt","html.vlt");
+ try {
+ final String content = getContent(displayUrl + ".html", CONTENT_TYPE_HTML);
+ assertTrue("Content includes VLT marker",content.contains("Velocity template"));
+ assertTrue("Content contains formatted test text",content.contains("<p><b>" + testText + "</b></p>"));
+ } finally {
+ testClient.delete(toDelete);
+ }
+ }
+
+ public void testJsHtml() throws IOException {
+ final String toDelete = uploadTestScript("rendering-test.js","html.js");
+ try {
+ final String content = getContent(displayUrl + ".html", CONTENT_TYPE_HTML);
+ assertTrue("Content includes JS marker",content.contains("Raw javascript template"));
+ assertTrue("Content contains formatted test text",content.contains("<p><em>" + testText + "</em></p>"));
+ } finally {
+ testClient.delete(toDelete);
+ }
+ }
+
+ public void testFtlHtml() throws IOException {
+ final String toDelete = uploadTestScript("rendering-test.ftl","html.ftl");
+ try {
+ final String content = getContent(displayUrl + ".html", CONTENT_TYPE_HTML);
+ assertTrue("Content includes FreeMarker marker",content.contains("FreeMarker template"));
+ assertTrue("Content contains formatted test text",content.contains("<p><span>" + testText + "</span></p>"));
+ } finally {
+ testClient.delete(toDelete);
+ }
+ }
+}
\ No newline at end of file
Added: sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/RenderingTestBase.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/RenderingTestBase.java?rev=1807480&view=auto
==============================================================================
--- sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/RenderingTestBase.java (added)
+++ sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/RenderingTestBase.java Wed Sep 6 13:24:23 2017
@@ -0,0 +1,70 @@
+/*
+ * 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.sling.microsling.integration;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.methods.GetMethod;
+
+/** Base class for rendering tests
+ */
+class RenderingTestBase extends MicroslingHttpTestBase {
+
+ protected String scriptPath;
+ protected String testText;
+ protected String displayUrl;
+
+ /** upload rendering test script, and return its URL for future deletion */
+ protected String uploadTestScript(String localFilename,String filenameOnServer) throws IOException {
+ final String url = WEBDAV_BASE_URL + scriptPath + "/" + filenameOnServer;
+ final String testFile = "/integration-test/" + localFilename;
+ final InputStream data = getClass().getResourceAsStream(testFile);
+ try {
+ testClient.upload(url, data);
+ } finally {
+ if(data!=null) {
+ data.close();
+ }
+ }
+ return url;
+ }
+
+ /** retrieve the contents of given URL and assert its content type
+ * @throws IOException
+ * @throws HttpException */
+ protected String getContent(String url, String expectedContentType) throws IOException {
+ final GetMethod get = new GetMethod(url);
+ final int status = httpClient.executeMethod(get);
+ assertEquals("Expected status 200 for " + url,200,status);
+ final Header h = get.getResponseHeader("Content-Type");
+ if(expectedContentType == null) {
+ if(h!=null) {
+ fail("Expected null Content-Type, got " + h.getValue());
+ }
+ } else {
+ assertTrue(
+ "Expected Content-Type '" + expectedContentType + "' for " + url,
+ h.getValue().startsWith(expectedContentType)
+ );
+ }
+ return get.getResponseBodyAsString();
+ }
+
+}
\ No newline at end of file
Added: sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java?rev=1807480&view=auto
==============================================================================
--- sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java (added)
+++ sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java Wed Sep 6 13:24:23 2017
@@ -0,0 +1,121 @@
+/*
+ * 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.sling.microsling.integration;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/** Test creating a Node and rendering it using scripts in
+ * various supported languages, using slingResourceType-based
+ * script resolution
+ */
+public class SlingResourceTypeRenderingTest extends RenderingTestBase {
+
+ private String slingResourceType;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // set test values
+ slingResourceType = "integration-test/srt." + System.currentTimeMillis();
+ testText = "This is a test " + System.currentTimeMillis();
+
+ // create the test node
+ final String url = HTTP_BASE_URL + TEST_PATH + ".sling";
+ final Map<String,String> props = new HashMap<String,String>();
+ props.put("slingResourceType", slingResourceType);
+ props.put("text", testText);
+ displayUrl = testClient.createNode(url, props);
+
+ // the rendering script goes under /sling/scripts in the repository
+ scriptPath = "/sling/scripts/" + slingResourceType;
+ testClient.mkdirs(WEBDAV_BASE_URL, scriptPath);
+ }
+
+ public void testWithoutScript() throws IOException {
+ final String content = getContent(displayUrl + ".html", CONTENT_TYPE_PLAIN);
+ assertTrue("Content includes default servlet marker",content.contains("dumped by DefaultSlingServlet"));
+ }
+
+ public void testEspHtml() throws IOException {
+ final String toDelete = uploadTestScript("rendering-test.esp","html.esp");
+ try {
+ final String content = getContent(displayUrl + ".html", CONTENT_TYPE_HTML);
+ assertTrue("Content includes ESP marker",content.contains("ESP template"));
+ assertTrue("Content contains formatted test text",content.contains("<p>" + testText + "</p>"));
+ } finally {
+ testClient.delete(toDelete);
+ }
+ }
+
+ public void testEspXml() throws IOException {
+ final String toDelete = uploadTestScript("rendering-test.esp","xml.esp");
+ try {
+ final String content = getContent(displayUrl + ".xml", CONTENT_TYPE_XML);
+ assertTrue("Content includes ESP marker",content.contains("ESP template"));
+ assertTrue("Content contains formatted test text",content.contains("<p>" + testText + "</p>"));
+ } finally {
+ testClient.delete(toDelete);
+ }
+ }
+
+ public void testEspPlain() throws IOException {
+ final String toDelete = uploadTestScript("rendering-test.esp","plain.esp");
+ try {
+ final String content = getContent(displayUrl + ".txt", CONTENT_TYPE_PLAIN);
+ assertTrue("Content includes ESP marker",content.contains("ESP template"));
+ assertTrue("Content contains formatted test text",content.contains("<p>" + testText + "</p>"));
+ } finally {
+ testClient.delete(toDelete);
+ }
+ }
+
+ public void testVltHtml() throws IOException {
+ final String toDelete = uploadTestScript("rendering-test.vlt","html.vlt");
+ try {
+ final String content = getContent(displayUrl + ".html", CONTENT_TYPE_HTML);
+ assertTrue("Content includes VLT marker",content.contains("Velocity template"));
+ assertTrue("Content contains formatted test text",content.contains("<p><b>" + testText + "</b></p>"));
+ } finally {
+ testClient.delete(toDelete);
+ }
+ }
+
+ public void testJsHtml() throws IOException {
+ final String toDelete = uploadTestScript("rendering-test.js","html.js");
+ try {
+ final String content = getContent(displayUrl + ".html", CONTENT_TYPE_HTML);
+ assertTrue("Content includes JS marker",content.contains("Raw javascript template"));
+ assertTrue("Content contains formatted test text",content.contains("<p><em>" + testText + "</em></p>"));
+ } finally {
+ testClient.delete(toDelete);
+ }
+ }
+
+ public void testFtlHtml() throws IOException {
+ final String toDelete = uploadTestScript("rendering-test.ftl","html.ftl");
+ try {
+ final String content = getContent(displayUrl + ".html", CONTENT_TYPE_HTML);
+ assertTrue("Content includes FreeMarker marker",content.contains("FreeMarker template"));
+ assertTrue("Content contains formatted test text",content.contains("<p><span>" + testText + "</span></p>"));
+ } finally {
+ testClient.delete(toDelete);
+ }
+ }
+}
\ No newline at end of file
Added: sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/StreamServletTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/StreamServletTest.java?rev=1807480&view=auto
==============================================================================
--- sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/StreamServletTest.java (added)
+++ sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/StreamServletTest.java Wed Sep 6 13:24:23 2017
@@ -0,0 +1,64 @@
+/*
+ * 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.sling.microsling.integration;
+
+
+/** Test the StreamServlet by reading an uploaded file with a GET
+ */
+public class StreamServletTest extends RenderingTestBase {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ scriptPath = TEST_PATH + "/StreamServletTest." + System.currentTimeMillis();
+ displayUrl = HTTP_BASE_URL + scriptPath;
+ testClient.mkdirs(WEBDAV_BASE_URL, scriptPath);
+ }
+
+ public void testPlainTextFile() throws Exception {
+ final String filename = "testfile.txt";
+ final String toDelete = uploadTestScript(filename,filename);
+ try {
+ final String url = displayUrl + "/" + filename;
+ // TODO why don't we get a content-type here?
+ final String content = getContent(url, null);
+ assertTrue(
+ "Content at " + url + " must include expected marker, got " + content,
+ content.contains("This is just some text in an ASCII file.")
+ );
+ } finally {
+ // TODO testClient.delete(toDelete);
+ }
+ }
+
+ public void testHtmlTextFile() throws Exception {
+ final String filename = "testfile.html";
+ final String toDelete = uploadTestScript(filename,filename);
+ try {
+ // TODO this should really be text/html, not sure why it is not
+ final String url = displayUrl + "/" + filename;
+ // TODO why don't we get a content-type here?
+ final String content = getContent(url, null);
+ assertTrue(
+ "Content at " + url + " must include expected marker, got " + content,
+ content.contains("This is <em>testfile.html</em>.")
+ );
+ } finally {
+ // TODO testClient.delete(toDelete);
+ }
+ }
+}
Added: sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/HttpAnyMethod.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/HttpAnyMethod.java?rev=1807480&view=auto
==============================================================================
--- sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/HttpAnyMethod.java (added)
+++ sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/HttpAnyMethod.java Wed Sep 6 13:24:23 2017
@@ -0,0 +1,34 @@
+/*
+ * 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.sling.microsling.integration.helpers;
+
+import org.apache.commons.httpclient.HttpMethodBase;
+
+/** Allows any HTTP method for HtttpClient */
+public class HttpAnyMethod extends HttpMethodBase {
+ private final String methodName;
+
+ public HttpAnyMethod(String methodName, String uri) {
+ super(uri);
+ this.methodName = methodName;
+ }
+
+ @Override
+ public String getName() {
+ return methodName;
+ }
+}
Added: sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/MicroslingIntegrationTestClient.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/MicroslingIntegrationTestClient.java?rev=1807480&view=auto
==============================================================================
--- sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/MicroslingIntegrationTestClient.java (added)
+++ sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/MicroslingIntegrationTestClient.java Wed Sep 6 13:24:23 2017
@@ -0,0 +1,112 @@
+/*
+ * 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.sling.microsling.integration.helpers;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+
+/** Client functions to interact with microsling in integration tests */
+public class MicroslingIntegrationTestClient {
+ private final HttpClient httpClient;
+
+ public MicroslingIntegrationTestClient(HttpClient client) {
+ this.httpClient = client;
+ }
+
+ /** Upload a file to the microsling repository
+ * @return the HTTP status code
+ */
+ public int upload(String toUrl, InputStream is) throws IOException {
+ final PutMethod put = new PutMethod(toUrl);
+ put.setRequestEntity(new InputStreamRequestEntity(is));
+ return httpClient.executeMethod(put);
+ }
+
+ /** Delete a file from the microsling repository
+ * @return the HTTP status code
+ */
+ public int delete(String url) throws IOException {
+ final DeleteMethod delete = new DeleteMethod(url);
+ return httpClient.executeMethod(delete);
+ }
+
+ /** Create the given directory via WebDAV, if needed, under given URL */
+ public void mkdir(String url) throws IOException {
+ int status = 0;
+ status = httpClient.executeMethod(new GetMethod(url));
+ if(status != 200) {
+ status = httpClient.executeMethod(new HttpAnyMethod("MKCOL",url));
+ if(status!=201) {
+ throw new IOException("mkdir(" + url + ") failed, status code=" + status);
+ }
+ }
+ }
+
+ /** Create the given directory via WebDAV, including parent directories */
+ public void mkdirs(String baseUrl,String path) throws IOException {
+ final String [] paths = path.split("/");
+ if(baseUrl.endsWith("/")) {
+ baseUrl = baseUrl.substring(0,baseUrl.length() - 1);
+ }
+
+ String currentPath = baseUrl;
+ for(String pathElement : paths) {
+ if(pathElement.length() == 0) {
+ continue;
+ }
+ currentPath += "/" + pathElement;
+ mkdir(currentPath);
+ }
+
+ final String url = baseUrl + path;
+ final int status = httpClient.executeMethod(new GetMethod(url));
+ if(status!=200) {
+ throw new IOException("Expected status 200, got " + status + " for URL=" + url);
+ }
+ }
+
+ /** Create a node under given path, using a POST to microsling
+ * @param url must end with ".sling" to use the microsling's default
+ * servlet POST behaviour.
+ * @return the URL that microsling provides to display the node
+ */
+ public String createNode(String url, Map<String,String> nodeProperties) throws IOException {
+ final PostMethod post = new PostMethod(url);
+ post.setFollowRedirects(false);
+
+ if(nodeProperties!=null) {
+ for(Map.Entry<String,String> e : nodeProperties.entrySet()) {
+ post.addParameter(e.getKey(),e.getValue());
+ }
+ }
+
+ final int status = httpClient.executeMethod(post);
+ if(status!=302) {
+ throw new IOException("Expected status code 302 for POST, got " + status + ", URL=" + url);
+ }
+ final String location = post.getResponseHeader("Location").getValue();
+ return location;
+ }
+}
Added: sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/package.html
URL: http://svn.apache.org/viewvc/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/package.html?rev=1807480&view=auto
==============================================================================
--- sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/package.html (added)
+++ sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/package.html Wed Sep 6 13:24:23 2017
@@ -0,0 +1,20 @@
+<html>
+<body>
+ <p>
+ The tests found in and under this package are used in the
+ "integration-test" build phase (SLING-82), they are not run
+ as part of the normal "test" build phase.
+ </p>
+ <p>
+ To debug the integration tests, however, it is useful to run
+ them as part of the normal test phase, after starting a separate
+ microsling instance that they can talk to.
+ </p>
+ <p>
+ This is implemented using Maven profiles: to run the integration
+ tests during the normal test phase, disable the "disableIntegrationTestsInTestPhase"
+ Maven profile, for example using <code>mvn -P nullMicroslingProfile test</code>.
+ See pom.xml for more details.
+ </p>
+</body>
+</html>
\ No newline at end of file
Added: sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/MicroslingRequestPathInfoTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/MicroslingRequestPathInfoTest.java?rev=1807480&view=auto
==============================================================================
--- sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/MicroslingRequestPathInfoTest.java (added)
+++ sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/MicroslingRequestPathInfoTest.java Wed Sep 6 13:24:23 2017
@@ -0,0 +1,184 @@
+/*
+ * 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.sling.microsling.request.helpers;
+
+import javax.jcr.Item;
+
+import junit.framework.TestCase;
+
+import org.apache.sling.microsling.api.Resource;
+import org.apache.sling.microsling.api.ResourceMetadata;
+import org.apache.sling.microsling.api.SlingRequestPathInfo;
+
+/** Test the MicroslingRequestPathInfo */
+public class MicroslingRequestPathInfoTest extends TestCase {
+
+ static class MockResource implements Resource {
+
+ private final ResourceMetadata metadata;
+
+ MockResource(String resolutionPath) {
+ metadata = new ResourceMetadata();
+ metadata.put(ResourceMetadata.RESOLUTION_PATH, resolutionPath);
+ }
+
+ public Object getData() {
+ throw new Error("MockResource does not implement this method");
+ }
+
+ public Item getItem() {
+ throw new Error("MockResource does not implement this method");
+ }
+
+ public String getResourceType() {
+ throw new Error("MockResource does not implement this method");
+ }
+
+ public String getURI() {
+ throw new Error("MockResource does not implement this method");
+ }
+
+ public ResourceMetadata getMetadata() {
+ return metadata;
+ }
+
+ }
+
+ public void testSimplePath() {
+ SlingRequestPathInfo p = new MicroslingRequestPathInfo(new MockResource(""),"/some/path.print.a4.html/some/suffix");
+ assertEquals("/some/path",p.getUnusedContentPath());
+ assertEquals("",p.getResourcePath());
+ }
+
+ public void testNullResource() {
+ SlingRequestPathInfo p = new MicroslingRequestPathInfo(null,"/some/path.print.a4.html/some/suffix");
+ assertEquals("/some/path",p.getUnusedContentPath());
+ assertEquals(null,p.getResourcePath());
+ }
+
+ public void testSimpleSuffix() {
+ SlingRequestPathInfo p = new MicroslingRequestPathInfo(new MockResource(""),"/some/path.print.a4.html/some/suffix");
+ assertEquals("/some/suffix",p.getSuffix());
+ }
+
+ public void testSimpleSelectorString() {
+ SlingRequestPathInfo p = new MicroslingRequestPathInfo(new MockResource(""),"/some/path.print.a4.html/some/suffix");
+ assertEquals("print.a4",p.getSelectorString());
+ }
+
+ public void testSimpleExtension() {
+ SlingRequestPathInfo p = new MicroslingRequestPathInfo(new MockResource(""),"/some/path.print.a4.html/some/suffix");
+ assertEquals("html",p.getExtension());
+ }
+
+ public void testAllOptions() {
+ SlingRequestPathInfo p = new MicroslingRequestPathInfo(new MockResource(""),"/some/path.print.a4.html/some/suffix");
+ assertEquals("/some/path",p.getUnusedContentPath());
+ assertEquals("print.a4",p.getSelectorString());
+ assertEquals("html",p.getExtension());
+ assertEquals("/some/suffix",p.getSuffix());
+ }
+
+ public void testAllEmpty() {
+ SlingRequestPathInfo p = new MicroslingRequestPathInfo(new MockResource(""),null);
+ assertEquals("",p.getUnusedContentPath());
+ assertEquals("",p.getSelectorString());
+ assertEquals("",p.getExtension());
+ assertEquals("",p.getSuffix());
+ }
+
+ public void testPathOnly() {
+ SlingRequestPathInfo p = new MicroslingRequestPathInfo(new MockResource(""),"/some/path/here");
+ assertEquals("/some/path/here",p.getUnusedContentPath());
+ assertEquals("",p.getSelectorString());
+ assertEquals("",p.getExtension());
+ assertEquals("",p.getSuffix());
+ }
+
+ public void testPathAndExtensionOnly() {
+ SlingRequestPathInfo p = new MicroslingRequestPathInfo(new MockResource(""),"/some/path/here.html");
+ assertEquals("/some/path/here",p.getUnusedContentPath());
+ assertEquals("",p.getSelectorString());
+ assertEquals("html",p.getExtension());
+ assertEquals("",p.getSuffix());
+ }
+
+ public void testPathAndOneSelectorOnly() {
+ SlingRequestPathInfo p = new MicroslingRequestPathInfo(new MockResource(""),"/some/path/here.print.html");
+ assertEquals("/some/path/here",p.getUnusedContentPath());
+ assertEquals("print",p.getSelectorString());
+ assertEquals("html",p.getExtension());
+ assertEquals("",p.getSuffix());
+ }
+
+ public void testPathExtAndSuffix() {
+ SlingRequestPathInfo p = new MicroslingRequestPathInfo(new MockResource(""),"/some/path/here.html/something");
+ assertEquals("/some/path/here",p.getUnusedContentPath());
+ assertEquals("",p.getSelectorString());
+ assertEquals("html",p.getExtension());
+ assertEquals("/something",p.getSuffix());
+ }
+
+ public void testSelectorsSplit() {
+ SlingRequestPathInfo p = new MicroslingRequestPathInfo(new MockResource(""),"/some/path.print.a4.html/some/suffix");
+ assertEquals(2,p.getSelectors().length);
+ assertEquals("print",p.getSelector(0));
+ assertEquals("a4",p.getSelector(1));
+ }
+
+ public void testPartialResolutionA() {
+ SlingRequestPathInfo p = new MicroslingRequestPathInfo(new MockResource("/some"),"/some/path.print.a4.html/some/suffix");
+ assertEquals("/some",p.getResourcePath());
+ assertEquals("print.a4",p.getSelectorString());
+ assertEquals("html",p.getExtension());
+ assertEquals("/some/suffix",p.getSuffix());
+ assertEquals("/path",p.getUnusedContentPath());
+ }
+
+ public void testPartialResolutionB() {
+ SlingRequestPathInfo p = new MicroslingRequestPathInfo(new MockResource("/some/path"),"/some/path.print.a4.html/some/suffix");
+ assertEquals("print.a4",p.getSelectorString());
+ assertEquals("html",p.getExtension());
+ assertEquals("/some/suffix",p.getSuffix());
+ assertEquals("",p.getUnusedContentPath());
+ }
+
+ public void testPartialResolutionC() {
+ SlingRequestPathInfo p = new MicroslingRequestPathInfo(new MockResource("/some/path.print"),"/some/path.print.a4.html/some/suffix");
+ assertEquals("a4",p.getSelectorString());
+ assertEquals("html",p.getExtension());
+ assertEquals("/some/suffix",p.getSuffix());
+ assertEquals("",p.getUnusedContentPath());
+ }
+
+ public void testPartialResolutionD() {
+ SlingRequestPathInfo p = new MicroslingRequestPathInfo(new MockResource("/some/path.print.a"),"/some/path.print.a4.html/some/suffix");
+ assertEquals("",p.getSelectorString());
+ assertEquals("html",p.getExtension());
+ assertEquals("/some/suffix",p.getSuffix());
+ assertEquals("4",p.getUnusedContentPath());
+ }
+
+ public void testPartialResolutionE() {
+ SlingRequestPathInfo p = new MicroslingRequestPathInfo(new MockResource("/some/path.print.a4.html"),"/some/path.print.a4.html/some/suffix");
+ assertEquals("",p.getSelectorString());
+ assertEquals("",p.getExtension());
+ assertEquals("",p.getSuffix());
+ assertEquals("/some/suffix",p.getUnusedContentPath());
+ }
+
+}