Author: chetanm
Date: Fri Nov 27 11:27:34 2015
New Revision: 1716836
URL: http://svn.apache.org/viewvc?rev=1716836&view=rev
Log:
OAK-3687 - Oak standalone application example based on Spring Boot
Initial working application
Added:
jackrabbit/oak/trunk/oak-examples/standalone/
jackrabbit/oak/trunk/oak-examples/standalone/pom.xml (with props)
jackrabbit/oak/trunk/oak-examples/standalone/src/
jackrabbit/oak/trunk/oak-examples/standalone/src/main/
jackrabbit/oak/trunk/oak-examples/standalone/src/main/java/
jackrabbit/oak/trunk/oak-examples/standalone/src/main/java/org/
jackrabbit/oak/trunk/oak-examples/standalone/src/main/java/org/apache/
jackrabbit/oak/trunk/oak-examples/standalone/src/main/java/org/apache/jackrabbit/
jackrabbit/oak/trunk/oak-examples/standalone/src/main/java/org/apache/jackrabbit/oak/
jackrabbit/oak/trunk/oak-examples/standalone/src/main/java/org/apache/jackrabbit/oak/standalone/
jackrabbit/oak/trunk/oak-examples/standalone/src/main/java/org/apache/jackrabbit/oak/standalone/OakServer.java
(with props)
jackrabbit/oak/trunk/oak-examples/standalone/src/main/java/org/apache/jackrabbit/oak/standalone/RepositoryInitializer.java
(with props)
jackrabbit/oak/trunk/oak-examples/standalone/src/main/resources/
jackrabbit/oak/trunk/oak-examples/standalone/src/main/resources/application.yml
jackrabbit/oak/trunk/oak-examples/standalone/src/main/resources/repository-config.json
Added: jackrabbit/oak/trunk/oak-examples/standalone/pom.xml
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-examples/standalone/pom.xml?rev=1716836&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-examples/standalone/pom.xml (added)
+++ jackrabbit/oak/trunk/oak-examples/standalone/pom.xml Fri Nov 27 11:27:34
2015
@@ -0,0 +1,238 @@
+<?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>
+
+<!-- ====================================================================== -->
+<!-- P R O J E C T D E S C R I P T I O N -->
+<!-- ====================================================================== -->
+ <parent>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>oak-parent</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../../oak-parent/pom.xml</relativePath>
+ </parent>
+ <artifactId>oak-standalone</artifactId>
+
+ <name>Oak Standalone Example</name>
+ <description>Standalone application based on Spring Boot then embeds a
Jackrabbit Oak content repository</description>
+
+ <properties>
+ <oak.version>1.4-SNAPSHOT</oak.version>
+ <tika.version>1.7</tika.version>
+ <skip.deployment>true</skip.deployment>
+ <spring.boot.version>1.3.0.RELEASE</spring.boot.version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-dependencies</artifactId>
+ <version>${spring.boot.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-actuator</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-devtools</artifactId>
+ <optional>true</optional>
+ </dependency>
+
+ <!-- For colored console logging -->
+ <dependency>
+ <groupId>org.fusesource.jansi</groupId>
+ <artifactId>jansi</artifactId>
+ <version>1.11</version>
+ <optional>true</optional>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.jcr</groupId>
+ <artifactId>jcr</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tika</groupId>
+ <artifactId>tika-parsers</artifactId>
+ <version>${tika.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-jcr-server</artifactId>
+ <version>${jackrabbit.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-jcr-servlet</artifactId>
+ <version>${jackrabbit.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-jcr-rmi</artifactId>
+ <version>${jackrabbit.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>oak-jcr</artifactId>
+ <version>${oak.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>oak-pojosr</artifactId>
+ <version>${oak.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>oak-lucene</artifactId>
+ <version>${oak.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.googlecode.json-simple</groupId>
+ <artifactId>json-simple</artifactId>
+ <version>1.1</version>
+ </dependency>
+
+ <!-- Required for Felix WebConsole -->
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.http.proxy</artifactId>
+ <version>2.3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.http.bridge</artifactId>
+ <version>2.3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.webconsole</artifactId>
+ <version>4.2.10</version>
+ <classifier>all</classifier>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+
<artifactId>org.apache.felix.webconsole.plugins.scriptconsole</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy-all</artifactId>
+ <version>2.3.6</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>${spring.boot.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>src/main/webapp/WEB-INF/log4j.dtd</exclude>
+
<exclude>src/main/webapp/WEB-INF/templates/repository-config.json</exclude>
+ <exclude>*.sh</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-clean-plugin</artifactId>
+ <version>2.5</version>
+ <configuration>
+ <filesets>
+ <fileset>
+ <directory>oak</directory>
+ </fileset>
+ </filesets>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <configuration>
+ <systemPropertyVariables>
+ <java.util.logging.config.file>
+ src/test/resources/logging.properties
+ </java.util.logging.config.file>
+ </systemPropertyVariables>
+ </configuration>
+ <executions>
+ <execution>
+ <id>failsafe-integration-tests</id>
+ <phase>integration-test</phase>
+ <goals>
+ <goal>integration-test</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>failsafe-verify</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Propchange: jackrabbit/oak/trunk/oak-examples/standalone/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added:
jackrabbit/oak/trunk/oak-examples/standalone/src/main/java/org/apache/jackrabbit/oak/standalone/OakServer.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-examples/standalone/src/main/java/org/apache/jackrabbit/oak/standalone/OakServer.java?rev=1716836&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-examples/standalone/src/main/java/org/apache/jackrabbit/oak/standalone/OakServer.java
(added)
+++
jackrabbit/oak/trunk/oak-examples/standalone/src/main/java/org/apache/jackrabbit/oak/standalone/OakServer.java
Fri Nov 27 11:27:34 2015
@@ -0,0 +1,31 @@
+/*
+ * 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.standalone;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class OakServer {
+
+ public static void main(String[] args) {
+ SpringApplication.run(OakServer.class, args);
+ }
+}
Propchange:
jackrabbit/oak/trunk/oak-examples/standalone/src/main/java/org/apache/jackrabbit/oak/standalone/OakServer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
jackrabbit/oak/trunk/oak-examples/standalone/src/main/java/org/apache/jackrabbit/oak/standalone/RepositoryInitializer.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-examples/standalone/src/main/java/org/apache/jackrabbit/oak/standalone/RepositoryInitializer.java?rev=1716836&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-examples/standalone/src/main/java/org/apache/jackrabbit/oak/standalone/RepositoryInitializer.java
(added)
+++
jackrabbit/oak/trunk/oak-examples/standalone/src/main/java/org/apache/jackrabbit/oak/standalone/RepositoryInitializer.java
Fri Nov 27 11:27:34 2015
@@ -0,0 +1,139 @@
+/*
+ * 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.standalone;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Map;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.servlet.ServletContext;
+
+import com.google.common.collect.Maps;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.jackrabbit.api.JackrabbitRepository;
+import org.apache.jackrabbit.oak.run.osgi.OakOSGiRepositoryFactory;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.Resource;
+
+@Configuration
+public class RepositoryInitializer {
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ @Autowired
+ private ServletContext servletContext;
+
+ private Repository repository;
+
+ @Value("classpath:/repository-config.json")
+ private Resource defaultRepoConfig;
+
+ @Value("${repo.home}")
+ private String repoHome;
+
+ @PostConstruct
+ public void initialize() throws Exception {
+ initRepository();
+ }
+
+ @PreDestroy
+ public void close() {
+ if (repository instanceof JackrabbitRepository) {
+ ((JackrabbitRepository) repository).shutdown();
+ log.info("Repository shutdown complete");
+ repository = null;
+ }
+ }
+
+ @Bean(name="repository")
+ public Repository getRepository(){
+ return repository;
+ }
+
+ private void initRepository() throws IOException, RepositoryException {
+ File repoHomeDir = new File(repoHome);
+ FileUtils.forceMkdir(repoHomeDir);
+
+ File repoConfig = new File(repoHomeDir, "repository-config.json");
+ copyDefaultConfig(repoConfig, defaultRepoConfig);
+ repository = createRepository(repoConfig, repoHomeDir);
+ }
+
+ private Repository createRepository(File repoConfig, File repoHomeDir)
throws RepositoryException {
+ Map<String,Object> config = Maps.newHashMap();
+ config.put(OakOSGiRepositoryFactory.REPOSITORY_HOME,
repoHomeDir.getAbsolutePath());
+ config.put(OakOSGiRepositoryFactory.REPOSITORY_CONFIG_FILE,
repoConfig.getAbsolutePath());
+ config.put(OakOSGiRepositoryFactory.REPOSITORY_SHUTDOWN_ON_TIMEOUT,
false);
+ config.put(OakOSGiRepositoryFactory.REPOSITORY_ENV_SPRING_BOOT, true);
+ config.put(OakOSGiRepositoryFactory.REPOSITORY_TIMEOUT_IN_SECS, 10);
+
+ configureActivator(config);
+ return new OakOSGiRepositoryFactory().getRepository(config);
+ }
+
+ private void configureActivator(Map<String, Object> config) {
+ config.put(BundleActivator.class.getName(), new BundleActivator() {
+ @Override
+ public void start(BundleContext bundleContext) throws Exception {
+ servletContext.setAttribute(BundleContext.class.getName(),
bundleContext);
+ }
+
+ @Override
+ public void stop(BundleContext bundleContext) throws Exception {
+ servletContext.removeAttribute(BundleContext.class.getName());
+ }
+ });
+
+ }
+
+ private void copyDefaultConfig(File repoConfig, Resource defaultRepoConfig)
+ throws IOException, RepositoryException {
+ if (!repoConfig.exists()){
+ log.info("Copying default repository config to {}",
repoConfig.getAbsolutePath());
+ InputStream in = defaultRepoConfig.getInputStream();
+ if (in == null){
+ throw new RepositoryException("No config file found in
classpath " + defaultRepoConfig);
+ }
+ OutputStream os = null;
+ try {
+ os = FileUtils.openOutputStream(repoConfig);
+ IOUtils.copy(in, os);
+ } finally {
+ IOUtils.closeQuietly(os);
+ IOUtils.closeQuietly(in);
+ }
+ }
+ }
+
+
+}
Propchange:
jackrabbit/oak/trunk/oak-examples/standalone/src/main/java/org/apache/jackrabbit/oak/standalone/RepositoryInitializer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
jackrabbit/oak/trunk/oak-examples/standalone/src/main/resources/application.yml
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-examples/standalone/src/main/resources/application.yml?rev=1716836&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-examples/standalone/src/main/resources/application.yml
(added)
+++
jackrabbit/oak/trunk/oak-examples/standalone/src/main/resources/application.yml
Fri Nov 27 11:27:34 2015
@@ -0,0 +1,2 @@
+repo:
+ home: repository
\ No newline at end of file
Added:
jackrabbit/oak/trunk/oak-examples/standalone/src/main/resources/repository-config.json
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-examples/standalone/src/main/resources/repository-config.json?rev=1716836&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-examples/standalone/src/main/resources/repository-config.json
(added)
+++
jackrabbit/oak/trunk/oak-examples/standalone/src/main/resources/repository-config.json
Fri Nov 27 11:27:34 2015
@@ -0,0 +1,25 @@
+{
+ "org.apache.felix.jaas.Configuration.factory-GuestLoginModule": {
+ "jaas.controlFlag": "optional",
+ "jaas.classname":
"org.apache.jackrabbit.oak.spi.security.authentication.GuestLoginModule",
+ "jaas.ranking": 300
+ },
+ "org.apache.felix.jaas.Configuration.factory-LoginModuleImpl": {
+ "jaas.controlFlag": "required",
+ "jaas.classname":
"org.apache.jackrabbit.oak.security.authentication.user.LoginModuleImpl",
+ "jaas.ranking": 100
+ },
+ "org.apache.felix.jaas.Configuration.factory-TokenLoginModule": {
+ "jaas.controlFlag": "sufficient",
+ "jaas.classname":
"org.apache.jackrabbit.oak.security.authentication.token.TokenLoginModule",
+ "jaas.ranking": 200
+ },
+ "org.apache.felix.jaas.ConfigurationSpi": {
+ "jaas.defaultRealmName": "jackrabbit.oak",
+ "jaas.globalConfigPolicy": "proxy",
+ "jaas.configProviderName": "FelixJaasProvider"
+ },
+ "org.apache.jackrabbit.oak.jcr.osgi.RepositoryManager": {},
+ "org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStoreService" : {
+ }
+}
\ No newline at end of file