jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1353302 - in /jackrabbit/oak/trunk: ./ oak-http/ oak-http/src/ oak-http/src/main/ oak-http/src/main/java/ oak-http/src/main/java/org/ oak-http/src/main/java/org/apache/ oak-http/src/main/java/org/apache/jackrabbit/ oak-http/src/main/java/o...
Date Sun, 24 Jun 2012 17:51:23 GMT
Author: jukka
Date: Sun Jun 24 17:51:22 2012
New Revision: 1353302

URL: http://svn.apache.org/viewvc?rev=1353302&view=rev
Log:
OAK-104: HTTP bindings for Oak

Add initial oak-http component

Added:
    jackrabbit/oak/trunk/oak-http/
    jackrabbit/oak/trunk/oak-http/pom.xml
    jackrabbit/oak/trunk/oak-http/src/
    jackrabbit/oak/trunk/oak-http/src/main/
    jackrabbit/oak/trunk/oak-http/src/main/java/
    jackrabbit/oak/trunk/oak-http/src/main/java/org/
    jackrabbit/oak/trunk/oak-http/src/main/java/org/apache/
    jackrabbit/oak/trunk/oak-http/src/main/java/org/apache/jackrabbit/
    jackrabbit/oak/trunk/oak-http/src/main/java/org/apache/jackrabbit/oak/
    jackrabbit/oak/trunk/oak-http/src/main/java/org/apache/jackrabbit/oak/http/
    jackrabbit/oak/trunk/oak-http/src/main/java/org/apache/jackrabbit/oak/http/OakServlet.java
Modified:
    jackrabbit/oak/trunk/oak-run/pom.xml
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/RepositoryServlet.java
    jackrabbit/oak/trunk/pom.xml

Added: jackrabbit/oak/trunk/oak-http/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-http/pom.xml?rev=1353302&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-http/pom.xml (added)
+++ jackrabbit/oak/trunk/oak-http/pom.xml Sun Jun 24 17:51:22 2012
@@ -0,0 +1,106 @@
+<?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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd
">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.jackrabbit</groupId>
+    <artifactId>oak-parent</artifactId>
+    <version>0.3-SNAPSHOT</version>
+    <relativePath>../oak-parent/pom.xml</relativePath>
+  </parent>
+
+  <artifactId>oak-http</artifactId>
+  <name>Oak HTTP Binding</name>
+  <packaging>bundle</packaging>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <configuration>
+          <instructions>
+            <Export-Package>
+              !
+            </Export-Package>
+            <Bundle-Activator>
+              org.apache.jackrabbit.oak.http.osgi.Activator
+            </Bundle-Activator>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.rat</groupId>
+          <artifactId>apache-rat-plugin</artifactId>
+          <configuration>
+            <excludes/>
+          </configuration>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+
+  <dependencies>
+    <!-- Optional OSGi dependencies, used only when running within OSGi -->
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.core</artifactId>
+      <scope>provided</scope>
+      <optional>true</optional>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.compendium</artifactId>
+      <scope>provided</scope>
+      <optional>true</optional>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.jackrabbit</groupId>
+      <artifactId>oak-core</artifactId>
+      <version>0.3-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>servlet-api</artifactId>
+      <version>2.5</version>
+      <scope>provided</scope>
+    </dependency>
+
+    <!-- Findbugs annotations -->
+    <dependency>
+      <groupId>com.google.code.findbugs</groupId>
+      <artifactId>jsr305</artifactId>
+      <version>2.0.0</version>
+      <scope>provided</scope>
+    </dependency>
+
+    <!-- Test dependencies -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+</project>

Added: jackrabbit/oak/trunk/oak-http/src/main/java/org/apache/jackrabbit/oak/http/OakServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-http/src/main/java/org/apache/jackrabbit/oak/http/OakServlet.java?rev=1353302&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-http/src/main/java/org/apache/jackrabbit/oak/http/OakServlet.java
(added)
+++ jackrabbit/oak/trunk/oak-http/src/main/java/org/apache/jackrabbit/oak/http/OakServlet.java
Sun Jun 24 17:51:22 2012
@@ -0,0 +1,74 @@
+/*
+ * 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.jackrabbit.oak.http;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.jcr.GuestCredentials;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.security.auth.login.LoginException;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.jackrabbit.oak.api.ContentRepository;
+import org.apache.jackrabbit.oak.api.ContentSession;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Tree;
+
+public class OakServlet extends HttpServlet {
+
+    private final ContentRepository repository;
+
+    public OakServlet(ContentRepository repository) {
+        this.repository = repository;
+    }
+
+    @Override
+    protected void service(
+            HttpServletRequest request, HttpServletResponse response)
+            throws ServletException, IOException {
+        try {
+            ContentSession session = repository.login(new GuestCredentials(), null);
+            try {
+                response.setContentType("text/plain");
+                PrintWriter writer = response.getWriter();
+                Tree tree =
+                        session.getCurrentRoot().getTree(request.getPathInfo());
+                if (tree != null) {
+                    for (PropertyState property : tree.getProperties()) {
+                        writer.print("- " + property.getName() + "\n");
+                    }
+                    for (Tree child : tree.getChildren()) {
+                        writer.print("+ " + child.getName() + "\n");
+                    }
+                } else {
+                    response.sendError(HttpServletResponse.SC_NOT_FOUND);
+                }
+            } finally {
+                session.close();
+            }
+        } catch (NoSuchWorkspaceException e) {
+            response.sendError(HttpServletResponse.SC_NOT_FOUND);
+        } catch (LoginException e) {
+            throw new ServletException(e);
+        }
+    }
+
+}

Modified: jackrabbit/oak/trunk/oak-run/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/pom.xml?rev=1353302&r1=1353301&r2=1353302&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-run/pom.xml Sun Jun 24 17:51:22 2012
@@ -83,6 +83,11 @@
       <version>${project.version}</version>
     </dependency>
     <dependency>
+      <groupId>org.apache.jackrabbit</groupId>
+      <artifactId>oak-http</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
       <groupId>com.h2database</groupId>
       <artifactId>h2</artifactId>
       <version>1.3.158</version>

Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java?rev=1353302&r1=1353301&r2=1353302&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java (original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java Sun
Jun 24 17:51:22 2012
@@ -19,8 +19,17 @@ package org.apache.jackrabbit.oak.run;
 import java.io.InputStream;
 import java.util.Properties;
 
+import javax.jcr.Repository;
 import javax.servlet.Servlet;
 
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.core.MicroKernelImpl;
+import org.apache.jackrabbit.oak.api.ContentRepository;
+import org.apache.jackrabbit.oak.core.ContentRepositoryImpl;
+import org.apache.jackrabbit.oak.http.OakServlet;
+import org.apache.jackrabbit.oak.jcr.RepositoryImpl;
+import org.apache.jackrabbit.webdav.jcr.JCRWebdavServerServlet;
+import org.apache.jackrabbit.webdav.simple.SimpleWebdavServlet;
 import org.eclipse.jetty.server.Server;
 import org.eclipse.jetty.servlet.ServletContextHandler;
 import org.eclipse.jetty.servlet.ServletHolder;
@@ -77,6 +86,8 @@ public class Main {
 
         private final Server server;
 
+        private final MicroKernel[] kernels;
+
         public HttpServer(String uri, String args[]) {
             context = new ServletContextHandler(ServletContextHandler.SECURITY);
             context.setContextPath("/");
@@ -84,17 +95,21 @@ public class Main {
             if (args.length == 0) {
                 System.out.println("Starting an in-memory repository");
                 System.out.println(URI + " -> [memory]");
-                addServlet(null, "/*");
+                kernels = new MicroKernel[] { new MicroKernelImpl() };
+                addServlets(kernels[0], "");
             } else if (args.length == 1) {
                 System.out.println("Starting a standalone repository");
                 System.out.println(URI + " -> " + args[0]);
-                addServlet(args[0], "/*");
+                kernels = new MicroKernel[] { new MicroKernelImpl(args[0]) };
+                addServlets(kernels[0], "");
             } else {
                 System.out.println("Starting a clustered repository");
+                kernels = new MicroKernel[args.length];
                 for (int i = 0; i < args.length; i++) {
                     // FIXME: Use a clustered MicroKernel implementation
                     System.out.println(URI + "/node" + i + "/ -> " + args[i]);
-                    addServlet(args[i], "/node" + i + "/*");
+                    kernels[i] = new MicroKernelImpl(args[i]);
+                    addServlets(kernels[i], "/node" + i);
                 }
             }
 
@@ -114,13 +129,39 @@ public class Main {
             server.stop();
         }
 
-        private void addServlet(String repo, String path) {
-            Servlet servlet = new RepositoryServlet(repo);
-            ServletHolder holder = new ServletHolder(servlet);
-            holder.setInitParameter(
+        private void addServlets(MicroKernel kernel, String path) {
+            ContentRepository repository =
+                    new ContentRepositoryImpl(kernel, null, null);
+
+            ServletHolder oak =
+                    new ServletHolder(new OakServlet(repository));
+            context.addServlet(oak, path + "/*");
+
+            final Repository jcrRepository = new RepositoryImpl(repository);
+
+            ServletHolder webdav =
+                    new ServletHolder(new SimpleWebdavServlet() {
+                        @Override
+                        public Repository getRepository() {
+                            return jcrRepository;
+                        }
+                    });
+            webdav.setInitParameter(
+                    RepositoryServlet.INIT_PARAM_MISSING_AUTH_MAPPING,
+                    "admin:admin");
+            context.addServlet(webdav, path + "/webdav/*");
+
+            ServletHolder davex =
+                    new ServletHolder(new JCRWebdavServerServlet() {
+                        @Override
+                        protected Repository getRepository() {
+                            return jcrRepository;
+                        }
+                    });
+            davex.setInitParameter(
                     RepositoryServlet.INIT_PARAM_MISSING_AUTH_MAPPING,
                     "admin:admin");
-            context.addServlet(holder, path);
+            context.addServlet(davex, path + "/davex/*");
         }
 
     }

Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/RepositoryServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/RepositoryServlet.java?rev=1353302&r1=1353301&r2=1353302&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/RepositoryServlet.java
(original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/RepositoryServlet.java
Sun Jun 24 17:51:22 2012
@@ -16,36 +16,18 @@
  */
 package org.apache.jackrabbit.oak.run;
 
-import org.apache.jackrabbit.mk.api.MicroKernel;
-import org.apache.jackrabbit.mk.core.MicroKernelImpl;
+import javax.jcr.Repository;
+
+import org.apache.jackrabbit.oak.api.ContentRepository;
 import org.apache.jackrabbit.oak.jcr.RepositoryImpl;
 import org.apache.jackrabbit.webdav.jcr.JCRWebdavServerServlet;
 
-import javax.jcr.Repository;
-import javax.servlet.ServletException;
-
 class RepositoryServlet extends JCRWebdavServerServlet {
 
-    private final String path;
-
-    private MicroKernelImpl kernel;
-
     private Repository repository;
 
-    public RepositoryServlet(String path) {
-        this.path = path;
-    }
-
-    @Override
-    public void init() throws ServletException {
-        if (path != null) {
-            kernel = new MicroKernelImpl(path);
-        } else {
-            kernel = new MicroKernelImpl();
-        }
-
-        repository = new RepositoryImpl();
-        super.init();
+    public RepositoryServlet(ContentRepository repository) {
+        this.repository = new RepositoryImpl(repository);
     }
 
     @Override
@@ -53,11 +35,4 @@ class RepositoryServlet extends JCRWebda
         return repository;
     }
 
-    @Override
-    public void destroy() {
-        super.destroy();
-
-        kernel.dispose();
-    }
-
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/pom.xml?rev=1353302&r1=1353301&r2=1353302&view=diff
==============================================================================
--- jackrabbit/oak/trunk/pom.xml (original)
+++ jackrabbit/oak/trunk/pom.xml Sun Jun 24 17:51:22 2012
@@ -44,6 +44,7 @@
     <module>oak-core</module>
     <module>oak-jcr</module>
     <module>oak-sling</module>
+    <module>oak-http</module>
     <module>oak-run</module>
     <module>oak-it</module>
     <module>oak-bench</module>



Mime
View raw message