Author: rhauch
Date: 2009-09-11 16:48:26 -0400 (Fri, 11 Sep 2009)
New Revision: 1211
Added:
trunk/web/
trunk/web/dna-web-jcr-rest-war/
trunk/web/dna-web-jcr-rest-war/.classpath
trunk/web/dna-web-jcr-rest-war/.project
trunk/web/dna-web-jcr-rest-war/.settings/
trunk/web/dna-web-jcr-rest-war/.settings/.jsdtscope
trunk/web/dna-web-jcr-rest-war/.settings/org.eclipse.wst.common.component
trunk/web/dna-web-jcr-rest-war/.settings/org.eclipse.wst.common.project.facet.core.xml
trunk/web/dna-web-jcr-rest-war/.settings/org.eclipse.wst.jsdt.ui.superType.container
trunk/web/dna-web-jcr-rest-war/.settings/org.eclipse.wst.jsdt.ui.superType.name
trunk/web/dna-web-jcr-rest-war/.settings/org.maven.ide.eclipse.prefs
trunk/web/dna-web-jcr-rest-war/pom.xml
trunk/web/dna-web-jcr-rest-war/src/
trunk/web/dna-web-jcr-rest-war/src/main/
trunk/web/dna-web-jcr-rest-war/src/main/resources/
trunk/web/dna-web-jcr-rest-war/src/main/resources/configRepository.xml
trunk/web/dna-web-jcr-rest-war/src/main/resources/log4j.properties
trunk/web/dna-web-jcr-rest-war/src/main/webapp/
trunk/web/dna-web-jcr-rest-war/src/main/webapp/META-INF/
trunk/web/dna-web-jcr-rest-war/src/main/webapp/META-INF/MANIFEST.MF
trunk/web/dna-web-jcr-rest-war/src/main/webapp/WEB-INF/
trunk/web/dna-web-jcr-rest-war/src/main/webapp/WEB-INF/web.xml
trunk/web/dna-web-jcr-rest-war/src/test/
trunk/web/dna-web-jcr-rest-war/src/test/java/
trunk/web/dna-web-jcr-rest-war/src/test/java/org/
trunk/web/dna-web-jcr-rest-war/src/test/java/org/jboss/
trunk/web/dna-web-jcr-rest-war/src/test/java/org/jboss/dna/
trunk/web/dna-web-jcr-rest-war/src/test/java/org/jboss/dna/web/
trunk/web/dna-web-jcr-rest-war/src/test/java/org/jboss/dna/web/jcr/
trunk/web/dna-web-jcr-rest-war/src/test/java/org/jboss/dna/web/jcr/rest/
trunk/web/dna-web-jcr-rest-war/src/test/java/org/jboss/dna/web/jcr/rest/JcrResourcesTest.java
trunk/web/dna-web-jcr-rest-war/src/test/resources/
trunk/web/dna-web-jcr-rest-war/src/test/resources/log4j.properties
trunk/web/dna-web-jcr-rest/
trunk/web/dna-web-jcr-rest/.classpath
trunk/web/dna-web-jcr-rest/.project
trunk/web/dna-web-jcr-rest/.settings/
trunk/web/dna-web-jcr-rest/.settings/org.eclipse.wst.common.component
trunk/web/dna-web-jcr-rest/.settings/org.eclipse.wst.common.project.facet.core.xml
trunk/web/dna-web-jcr-rest/.settings/org.maven.ide.eclipse.prefs
trunk/web/dna-web-jcr-rest/pom.xml
trunk/web/dna-web-jcr-rest/src/
trunk/web/dna-web-jcr-rest/src/main/
trunk/web/dna-web-jcr-rest/src/main/java/
trunk/web/dna-web-jcr-rest/src/main/java/org/
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/DnaJcrDeployer.java
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/JcrApplication.java
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/JcrResources.java
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/RepositoryFactory.java
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/ServletSecurityContext.java
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/RepositoryEntry.java
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/RepositoryResources.java
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/WorkspaceEntry.java
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/WorkspaceResources.java
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/package-info.java
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/package-info.java
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/DnaJcrRepositoryProvider.java
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/RepositoryProvider.java
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/package-info.java
Removed:
trunk/extensions/dna-web-jcr-rest-war/.classpath
trunk/extensions/dna-web-jcr-rest-war/.project
trunk/extensions/dna-web-jcr-rest-war/.settings/.jsdtscope
trunk/extensions/dna-web-jcr-rest-war/.settings/org.eclipse.wst.common.component
trunk/extensions/dna-web-jcr-rest-war/.settings/org.eclipse.wst.common.project.facet.core.xml
trunk/extensions/dna-web-jcr-rest-war/.settings/org.eclipse.wst.jsdt.ui.superType.container
trunk/extensions/dna-web-jcr-rest-war/.settings/org.eclipse.wst.jsdt.ui.superType.name
trunk/extensions/dna-web-jcr-rest-war/.settings/org.maven.ide.eclipse.prefs
trunk/extensions/dna-web-jcr-rest-war/pom.xml
trunk/extensions/dna-web-jcr-rest-war/src/main/resources/configRepository.xml
trunk/extensions/dna-web-jcr-rest-war/src/main/resources/log4j.properties
trunk/extensions/dna-web-jcr-rest-war/src/main/webapp/META-INF/MANIFEST.MF
trunk/extensions/dna-web-jcr-rest-war/src/main/webapp/WEB-INF/web.xml
trunk/extensions/dna-web-jcr-rest-war/src/test/java/org/jboss/dna/web/jcr/rest/JcrResourcesTest.java
trunk/extensions/dna-web-jcr-rest-war/src/test/resources/log4j.properties
trunk/extensions/dna-web-jcr-rest/.classpath
trunk/extensions/dna-web-jcr-rest/.project
trunk/extensions/dna-web-jcr-rest/.settings/org.eclipse.wst.common.component
trunk/extensions/dna-web-jcr-rest/.settings/org.eclipse.wst.common.project.facet.core.xml
trunk/extensions/dna-web-jcr-rest/.settings/org.maven.ide.eclipse.prefs
trunk/extensions/dna-web-jcr-rest/pom.xml
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/DnaJcrDeployer.java
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/JcrApplication.java
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/JcrResources.java
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/RepositoryFactory.java
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/ServletSecurityContext.java
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/RepositoryEntry.java
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/RepositoryResources.java
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/WorkspaceEntry.java
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/WorkspaceResources.java
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/package-info.java
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/package-info.java
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/DnaJcrRepositoryProvider.java
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/RepositoryProvider.java
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/package-info.java
Modified:
trunk/.gitignore
trunk/docs/reference/src/main/docbook/en-US/content/introduction.xml
Log:
Merge branch 'quick_patch'
Modified: trunk/.gitignore
===================================================================
--- trunk/.gitignore 2009-09-11 20:31:32 UTC (rev 1210)
+++ trunk/.gitignore 2009-09-11 20:48:26 UTC (rev 1211)
@@ -33,6 +33,10 @@
/extensions/dna-web-jcr-rest/target/
/extensions/dna-web-jcr-rest-war/target/
+
+/web/dna-web-jcr-rest/target/
+/web/dna-web-jcr-rest-war/target/
+
/extensions/dna-classloader-maven/target
/extensions/dna-common-jdbc/target
/extensions/dna-connector-federation/target
Modified: trunk/docs/reference/src/main/docbook/en-US/content/introduction.xml
===================================================================
--- trunk/docs/reference/src/main/docbook/en-US/content/introduction.xml 2009-09-11
20:31:32 UTC (rev 1210)
+++ trunk/docs/reference/src/main/docbook/en-US/content/introduction.xml 2009-09-11
20:48:26 UTC (rev 1211)
@@ -490,6 +490,12 @@
library to determine the best MIME type from the filename and file contents.
</para>
</listitem>
+ </itemizedlist>
+ The following modules make up the various web application projects (and are located
in the source
+ under the
+ <code>web/</code>
+ directory):
+ <itemizedlist>
<listitem>
<para>
<emphasis role="strong">dna-web-jcr-rest</emphasis>
Deleted: trunk/extensions/dna-web-jcr-rest/.classpath
===================================================================
--- trunk/extensions/dna-web-jcr-rest/.classpath 2009-09-11 20:31:32 UTC (rev 1210)
+++ trunk/extensions/dna-web-jcr-rest/.classpath 2009-09-11 20:48:26 UTC (rev 1211)
@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" output="target/classes"
path="src/main/java"/>
- <classpathentry kind="con"
path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
- <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="con"
path="org.eclipse.jst.j2ee.internal.module.container"/>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
Deleted: trunk/extensions/dna-web-jcr-rest/.project
===================================================================
--- trunk/extensions/dna-web-jcr-rest/.project 2009-09-11 20:31:32 UTC (rev 1210)
+++ trunk/extensions/dna-web-jcr-rest/.project 2009-09-11 20:48:26 UTC (rev 1211)
@@ -1,36 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>dna-web-jcr-rest</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.wst.common.project.facet.core.builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.maven.ide.eclipse.maven2Builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.wst.validation.validationbuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
- <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- <nature>org.maven.ide.eclipse.maven2Nature</nature>
- <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
- </natures>
-</projectDescription>
Deleted: trunk/extensions/dna-web-jcr-rest/.settings/org.eclipse.wst.common.component
===================================================================
---
trunk/extensions/dna-web-jcr-rest/.settings/org.eclipse.wst.common.component 2009-09-11
20:31:32 UTC (rev 1210)
+++
trunk/extensions/dna-web-jcr-rest/.settings/org.eclipse.wst.common.component 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project-modules id="moduleCoreId" project-version="1.5.0">
- <wb-module deploy-name="dna-web-jcr-rest">
- <wb-resource deploy-path="/"
source-path="/src/main/java"/>
- <wb-resource deploy-path="/"
source-path="/src/main/resources"/>
- <wb-resource deploy-path="/"
source-path="/src/test/java"/>
- <wb-resource deploy-path="/"
source-path="/src/test/resources"/>
- </wb-module>
-</project-modules>
Deleted:
trunk/extensions/dna-web-jcr-rest/.settings/org.eclipse.wst.common.project.facet.core.xml
===================================================================
---
trunk/extensions/dna-web-jcr-rest/.settings/org.eclipse.wst.common.project.facet.core.xml 2009-09-11
20:31:32 UTC (rev 1210)
+++
trunk/extensions/dna-web-jcr-rest/.settings/org.eclipse.wst.common.project.facet.core.xml 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<faceted-project>
- <installed facet="jst.java" version="5.0"/>
- <installed facet="jst.utility" version="1.0"/>
-</faceted-project>
Deleted: trunk/extensions/dna-web-jcr-rest/.settings/org.maven.ide.eclipse.prefs
===================================================================
--- trunk/extensions/dna-web-jcr-rest/.settings/org.maven.ide.eclipse.prefs 2009-09-11
20:31:32 UTC (rev 1210)
+++ trunk/extensions/dna-web-jcr-rest/.settings/org.maven.ide.eclipse.prefs 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,9 +0,0 @@
-#Wed May 27 16:24:52 EDT 2009
-activeProfiles=
-eclipse.preferences.version=1
-fullBuildGoals=process-test-resources
-includeModules=false
-resolveWorkspaceProjects=true
-resourceFilterGoals=process-resources resources\:testResources
-skipCompilerPlugin=true
-version=1
Deleted: trunk/extensions/dna-web-jcr-rest/pom.xml
===================================================================
--- trunk/extensions/dna-web-jcr-rest/pom.xml 2009-09-11 20:31:32 UTC (rev 1210)
+++ trunk/extensions/dna-web-jcr-rest/pom.xml 2009-09-11 20:48:26 UTC (rev 1211)
@@ -1,85 +0,0 @@
-<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>
- <artifactId>dna</artifactId>
- <groupId>org.jboss.dna</groupId>
- <version>0.6-SNAPSHOT</version>
- <relativePath>../..</relativePath>
- </parent>
- <artifactId>dna-web-jcr-rest</artifactId>
- <packaging>jar</packaging>
- <name>JBoss DNA JCR REST Library</name>
- <description>JBoss DNA REST support library</description>
- <
url>http://labs.jboss.org/dna</url>
- <dependencies>
- <dependency>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>resteasy-jaxrs</artifactId>
- <version>1.1.GA</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>resteasy-jaxb-provider</artifactId>
- <version>1.1.GA</version>
- <exclusions>
- <exclusion>
- <groupId>com.sun.xml.bind</groupId>
- <artifactId>jaxb-impl</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <!--
- This is only included as a temp. workaround. Current release of
- RESTEasy depends on 2.1.8, which is not in our repo at this time This
- should be removed after RESTEasy 1.1GA is released and added to this
- pom.
- -->
- <dependency>
- <groupId>com.sun.xml.bind</groupId>
- <artifactId>jaxb-impl</artifactId>
- <version>2.1.9</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.dna</groupId>
- <artifactId>dna-jcr</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.5.8</version>
- <scope>runtime</scope>
- </dependency>
- <!--
- Java Content Repository API
- -->
- <dependency>
- <groupId>javax.jcr</groupId>
- <artifactId>jcr</artifactId>
- </dependency>
-
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <version>2.5</version>
- <scope>provided</scope>
- </dependency>
-
- <!-- TESTING DEPENDENCIES -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit-dep</artifactId>
- <version>4.4</version>
- <scope>integration-test</scope>
- </dependency>
-
- <dependency>
- <groupId>javax.xml.bind</groupId>
- <artifactId>jaxb-api</artifactId>
- <version>2.1</version>
- </dependency>
-
- </dependencies>
-</project>
Deleted:
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/DnaJcrDeployer.java
===================================================================
---
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/DnaJcrDeployer.java 2009-09-11
20:31:32 UTC (rev 1210)
+++
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/DnaJcrDeployer.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,64 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.dna.web.jcr.rest;
-
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-import net.jcip.annotations.NotThreadSafe;
-import org.jboss.dna.web.jcr.rest.spi.RepositoryProvider;
-
-/**
- * Servlet context listener that is responsible for {@link
RepositoryFactory#initialize(javax.servlet.ServletContext)
- * initializing} the {@link RepositoryFactory repository factory}.
- * <p>
- * This class is not thread safe, but in practice this does not matter as the servlet
container must ensure that only a single
- * instance of this exists per web context and that it is only called in a
single-threaded manner.
- * </p>
- *
- * @see RepositoryFactory
- */
-@NotThreadSafe
-public class DnaJcrDeployer implements ServletContextListener {
-
- /**
- * Alerts the repository factory that the web application is shutting down
- *
- * @param event the servlet context event
- * @see RepositoryFactory#shutdown()
- * @see RepositoryProvider#shutdown()
- */
- public void contextDestroyed( ServletContextEvent event ) {
- RepositoryFactory.shutdown();
- }
-
- /**
- * Initializes the repository factory
- *
- * @param event the servlet context event
- * @see RepositoryFactory#initialize(javax.servlet.ServletContext)
- */
- public void contextInitialized( ServletContextEvent event ) {
- RepositoryFactory.initialize(event.getServletContext());
- }
-}
Deleted:
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/JcrApplication.java
===================================================================
---
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/JcrApplication.java 2009-09-11
20:31:32 UTC (rev 1210)
+++
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/JcrApplication.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,53 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.dna.web.jcr.rest;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-import javax.ws.rs.core.Application;
-
-/**
- * Implementation of the JAX-RS {@code Application} class to identify all JAX-RS
providers and classes in the application.
- *
- * @see Application
- */
-public class JcrApplication extends Application {
-
- /**
- * {@inheritDoc}
- *
- * @see Application#getClasses()
- */
- @Override
- public Set<Class<?>> getClasses() {
- return new HashSet<Class<?>>(Arrays.asList(new Class<?>[] {
- JcrResources.class,
- JcrResources.JSONExceptionMapper.class,
- JcrResources.NotFoundExceptionMapper.class,
- JcrResources.RepositoryExceptionMapper.class,
- }));
- }
-
-}
Deleted:
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/JcrResources.java
===================================================================
---
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/JcrResources.java 2009-09-11
20:31:32 UTC (rev 1210)
+++
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/JcrResources.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,831 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.dna.web.jcr.rest;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import javax.jcr.Item;
-import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.PathNotFoundException;
-import javax.jcr.Property;
-import javax.jcr.PropertyIterator;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.Value;
-import javax.jcr.ValueFactory;
-import javax.jcr.nodetype.NodeType;
-import javax.jcr.nodetype.PropertyDefinition;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.DefaultValue;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-import javax.ws.rs.ext.ExceptionMapper;
-import javax.ws.rs.ext.Provider;
-import net.jcip.annotations.Immutable;
-import org.codehaus.jettison.json.JSONArray;
-import org.codehaus.jettison.json.JSONException;
-import org.codehaus.jettison.json.JSONObject;
-import org.jboss.dna.common.text.UrlEncoder;
-import org.jboss.dna.common.util.Base64;
-import org.jboss.dna.web.jcr.rest.model.RepositoryEntry;
-import org.jboss.dna.web.jcr.rest.model.WorkspaceEntry;
-import org.jboss.resteasy.spi.NotFoundException;
-import org.jboss.resteasy.spi.UnauthorizedException;
-
-/**
- * RESTEasy handler to provide the JCR resources at the URIs below. Please note that
these URIs assume a context of {@code
- * /resources} for the web application.
- * <table border="1">
- * <tr>
- * <th>URI Pattern</th>
- * <th>Description</th>
- * <th>Supported Methods</th>
- * </tr>
- * <tr>
- * <td>/resources</td>
- * <td>returns a list of accessible repositories</td>
- * <td>GET</td>
- * </tr>
- * <tr>
- * <td>/resources/{repositoryName}</td>
- * <td>returns a list of accessible workspaces within that repository</td>
- * <td>GET</td>
- * </tr>
- * <tr>
- * <td>/resources/{repositoryName}/{workspaceName}</td>
- * <td>returns a list of operations within the workspace</td>
- * <td>GET</td>
- * </tr>
- * <tr>
- * <td>/resources/{repositoryName}/{workspaceName}/item/{path}</td>
- * <td>accesses the item (node or property) at the path</td>
- * <td>ALL</td>
- * </tr>
- * </table>
- * <h3>Binary data</h3>
- * <p>
- * There are several ways to transfer binary property values, but all involve encoding
the binary value into ASCII characters
- * using a {@link Base64} notation and denoting this by adding annotating the property
name with a suffix defining the type of
- * encoding. Currently, only "base64" encoding is supported.
- * </p>
- * <p>
- * For example, if the "jcr:data" property contains a single binary value of
"propertyValue", then the JSON object representing
- * that property will be:
- *
- * <pre>
- * "jcr:data/base64/" : "cHJvcGVydHlWYWx1ZQ=="
- * </pre>
- *
- * Likewise, if the "jcr:data" property contains two binary values each being
"propertyValue", then the JSON object representing
- * that property will be:
- *
- * <pre>
- * "jcr:data/base64/" : [ "cHJvcGVydHlWYWx1ZQ==",
"cHJvcGVydHlWYWx1ZQ==" ]
- * </pre>
- *
- * Note that JCR 1.0.1 does not allow property names to and with a '/' character
(among others), while JCR 2.0 does not allow
- * property names to contain an unescaped or unencoded '/' character. Therefore,
the "/{encoding}/" suffix can never appear in a
- * valid JCR property name, and will always identify an encoded property.
- * </p>
- * <p>
- * Here are the details:
- * <ul>
- * <li>Getting a node with <code>GET
/resources/{repositoryName}/item/{pathToNode}</code> obtains the JSON object
representing the
- * node, and each property is represented as a nested JSON object where the name is the
property name and the value(s) are
- * represented as either a single string value or an array of string values. If the
property has a binary value, then the property
- * name is appended with "/base64/" and the string representation of each value
is encoded in Base64.</li>
- * <li>Getting a property with <code>GET
/resources/{repositoryName}/item/{pathToProperty}</code> allows only the value(s)
for the
- * one property to be included in the response. If any of the values is a binary value,
then <i>all</i> of the values will be
- * encoded in Base64.</li>
- * <li>Setting a property with <code>PUT
/resources/{repositoryName}/item/{pathToProperty}</code> allows setting the property
to a
- * single value, and only that value needs to be included in the body of the request. If
the value is binary, the value
- * <i>must</i> be {@link Base64 encoded} by the client and the
"Content-Transfer-Encoding" header must be set to "base64" (case
- * does not matter). When the request is received, the value is decoded before the
property value is updated on the node.</li>
- * <li>Creating a node with <code>POST
/resources/{repositoryName}/item/{pathToNode}</code> requires a request that is
structured
- * in the same way as the response from getting a node: the resulting JSON object
represents the node, with nested JSON objects
- * for the properties and children. If any property of the new node has a binary value,
then the name of the property <i>must</i>
- * be appended with "/base64/" and the string representation of each value are
to be encoded in Base64.</li>
- * <li>Updating a node with <code>PUT
/resources/{repositoryName}/item/{pathToNode}</code> requires a request that is
structured
- * in the same way as the response from getting or posting a node: the resulting JSON
object represents the node, with nested JSON
- * objects for the properties and children. If any property of the new node has a binary
value, then the name of the property
- * <i>must</i> be appended with "/base64/" and the string
representation of each value are to be encoded in Base64.</li>
- * </ul>
- * </p>
- */
-@Immutable
-@Path( "/" )
-public class JcrResources {
-
- private static final String BASE64_ENCODING_SUFFIX = "/base64/";
-
- private static final UrlEncoder URL_ENCODER = new UrlEncoder();
-
- private static final String PROPERTIES_HOLDER = "properties";
- private static final String CHILD_NODE_HOLDER = "children";
-
- private static final String PRIMARY_TYPE_PROPERTY = "jcr:primaryType";
- private static final String MIXIN_TYPES_PROPERTY = "jcr:mixinTypes";
-
- /** Name to be used when the repository name is empty string as {@code
"//"} is not a valid path. */
- public static final String EMPTY_REPOSITORY_NAME = "<default>";
- /** Name to be used when the workspace name is empty string as {@code "//"}
is not a valid path. */
- public static final String EMPTY_WORKSPACE_NAME = "<default>";
-
- /**
- * Returns an active session for the given workspace name in the named repository.
- *
- * @param request the servlet request; may not be null or unauthenticated
- * @param rawRepositoryName the URL-encoded name of the repository in which the
session is created
- * @param rawWorkspaceName the URL-encoded name of the workspace to which the session
should be connected
- * @return an active session with the given workspace in the named repository
- * @throws RepositoryException if any other error occurs
- */
- private Session getSession( HttpServletRequest request,
- String rawRepositoryName,
- String rawWorkspaceName ) throws RepositoryException {
- assert request != null;
- assert request.getUserPrincipal() != null : "Request must be
authorized";
-
- // Sanity check
- if (request.getUserPrincipal() == null) {
- throw new UnauthorizedException("Client is not authorized");
- }
-
- return RepositoryFactory.getSession(request,
repositoryNameFor(rawRepositoryName), workspaceNameFor(rawWorkspaceName));
- }
-
- /**
- * Returns the list of JCR repositories available on this server
- *
- * @param request the servlet request; may not be null
- * @return the list of JCR repositories available on this server
- */
- @GET
- @Path( "/" )
- @Produces( "application/json" )
- public Map<String, RepositoryEntry> getRepositories( @Context
HttpServletRequest request ) {
- assert request != null;
-
- Map<String, RepositoryEntry> repositories = new HashMap<String,
RepositoryEntry>();
-
- for (String name : RepositoryFactory.getJcrRepositoryNames()) {
- if (name.trim().length() == 0) {
- name = EMPTY_REPOSITORY_NAME;
- }
- name = URL_ENCODER.encode(name);
- repositories.put(name, new RepositoryEntry(request.getContextPath(), name));
- }
-
- return repositories;
- }
-
- /**
- * Returns the list of workspaces available to this user within the named
repository.
- *
- * @param rawRepositoryName the name of the repository; may not be null
- * @param request the servlet request; may not be null
- * @return the list of workspaces available to this user within the named
repository.
- * @throws IOException if the given repository name does not map to any repositories
and there is an error writing the error
- * code to the response.
- * @throws RepositoryException if there is any other error accessing the list of
available workspaces for the repository
- */
- @GET
- @Path( "/{repositoryName}" )
- @Produces( "application/json" )
- public Map<String, WorkspaceEntry> getWorkspaces( @Context HttpServletRequest
request,
- @PathParam(
"repositoryName" ) String rawRepositoryName )
- throws RepositoryException, IOException {
-
- assert request != null;
- assert rawRepositoryName != null;
-
- Map<String, WorkspaceEntry> workspaces = new HashMap<String,
WorkspaceEntry>();
-
- Session session = getSession(request, rawRepositoryName, null);
- rawRepositoryName = URL_ENCODER.encode(rawRepositoryName);
-
- for (String name : session.getWorkspace().getAccessibleWorkspaceNames()) {
- if (name.trim().length() == 0) {
- name = EMPTY_WORKSPACE_NAME;
- }
- name = URL_ENCODER.encode(name);
- workspaces.put(name, new WorkspaceEntry(request.getContextPath(),
rawRepositoryName, name));
- }
-
- return workspaces;
- }
-
- /**
- * Handles GET requests for an item in a workspace.
- *
- * @param request the servlet request; may not be null or unauthenticated
- * @param rawRepositoryName the URL-encoded repository name
- * @param rawWorkspaceName the URL-encoded workspace name
- * @param path the path to the item
- * @param depth the depth of the node graph that should be returned if {@code path}
refers to a node. @{code 0} means return
- * the requested node only. A negative value indicates that the full subgraph
under the node should be returned. This
- * parameter defaults to {@code 0} and is ignored if {@code path} refers to a
property.
- * @return the JSON-encoded version of the item (and, if the item is a node, its
subgraph, depending on the value of {@code
- * depth})
- * @throws NotFoundException if the named repository does not exists, the named
workspace does not exist, or the user does not
- * have access to the named workspace
- * @throws JSONException if there is an error encoding the node
- * @throws UnauthorizedException if the given login information is invalid
- * @throws RepositoryException if any other error occurs
- * @see #EMPTY_REPOSITORY_NAME
- * @see #EMPTY_WORKSPACE_NAME
- * @see Session#getItem(String)
- */
- @GET
- @Path( "/{repositoryName}/{workspaceName}/items{path:.*}" )
- @Produces( "application/json" )
- public String getItem( @Context HttpServletRequest request,
- @PathParam( "repositoryName" ) String
rawRepositoryName,
- @PathParam( "workspaceName" ) String
rawWorkspaceName,
- @PathParam( "path" ) String path,
- @QueryParam( "dna:depth" ) @DefaultValue(
"0" ) int depth )
- throws JSONException, UnauthorizedException, RepositoryException {
- assert path != null;
- assert rawRepositoryName != null;
- assert rawWorkspaceName != null;
-
- Session session = getSession(request, rawRepositoryName, rawWorkspaceName);
- Item item;
-
- if ("/".equals(path) || "".equals(path)) {
- item = session.getRootNode();
- } else {
- try {
- item = session.getItem(path);
- } catch (PathNotFoundException pnfe) {
- throw new NotFoundException(pnfe.getMessage(), pnfe);
- }
- }
-
- if (item instanceof Node) {
- return jsonFor((Node)item, depth).toString();
- }
- return jsonFor((Property)item).toString();
- }
-
- /**
- * Returns the JSON-encoded version of the given property. If the property is
single-valued, the returned string is the value
- * of the property encoded as a JSON string, including the name. If the property is
multi-valued with {@code N} values, this
- * method returns a JSON array containing the JSON string for each value.
- * <p>
- * Note that if any of the values are binary, then <i>all</i> values will
be first encoded as {@link Base64} string values.
- * However, if no values are binary, then all values will simply be the {@link
Value#getString() string} representation of the
- * value.
- * </p>
- *
- * @param property the property to be encoded
- * @return the JSON-encoded version of the property
- * @throws JSONException if there is an error encoding the node
- * @throws RepositoryException if an error occurs accessing the property, its values,
or its definition.
- * @see Property#getDefinition()
- * @see PropertyDefinition#isMultiple()
- */
- private JSONObject jsonFor( Property property ) throws JSONException,
RepositoryException {
- boolean encoded = false;
- Object valueObject = null;
- if (property.getDefinition().isMultiple()) {
- Value[] values = property.getValues();
- for (Value value : values) {
- if (value.getType() == PropertyType.BINARY) {
- encoded = true;
- break;
- }
- }
- List<String> list = new ArrayList<String>(values.length);
- if (encoded) {
- for (Value value : values) {
- list.add(jsonEncodedStringFor(value));
- }
- } else {
- for (Value value : values) {
- list.add(value.getString());
- }
- }
- valueObject = new JSONArray(list);
- } else {
- Value value = property.getValue();
- encoded = value.getType() == PropertyType.BINARY;
- valueObject = encoded ? jsonEncodedStringFor(value) : value.getString();
- }
- String propertyName = property.getName();
- if (encoded) propertyName = propertyName + BASE64_ENCODING_SUFFIX;
- JSONObject jsonProperty = new JSONObject();
- jsonProperty.put(propertyName, valueObject);
- return jsonProperty;
- }
-
- /**
- * Return the JSON-compatible string representation of the given property value. If
the value is a {@link PropertyType#BINARY
- * binary} value, then this method returns the Base-64 encoding of that value.
Otherwise, it just returns the string
- * representation of the value.
- *
- * @param value the property value; may not be null
- * @return the string representation of the value
- * @throws RepositoryException if there is a problem accessing the value
- */
- private String jsonEncodedStringFor( Value value ) throws RepositoryException {
- // Encode the binary value in Base64 ...
- InputStream stream = value.getStream();
- try {
- return Base64.encode(stream);
- } finally {
- if (stream != null) {
- try {
- stream.close();
- } catch (IOException e) {
- // Error accessing the value, so throw this ...
- throw new RepositoryException(e);
- }
- }
- }
- }
-
- /**
- * Recursively returns the JSON-encoding of a node and its children to depth {@code
toDepth}.
- *
- * @param node the node to be encoded
- * @param toDepth the depth to which the recursion should extend; {@code 0} means no
further recursion should occur.
- * @return the JSON-encoding of a node and its children to depth {@code toDepth}.
- * @throws JSONException if there is an error encoding the node
- * @throws RepositoryException if any other error occurs
- */
- private JSONObject jsonFor( Node node,
- int toDepth ) throws JSONException, RepositoryException
{
- JSONObject jsonNode = new JSONObject();
-
- JSONObject properties = new JSONObject();
-
- for (PropertyIterator iter = node.getProperties(); iter.hasNext();) {
- Property prop = iter.nextProperty();
- String propName = prop.getName();
-
- boolean encoded = false;
-
- if (prop.getDefinition().isMultiple()) {
- Value[] values = prop.getValues();
- // Do any of the property values need to be encoded ?
- for (Value value : values) {
- if (value.getType() == PropertyType.BINARY) {
- encoded = true;
- break;
- }
- }
- if (encoded) propName = propName + BASE64_ENCODING_SUFFIX;
- JSONArray array = new JSONArray();
- for (int i = 0; i < values.length; i++) {
- array.put(encoded ? jsonEncodedStringFor(values[i]) :
values[i].getString());
- }
- properties.put(propName, array);
-
- } else {
- Value value = prop.getValue();
- encoded = value.getType() == PropertyType.BINARY;
- if (encoded) propName = propName + BASE64_ENCODING_SUFFIX;
- properties.put(propName, encoded ? jsonEncodedStringFor(value) :
value.getString());
- }
-
- }
- if (properties.length() > 0) {
- jsonNode.put(PROPERTIES_HOLDER, properties);
- }
-
- if (toDepth == 0) {
- List<String> children = new ArrayList<String>();
-
- for (NodeIterator iter = node.getNodes(); iter.hasNext();) {
- Node child = iter.nextNode();
-
- children.add(child.getName());
- }
-
- if (children.size() > 0) {
- jsonNode.put(CHILD_NODE_HOLDER, new JSONArray(children));
- }
- } else {
- JSONObject children = new JSONObject();
-
- for (NodeIterator iter = node.getNodes(); iter.hasNext();) {
- Node child = iter.nextNode();
-
- children.put(child.getName(), jsonFor(child, toDepth - 1));
- }
-
- if (children.length() > 0) {
- jsonNode.put(CHILD_NODE_HOLDER, children);
- }
- }
-
- return jsonNode;
- }
-
- /**
- * Adds the content of the request as a node (or subtree of nodes) at the location
specified by {@code path}.
- * <p>
- * The primary type and mixin type(s) may optionally be specified through the {@code
jcr:primaryType} and {@code
- * jcr:mixinTypes} properties.
- * </p>
- *
- * @param request the servlet request; may not be null or unauthenticated
- * @param rawRepositoryName the URL-encoded repository name
- * @param rawWorkspaceName the URL-encoded workspace name
- * @param path the path to the item
- * @param requestContent the JSON-encoded representation of the node or nodes to be
added
- * @return the JSON-encoded representation of the node or nodes that were added. This
will differ from {@code requestContent}
- * in that auto-created and protected properties (e.g., jcr:uuid) will be
populated.
- * @throws NotFoundException if the parent of the item to be added does not exist
- * @throws UnauthorizedException if the user does not have the access required to
create the node at this path
- * @throws JSONException if there is an error encoding the node
- * @throws RepositoryException if any other error occurs
- */
- @POST
- @Path( "/{repositoryName}/{workspaceName}/items/{path:.*}" )
- @Consumes( "application/json" )
- public Response postItem( @Context HttpServletRequest request,
- @PathParam( "repositoryName" ) String
rawRepositoryName,
- @PathParam( "workspaceName" ) String
rawWorkspaceName,
- @PathParam( "path" ) String path,
- String requestContent )
- throws NotFoundException, UnauthorizedException, RepositoryException,
JSONException {
-
- assert rawRepositoryName != null;
- assert rawWorkspaceName != null;
- assert path != null;
- JSONObject body = new JSONObject(requestContent);
-
- int lastSlashInd = path.lastIndexOf('/');
- String parentPath = lastSlashInd == -1 ? "/" : "/" +
path.substring(0, lastSlashInd);
- String newNodeName = lastSlashInd == -1 ? path : path.substring(lastSlashInd +
1);
-
- Session session = getSession(request, rawRepositoryName, rawWorkspaceName);
-
- Node parentNode = (Node)session.getItem(parentPath);
-
- Node newNode = addNode(parentNode, newNodeName, body);
-
- session.save();
-
- String json = jsonFor(newNode, -1).toString();
- return Response.status(Status.CREATED).entity(json).build();
- }
-
- /**
- * Adds the node described by {@code jsonNode} with name {@code nodeName} to the
existing node {@code parentNode}.
- *
- * @param parentNode the parent of the node to be added
- * @param nodeName the name of the node to be added
- * @param jsonNode the JSON-encoded representation of the node or nodes to be added.
- * @return the JSON-encoded representation of the node or nodes that were added. This
will differ from {@code requestContent}
- * in that auto-created and protected properties (e.g., jcr:uuid) will be
populated.
- * @throws JSONException if there is an error encoding the node
- * @throws RepositoryException if any other error occurs
- */
- private Node addNode( Node parentNode,
- String nodeName,
- JSONObject jsonNode ) throws RepositoryException, JSONException
{
- Node newNode;
-
- JSONObject properties = jsonNode.has(PROPERTIES_HOLDER) ?
jsonNode.getJSONObject(PROPERTIES_HOLDER) : new JSONObject();
-
- if (properties.has(PRIMARY_TYPE_PROPERTY)) {
- String primaryType = properties.getString(PRIMARY_TYPE_PROPERTY);
- newNode = parentNode.addNode(nodeName, primaryType);
- } else {
- newNode = parentNode.addNode(nodeName);
- }
-
- if (properties.has(MIXIN_TYPES_PROPERTY)) {
- Object rawMixinTypes = properties.get(MIXIN_TYPES_PROPERTY);
-
- if (rawMixinTypes instanceof JSONArray) {
- JSONArray mixinTypes = (JSONArray)rawMixinTypes;
- for (int i = 0; i < mixinTypes.length(); i++) {
- newNode.addMixin(mixinTypes.getString(i));
- }
-
- } else {
- newNode.addMixin(rawMixinTypes.toString());
-
- }
- }
-
- for (Iterator<?> iter = properties.keys(); iter.hasNext();) {
- String key = (String)iter.next();
-
- if (PRIMARY_TYPE_PROPERTY.equals(key)) continue;
- if (MIXIN_TYPES_PROPERTY.equals(key)) continue;
- setPropertyOnNode(newNode, key, properties.get(key));
- }
-
- if (jsonNode.has(CHILD_NODE_HOLDER)) {
- JSONObject children = jsonNode.getJSONObject(CHILD_NODE_HOLDER);
-
- for (Iterator<?> iter = children.keys(); iter.hasNext();) {
- String childName = (String)iter.next();
- JSONObject child = children.getJSONObject(childName);
-
- addNode(newNode, childName, child);
- }
- }
-
- return newNode;
- }
-
- private Value decodeValue( String encodedValue,
- ValueFactory valueFactory ) throws RepositoryException {
- byte[] binaryValue = Base64.decode(encodedValue);
- InputStream stream = new ByteArrayInputStream(binaryValue);
- try {
- return valueFactory.createValue(stream);
- } finally {
- try {
- stream.close();
- } catch (IOException e) {
- // Error accessing the value, so throw this ...
- throw new RepositoryException(e);
- }
- }
- }
-
- /**
- * Sets the named property on the given node. This method expects {@code value} to be
either a JSON string or a JSON array of
- * JSON strings. If {@code value} is a JSON array, {@code Node#setProperty(String,
String[]) the multi-valued property setter}
- * will be used.
- *
- * @param node the node on which the property is to be set
- * @param propName the name of the property to set
- * @param value the JSON-encoded values to be set
- * @throws RepositoryException if there is an error setting the property
- * @throws JSONException if {@code value} cannot be decoded
- */
- private void setPropertyOnNode( Node node,
- String propName,
- Object value ) throws RepositoryException,
JSONException {
- // Are the property values encoded ?
- boolean encoded = propName.endsWith(BASE64_ENCODING_SUFFIX);
- if (encoded) {
- int newLength = propName.length() - BASE64_ENCODING_SUFFIX.length();
- propName = newLength > 0 ? propName.substring(0, newLength) :
"";
- }
-
- Value[] values;
- ValueFactory valueFactory = node.getSession().getValueFactory();
- if (value instanceof JSONArray) {
- JSONArray jsonValues = (JSONArray)value;
- values = new Value[jsonValues.length()];
-
- for (int i = 0; i < values.length; i++) {
- String strValue = jsonValues.getString(i);
- if (encoded) {
- values[i] = decodeValue(strValue, valueFactory);
- } else {
- values[i] = valueFactory.createValue(strValue);
- }
- }
- } else {
- String strValue = (String)value;
- if (encoded) {
- values = new Value[] {decodeValue(strValue, valueFactory)};
- } else {
- values = new Value[] {valueFactory.createValue(strValue)};
- }
- }
-
- if (propName.equals(JcrResources.MIXIN_TYPES_PROPERTY)) {
- Set<String> toBeMixins = new HashSet<String>();
- for (Value theValue : values) {
- toBeMixins.add(theValue.getString());
- }
- Set<String> asIsMixins = new HashSet<String>();
-
- for (NodeType nodeType : node.getMixinNodeTypes()) {
- asIsMixins.add(nodeType.getName());
- }
-
- Set<String> mixinsToAdd = new HashSet<String>(toBeMixins);
- mixinsToAdd.removeAll(asIsMixins);
- asIsMixins.removeAll(toBeMixins);
-
- for (String nodeType : mixinsToAdd) {
- node.addMixin(nodeType);
- }
-
- for (String nodeType : asIsMixins) {
- node.removeMixin(nodeType);
- }
- } else {
- if (values.length == 1) {
- node.setProperty(propName, values[0]);
-
- } else {
- node.setProperty(propName, values);
- }
- }
- }
-
- /**
- * Deletes the item at {@code path}.
- *
- * @param request the servlet request; may not be null or unauthenticated
- * @param rawRepositoryName the URL-encoded repository name
- * @param rawWorkspaceName the URL-encoded workspace name
- * @param path the path to the item
- * @throws NotFoundException if no item exists at {@code path}
- * @throws UnauthorizedException if the user does not have the access required to
delete the item at this path
- * @throws RepositoryException if any other error occurs
- */
- @DELETE
- @Path( "/{repositoryName}/{workspaceName}/items{path:.*}" )
- @Consumes( "application/json" )
- public void deleteItem( @Context HttpServletRequest request,
- @PathParam( "repositoryName" ) String
rawRepositoryName,
- @PathParam( "workspaceName" ) String
rawWorkspaceName,
- @PathParam( "path" ) String path )
- throws NotFoundException, UnauthorizedException, RepositoryException {
-
- assert rawRepositoryName != null;
- assert rawWorkspaceName != null;
- assert path != null;
-
- Session session = getSession(request, rawRepositoryName, rawWorkspaceName);
-
- Item item;
- try {
- item = session.getItem(path);
- } catch (PathNotFoundException pnfe) {
- throw new NotFoundException(pnfe.getMessage(), pnfe);
- }
- item.remove();
- session.save();
- }
-
- /**
- * Updates the properties at the path.
- * <p>
- * If path points to a property, this method expects the request content to be either
a JSON array or a JSON string. The array
- * or string will become the values or value of the property. If path points to a
node, this method expects the request
- * content to be a JSON object. The keys of the objects correspond to property names
that will be set and the values for the
- * keys correspond to the values that will be set on the properties.
- * </p>
- *
- * @param request the servlet request; may not be null or unauthenticated
- * @param rawRepositoryName the URL-encoded repository name
- * @param rawWorkspaceName the URL-encoded workspace name
- * @param path the path to the item
- * @param requestContent the JSON-encoded representation of the values and, possibly,
properties to be set
- * @return the JSON-encoded representation of the node on which the property or
properties were set.
- * @throws NotFoundException if the parent of the item to be added does not exist
- * @throws UnauthorizedException if the user does not have the access required to
create the node at this path
- * @throws JSONException if there is an error encoding the node
- * @throws RepositoryException if any other error occurs
- * @throws IOException if there is a problem reading the value
- */
- @PUT
- @Path( "/{repositoryName}/{workspaceName}/items{path:.*}" )
- @Consumes( "application/json" )
- public String putItem( @Context HttpServletRequest request,
- @PathParam( "repositoryName" ) String
rawRepositoryName,
- @PathParam( "workspaceName" ) String
rawWorkspaceName,
- @PathParam( "path" ) String path,
- String requestContent ) throws UnauthorizedException,
JSONException, RepositoryException, IOException {
-
- assert path != null;
- assert rawRepositoryName != null;
- assert rawWorkspaceName != null;
-
- Session session = getSession(request, rawRepositoryName, rawWorkspaceName);
- Node node;
- Item item;
- if ("".equals(path) || "/".equals(path)) {
- item = session.getRootNode();
- } else {
- try {
- item = session.getItem(path);
- } catch (PathNotFoundException pnfe) {
- throw new NotFoundException(pnfe.getMessage(), pnfe);
- }
- }
-
- if (item instanceof Node) {
- JSONObject properties = new JSONObject(requestContent);
- node = (Node)item;
-
- for (Iterator<?> iter = properties.keys(); iter.hasNext();) {
- String key = (String)iter.next();
-
- setPropertyOnNode(node, key, properties.get(key));
- }
-
- } else {
- /*
- * The incoming content should be a JSON object containing the property name
and a value that is either a JSON
- * string or a JSON array.
- */
- Property property = (Property)item;
- String propertyName = property.getName();
- JSONObject jsonProperty = new JSONObject(requestContent);
- String jsonPropertyName = jsonProperty.has(propertyName) ? propertyName :
propertyName + BASE64_ENCODING_SUFFIX;
- node = property.getParent();
- setPropertyOnNode(node, jsonPropertyName,
jsonProperty.get(jsonPropertyName));
- }
- node.save();
- return jsonFor(node, 0).toString();
- }
-
- private String workspaceNameFor( String rawWorkspaceName ) {
- String workspaceName = URL_ENCODER.decode(rawWorkspaceName);
-
- if (EMPTY_WORKSPACE_NAME.equals(workspaceName)) {
- workspaceName = "";
- }
-
- return workspaceName;
- }
-
- private String repositoryNameFor( String rawRepositoryName ) {
- String repositoryName = URL_ENCODER.decode(rawRepositoryName);
-
- if (EMPTY_REPOSITORY_NAME.equals(repositoryName)) {
- repositoryName = "";
- }
-
- return repositoryName;
- }
-
- @Provider
- public static class NotFoundExceptionMapper implements
ExceptionMapper<NotFoundException> {
-
- public Response toResponse( NotFoundException exception ) {
- return
Response.status(Status.NOT_FOUND).entity(exception.getMessage()).build();
- }
-
- }
-
- @Provider
- public static class JSONExceptionMapper implements
ExceptionMapper<JSONException> {
-
- public Response toResponse( JSONException exception ) {
- return
Response.status(Status.BAD_REQUEST).entity(exception.getMessage()).build();
- }
-
- }
-
- @Provider
- public static class RepositoryExceptionMapper implements
ExceptionMapper<RepositoryException> {
-
- public Response toResponse( RepositoryException exception ) {
- /*
- * This error code is murky - the request must have been syntactically valid
to get to
- * the JCR operations, but there isn't an HTTP status code for
"semantically invalid."
- */
- return
Response.status(Status.BAD_REQUEST).entity(exception.getMessage()).build();
- }
-
- }
-
-}
Deleted:
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/RepositoryFactory.java
===================================================================
---
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/RepositoryFactory.java 2009-09-11
20:31:32 UTC (rev 1210)
+++
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/RepositoryFactory.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,100 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.dna.web.jcr.rest;
-
-import java.util.Collection;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import net.jcip.annotations.ThreadSafe;
-import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.web.jcr.rest.spi.RepositoryProvider;
-
-/**
- * Factory that provides implementations of the {@link RepositoryProvider repository
provider SPI} by wrapping a
- * {@link RepositoryProvider}.
- * <p>
- * The repository factory implements a lifecycle for the repository providers. It is
first {@link #initialize(ServletContext)
- * initialized} by {@link DnaJcrDeployer}, a servlet context listener that must be
configured in the DNA JCR REST web
- * configuration (web.xml). The repository factory looks in the context for a parameter
with the name of {@link #PROVIDER_KEY}.
- * This is assumed to be the FQN of the {@link RepositoryProvider repository provider},
which the factory will then instantiate.
- * </p>
- * <p>
- * The repository factory is then able to respond to multiple requests to {@link
#getJcrRepositoryNames() list the repository
- * names} and {@link #getSession(HttpServletRequest, String, String) return active JCR
sessions} until the {@link #shutdown()
- * shutdown method} is called.
- * </p>
- * <p>
- * The {@link #shutdown() shutdown method} is a simple proxy to the {@link
RepositoryProvider#shutdown()} repository provider's
- * shutdown method}.
- * </p>
- */
-@ThreadSafe
-public class RepositoryFactory {
-
- /** The FQN of the repository provider class. Currently set to {@value} . */
- public static final String PROVIDER_KEY =
"org.jboss.dna.web.jcr.rest.REPOSITORY_PROVIDER";
-
- private static RepositoryProvider provider;
-
- private RepositoryFactory() {
-
- }
-
- /**
- * Initializes the repository factory. For more details, please see the {@link
RepositoryFactory class-level documentation}.
- *
- * @param context the servlet context; may not be null
- * @see RepositoryFactory
- */
- static void initialize( ServletContext context ) {
- CheckArg.isNotNull(context, "context");
- String className = context.getInitParameter(PROVIDER_KEY);
-
- try {
- Class<? extends RepositoryProvider> providerClass =
Class.forName(className).asSubclass(RepositoryProvider.class);
- provider = providerClass.newInstance();
-
- } catch (Exception ex) {
- throw new IllegalStateException(ex);
- }
-
- provider.startup(context);
- }
-
- public static Session getSession( HttpServletRequest request,
- String repositoryName,
- String workspaceName ) throws RepositoryException
{
- return provider.getSession(request, repositoryName, workspaceName);
- }
-
- public static Collection<String> getJcrRepositoryNames() {
- return provider.getJcrRepositoryNames();
- }
-
- static void shutdown() {
- provider.shutdown();
- }
-}
Deleted:
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/ServletSecurityContext.java
===================================================================
---
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/ServletSecurityContext.java 2009-09-11
20:31:32 UTC (rev 1210)
+++
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/ServletSecurityContext.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,82 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.dna.web.jcr.rest;
-
-import javax.servlet.http.HttpServletRequest;
-import net.jcip.annotations.ThreadSafe;
-import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.graph.SecurityContext;
-
-/**
- * Servlet-based {@link SecurityContext security context} that assumes servlet-based
authentication and provides authorization
- * through the {@link HttpServletRequest#isUserInRole(String) servlet role-checking
mechanism}.
- * <p>
- * This security context is really only valid for the life of the {@link
HttpServletRequest servlet request} and should
- * only be used to support longer-lasting session scopes with great care. *
- * </p>
- */
-@ThreadSafe
-public class ServletSecurityContext implements SecurityContext {
-
- private final String userName;
- private final HttpServletRequest request;
-
- /**
- * Create a {@link ServletSecurityContext} with the supplied {@link
HttpServletRequest servlet information}.
- *
- * @param request the servlet request; may not be null
- */
- public ServletSecurityContext( HttpServletRequest request ) {
- CheckArg.isNotNull(request, "request");
- this.request = request;
- this.userName = request.getUserPrincipal() != null ?
request.getUserPrincipal().getName() : null;
- }
-
- /**
- * {@inheritDoc SecurityContext#getUserName()}
- *
- * @see SecurityContext#getUserName()
- */
- public final String getUserName() {
- return userName;
- }
-
- /**
- * {@inheritDoc SecurityContext#hasRole(String)}
- *
- * @see SecurityContext#hasRole(String)
- */
- public final boolean hasRole( String roleName ) {
- return request.isUserInRole(roleName);
- }
-
- /**
- * {@inheritDoc SecurityContext#logout()}
- *
- * @see SecurityContext#logout()
- */
- public void logout() {
- }
-
-}
Deleted:
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/RepositoryEntry.java
===================================================================
---
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/RepositoryEntry.java 2009-09-11
20:31:32 UTC (rev 1210)
+++
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/RepositoryEntry.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,63 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.dna.web.jcr.rest.model;
-
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-
-@XmlRootElement( name = "repository" )
-public class RepositoryEntry {
-
- private String name;
- private RepositoryResources resources;
-
- public RepositoryEntry() {
- resources = new RepositoryResources();
- }
-
- public RepositoryEntry( String contextName,
- String repositoryName ) {
- this.name = repositoryName;
-
- resources = new RepositoryResources(contextName, repositoryName);
- }
-
- @XmlElement
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- @XmlElement
- public RepositoryResources getResources() {
- return resources;
- }
-
- public void setResources(RepositoryResources resources) {
- this.resources = resources;
- }
-}
Deleted:
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/RepositoryResources.java
===================================================================
---
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/RepositoryResources.java 2009-09-11
20:31:32 UTC (rev 1210)
+++
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/RepositoryResources.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,48 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.dna.web.jcr.rest.model;
-
-import javax.xml.bind.annotation.XmlElement;
-
-public class RepositoryResources {
- private String baseUri;
-
- public RepositoryResources() {
- }
-
- public RepositoryResources( String contextName,
- String repositoryName ) {
- this.baseUri = contextName + "/" + repositoryName;
- }
-
- @XmlElement( name = "workspaces" )
- public String getWorkspaces() {
- return baseUri;
- }
-
- public void setWorkspaces(String workspaces) {
- this.baseUri = workspaces;
- }
-}
-
Deleted:
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/WorkspaceEntry.java
===================================================================
---
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/WorkspaceEntry.java 2009-09-11
20:31:32 UTC (rev 1210)
+++
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/WorkspaceEntry.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,65 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.dna.web.jcr.rest.model;
-
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-
-@XmlRootElement( name = "workspace" )
-public class WorkspaceEntry {
-
- private String name;
- private WorkspaceResources resources;
-
- public WorkspaceEntry() {
-
- }
-
- public WorkspaceEntry( String contextName,
- String repositoryName,
- String workspaceName ) {
- this.name = workspaceName;
-
- resources = new WorkspaceResources(contextName, repositoryName, workspaceName);
- }
-
- @XmlElement
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- @XmlElement
- public WorkspaceResources getResources() {
- return resources;
- }
-
- public void setResources(WorkspaceResources resources) {
- this.resources = resources;
- }
-}
-
Deleted:
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/WorkspaceResources.java
===================================================================
---
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/WorkspaceResources.java 2009-09-11
20:31:32 UTC (rev 1210)
+++
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/WorkspaceResources.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,49 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.dna.web.jcr.rest.model;
-
-import javax.xml.bind.annotation.XmlElement;
-
-public class WorkspaceResources {
- private String baseUri;
-
- public WorkspaceResources() {
- }
-
- public WorkspaceResources( String contextName,
- String repositoryName,
- String workspaceName ) {
- this.baseUri = contextName + "/" + repositoryName + "/" +
workspaceName;
- }
-
- @XmlElement( name = "items" )
- public String getWorkspaces() {
- return baseUri + "/items";
- }
-
- public void setWorkspaces(String workspaces) {
- this.baseUri = workspaces;
- }
-}
-
Deleted:
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/package-info.java
===================================================================
---
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/package-info.java 2009-09-11
20:31:32 UTC (rev 1210)
+++
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/package-info.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,28 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-/**
- * Models for the DNA interface to faciliate serving basic information as XML or JSON in
the future.
- */
-package org.jboss.dna.web.jcr.rest.model;
-
Deleted:
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/package-info.java
===================================================================
---
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/package-info.java 2009-09-11
20:31:32 UTC (rev 1210)
+++
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/package-info.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,36 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-/**
- * This package contains the core components for the DNA REST server implementation.
- * <p>
- * The key classes are:
- * <ul>
- * <li>{@link JcrResources} - the class that handles requests for valid
URIs</li>
- * <li>{@link JcrApplication} - the JAX-RS application class that indicates that
JcrResources should be used to handle URIs</li>
- * <li>{@link RepositoryFactory} - the interface to the DNA JCR SPI</li>
- * </ul>
- * </p>
- */
-package org.jboss.dna.web.jcr.rest;
-
Deleted:
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/DnaJcrRepositoryProvider.java
===================================================================
---
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/DnaJcrRepositoryProvider.java 2009-09-11
20:31:32 UTC (rev 1210)
+++
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/DnaJcrRepositoryProvider.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,124 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.dna.web.jcr.rest.spi;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashSet;
-import java.util.Set;
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import net.jcip.annotations.ThreadSafe;
-import org.jboss.dna.jcr.JcrConfiguration;
-import org.jboss.dna.jcr.JcrEngine;
-import org.jboss.dna.jcr.SecurityContextCredentials;
-import org.jboss.dna.web.jcr.rest.ServletSecurityContext;
-import org.jboss.resteasy.spi.NotFoundException;
-import org.jboss.resteasy.spi.UnauthorizedException;
-import org.xml.sax.SAXException;
-
-/**
- * Repository provider backed by the DNA JCR implementation.
- * <p>
- * The provider instantiates a {@link JcrEngine} that is {@link
JcrConfiguration#loadFrom(InputStream) configured from} the file
- * in the location specified by the servlet context parameter {@code
org.jboss.dna.web.jcr.rest.CONFIG_FILE}. This location must
- * be accessible by the classloader for this class.
- * </p>
- *
- * @see RepositoryProvider
- * @see Class#getResourceAsStream(String)
- */
-@ThreadSafe
-public class DnaJcrRepositoryProvider implements RepositoryProvider {
-
- public static final String CONFIG_FILE =
"org.jboss.dna.web.jcr.rest.CONFIG_FILE";
-
- private JcrEngine jcrEngine;
-
- public DnaJcrRepositoryProvider() {
- }
-
- public Set<String> getJcrRepositoryNames() {
- return new HashSet<String>(jcrEngine.getRepositoryNames());
- }
-
- private Repository getRepository( String repositoryName ) throws RepositoryException
{
- return jcrEngine.getRepository(repositoryName);
- }
-
- public void startup( ServletContext context ) {
- String configFile = context.getInitParameter(CONFIG_FILE);
-
- try {
- InputStream configFileInputStream =
getClass().getResourceAsStream(configFile);
- jcrEngine = new JcrConfiguration().loadFrom(configFileInputStream).build();
- jcrEngine.start();
- } catch (IOException ioe) {
- throw new IllegalStateException(ioe);
- } catch (SAXException saxe) {
- throw new IllegalStateException(saxe);
- }
-
- }
-
- public void shutdown() {
- jcrEngine.shutdown();
- }
-
- /**
- * Returns an active session for the given workspace name in the named repository.
- *
- * @param request the servlet request; may not be null or unauthenticated
- * @param repositoryName the name of the repository in which the session is created
- * @param workspaceName the name of the workspace to which the session should be
connected
- * @return an active session with the given workspace in the named repository
- * @throws RepositoryException if any other error occurs
- */
- public Session getSession( HttpServletRequest request,
- String repositoryName,
- String workspaceName ) throws RepositoryException {
- assert request != null;
- assert request.getUserPrincipal() != null : "Request must be
authorized";
-
- // Sanity check in case assertions are disabled
- if (request.getUserPrincipal() == null) {
- throw new UnauthorizedException("Client is not authorized");
- }
-
- Repository repository;
-
- try {
- repository = getRepository(repositoryName);
-
- } catch (RepositoryException re) {
- throw new NotFoundException(re.getMessage(), re);
- }
-
- return repository.login(new SecurityContextCredentials(new
ServletSecurityContext(request)), workspaceName);
-
- }
-}
Deleted:
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/RepositoryProvider.java
===================================================================
---
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/RepositoryProvider.java 2009-09-11
20:31:32 UTC (rev 1210)
+++
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/RepositoryProvider.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,81 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.dna.web.jcr.rest.spi;
-
-import java.util.Set;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-
-/**
- * Interface for any class that provides access to one or more local JCR repositories.
- * <p>
- * Repository providers must provide a public, no-argument constructor and be
thread-safe.
- * </p>
- */
-public interface RepositoryProvider {
-
- /**
- * Returns an active session for the given workspace name in the named repository.
- * <p>
- * JCR implementations that do not support multiple repositories on the same server
can ignore the repositoryName parameter.
- * </p>
- *
- * @param request the servlet request; may not be null or unauthenticated
- * @param repositoryName the name of the repository in which the session is created
- * @param workspaceName the name of the workspace to which the session should be
connected
- * @return an active session with the given workspace in the named repository
- * @throws RepositoryException if any other error occurs
- */
- public Session getSession( HttpServletRequest request,
- String repositoryName,
- String workspaceName ) throws RepositoryException;
-
- /**
- * Returns the available repository names
- * <p>
- * JCR implementations that do not support multiple repositories on the same server
should provide a singleton set containing
- * some default repository name.
- * </p>
- *
- * @return the available repository names; may not be null or empty
- */
- Set<String> getJcrRepositoryNames();
-
- /**
- * Signals the repository provider that it should initialize itself based on the
provided {@link ServletContext servlet
- * context} and begin accepting connections.
- *
- * @param context the servlet context for the REST servlet
- */
- void startup( ServletContext context );
-
- /**
- * Signals the repository provider that it should complete any pending transactions,
shutdown, and release any external
- * resource held.
- */
- void shutdown();
-
-}
Deleted:
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/package-info.java
===================================================================
---
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/package-info.java 2009-09-11
20:31:32 UTC (rev 1210)
+++
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/package-info.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,42 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-/**
- * Service provider interface (SPI) for the JCR implementation that backs the DNA JCR
REST server.
- * <p>
- * Service providers must provide a thread-safe implementation of the {@link
RepositoryProvider} interface
- * which is then bundled in the server WAR. The REST server can be configured to use the
provider by specifying
- * the fully-qualified name (FQN) of the custom repository provider class in the {@code
org.jboss.dna.web.jcr.rest.REPOSITORY_PROVIDER} context parameter
- * in the web configuration file (web.xml).
- * </p>
- * <p>
- * Custom repository providers for JCR implementations that do not support hosting
multiple repositories in the same server
- * can context can ignore the {@code repositoryName} parameter for {@link
RepositoryProvider#getSession(javax.servlet.http.HttpServletRequest, String, String)},
- * but must always return a non-empty, non-null set containing some default repository
name from {@link RepositoryProvider#getJcrRepositoryNames()}.
- * </p>
- *
- * @see org.jboss.dna.web.jcr.rest.RepositoryFactory
- * @see org.jboss.dna.web.jcr.rest.spi.RepositoryProvider
- */
-package org.jboss.dna.web.jcr.rest.spi;
-
Deleted: trunk/extensions/dna-web-jcr-rest-war/.classpath
===================================================================
--- trunk/extensions/dna-web-jcr-rest-war/.classpath 2009-09-11 20:31:32 UTC (rev 1210)
+++ trunk/extensions/dna-web-jcr-rest-war/.classpath 2009-09-11 20:48:26 UTC (rev 1211)
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" output="target/test-classes"
path="src/test/java"/>
- <classpathentry excluding="**" kind="src"
output="target/test-classes" path="src/test/resources"/>
- <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="con"
path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER">
- <attributes>
- <attribute name="org.eclipse.jst.component.dependency"
value="/WEB-INF/lib"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="con"
path="org.eclipse.jst.j2ee.internal.web.container"/>
- <classpathentry kind="con"
path="org.eclipse.jst.j2ee.internal.module.container"/>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
Deleted: trunk/extensions/dna-web-jcr-rest-war/.project
===================================================================
--- trunk/extensions/dna-web-jcr-rest-war/.project 2009-09-11 20:31:32 UTC (rev 1210)
+++ trunk/extensions/dna-web-jcr-rest-war/.project 2009-09-11 20:48:26 UTC (rev 1211)
@@ -1,42 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>dna-web-jcr-rest-war</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.wst.common.project.facet.core.builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.wst.validation.validationbuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.maven.ide.eclipse.maven2Builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
- <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- <nature>org.maven.ide.eclipse.maven2Nature</nature>
- <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
- <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
- </natures>
-</projectDescription>
Deleted: trunk/extensions/dna-web-jcr-rest-war/.settings/.jsdtscope
===================================================================
--- trunk/extensions/dna-web-jcr-rest-war/.settings/.jsdtscope 2009-09-11 20:31:32 UTC
(rev 1210)
+++ trunk/extensions/dna-web-jcr-rest-war/.settings/.jsdtscope 2009-09-11 20:48:26 UTC
(rev 1211)
@@ -1,11 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="con"
path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="con"
path="org.eclipse.wst.jsdt.launching.WebProject">
- <attributes>
- <attribute name="hide" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="con"
path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
- <classpathentry kind="output" path=""/>
-</classpath>
Deleted: trunk/extensions/dna-web-jcr-rest-war/.settings/org.eclipse.wst.common.component
===================================================================
---
trunk/extensions/dna-web-jcr-rest-war/.settings/org.eclipse.wst.common.component 2009-09-11
20:31:32 UTC (rev 1210)
+++
trunk/extensions/dna-web-jcr-rest-war/.settings/org.eclipse.wst.common.component 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project-modules id="moduleCoreId" project-version="1.5.0">
- <wb-module deploy-name="dna-web-jcr-rest-war">
- <wb-resource deploy-path="/"
source-path="/src/main/webapp"/>
- <wb-resource deploy-path="/WEB-INF/classes"
source-path="/src/test/java"/>
- <wb-resource deploy-path="/WEB-INF/classes"
source-path="/src/test/resources"/>
- <dependent-module deploy-path="/WEB-INF/lib"
handle="module:/resource/dna-web-jcr-rest/dna-web-jcr-rest">
- <dependency-type>uses</dependency-type>
- </dependent-module>
- <dependent-module deploy-path="/WEB-INF/lib"
handle="module:/resource/dna-jcr/dna-jcr">
- <dependency-type>uses</dependency-type>
- </dependent-module>
- <dependent-module deploy-path="/WEB-INF/lib"
handle="module:/resource/dna-common/dna-common">
- <dependency-type>uses</dependency-type>
- </dependent-module>
- <dependent-module deploy-path="/WEB-INF/lib"
handle="module:/resource/dna-graph/dna-graph">
- <dependency-type>uses</dependency-type>
- </dependent-module>
- <dependent-module deploy-path="/WEB-INF/lib"
handle="module:/resource/dna-repository/dna-repository">
- <dependency-type>uses</dependency-type>
- </dependent-module>
- <dependent-module deploy-path="/WEB-INF/lib"
handle="module:/resource/dna-connector-federation/dna-connector-federation">
- <dependency-type>uses</dependency-type>
- </dependent-module>
- <dependent-module deploy-path="/WEB-INF/lib"
handle="module:/resource/dna-cnd/dna-cnd">
- <dependency-type>uses</dependency-type>
- </dependent-module>
- <property name="context-root"
value="dna-web-jcr-rest-war"/>
- <property name="java-output-path"/>
- </wb-module>
-</project-modules>
Deleted:
trunk/extensions/dna-web-jcr-rest-war/.settings/org.eclipse.wst.common.project.facet.core.xml
===================================================================
---
trunk/extensions/dna-web-jcr-rest-war/.settings/org.eclipse.wst.common.project.facet.core.xml 2009-09-11
20:31:32 UTC (rev 1210)
+++
trunk/extensions/dna-web-jcr-rest-war/.settings/org.eclipse.wst.common.project.facet.core.xml 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<faceted-project>
- <installed facet="jst.java" version="5.0"/>
- <installed facet="jst.web" version="2.3"/>
-</faceted-project>
Deleted:
trunk/extensions/dna-web-jcr-rest-war/.settings/org.eclipse.wst.jsdt.ui.superType.container
===================================================================
---
trunk/extensions/dna-web-jcr-rest-war/.settings/org.eclipse.wst.jsdt.ui.superType.container 2009-09-11
20:31:32 UTC (rev 1210)
+++
trunk/extensions/dna-web-jcr-rest-war/.settings/org.eclipse.wst.jsdt.ui.superType.container 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1 +0,0 @@
-org.eclipse.wst.jsdt.launching.baseBrowserLibrary
\ No newline at end of file
Deleted:
trunk/extensions/dna-web-jcr-rest-war/.settings/org.eclipse.wst.jsdt.ui.superType.name
===================================================================
---
trunk/extensions/dna-web-jcr-rest-war/.settings/org.eclipse.wst.jsdt.ui.superType.name 2009-09-11
20:31:32 UTC (rev 1210)
+++
trunk/extensions/dna-web-jcr-rest-war/.settings/org.eclipse.wst.jsdt.ui.superType.name 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1 +0,0 @@
-Window
\ No newline at end of file
Deleted: trunk/extensions/dna-web-jcr-rest-war/.settings/org.maven.ide.eclipse.prefs
===================================================================
--- trunk/extensions/dna-web-jcr-rest-war/.settings/org.maven.ide.eclipse.prefs 2009-09-11
20:31:32 UTC (rev 1210)
+++ trunk/extensions/dna-web-jcr-rest-war/.settings/org.maven.ide.eclipse.prefs 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,9 +0,0 @@
-#Wed May 27 16:41:08 EDT 2009
-activeProfiles=
-eclipse.preferences.version=1
-fullBuildGoals=process-test-resources
-includeModules=true
-resolveWorkspaceProjects=true
-resourceFilterGoals=process-resources resources\:testResources
-skipCompilerPlugin=true
-version=1
Deleted: trunk/extensions/dna-web-jcr-rest-war/pom.xml
===================================================================
--- trunk/extensions/dna-web-jcr-rest-war/pom.xml 2009-09-11 20:31:32 UTC (rev 1210)
+++ trunk/extensions/dna-web-jcr-rest-war/pom.xml 2009-09-11 20:48:26 UTC (rev 1211)
@@ -1,96 +0,0 @@
-<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>
- <artifactId>dna</artifactId>
- <groupId>org.jboss.dna</groupId>
- <version>0.6-SNAPSHOT</version>
- <relativePath>../..</relativePath>
- </parent>
- <artifactId>dna-web-jcr-rest-war</artifactId>
- <packaging>war</packaging>
- <name>JBoss DNA JCR REST Servlet</name>
- <description>JBoss DNA servlet that provides RESTful access to JCR
items</description>
- <
url>http://labs.jboss.org/dna</url>
- <dependencies>
- <dependency>
- <groupId>org.jboss.dna</groupId>
- <artifactId>dna-web-jcr-rest</artifactId>
- <version>${pom.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.5.8</version>
- <scope>runtime</scope>
- </dependency>
-
- <!-- TESTING DEPENDENCIES -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit-dep</artifactId>
- <version>4.4</version>
- <scope>integration-test</scope>
- </dependency>
- </dependencies>
- <build>
- <finalName>resources</finalName>
- <plugins>
- <plugin>
- <groupId>org.codehaus.cargo</groupId>
- <artifactId>cargo-maven2-plugin</artifactId>
- <!-- >version>1.0.1-SNAPSHOT</version -->
- <executions>
- <execution>
- <id>start-container</id>
- <phase>pre-integration-test</phase>
- <goals>
- <goal>start</goal>
- </goals>
- </execution>
- <execution>
- <id>stop-container</id>
- <phase>post-integration-test</phase>
- <goals>
- <goal>stop</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <configuration>
- <properties>
- <cargo.logging>low</cargo.logging>
- <cargo.servlet.users>dnauser:password:connect,readwrite|unauthorized:password:bogus</cargo.servlet.users>
- </properties>
- </configuration>
- <wait>false</wait>
- </configuration>
- </plugin>
- <!--
- Override the default Surefire behavior to run during
- integration-test phase
- -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <skip>true</skip>
- </configuration>
- <executions>
- <execution>
- <id>surefire-it</id>
- <phase>integration-test</phase>
- <goals>
- <goal>test</goal>
- </goals>
- <configuration>
- <skip>false</skip>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
-
- </build>
-
-</project>
Deleted: trunk/extensions/dna-web-jcr-rest-war/src/main/resources/configRepository.xml
===================================================================
---
trunk/extensions/dna-web-jcr-rest-war/src/main/resources/configRepository.xml 2009-09-11
20:31:32 UTC (rev 1210)
+++
trunk/extensions/dna-web-jcr-rest-war/src/main/resources/configRepository.xml 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,51 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ JBoss DNA (
http://www.jboss.org/dna)
- ~
- ~ See the COPYRIGHT.txt file distributed with this work for information
- ~ regarding copyright ownership. Some portions may be licensed
- ~ to Red Hat, Inc. under one or more contributor license agreements.
- ~ See the AUTHORS.txt file in the distribution for a full listing of
- ~ individual contributors.
- ~
- ~ JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- ~ is licensed to you under the terms of the GNU Lesser General Public License as
- ~ published by the Free Software Foundation; either version 2.1 of
- ~ the License, or (at your option) any later version.
- ~
- ~ JBoss DNA is distributed in the hope that it will be useful,
- ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- ~ for more details.
- ~
- ~ You should have received a copy of the GNU Lesser General Public License
- ~ along with this distribution; if not, write to:
- ~ Free Software Foundation, Inc.
- ~ 51 Franklin Street, Fifth Floor
- ~ Boston, MA 02110-1301 USA
- -->
-<configuration
xmlns="http://www.jboss.org/dna/1.0"
xmlns:jcr="http://www.jcp.org/jcr/1.0">
- <!-- Define the sources from which content is made available -->
- <sources jcr:primaryType="nt:unstructured">
- <source jcr:name="repositorySource"
classname="org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource"
retryLimit="3" defaultWorkspaceName="default"/>
- </sources>
- <!-- Define the JCR repositories -->
- <repositories>
- <!-- Specify the source that should be used for the repository -->
- <repository jcr:name="repository"
sourceName="repositorySource">
- <source>repositorySource</source>
- <!-- Define the options for the JCR repository, using camelcase version of
JcrRepository.Option names
--->
- <options jcr:primaryType="dna:options">
- <projectNodeTypes jcr:primaryType="dna:option"
value="false"/>
- <jaasLoginConfigName jcr:primaryType="dna:option"
value="dna-jcr"/>
- </options>
- <!-- Define any custom node types. Importing CND files via
JcrConfiguration is equivalent to specifying here.
--->
- <nodeTypes jcr:primaryType="dna:nodeTypes"/>
- <!-- Define any namespaces for this repository, other than those already
defined by JCR or DNA
--->
- <namespaces jcr:primaryType="dna:namespaces" />
- </repository>
- </repositories>
-</configuration>
\ No newline at end of file
Deleted: trunk/extensions/dna-web-jcr-rest-war/src/main/resources/log4j.properties
===================================================================
--- trunk/extensions/dna-web-jcr-rest-war/src/main/resources/log4j.properties 2009-09-11
20:31:32 UTC (rev 1210)
+++ trunk/extensions/dna-web-jcr-rest-war/src/main/resources/log4j.properties 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,13 +0,0 @@
-log4j.rootLogger = INFO, stdout
-
-log4j.category.org.apache=DEBUG
-log4j.category.org.jboss.resteasy=DEBUG
-log4j.category.org.mortbay.jetty.security=ERROR
-log4j.category.org.slf4j.impl.JCLLoggerAdapter=DEBUG
-log4j.category.org.springframework=INFO
-
-log4j.appender.stdout = org.apache.log4j.ConsoleAppender
-log4j.appender.stdout.Threshold = INFO
-log4j.appender.stdout.Target = System.out
-log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
-log4j.appender.stdout.layout.ConversionPattern = [%-5p] [%C] : %m%n [%F:%L]
Deleted: trunk/extensions/dna-web-jcr-rest-war/src/main/webapp/META-INF/MANIFEST.MF
===================================================================
--- trunk/extensions/dna-web-jcr-rest-war/src/main/webapp/META-INF/MANIFEST.MF 2009-09-11
20:31:32 UTC (rev 1210)
+++ trunk/extensions/dna-web-jcr-rest-war/src/main/webapp/META-INF/MANIFEST.MF 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,3 +0,0 @@
-Manifest-Version: 1.0
-Class-Path:
-
Deleted: trunk/extensions/dna-web-jcr-rest-war/src/main/webapp/WEB-INF/web.xml
===================================================================
--- trunk/extensions/dna-web-jcr-rest-war/src/main/webapp/WEB-INF/web.xml 2009-09-11
20:31:32 UTC (rev 1210)
+++ trunk/extensions/dna-web-jcr-rest-war/src/main/webapp/WEB-INF/web.xml 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,116 +0,0 @@
-<?xml version="1.0"?>
-<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application
2.3//EN"
- "http://java.sun.com/dtd/web-app_2_3.dtd">
- <!--
- JBoss DNA (
http://www.jboss.org/dna) See the COPYRIGHT.txt file
- distributed with this work for information regarding copyright
- ownership. Some portions may be licensed to Red Hat, Inc. under one or
- more contributor license agreements. See the AUTHORS.txt file in the
- distribution for a full listing of individual contributors. JBoss DNA
- is free software. Unless otherwise indicated, all code in JBoss DNA is
- licensed to you under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either version
- 2.1 of the License, or (at your option) any later version. JBoss DNA
- is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- License for more details. You should have received a copy of the GNU
- Lesser General Public License along with this software; if not, write
- to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
- Boston, MA 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- -->
-<web-app>
- <display-name>JBoss DNA JCR RESTful Interface</display-name>
-
- <!--
- This parameter provides the fully-qualified name of a class that implements
- the o.j.d.web.jcr.rest.spi.RepositoryProvider interface. It is required
- by the DnaJcrDeployer that controls the lifecycle for the DNA REST server.
- -->
- <context-param>
- <param-name>org.jboss.dna.web.jcr.rest.REPOSITORY_PROVIDER</param-name>
- <param-value>org.jboss.dna.web.jcr.rest.spi.DnaJcrRepositoryProvider</param-value>
- </context-param>
-
- <!--
- This parameter, specific to the DnaJcrRepositoryProvider implementation, specifies
- the name of the configuration file to initialize the repository or repositories.
- This configuration file must be on the classpath and is given as a classpath-relative
- directory.
- -->
- <context-param>
- <param-name>org.jboss.dna.web.jcr.rest.CONFIG_FILE</param-name>
- <param-value>/configRepository.xml</param-value>
- </context-param>
-
- <!--
- This parameter defines the JAX-RS application class, which is really just a metadata
class
- that lets the JAX-RS engine (RESTEasy in this case) know which classes implement
pieces
- of the JAX-RS specification like exception handling and resource serving.
-
- This should not be modified.
- -->
- <context-param>
- <param-name>javax.ws.rs.Application</param-name>
- <param-value>org.jboss.dna.web.jcr.rest.JcrApplication</param-value>
- </context-param>
-
- <!-- Required parameter for RESTEasy - should not be modified -->
- <listener>
- <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
- </listener>
-
- <!-- Required parameter for JBoss DNA REST - should not be modified -->
- <listener>
- <listener-class>org.jboss.dna.web.jcr.rest.DnaJcrDeployer</listener-class>
- </listener>
-
- <!-- Required parameter for RESTEasy - should not be modified -->
- <servlet>
- <servlet-name>Resteasy</servlet-name>
- <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
- </servlet>
-
- <!-- Required parameter for JBoss DNA REST - should not be modified -->
- <servlet-mapping>
- <servlet-name>Resteasy</servlet-name>
- <url-pattern>/*</url-pattern>
- </servlet-mapping>
-
- <!--
- The JBoss DNA REST implementation leverages the HTTP credentials to for authentication
and authorization
- within the JCR repository. It makes no sense to try to log into the JCR repository
without credentials,
- so this constraint helps lock down the repository.
-
- This should generally not be modified.
- -->
- <security-constraint>
- <display-name>DNA REST</display-name>
- <web-resource-collection>
- <web-resource-name>RestEasy</web-resource-name>
- <url-pattern>/*</url-pattern>
- </web-resource-collection>
- <auth-constraint>
- <!--
- A user must be assigned this role to connect to any JCR repository, in addition to
needing the READONLY
- or READWRITE roles to actually read or modify the data. This is not used internally,
so another
- role could be substituted here.
- -->
- <role-name>connect</role-name>
- </auth-constraint>
- </security-constraint>
-
- <!--
- Any auth-method will work for JBoss DNA. BASIC is used this example for simplicity.
- -->
- <login-config>
- <auth-method>BASIC</auth-method>
- </login-config>
-
- <!--
- This must match the role-name in the auth-constraint above.
- -->
- <security-role>
- <role-name>connect</role-name>
- </security-role>
-</web-app>
Deleted:
trunk/extensions/dna-web-jcr-rest-war/src/test/java/org/jboss/dna/web/jcr/rest/JcrResourcesTest.java
===================================================================
---
trunk/extensions/dna-web-jcr-rest-war/src/test/java/org/jboss/dna/web/jcr/rest/JcrResourcesTest.java 2009-09-11
20:31:32 UTC (rev 1210)
+++
trunk/extensions/dna-web-jcr-rest-war/src/test/java/org/jboss/dna/web/jcr/rest/JcrResourcesTest.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,968 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.dna.web.jcr.rest;
-
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsInstanceOf.instanceOf;
-import static org.hamcrest.core.IsNull.notNullValue;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.Authenticator;
-import java.net.HttpURLConnection;
-import java.net.PasswordAuthentication;
-import java.net.URL;
-import java.util.HashSet;
-import java.util.Set;
-import javax.ws.rs.core.MediaType;
-import org.codehaus.jettison.json.JSONArray;
-import org.codehaus.jettison.json.JSONObject;
-import org.jboss.dna.common.util.Base64;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Test of the DNA JCR REST resource. Note that this test case uses a very low-level API
to construct requests and deconstruct the
- * responses. Users are encouraged to use a higher-level library to communicate with the
REST server (e.g., Apache HTTP Commons).
- */
-public class JcrResourcesTest {
-
- private static final String SERVER_CONTEXT = "/resources";
- private static final String SERVER_URL = "http://localhost:8080" +
SERVER_CONTEXT;
-
- @Before
- public void beforeEach() {
-
- // Configured in pom
- final String login = "dnauser";
- final String password = "password";
-
- Authenticator.setDefault(new Authenticator() {
- @Override
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(login, password.toCharArray());
- }
- });
- }
-
- private String getResponseFor( HttpURLConnection connection ) throws IOException {
- StringBuffer buff = new StringBuffer();
-
- InputStream stream = connection.getInputStream();
- int bytesRead;
- byte[] bytes = new byte[1024];
- while (-1 != (bytesRead = stream.read(bytes, 0, 1024))) {
- buff.append(new String(bytes, 0, bytesRead));
- }
-
- return buff.toString();
- }
-
- @Test
- public void shouldNotServeContentToUnauthorizedUser() throws Exception {
-
- final String login = "dnauser";
- final String password = "invalidpassword";
-
- Authenticator.setDefault(new Authenticator() {
- @Override
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(login, password.toCharArray());
- }
- });
-
- URL postUrl = new URL(SERVER_URL + "/");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("GET");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- assertThat(connection.getResponseCode(),
is(HttpURLConnection.HTTP_UNAUTHORIZED));
- connection.disconnect();
-
- }
-
- @Test
- public void shouldNotServeContentToUserWithoutConnectRole() throws Exception {
-
- // Configured in pom
- final String login = "unauthorizeduser";
- final String password = "password";
-
- Authenticator.setDefault(new Authenticator() {
- @Override
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(login, password.toCharArray());
- }
- });
-
- URL postUrl = new URL(SERVER_URL + "/");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("GET");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- assertThat(connection.getResponseCode(),
is(HttpURLConnection.HTTP_UNAUTHORIZED));
- connection.disconnect();
-
- }
-
- @Test
- public void shouldServeContentAtRoot() throws Exception {
- URL postUrl = new URL(SERVER_URL + "/");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("GET");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
- String body = getResponseFor(connection);
-
- JSONObject objFromResponse = new JSONObject(body);
- JSONObject expected = new JSONObject(
-
"{\"dna%3arepository\":{\"repository\":{\"name\":\"dna%3arepository\",\"resources\":{\"workspaces\":\"/resources/dna%3arepository\"}}}}");
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
- assertThat(objFromResponse.toString(), is(expected.toString()));
- connection.disconnect();
- }
-
- @Test
- public void shouldServeListOfWorkspacesForValidRepository() throws Exception {
- URL postUrl = new URL(SERVER_URL + "/dna%3arepository");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("GET");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
- String body = getResponseFor(connection);
-
- JSONObject objFromResponse = new JSONObject(body);
- JSONObject expected = new JSONObject(
-
"{\"default\":{\"workspace\":{\"name\":\"default\",\"resources\":{\"items\":\"/resources/dna%3arepository/default/items\"}}}}");
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
- assertThat(objFromResponse.toString(), is(expected.toString()));
- connection.disconnect();
- }
-
- @Test
- public void shouldReturnErrorForInvalidWorkspace() throws Exception {
- URL postUrl = new URL(SERVER_URL + "/XXX");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("GET");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_NOT_FOUND));
- connection.disconnect();
- }
-
- @Test
- public void shouldRetrieveRootNodeForValidRepository() throws Exception {
- URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("GET");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- JSONObject body = new JSONObject(getResponseFor(connection));
- assertThat(body.length(), is(2));
-
- JSONObject properties = body.getJSONObject("properties");
- assertThat(properties, is(notNullValue()));
- assertThat(properties.length(), is(2));
- assertThat(properties.getString("jcr:primaryType"),
is("dna:root"));
- assertThat(properties.get("jcr:uuid"), is(notNullValue()));
-
- JSONArray children = body.getJSONArray("children");
- assertThat(children.length(), is(1));
- assertThat(children.getString(0), is("jcr:system"));
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
- connection.disconnect();
- }
-
- @Test
- public void shouldRetrieveRootNodeAndChildrenWhenDepthSet() throws Exception {
- URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items?dna:depth=1");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("GET");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
- JSONObject body = new JSONObject(getResponseFor(connection));
- assertThat(body.length(), is(2));
-
- JSONObject properties = body.getJSONObject("properties");
- assertThat(properties, is(notNullValue()));
- assertThat(properties.length(), is(2));
- assertThat(properties.getString("jcr:primaryType"),
is("dna:root"));
- assertThat(properties.get("jcr:uuid"), is(notNullValue()));
-
- JSONObject children = body.getJSONObject("children");
- assertThat(children.length(), is(1));
-
- JSONObject system = children.getJSONObject("jcr:system");
- assertThat(system.length(), is(2));
-
- properties = system.getJSONObject("properties");
- assertThat(properties.length(), is(1));
- assertThat(properties.getString("jcr:primaryType"),
is("dna:system"));
-
- JSONArray namespaces = system.getJSONArray("children");
- assertThat(namespaces.length(), is(1));
- assertThat(namespaces.getString(0), is("dna:namespaces"));
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
- connection.disconnect();
- }
-
- @Test
- public void shouldRetrieveNodeAndChildrenWhenDepthSet() throws Exception {
- URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/jcr:system?dna:depth=1");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("GET");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
- JSONObject body = new JSONObject(getResponseFor(connection));
- assertThat(body.length(), is(2));
-
- JSONObject properties = body.getJSONObject("properties");
- assertThat(properties, is(notNullValue()));
- assertThat(properties.length(), is(1));
- assertThat(properties.getString("jcr:primaryType"),
is("dna:system"));
-
- JSONObject children = body.getJSONObject("children");
- assertThat(children.length(), is(1));
-
- JSONObject namespaces = children.getJSONObject("dna:namespaces");
- assertThat(namespaces.length(), is(2));
-
- properties = namespaces.getJSONObject("properties");
- assertThat(properties.length(), is(1));
- assertThat(properties.getString("jcr:primaryType"),
is("dna:namespaces"));
-
- JSONArray namespace = namespaces.getJSONArray("children");
- assertThat(namespace.length(), is(10));
- Set<String> prefixes = new HashSet<String>(namespace.length());
-
- for (int i = 0; i < namespace.length(); i++) {
- prefixes.add(namespace.getString(i));
- }
-
- String[] expectedNamespaces = new String[] {"dna", "jcr",
"nt", "mix", "sv", "xml", "dnaint",
"xmlns", "xsi", "xsd"};
- for (int i = 0; i < expectedNamespaces.length; i++) {
- assertTrue(prefixes.contains(expectedNamespaces[i]));
- }
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
- connection.disconnect();
- }
-
- @Test
- public void shouldNotRetrieveNonExistentNode() throws Exception {
- URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/foo");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("GET");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_NOT_FOUND));
- connection.disconnect();
- }
-
- @Test
- public void shouldNotRetrieveNonExistentProperty() throws Exception {
- URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/jcr:system/foobar");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("GET");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_NOT_FOUND));
- connection.disconnect();
- }
-
- @Test
- public void shouldRetrieveProperty() throws Exception {
- URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/jcr:system/jcr:primaryType");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("GET");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- String body = getResponseFor(connection);
- assertThat(body,
is("{\"jcr:primaryType\":\"dna:system\"}"));
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
- connection.disconnect();
- }
-
- @Test
- public void shouldPostNodeToValidPathWithPrimaryType() throws Exception {
- URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nodeA");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("POST");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- String payload = "{ \"properties\":
{\"jcr:primaryType\": \"nt:unstructured\", \"testProperty\":
\"testValue\", \"multiValuedProperty\": [\"value1\",
\"value2\"]}}";
- connection.getOutputStream().write(payload.getBytes());
-
- JSONObject body = new JSONObject(getResponseFor(connection));
- assertThat(body.length(), is(1));
-
- JSONObject properties = body.getJSONObject("properties");
- assertThat(properties, is(notNullValue()));
- assertThat(properties.length(), is(3));
- assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
- assertThat(properties.getString("testProperty"),
is("testValue"));
- assertThat(properties.get("multiValuedProperty"),
instanceOf(JSONArray.class));
-
- JSONArray values = properties.getJSONArray("multiValuedProperty");
- assertThat(values, is(notNullValue()));
- assertThat(values.length(), is(2));
- assertThat(values.getString(0), is("value1"));
- assertThat(values.getString(1), is("value2"));
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_CREATED));
- connection.disconnect();
- }
-
- @Test
- public void shouldPostNodeToValidPathWithoutPrimaryType() throws Exception {
- URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/noPrimaryType");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("POST");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- String payload = "{}";
- connection.getOutputStream().write(payload.getBytes());
-
- JSONObject body = new JSONObject(getResponseFor(connection));
- assertThat(body.length(), is(1));
-
- JSONObject properties = body.getJSONObject("properties");
- assertThat(properties, is(notNullValue()));
- assertThat(properties.length(), is(1));
- assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_CREATED));
- connection.disconnect();
- }
-
- @Test
- public void shouldPostNodeToValidPathWithMixinTypes() throws Exception {
- URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/withMixinType");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("POST");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- String payload = "{ \"properties\": {\"jcr:mixinTypes\":
\"mix:referenceable\"}}";
- connection.getOutputStream().write(payload.getBytes());
-
- JSONObject body = new JSONObject(getResponseFor(connection));
- assertThat(body.length(), is(1));
-
- JSONObject properties = body.getJSONObject("properties");
- assertThat(properties, is(notNullValue()));
- assertThat(properties.length(), is(3));
- assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
- assertThat(properties.getString("jcr:uuid"), is(notNullValue()));
-
- JSONArray values = properties.getJSONArray("jcr:mixinTypes");
- assertThat(values, is(notNullValue()));
- assertThat(values.length(), is(1));
- assertThat(values.getString(0), is("mix:referenceable"));
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_CREATED));
- connection.disconnect();
-
- postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/withMixinType");
- connection = (HttpURLConnection)postUrl.openConnection();
-
- // Make sure that we can retrieve the node with a GET
- connection.setDoOutput(true);
- connection.setRequestMethod("GET");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
- body = new JSONObject(getResponseFor(connection));
-
- assertThat(body.length(), is(1));
-
- properties = body.getJSONObject("properties");
- assertThat(properties, is(notNullValue()));
- assertThat(properties.length(), is(3));
- assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
- assertThat(properties.getString("jcr:uuid"), is(notNullValue()));
-
- values = properties.getJSONArray("jcr:mixinTypes");
- assertThat(values, is(notNullValue()));
- assertThat(values.length(), is(1));
- assertThat(values.getString(0), is("mix:referenceable"));
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
- connection.disconnect();
-
- }
-
- @Test
- public void shouldNotPostNodeAtInvalidParentPath() throws Exception {
- URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/foo/bar");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("GET");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_NOT_FOUND));
- connection.disconnect();
-
- }
-
- @Test
- public void shouldNotPostNodeWithInvalidPrimaryType() throws Exception {
- URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/invalidPrimaryType");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("POST");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- String payload = "{ \"properties\":
{\"jcr:primaryType\": \"invalidType\", \"testProperty\":
\"testValue\", \"multiValuedProperty\": [\"value1\",
\"value2\"]}}";
- connection.getOutputStream().write(payload.getBytes());
-
- assertThat(connection.getResponseCode(),
is(HttpURLConnection.HTTP_BAD_REQUEST));
- connection.disconnect();
-
- postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/invalidPrimaryType");
- connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("GET");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_NOT_FOUND));
- connection.disconnect();
-
- }
-
- @Test
- public void shouldPostNodeHierarchy() throws Exception {
- URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nestedPost");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("POST");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- String payload = "{ \"properties\":
{\"jcr:primaryType\": \"nt:unstructured\", \"testProperty\":
\"testValue\", \"multiValuedProperty\": [\"value1\",
\"value2\"]},"
- + " \"children\": { \"childNode\" : {
\"properties\": {\"nestedProperty\":
\"nestedValue\"}}}}";
-
- connection.getOutputStream().write(payload.getBytes());
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_CREATED));
- connection.disconnect();
-
- postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nestedPost?dna:depth=1");
- connection = (HttpURLConnection)postUrl.openConnection();
-
- // Make sure that we can retrieve the node with a GET
- connection.setDoOutput(true);
- connection.setRequestMethod("GET");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
- JSONObject body = new JSONObject(getResponseFor(connection));
-
- assertThat(body.length(), is(2));
-
- JSONObject properties = body.getJSONObject("properties");
- assertThat(properties, is(notNullValue()));
- assertThat(properties.length(), is(3));
- assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
- assertThat(properties.getString("testProperty"),
is("testValue"));
- assertThat(properties.get("multiValuedProperty"),
instanceOf(JSONArray.class));
-
- JSONArray values = properties.getJSONArray("multiValuedProperty");
- assertThat(values, is(notNullValue()));
- assertThat(values.length(), is(2));
- assertThat(values.getString(0), is("value1"));
- assertThat(values.getString(1), is("value2"));
-
- JSONObject children = body.getJSONObject("children");
- assertThat(children, is(notNullValue()));
- assertThat(children.length(), is(1));
-
- JSONObject child = children.getJSONObject("childNode");
- assertThat(child, is(notNullValue()));
- assertThat(child.length(), is(1));
-
- properties = child.getJSONObject("properties");
- assertThat(properties, is(notNullValue()));
- assertThat(properties.length(), is(2));
- // Parent primary type is nt:unstructured, so this should default to
nt:unstructured primary type
- assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
- assertThat(properties.getString("nestedProperty"),
is("nestedValue"));
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
- connection.disconnect();
-
- }
-
- @Test
- public void shouldFailWholeTransactionIfOneNodeIsBad() throws Exception {
- URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/invalidNestedPost");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("POST");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- String payload = "{ \"properties\":
{\"jcr:primaryType\": \"nt:unstructured\", \"testProperty\":
\"testValue\", \"multiValuedProperty\": [\"value1\",
\"value2\"]},"
- + " \"children\": { \"childNode\" : {
\"properties\": {\"jcr:primaryType\":
\"invalidType\"}}}}";
- connection.getOutputStream().write(payload.getBytes());
-
- assertThat(connection.getResponseCode(),
is(HttpURLConnection.HTTP_BAD_REQUEST));
- connection.disconnect();
-
- postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/invalidNestedPost?dna:depth=1");
- connection = (HttpURLConnection)postUrl.openConnection();
-
- // Make sure that we can retrieve the node with a GET
- connection.setDoOutput(true);
- connection.setRequestMethod("GET");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_NOT_FOUND));
- connection.disconnect();
-
- }
-
- @Test
- public void shouldNotDeleteNonExistentItem() throws Exception {
- URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/invalidItemForDelete");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("DELETE");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_NOT_FOUND));
- connection.disconnect();
- }
-
- @Test
- public void shouldDeleteExtantNode() throws Exception {
-
- // Create the node
- URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nodeForDeletion");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("POST");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- String payload = "{ \"properties\":
{\"jcr:primaryType\": \"nt:unstructured\", \"testProperty\":
\"testValue\", \"multiValuedProperty\": [\"value1\",
\"value2\"]}}";
- connection.getOutputStream().write(payload.getBytes());
-
- JSONObject body = new JSONObject(getResponseFor(connection));
- assertThat(body.length(), is(1));
-
- JSONObject properties = body.getJSONObject("properties");
- assertThat(properties, is(notNullValue()));
- assertThat(properties.length(), is(3));
- assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
- assertThat(properties.getString("testProperty"),
is("testValue"));
- assertThat(properties.get("multiValuedProperty"),
instanceOf(JSONArray.class));
-
- JSONArray values = properties.getJSONArray("multiValuedProperty");
- assertThat(values, is(notNullValue()));
- assertThat(values.length(), is(2));
- assertThat(values.getString(0), is("value1"));
- assertThat(values.getString(1), is("value2"));
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_CREATED));
- connection.disconnect();
-
- // Confirm that it exists
- postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nodeForDeletion");
- connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("GET");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
- connection.disconnect();
-
- // Delete the node
- postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nodeForDeletion");
- connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("DELETE");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_NO_CONTENT));
- connection.disconnect();
-
- // Confirm that it no longer exists
- postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nodeForDeletion");
- connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("GET");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_NOT_FOUND));
- connection.disconnect();
- }
-
- @Test
- public void shouldDeleteExtantProperty() throws Exception {
- URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/propertyForDeletion");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("POST");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- String payload = "{ \"properties\":
{\"jcr:primaryType\": \"nt:unstructured\", \"testProperty\":
\"testValue\", \"multiValuedProperty\": [\"value1\",
\"value2\"]}}";
- connection.getOutputStream().write(payload.getBytes());
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_CREATED));
- connection.disconnect();
-
- // Confirm that it exists
- postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/propertyForDeletion");
- connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("GET");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- JSONObject body = new JSONObject(getResponseFor(connection));
- assertThat(body.length(), is(1));
-
- JSONObject properties = body.getJSONObject("properties");
- assertThat(properties, is(notNullValue()));
- assertThat(properties.length(), is(3));
- assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
- assertThat(properties.getString("testProperty"),
is("testValue"));
- assertThat(properties.get("multiValuedProperty"),
instanceOf(JSONArray.class));
-
- JSONArray values = properties.getJSONArray("multiValuedProperty");
- assertThat(values, is(notNullValue()));
- assertThat(values.length(), is(2));
- assertThat(values.getString(0), is("value1"));
- assertThat(values.getString(1), is("value2"));
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
- connection.disconnect();
-
- // Delete the property
- postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/propertyForDeletion/multiValuedProperty");
- connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("DELETE");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_NO_CONTENT));
- connection.disconnect();
-
- // Confirm that it no longer exists
- postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/propertyForDeletion");
- connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("GET");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- body = new JSONObject(getResponseFor(connection));
- assertThat(body.length(), is(1));
-
- properties = body.getJSONObject("properties");
- assertThat(properties, is(notNullValue()));
- assertThat(properties.length(), is(2));
- assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
- assertThat(properties.getString("testProperty"),
is("testValue"));
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
- connection.disconnect();
-
- }
-
- @Test
- public void shouldNotBeAbleToPutAtInvalidPath() throws Exception {
-
- URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nonexistantNode");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("PUT");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- String payload = "{ \"firstProperty\": \"someValue\"
}";
- connection.getOutputStream().write(payload.getBytes());
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_NOT_FOUND));
- connection.disconnect();
- }
-
- @Test
- public void shouldBeAbleToPutValueToProperty() throws Exception {
- URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nodeForPutProperty");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("POST");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- String payload = "{ \"properties\":
{\"jcr:primaryType\": \"nt:unstructured\", \"testProperty\":
\"testValue\" }}";
- connection.getOutputStream().write(payload.getBytes());
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_CREATED));
- connection.disconnect();
-
- postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nodeForPutProperty/testProperty");
- connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("PUT");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- payload = "{\"testProperty\":\"someOtherValue\"}";
- connection.getOutputStream().write(payload.getBytes());
-
- JSONObject body = new JSONObject(getResponseFor(connection));
- assertThat(body.length(), is(1));
-
- JSONObject properties = body.getJSONObject("properties");
- assertThat(properties, is(notNullValue()));
- assertThat(properties.length(), is(2));
- assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
- assertThat(properties.getString("testProperty"),
is("someOtherValue"));
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
- connection.disconnect();
-
- }
-
- @Test
- public void shouldBeAbleToPutBinaryValueToProperty() throws Exception {
- URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nodeForPutBinaryProperty");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("POST");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- // Base64-encode a value ...
- String encodedValue =
Base64.encodeBytes("propertyValue".getBytes("UTF-8"));
-
- String payload = "{ \"properties\":
{\"jcr:primaryType\": \"nt:unstructured\",
\"testProperty/base64/\": \""
- + encodedValue + "\" }}";
- connection.getOutputStream().write(payload.getBytes());
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_CREATED));
- connection.disconnect();
-
- URL putUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nodeForPutBinaryProperty/testProperty");
- connection = (HttpURLConnection)putUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("PUT");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- String otherValue = "someOtherValue";
- payload = "{\"testProperty/base64/\":\"" +
Base64.encodeBytes(otherValue.getBytes("UTF-8")) + "\"}";
- connection.getOutputStream().write(payload.getBytes());
-
- JSONObject body = new JSONObject(getResponseFor(connection));
- assertThat(body.length(), is(1));
-
- JSONObject properties = body.getJSONObject("properties");
- assertThat(properties, is(notNullValue()));
- assertThat(properties.length(), is(2));
- assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
- String responseEncodedValue =
properties.getString("testProperty/base64/");
- String decodedValue = new String(Base64.decode(responseEncodedValue),
"UTF-8");
- assertThat(decodedValue, is(otherValue));
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
- connection.disconnect();
-
- // Try putting a non-binary value ...
- connection = (HttpURLConnection)putUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("PUT");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- String anotherValue = "yetAnotherValue";
- payload = "{\"testProperty\":\"" + anotherValue +
"\"}";
- connection.getOutputStream().write(payload.getBytes());
-
- body = new JSONObject(getResponseFor(connection));
- assertThat(body.length(), is(1));
-
- properties = body.getJSONObject("properties");
- assertThat(properties, is(notNullValue()));
- assertThat(properties.length(), is(2));
- assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
- assertThat(properties.getString("testProperty"), is(anotherValue));
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
- connection.disconnect();
- }
-
- @Test
- public void shouldBeAbleToPutPropertiesToNode() throws Exception {
-
- URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nodeForPutProperties");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("POST");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- String payload = "{ \"properties\":
{\"jcr:primaryType\": \"nt:unstructured\" }}";
- connection.getOutputStream().write(payload.getBytes());
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_CREATED));
- connection.disconnect();
-
- postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nodeForPutProperties");
- connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("PUT");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- payload = "{\"testProperty\": \"testValue\",
\"multiValuedProperty\": [\"value1\", \"value2\"]}";
- connection.getOutputStream().write(payload.getBytes());
-
- JSONObject body = new JSONObject(getResponseFor(connection));
- assertThat(body.length(), is(1));
-
- JSONObject properties = body.getJSONObject("properties");
- assertThat(properties, is(notNullValue()));
- assertThat(properties.length(), is(3));
- assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
- assertThat(properties.getString("testProperty"),
is("testValue"));
- assertThat(properties.get("multiValuedProperty"),
instanceOf(JSONArray.class));
-
- JSONArray values = properties.getJSONArray("multiValuedProperty");
- assertThat(values, is(notNullValue()));
- assertThat(values.length(), is(2));
- assertThat(values.getString(0), is("value1"));
- assertThat(values.getString(1), is("value2"));
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
- connection.disconnect();
-
- }
-
- @Test
- public void shouldBeAbleToAddAndRemoveMixinTypes() throws Exception {
-
- URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nodeWithNoMixins");
- HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("POST");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- String payload = "{ \"properties\":
{\"jcr:primaryType\": \"nt:unstructured\" }}";
- connection.getOutputStream().write(payload.getBytes());
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_CREATED));
- connection.disconnect();
-
- connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("PUT");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- payload = "{\"jcr:mixinTypes\":
\"mix:referenceable\"}";
- connection.getOutputStream().write(payload.getBytes());
-
- JSONObject body = new JSONObject(getResponseFor(connection));
- assertThat(body.length(), is(1));
-
- JSONObject properties = body.getJSONObject("properties");
- assertThat(properties, is(notNullValue()));
-
- assertThat(properties.length(), is(3));
- assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
- JSONArray mixinTypes = properties.getJSONArray("jcr:mixinTypes");
- assertThat(mixinTypes, is(notNullValue()));
- assertThat(mixinTypes.length(), is(1));
- assertThat(mixinTypes.getString(0), is("mix:referenceable"));
- assertThat(properties.getString("jcr:uuid"), is(notNullValue()));
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
- connection.disconnect();
-
- connection = (HttpURLConnection)postUrl.openConnection();
-
- connection.setDoOutput(true);
- connection.setRequestMethod("PUT");
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
-
- payload = "{\"jcr:mixinTypes\": []}";
- connection.getOutputStream().write(payload.getBytes());
-
- body = new JSONObject(getResponseFor(connection));
- assertThat(body.length(), is(1));
-
- properties = body.getJSONObject("properties");
- assertThat(properties, is(notNullValue()));
- assertThat(properties.length(), is(2));
- assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
-
- // removeMixin doesn't currently null out this value
- mixinTypes = properties.getJSONArray("jcr:mixinTypes");
- assertThat(mixinTypes, is(notNullValue()));
- assertThat(mixinTypes.length(), is(0));
-
- assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
- connection.disconnect();
-
- }
-
-}
Deleted: trunk/extensions/dna-web-jcr-rest-war/src/test/resources/log4j.properties
===================================================================
--- trunk/extensions/dna-web-jcr-rest-war/src/test/resources/log4j.properties 2009-09-11
20:31:32 UTC (rev 1210)
+++ trunk/extensions/dna-web-jcr-rest-war/src/test/resources/log4j.properties 2009-09-11
20:48:26 UTC (rev 1211)
@@ -1,13 +0,0 @@
-log4j.rootLogger = DEBUG, stdout
-
-log4j.category.org.apache=DEBUG
-log4j.category.org.jboss.resteasy=DEBUG
-log4j.category.org.mortbay.jetty.security=ERROR
-log4j.category.org.slf4j.impl.JCLLoggerAdapter=DEBUG
-log4j.category.org.springframework=INFO
-
-log4j.appender.stdout = org.apache.log4j.ConsoleAppender
-log4j.appender.stdout.Threshold = DEBUG
-log4j.appender.stdout.Target = System.out
-log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
-log4j.appender.stdout.layout.ConversionPattern = [%-5p] [%C] : %m%n [%F:%L]
Copied: trunk/web/dna-web-jcr-rest/.classpath (from rev 1210,
trunk/extensions/dna-web-jcr-rest/.classpath)
===================================================================
--- trunk/web/dna-web-jcr-rest/.classpath (rev 0)
+++ trunk/web/dna-web-jcr-rest/.classpath 2009-09-11 20:48:26 UTC (rev 1211)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes"
path="src/main/java"/>
+ <classpathentry kind="con"
path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con"
path="org.eclipse.jst.j2ee.internal.module.container"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Property changes on: trunk/web/dna-web-jcr-rest/.classpath
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: trunk/web/dna-web-jcr-rest/.project (from rev 1210,
trunk/extensions/dna-web-jcr-rest/.project)
===================================================================
--- trunk/web/dna-web-jcr-rest/.project (rev 0)
+++ trunk/web/dna-web-jcr-rest/.project 2009-09-11 20:48:26 UTC (rev 1211)
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>dna-web-jcr-rest</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.wst.common.project.facet.core.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.wst.validation.validationbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
+ <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
+ </natures>
+</projectDescription>
Property changes on: trunk/web/dna-web-jcr-rest/.project
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: trunk/web/dna-web-jcr-rest/.settings/org.eclipse.wst.common.component (from rev
1210, trunk/extensions/dna-web-jcr-rest/.settings/org.eclipse.wst.common.component)
===================================================================
--- trunk/web/dna-web-jcr-rest/.settings/org.eclipse.wst.common.component
(rev 0)
+++ trunk/web/dna-web-jcr-rest/.settings/org.eclipse.wst.common.component 2009-09-11
20:48:26 UTC (rev 1211)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project-modules id="moduleCoreId" project-version="1.5.0">
+ <wb-module deploy-name="dna-web-jcr-rest">
+ <wb-resource deploy-path="/"
source-path="/src/main/java"/>
+ <wb-resource deploy-path="/"
source-path="/src/main/resources"/>
+ <wb-resource deploy-path="/"
source-path="/src/test/java"/>
+ <wb-resource deploy-path="/"
source-path="/src/test/resources"/>
+ </wb-module>
+</project-modules>
Copied: trunk/web/dna-web-jcr-rest/.settings/org.eclipse.wst.common.project.facet.core.xml
(from rev 1210,
trunk/extensions/dna-web-jcr-rest/.settings/org.eclipse.wst.common.project.facet.core.xml)
===================================================================
--- trunk/web/dna-web-jcr-rest/.settings/org.eclipse.wst.common.project.facet.core.xml
(rev 0)
+++
trunk/web/dna-web-jcr-rest/.settings/org.eclipse.wst.common.project.facet.core.xml 2009-09-11
20:48:26 UTC (rev 1211)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<faceted-project>
+ <installed facet="jst.java" version="5.0"/>
+ <installed facet="jst.utility" version="1.0"/>
+</faceted-project>
Property changes on:
trunk/web/dna-web-jcr-rest/.settings/org.eclipse.wst.common.project.facet.core.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: trunk/web/dna-web-jcr-rest/.settings/org.maven.ide.eclipse.prefs (from rev 1210,
trunk/extensions/dna-web-jcr-rest/.settings/org.maven.ide.eclipse.prefs)
===================================================================
--- trunk/web/dna-web-jcr-rest/.settings/org.maven.ide.eclipse.prefs
(rev 0)
+++ trunk/web/dna-web-jcr-rest/.settings/org.maven.ide.eclipse.prefs 2009-09-11 20:48:26
UTC (rev 1211)
@@ -0,0 +1,9 @@
+#Wed May 27 16:24:52 EDT 2009
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+includeModules=false
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+skipCompilerPlugin=true
+version=1
Copied: trunk/web/dna-web-jcr-rest/pom.xml (from rev 1210,
trunk/extensions/dna-web-jcr-rest/pom.xml)
===================================================================
--- trunk/web/dna-web-jcr-rest/pom.xml (rev 0)
+++ trunk/web/dna-web-jcr-rest/pom.xml 2009-09-11 20:48:26 UTC (rev 1211)
@@ -0,0 +1,85 @@
+<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>
+ <artifactId>dna</artifactId>
+ <groupId>org.jboss.dna</groupId>
+ <version>0.6-SNAPSHOT</version>
+ <relativePath>../..</relativePath>
+ </parent>
+ <artifactId>dna-web-jcr-rest</artifactId>
+ <packaging>jar</packaging>
+ <name>JBoss DNA JCR REST Library</name>
+ <description>JBoss DNA REST support library</description>
+ <
url>http://labs.jboss.org/dna</url>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.resteasy</groupId>
+ <artifactId>resteasy-jaxrs</artifactId>
+ <version>1.1.GA</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.resteasy</groupId>
+ <artifactId>resteasy-jaxb-provider</artifactId>
+ <version>1.1.GA</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.sun.xml.bind</groupId>
+ <artifactId>jaxb-impl</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <!--
+ This is only included as a temp. workaround. Current release of
+ RESTEasy depends on 2.1.8, which is not in our repo at this time This
+ should be removed after RESTEasy 1.1GA is released and added to this
+ pom.
+ -->
+ <dependency>
+ <groupId>com.sun.xml.bind</groupId>
+ <artifactId>jaxb-impl</artifactId>
+ <version>2.1.9</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-jcr</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.5.8</version>
+ <scope>runtime</scope>
+ </dependency>
+ <!--
+ Java Content Repository API
+ -->
+ <dependency>
+ <groupId>javax.jcr</groupId>
+ <artifactId>jcr</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- TESTING DEPENDENCIES -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit-dep</artifactId>
+ <version>4.4</version>
+ <scope>integration-test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.xml.bind</groupId>
+ <artifactId>jaxb-api</artifactId>
+ <version>2.1</version>
+ </dependency>
+
+ </dependencies>
+</project>
Property changes on: trunk/web/dna-web-jcr-rest/pom.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/DnaJcrDeployer.java
(from rev 1210,
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/DnaJcrDeployer.java)
===================================================================
---
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/DnaJcrDeployer.java
(rev 0)
+++
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/DnaJcrDeployer.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -0,0 +1,64 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.web.jcr.rest;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.web.jcr.rest.spi.RepositoryProvider;
+
+/**
+ * Servlet context listener that is responsible for {@link
RepositoryFactory#initialize(javax.servlet.ServletContext)
+ * initializing} the {@link RepositoryFactory repository factory}.
+ * <p>
+ * This class is not thread safe, but in practice this does not matter as the servlet
container must ensure that only a single
+ * instance of this exists per web context and that it is only called in a
single-threaded manner.
+ * </p>
+ *
+ * @see RepositoryFactory
+ */
+@NotThreadSafe
+public class DnaJcrDeployer implements ServletContextListener {
+
+ /**
+ * Alerts the repository factory that the web application is shutting down
+ *
+ * @param event the servlet context event
+ * @see RepositoryFactory#shutdown()
+ * @see RepositoryProvider#shutdown()
+ */
+ public void contextDestroyed( ServletContextEvent event ) {
+ RepositoryFactory.shutdown();
+ }
+
+ /**
+ * Initializes the repository factory
+ *
+ * @param event the servlet context event
+ * @see RepositoryFactory#initialize(javax.servlet.ServletContext)
+ */
+ public void contextInitialized( ServletContextEvent event ) {
+ RepositoryFactory.initialize(event.getServletContext());
+ }
+}
Property changes on:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/DnaJcrDeployer.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/JcrApplication.java
(from rev 1210,
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/JcrApplication.java)
===================================================================
---
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/JcrApplication.java
(rev 0)
+++
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/JcrApplication.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -0,0 +1,53 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.web.jcr.rest;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import javax.ws.rs.core.Application;
+
+/**
+ * Implementation of the JAX-RS {@code Application} class to identify all JAX-RS
providers and classes in the application.
+ *
+ * @see Application
+ */
+public class JcrApplication extends Application {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Application#getClasses()
+ */
+ @Override
+ public Set<Class<?>> getClasses() {
+ return new HashSet<Class<?>>(Arrays.asList(new Class<?>[] {
+ JcrResources.class,
+ JcrResources.JSONExceptionMapper.class,
+ JcrResources.NotFoundExceptionMapper.class,
+ JcrResources.RepositoryExceptionMapper.class,
+ }));
+ }
+
+}
Property changes on:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/JcrApplication.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/JcrResources.java
(from rev 1210,
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/JcrResources.java)
===================================================================
--- trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/JcrResources.java
(rev 0)
+++
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/JcrResources.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -0,0 +1,831 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.web.jcr.rest;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import javax.jcr.Item;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.PropertyDefinition;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+import net.jcip.annotations.Immutable;
+import org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
+import org.jboss.dna.common.text.UrlEncoder;
+import org.jboss.dna.common.util.Base64;
+import org.jboss.dna.web.jcr.rest.model.RepositoryEntry;
+import org.jboss.dna.web.jcr.rest.model.WorkspaceEntry;
+import org.jboss.resteasy.spi.NotFoundException;
+import org.jboss.resteasy.spi.UnauthorizedException;
+
+/**
+ * RESTEasy handler to provide the JCR resources at the URIs below. Please note that
these URIs assume a context of {@code
+ * /resources} for the web application.
+ * <table border="1">
+ * <tr>
+ * <th>URI Pattern</th>
+ * <th>Description</th>
+ * <th>Supported Methods</th>
+ * </tr>
+ * <tr>
+ * <td>/resources</td>
+ * <td>returns a list of accessible repositories</td>
+ * <td>GET</td>
+ * </tr>
+ * <tr>
+ * <td>/resources/{repositoryName}</td>
+ * <td>returns a list of accessible workspaces within that repository</td>
+ * <td>GET</td>
+ * </tr>
+ * <tr>
+ * <td>/resources/{repositoryName}/{workspaceName}</td>
+ * <td>returns a list of operations within the workspace</td>
+ * <td>GET</td>
+ * </tr>
+ * <tr>
+ * <td>/resources/{repositoryName}/{workspaceName}/item/{path}</td>
+ * <td>accesses the item (node or property) at the path</td>
+ * <td>ALL</td>
+ * </tr>
+ * </table>
+ * <h3>Binary data</h3>
+ * <p>
+ * There are several ways to transfer binary property values, but all involve encoding
the binary value into ASCII characters
+ * using a {@link Base64} notation and denoting this by adding annotating the property
name with a suffix defining the type of
+ * encoding. Currently, only "base64" encoding is supported.
+ * </p>
+ * <p>
+ * For example, if the "jcr:data" property contains a single binary value of
"propertyValue", then the JSON object representing
+ * that property will be:
+ *
+ * <pre>
+ * "jcr:data/base64/" : "cHJvcGVydHlWYWx1ZQ=="
+ * </pre>
+ *
+ * Likewise, if the "jcr:data" property contains two binary values each being
"propertyValue", then the JSON object representing
+ * that property will be:
+ *
+ * <pre>
+ * "jcr:data/base64/" : [ "cHJvcGVydHlWYWx1ZQ==",
"cHJvcGVydHlWYWx1ZQ==" ]
+ * </pre>
+ *
+ * Note that JCR 1.0.1 does not allow property names to and with a '/' character
(among others), while JCR 2.0 does not allow
+ * property names to contain an unescaped or unencoded '/' character. Therefore,
the "/{encoding}/" suffix can never appear in a
+ * valid JCR property name, and will always identify an encoded property.
+ * </p>
+ * <p>
+ * Here are the details:
+ * <ul>
+ * <li>Getting a node with <code>GET
/resources/{repositoryName}/item/{pathToNode}</code> obtains the JSON object
representing the
+ * node, and each property is represented as a nested JSON object where the name is the
property name and the value(s) are
+ * represented as either a single string value or an array of string values. If the
property has a binary value, then the property
+ * name is appended with "/base64/" and the string representation of each value
is encoded in Base64.</li>
+ * <li>Getting a property with <code>GET
/resources/{repositoryName}/item/{pathToProperty}</code> allows only the value(s)
for the
+ * one property to be included in the response. If any of the values is a binary value,
then <i>all</i> of the values will be
+ * encoded in Base64.</li>
+ * <li>Setting a property with <code>PUT
/resources/{repositoryName}/item/{pathToProperty}</code> allows setting the property
to a
+ * single value, and only that value needs to be included in the body of the request. If
the value is binary, the value
+ * <i>must</i> be {@link Base64 encoded} by the client and the
"Content-Transfer-Encoding" header must be set to "base64" (case
+ * does not matter). When the request is received, the value is decoded before the
property value is updated on the node.</li>
+ * <li>Creating a node with <code>POST
/resources/{repositoryName}/item/{pathToNode}</code> requires a request that is
structured
+ * in the same way as the response from getting a node: the resulting JSON object
represents the node, with nested JSON objects
+ * for the properties and children. If any property of the new node has a binary value,
then the name of the property <i>must</i>
+ * be appended with "/base64/" and the string representation of each value are
to be encoded in Base64.</li>
+ * <li>Updating a node with <code>PUT
/resources/{repositoryName}/item/{pathToNode}</code> requires a request that is
structured
+ * in the same way as the response from getting or posting a node: the resulting JSON
object represents the node, with nested JSON
+ * objects for the properties and children. If any property of the new node has a binary
value, then the name of the property
+ * <i>must</i> be appended with "/base64/" and the string
representation of each value are to be encoded in Base64.</li>
+ * </ul>
+ * </p>
+ */
+@Immutable
+@Path( "/" )
+public class JcrResources {
+
+ private static final String BASE64_ENCODING_SUFFIX = "/base64/";
+
+ private static final UrlEncoder URL_ENCODER = new UrlEncoder();
+
+ private static final String PROPERTIES_HOLDER = "properties";
+ private static final String CHILD_NODE_HOLDER = "children";
+
+ private static final String PRIMARY_TYPE_PROPERTY = "jcr:primaryType";
+ private static final String MIXIN_TYPES_PROPERTY = "jcr:mixinTypes";
+
+ /** Name to be used when the repository name is empty string as {@code
"//"} is not a valid path. */
+ public static final String EMPTY_REPOSITORY_NAME = "<default>";
+ /** Name to be used when the workspace name is empty string as {@code "//"}
is not a valid path. */
+ public static final String EMPTY_WORKSPACE_NAME = "<default>";
+
+ /**
+ * Returns an active session for the given workspace name in the named repository.
+ *
+ * @param request the servlet request; may not be null or unauthenticated
+ * @param rawRepositoryName the URL-encoded name of the repository in which the
session is created
+ * @param rawWorkspaceName the URL-encoded name of the workspace to which the session
should be connected
+ * @return an active session with the given workspace in the named repository
+ * @throws RepositoryException if any other error occurs
+ */
+ private Session getSession( HttpServletRequest request,
+ String rawRepositoryName,
+ String rawWorkspaceName ) throws RepositoryException {
+ assert request != null;
+ assert request.getUserPrincipal() != null : "Request must be
authorized";
+
+ // Sanity check
+ if (request.getUserPrincipal() == null) {
+ throw new UnauthorizedException("Client is not authorized");
+ }
+
+ return RepositoryFactory.getSession(request,
repositoryNameFor(rawRepositoryName), workspaceNameFor(rawWorkspaceName));
+ }
+
+ /**
+ * Returns the list of JCR repositories available on this server
+ *
+ * @param request the servlet request; may not be null
+ * @return the list of JCR repositories available on this server
+ */
+ @GET
+ @Path( "/" )
+ @Produces( "application/json" )
+ public Map<String, RepositoryEntry> getRepositories( @Context
HttpServletRequest request ) {
+ assert request != null;
+
+ Map<String, RepositoryEntry> repositories = new HashMap<String,
RepositoryEntry>();
+
+ for (String name : RepositoryFactory.getJcrRepositoryNames()) {
+ if (name.trim().length() == 0) {
+ name = EMPTY_REPOSITORY_NAME;
+ }
+ name = URL_ENCODER.encode(name);
+ repositories.put(name, new RepositoryEntry(request.getContextPath(), name));
+ }
+
+ return repositories;
+ }
+
+ /**
+ * Returns the list of workspaces available to this user within the named
repository.
+ *
+ * @param rawRepositoryName the name of the repository; may not be null
+ * @param request the servlet request; may not be null
+ * @return the list of workspaces available to this user within the named
repository.
+ * @throws IOException if the given repository name does not map to any repositories
and there is an error writing the error
+ * code to the response.
+ * @throws RepositoryException if there is any other error accessing the list of
available workspaces for the repository
+ */
+ @GET
+ @Path( "/{repositoryName}" )
+ @Produces( "application/json" )
+ public Map<String, WorkspaceEntry> getWorkspaces( @Context HttpServletRequest
request,
+ @PathParam(
"repositoryName" ) String rawRepositoryName )
+ throws RepositoryException, IOException {
+
+ assert request != null;
+ assert rawRepositoryName != null;
+
+ Map<String, WorkspaceEntry> workspaces = new HashMap<String,
WorkspaceEntry>();
+
+ Session session = getSession(request, rawRepositoryName, null);
+ rawRepositoryName = URL_ENCODER.encode(rawRepositoryName);
+
+ for (String name : session.getWorkspace().getAccessibleWorkspaceNames()) {
+ if (name.trim().length() == 0) {
+ name = EMPTY_WORKSPACE_NAME;
+ }
+ name = URL_ENCODER.encode(name);
+ workspaces.put(name, new WorkspaceEntry(request.getContextPath(),
rawRepositoryName, name));
+ }
+
+ return workspaces;
+ }
+
+ /**
+ * Handles GET requests for an item in a workspace.
+ *
+ * @param request the servlet request; may not be null or unauthenticated
+ * @param rawRepositoryName the URL-encoded repository name
+ * @param rawWorkspaceName the URL-encoded workspace name
+ * @param path the path to the item
+ * @param depth the depth of the node graph that should be returned if {@code path}
refers to a node. @{code 0} means return
+ * the requested node only. A negative value indicates that the full subgraph
under the node should be returned. This
+ * parameter defaults to {@code 0} and is ignored if {@code path} refers to a
property.
+ * @return the JSON-encoded version of the item (and, if the item is a node, its
subgraph, depending on the value of {@code
+ * depth})
+ * @throws NotFoundException if the named repository does not exists, the named
workspace does not exist, or the user does not
+ * have access to the named workspace
+ * @throws JSONException if there is an error encoding the node
+ * @throws UnauthorizedException if the given login information is invalid
+ * @throws RepositoryException if any other error occurs
+ * @see #EMPTY_REPOSITORY_NAME
+ * @see #EMPTY_WORKSPACE_NAME
+ * @see Session#getItem(String)
+ */
+ @GET
+ @Path( "/{repositoryName}/{workspaceName}/items{path:.*}" )
+ @Produces( "application/json" )
+ public String getItem( @Context HttpServletRequest request,
+ @PathParam( "repositoryName" ) String
rawRepositoryName,
+ @PathParam( "workspaceName" ) String
rawWorkspaceName,
+ @PathParam( "path" ) String path,
+ @QueryParam( "dna:depth" ) @DefaultValue(
"0" ) int depth )
+ throws JSONException, UnauthorizedException, RepositoryException {
+ assert path != null;
+ assert rawRepositoryName != null;
+ assert rawWorkspaceName != null;
+
+ Session session = getSession(request, rawRepositoryName, rawWorkspaceName);
+ Item item;
+
+ if ("/".equals(path) || "".equals(path)) {
+ item = session.getRootNode();
+ } else {
+ try {
+ item = session.getItem(path);
+ } catch (PathNotFoundException pnfe) {
+ throw new NotFoundException(pnfe.getMessage(), pnfe);
+ }
+ }
+
+ if (item instanceof Node) {
+ return jsonFor((Node)item, depth).toString();
+ }
+ return jsonFor((Property)item).toString();
+ }
+
+ /**
+ * Returns the JSON-encoded version of the given property. If the property is
single-valued, the returned string is the value
+ * of the property encoded as a JSON string, including the name. If the property is
multi-valued with {@code N} values, this
+ * method returns a JSON array containing the JSON string for each value.
+ * <p>
+ * Note that if any of the values are binary, then <i>all</i> values will
be first encoded as {@link Base64} string values.
+ * However, if no values are binary, then all values will simply be the {@link
Value#getString() string} representation of the
+ * value.
+ * </p>
+ *
+ * @param property the property to be encoded
+ * @return the JSON-encoded version of the property
+ * @throws JSONException if there is an error encoding the node
+ * @throws RepositoryException if an error occurs accessing the property, its values,
or its definition.
+ * @see Property#getDefinition()
+ * @see PropertyDefinition#isMultiple()
+ */
+ private JSONObject jsonFor( Property property ) throws JSONException,
RepositoryException {
+ boolean encoded = false;
+ Object valueObject = null;
+ if (property.getDefinition().isMultiple()) {
+ Value[] values = property.getValues();
+ for (Value value : values) {
+ if (value.getType() == PropertyType.BINARY) {
+ encoded = true;
+ break;
+ }
+ }
+ List<String> list = new ArrayList<String>(values.length);
+ if (encoded) {
+ for (Value value : values) {
+ list.add(jsonEncodedStringFor(value));
+ }
+ } else {
+ for (Value value : values) {
+ list.add(value.getString());
+ }
+ }
+ valueObject = new JSONArray(list);
+ } else {
+ Value value = property.getValue();
+ encoded = value.getType() == PropertyType.BINARY;
+ valueObject = encoded ? jsonEncodedStringFor(value) : value.getString();
+ }
+ String propertyName = property.getName();
+ if (encoded) propertyName = propertyName + BASE64_ENCODING_SUFFIX;
+ JSONObject jsonProperty = new JSONObject();
+ jsonProperty.put(propertyName, valueObject);
+ return jsonProperty;
+ }
+
+ /**
+ * Return the JSON-compatible string representation of the given property value. If
the value is a {@link PropertyType#BINARY
+ * binary} value, then this method returns the Base-64 encoding of that value.
Otherwise, it just returns the string
+ * representation of the value.
+ *
+ * @param value the property value; may not be null
+ * @return the string representation of the value
+ * @throws RepositoryException if there is a problem accessing the value
+ */
+ private String jsonEncodedStringFor( Value value ) throws RepositoryException {
+ // Encode the binary value in Base64 ...
+ InputStream stream = value.getStream();
+ try {
+ return Base64.encode(stream);
+ } finally {
+ if (stream != null) {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ // Error accessing the value, so throw this ...
+ throw new RepositoryException(e);
+ }
+ }
+ }
+ }
+
+ /**
+ * Recursively returns the JSON-encoding of a node and its children to depth {@code
toDepth}.
+ *
+ * @param node the node to be encoded
+ * @param toDepth the depth to which the recursion should extend; {@code 0} means no
further recursion should occur.
+ * @return the JSON-encoding of a node and its children to depth {@code toDepth}.
+ * @throws JSONException if there is an error encoding the node
+ * @throws RepositoryException if any other error occurs
+ */
+ private JSONObject jsonFor( Node node,
+ int toDepth ) throws JSONException, RepositoryException
{
+ JSONObject jsonNode = new JSONObject();
+
+ JSONObject properties = new JSONObject();
+
+ for (PropertyIterator iter = node.getProperties(); iter.hasNext();) {
+ Property prop = iter.nextProperty();
+ String propName = prop.getName();
+
+ boolean encoded = false;
+
+ if (prop.getDefinition().isMultiple()) {
+ Value[] values = prop.getValues();
+ // Do any of the property values need to be encoded ?
+ for (Value value : values) {
+ if (value.getType() == PropertyType.BINARY) {
+ encoded = true;
+ break;
+ }
+ }
+ if (encoded) propName = propName + BASE64_ENCODING_SUFFIX;
+ JSONArray array = new JSONArray();
+ for (int i = 0; i < values.length; i++) {
+ array.put(encoded ? jsonEncodedStringFor(values[i]) :
values[i].getString());
+ }
+ properties.put(propName, array);
+
+ } else {
+ Value value = prop.getValue();
+ encoded = value.getType() == PropertyType.BINARY;
+ if (encoded) propName = propName + BASE64_ENCODING_SUFFIX;
+ properties.put(propName, encoded ? jsonEncodedStringFor(value) :
value.getString());
+ }
+
+ }
+ if (properties.length() > 0) {
+ jsonNode.put(PROPERTIES_HOLDER, properties);
+ }
+
+ if (toDepth == 0) {
+ List<String> children = new ArrayList<String>();
+
+ for (NodeIterator iter = node.getNodes(); iter.hasNext();) {
+ Node child = iter.nextNode();
+
+ children.add(child.getName());
+ }
+
+ if (children.size() > 0) {
+ jsonNode.put(CHILD_NODE_HOLDER, new JSONArray(children));
+ }
+ } else {
+ JSONObject children = new JSONObject();
+
+ for (NodeIterator iter = node.getNodes(); iter.hasNext();) {
+ Node child = iter.nextNode();
+
+ children.put(child.getName(), jsonFor(child, toDepth - 1));
+ }
+
+ if (children.length() > 0) {
+ jsonNode.put(CHILD_NODE_HOLDER, children);
+ }
+ }
+
+ return jsonNode;
+ }
+
+ /**
+ * Adds the content of the request as a node (or subtree of nodes) at the location
specified by {@code path}.
+ * <p>
+ * The primary type and mixin type(s) may optionally be specified through the {@code
jcr:primaryType} and {@code
+ * jcr:mixinTypes} properties.
+ * </p>
+ *
+ * @param request the servlet request; may not be null or unauthenticated
+ * @param rawRepositoryName the URL-encoded repository name
+ * @param rawWorkspaceName the URL-encoded workspace name
+ * @param path the path to the item
+ * @param requestContent the JSON-encoded representation of the node or nodes to be
added
+ * @return the JSON-encoded representation of the node or nodes that were added. This
will differ from {@code requestContent}
+ * in that auto-created and protected properties (e.g., jcr:uuid) will be
populated.
+ * @throws NotFoundException if the parent of the item to be added does not exist
+ * @throws UnauthorizedException if the user does not have the access required to
create the node at this path
+ * @throws JSONException if there is an error encoding the node
+ * @throws RepositoryException if any other error occurs
+ */
+ @POST
+ @Path( "/{repositoryName}/{workspaceName}/items/{path:.*}" )
+ @Consumes( "application/json" )
+ public Response postItem( @Context HttpServletRequest request,
+ @PathParam( "repositoryName" ) String
rawRepositoryName,
+ @PathParam( "workspaceName" ) String
rawWorkspaceName,
+ @PathParam( "path" ) String path,
+ String requestContent )
+ throws NotFoundException, UnauthorizedException, RepositoryException,
JSONException {
+
+ assert rawRepositoryName != null;
+ assert rawWorkspaceName != null;
+ assert path != null;
+ JSONObject body = new JSONObject(requestContent);
+
+ int lastSlashInd = path.lastIndexOf('/');
+ String parentPath = lastSlashInd == -1 ? "/" : "/" +
path.substring(0, lastSlashInd);
+ String newNodeName = lastSlashInd == -1 ? path : path.substring(lastSlashInd +
1);
+
+ Session session = getSession(request, rawRepositoryName, rawWorkspaceName);
+
+ Node parentNode = (Node)session.getItem(parentPath);
+
+ Node newNode = addNode(parentNode, newNodeName, body);
+
+ session.save();
+
+ String json = jsonFor(newNode, -1).toString();
+ return Response.status(Status.CREATED).entity(json).build();
+ }
+
+ /**
+ * Adds the node described by {@code jsonNode} with name {@code nodeName} to the
existing node {@code parentNode}.
+ *
+ * @param parentNode the parent of the node to be added
+ * @param nodeName the name of the node to be added
+ * @param jsonNode the JSON-encoded representation of the node or nodes to be added.
+ * @return the JSON-encoded representation of the node or nodes that were added. This
will differ from {@code requestContent}
+ * in that auto-created and protected properties (e.g., jcr:uuid) will be
populated.
+ * @throws JSONException if there is an error encoding the node
+ * @throws RepositoryException if any other error occurs
+ */
+ private Node addNode( Node parentNode,
+ String nodeName,
+ JSONObject jsonNode ) throws RepositoryException, JSONException
{
+ Node newNode;
+
+ JSONObject properties = jsonNode.has(PROPERTIES_HOLDER) ?
jsonNode.getJSONObject(PROPERTIES_HOLDER) : new JSONObject();
+
+ if (properties.has(PRIMARY_TYPE_PROPERTY)) {
+ String primaryType = properties.getString(PRIMARY_TYPE_PROPERTY);
+ newNode = parentNode.addNode(nodeName, primaryType);
+ } else {
+ newNode = parentNode.addNode(nodeName);
+ }
+
+ if (properties.has(MIXIN_TYPES_PROPERTY)) {
+ Object rawMixinTypes = properties.get(MIXIN_TYPES_PROPERTY);
+
+ if (rawMixinTypes instanceof JSONArray) {
+ JSONArray mixinTypes = (JSONArray)rawMixinTypes;
+ for (int i = 0; i < mixinTypes.length(); i++) {
+ newNode.addMixin(mixinTypes.getString(i));
+ }
+
+ } else {
+ newNode.addMixin(rawMixinTypes.toString());
+
+ }
+ }
+
+ for (Iterator<?> iter = properties.keys(); iter.hasNext();) {
+ String key = (String)iter.next();
+
+ if (PRIMARY_TYPE_PROPERTY.equals(key)) continue;
+ if (MIXIN_TYPES_PROPERTY.equals(key)) continue;
+ setPropertyOnNode(newNode, key, properties.get(key));
+ }
+
+ if (jsonNode.has(CHILD_NODE_HOLDER)) {
+ JSONObject children = jsonNode.getJSONObject(CHILD_NODE_HOLDER);
+
+ for (Iterator<?> iter = children.keys(); iter.hasNext();) {
+ String childName = (String)iter.next();
+ JSONObject child = children.getJSONObject(childName);
+
+ addNode(newNode, childName, child);
+ }
+ }
+
+ return newNode;
+ }
+
+ private Value decodeValue( String encodedValue,
+ ValueFactory valueFactory ) throws RepositoryException {
+ byte[] binaryValue = Base64.decode(encodedValue);
+ InputStream stream = new ByteArrayInputStream(binaryValue);
+ try {
+ return valueFactory.createValue(stream);
+ } finally {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ // Error accessing the value, so throw this ...
+ throw new RepositoryException(e);
+ }
+ }
+ }
+
+ /**
+ * Sets the named property on the given node. This method expects {@code value} to be
either a JSON string or a JSON array of
+ * JSON strings. If {@code value} is a JSON array, {@code Node#setProperty(String,
String[]) the multi-valued property setter}
+ * will be used.
+ *
+ * @param node the node on which the property is to be set
+ * @param propName the name of the property to set
+ * @param value the JSON-encoded values to be set
+ * @throws RepositoryException if there is an error setting the property
+ * @throws JSONException if {@code value} cannot be decoded
+ */
+ private void setPropertyOnNode( Node node,
+ String propName,
+ Object value ) throws RepositoryException,
JSONException {
+ // Are the property values encoded ?
+ boolean encoded = propName.endsWith(BASE64_ENCODING_SUFFIX);
+ if (encoded) {
+ int newLength = propName.length() - BASE64_ENCODING_SUFFIX.length();
+ propName = newLength > 0 ? propName.substring(0, newLength) :
"";
+ }
+
+ Value[] values;
+ ValueFactory valueFactory = node.getSession().getValueFactory();
+ if (value instanceof JSONArray) {
+ JSONArray jsonValues = (JSONArray)value;
+ values = new Value[jsonValues.length()];
+
+ for (int i = 0; i < values.length; i++) {
+ String strValue = jsonValues.getString(i);
+ if (encoded) {
+ values[i] = decodeValue(strValue, valueFactory);
+ } else {
+ values[i] = valueFactory.createValue(strValue);
+ }
+ }
+ } else {
+ String strValue = (String)value;
+ if (encoded) {
+ values = new Value[] {decodeValue(strValue, valueFactory)};
+ } else {
+ values = new Value[] {valueFactory.createValue(strValue)};
+ }
+ }
+
+ if (propName.equals(JcrResources.MIXIN_TYPES_PROPERTY)) {
+ Set<String> toBeMixins = new HashSet<String>();
+ for (Value theValue : values) {
+ toBeMixins.add(theValue.getString());
+ }
+ Set<String> asIsMixins = new HashSet<String>();
+
+ for (NodeType nodeType : node.getMixinNodeTypes()) {
+ asIsMixins.add(nodeType.getName());
+ }
+
+ Set<String> mixinsToAdd = new HashSet<String>(toBeMixins);
+ mixinsToAdd.removeAll(asIsMixins);
+ asIsMixins.removeAll(toBeMixins);
+
+ for (String nodeType : mixinsToAdd) {
+ node.addMixin(nodeType);
+ }
+
+ for (String nodeType : asIsMixins) {
+ node.removeMixin(nodeType);
+ }
+ } else {
+ if (values.length == 1) {
+ node.setProperty(propName, values[0]);
+
+ } else {
+ node.setProperty(propName, values);
+ }
+ }
+ }
+
+ /**
+ * Deletes the item at {@code path}.
+ *
+ * @param request the servlet request; may not be null or unauthenticated
+ * @param rawRepositoryName the URL-encoded repository name
+ * @param rawWorkspaceName the URL-encoded workspace name
+ * @param path the path to the item
+ * @throws NotFoundException if no item exists at {@code path}
+ * @throws UnauthorizedException if the user does not have the access required to
delete the item at this path
+ * @throws RepositoryException if any other error occurs
+ */
+ @DELETE
+ @Path( "/{repositoryName}/{workspaceName}/items{path:.*}" )
+ @Consumes( "application/json" )
+ public void deleteItem( @Context HttpServletRequest request,
+ @PathParam( "repositoryName" ) String
rawRepositoryName,
+ @PathParam( "workspaceName" ) String
rawWorkspaceName,
+ @PathParam( "path" ) String path )
+ throws NotFoundException, UnauthorizedException, RepositoryException {
+
+ assert rawRepositoryName != null;
+ assert rawWorkspaceName != null;
+ assert path != null;
+
+ Session session = getSession(request, rawRepositoryName, rawWorkspaceName);
+
+ Item item;
+ try {
+ item = session.getItem(path);
+ } catch (PathNotFoundException pnfe) {
+ throw new NotFoundException(pnfe.getMessage(), pnfe);
+ }
+ item.remove();
+ session.save();
+ }
+
+ /**
+ * Updates the properties at the path.
+ * <p>
+ * If path points to a property, this method expects the request content to be either
a JSON array or a JSON string. The array
+ * or string will become the values or value of the property. If path points to a
node, this method expects the request
+ * content to be a JSON object. The keys of the objects correspond to property names
that will be set and the values for the
+ * keys correspond to the values that will be set on the properties.
+ * </p>
+ *
+ * @param request the servlet request; may not be null or unauthenticated
+ * @param rawRepositoryName the URL-encoded repository name
+ * @param rawWorkspaceName the URL-encoded workspace name
+ * @param path the path to the item
+ * @param requestContent the JSON-encoded representation of the values and, possibly,
properties to be set
+ * @return the JSON-encoded representation of the node on which the property or
properties were set.
+ * @throws NotFoundException if the parent of the item to be added does not exist
+ * @throws UnauthorizedException if the user does not have the access required to
create the node at this path
+ * @throws JSONException if there is an error encoding the node
+ * @throws RepositoryException if any other error occurs
+ * @throws IOException if there is a problem reading the value
+ */
+ @PUT
+ @Path( "/{repositoryName}/{workspaceName}/items{path:.*}" )
+ @Consumes( "application/json" )
+ public String putItem( @Context HttpServletRequest request,
+ @PathParam( "repositoryName" ) String
rawRepositoryName,
+ @PathParam( "workspaceName" ) String
rawWorkspaceName,
+ @PathParam( "path" ) String path,
+ String requestContent ) throws UnauthorizedException,
JSONException, RepositoryException, IOException {
+
+ assert path != null;
+ assert rawRepositoryName != null;
+ assert rawWorkspaceName != null;
+
+ Session session = getSession(request, rawRepositoryName, rawWorkspaceName);
+ Node node;
+ Item item;
+ if ("".equals(path) || "/".equals(path)) {
+ item = session.getRootNode();
+ } else {
+ try {
+ item = session.getItem(path);
+ } catch (PathNotFoundException pnfe) {
+ throw new NotFoundException(pnfe.getMessage(), pnfe);
+ }
+ }
+
+ if (item instanceof Node) {
+ JSONObject properties = new JSONObject(requestContent);
+ node = (Node)item;
+
+ for (Iterator<?> iter = properties.keys(); iter.hasNext();) {
+ String key = (String)iter.next();
+
+ setPropertyOnNode(node, key, properties.get(key));
+ }
+
+ } else {
+ /*
+ * The incoming content should be a JSON object containing the property name
and a value that is either a JSON
+ * string or a JSON array.
+ */
+ Property property = (Property)item;
+ String propertyName = property.getName();
+ JSONObject jsonProperty = new JSONObject(requestContent);
+ String jsonPropertyName = jsonProperty.has(propertyName) ? propertyName :
propertyName + BASE64_ENCODING_SUFFIX;
+ node = property.getParent();
+ setPropertyOnNode(node, jsonPropertyName,
jsonProperty.get(jsonPropertyName));
+ }
+ node.save();
+ return jsonFor(node, 0).toString();
+ }
+
+ private String workspaceNameFor( String rawWorkspaceName ) {
+ String workspaceName = URL_ENCODER.decode(rawWorkspaceName);
+
+ if (EMPTY_WORKSPACE_NAME.equals(workspaceName)) {
+ workspaceName = "";
+ }
+
+ return workspaceName;
+ }
+
+ private String repositoryNameFor( String rawRepositoryName ) {
+ String repositoryName = URL_ENCODER.decode(rawRepositoryName);
+
+ if (EMPTY_REPOSITORY_NAME.equals(repositoryName)) {
+ repositoryName = "";
+ }
+
+ return repositoryName;
+ }
+
+ @Provider
+ public static class NotFoundExceptionMapper implements
ExceptionMapper<NotFoundException> {
+
+ public Response toResponse( NotFoundException exception ) {
+ return
Response.status(Status.NOT_FOUND).entity(exception.getMessage()).build();
+ }
+
+ }
+
+ @Provider
+ public static class JSONExceptionMapper implements
ExceptionMapper<JSONException> {
+
+ public Response toResponse( JSONException exception ) {
+ return
Response.status(Status.BAD_REQUEST).entity(exception.getMessage()).build();
+ }
+
+ }
+
+ @Provider
+ public static class RepositoryExceptionMapper implements
ExceptionMapper<RepositoryException> {
+
+ public Response toResponse( RepositoryException exception ) {
+ /*
+ * This error code is murky - the request must have been syntactically valid
to get to
+ * the JCR operations, but there isn't an HTTP status code for
"semantically invalid."
+ */
+ return
Response.status(Status.BAD_REQUEST).entity(exception.getMessage()).build();
+ }
+
+ }
+
+}
Property changes on:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/JcrResources.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/RepositoryFactory.java
(from rev 1210,
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/RepositoryFactory.java)
===================================================================
---
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/RepositoryFactory.java
(rev 0)
+++
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/RepositoryFactory.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -0,0 +1,100 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.web.jcr.rest;
+
+import java.util.Collection;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.web.jcr.rest.spi.RepositoryProvider;
+
+/**
+ * Factory that provides implementations of the {@link RepositoryProvider repository
provider SPI} by wrapping a
+ * {@link RepositoryProvider}.
+ * <p>
+ * The repository factory implements a lifecycle for the repository providers. It is
first {@link #initialize(ServletContext)
+ * initialized} by {@link DnaJcrDeployer}, a servlet context listener that must be
configured in the DNA JCR REST web
+ * configuration (web.xml). The repository factory looks in the context for a parameter
with the name of {@link #PROVIDER_KEY}.
+ * This is assumed to be the FQN of the {@link RepositoryProvider repository provider},
which the factory will then instantiate.
+ * </p>
+ * <p>
+ * The repository factory is then able to respond to multiple requests to {@link
#getJcrRepositoryNames() list the repository
+ * names} and {@link #getSession(HttpServletRequest, String, String) return active JCR
sessions} until the {@link #shutdown()
+ * shutdown method} is called.
+ * </p>
+ * <p>
+ * The {@link #shutdown() shutdown method} is a simple proxy to the {@link
RepositoryProvider#shutdown()} repository provider's
+ * shutdown method}.
+ * </p>
+ */
+@ThreadSafe
+public class RepositoryFactory {
+
+ /** The FQN of the repository provider class. Currently set to {@value} . */
+ public static final String PROVIDER_KEY =
"org.jboss.dna.web.jcr.rest.REPOSITORY_PROVIDER";
+
+ private static RepositoryProvider provider;
+
+ private RepositoryFactory() {
+
+ }
+
+ /**
+ * Initializes the repository factory. For more details, please see the {@link
RepositoryFactory class-level documentation}.
+ *
+ * @param context the servlet context; may not be null
+ * @see RepositoryFactory
+ */
+ static void initialize( ServletContext context ) {
+ CheckArg.isNotNull(context, "context");
+ String className = context.getInitParameter(PROVIDER_KEY);
+
+ try {
+ Class<? extends RepositoryProvider> providerClass =
Class.forName(className).asSubclass(RepositoryProvider.class);
+ provider = providerClass.newInstance();
+
+ } catch (Exception ex) {
+ throw new IllegalStateException(ex);
+ }
+
+ provider.startup(context);
+ }
+
+ public static Session getSession( HttpServletRequest request,
+ String repositoryName,
+ String workspaceName ) throws RepositoryException
{
+ return provider.getSession(request, repositoryName, workspaceName);
+ }
+
+ public static Collection<String> getJcrRepositoryNames() {
+ return provider.getJcrRepositoryNames();
+ }
+
+ static void shutdown() {
+ provider.shutdown();
+ }
+}
Property changes on:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/RepositoryFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/ServletSecurityContext.java
(from rev 1210,
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/ServletSecurityContext.java)
===================================================================
---
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/ServletSecurityContext.java
(rev 0)
+++
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/ServletSecurityContext.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -0,0 +1,82 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.web.jcr.rest;
+
+import javax.servlet.http.HttpServletRequest;
+import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.graph.SecurityContext;
+
+/**
+ * Servlet-based {@link SecurityContext security context} that assumes servlet-based
authentication and provides authorization
+ * through the {@link HttpServletRequest#isUserInRole(String) servlet role-checking
mechanism}.
+ * <p>
+ * This security context is really only valid for the life of the {@link
HttpServletRequest servlet request} and should
+ * only be used to support longer-lasting session scopes with great care. *
+ * </p>
+ */
+@ThreadSafe
+public class ServletSecurityContext implements SecurityContext {
+
+ private final String userName;
+ private final HttpServletRequest request;
+
+ /**
+ * Create a {@link ServletSecurityContext} with the supplied {@link
HttpServletRequest servlet information}.
+ *
+ * @param request the servlet request; may not be null
+ */
+ public ServletSecurityContext( HttpServletRequest request ) {
+ CheckArg.isNotNull(request, "request");
+ this.request = request;
+ this.userName = request.getUserPrincipal() != null ?
request.getUserPrincipal().getName() : null;
+ }
+
+ /**
+ * {@inheritDoc SecurityContext#getUserName()}
+ *
+ * @see SecurityContext#getUserName()
+ */
+ public final String getUserName() {
+ return userName;
+ }
+
+ /**
+ * {@inheritDoc SecurityContext#hasRole(String)}
+ *
+ * @see SecurityContext#hasRole(String)
+ */
+ public final boolean hasRole( String roleName ) {
+ return request.isUserInRole(roleName);
+ }
+
+ /**
+ * {@inheritDoc SecurityContext#logout()}
+ *
+ * @see SecurityContext#logout()
+ */
+ public void logout() {
+ }
+
+}
Property changes on:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/ServletSecurityContext.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/RepositoryEntry.java
(from rev 1210,
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/RepositoryEntry.java)
===================================================================
---
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/RepositoryEntry.java
(rev 0)
+++
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/RepositoryEntry.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -0,0 +1,63 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.web.jcr.rest.model;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement( name = "repository" )
+public class RepositoryEntry {
+
+ private String name;
+ private RepositoryResources resources;
+
+ public RepositoryEntry() {
+ resources = new RepositoryResources();
+ }
+
+ public RepositoryEntry( String contextName,
+ String repositoryName ) {
+ this.name = repositoryName;
+
+ resources = new RepositoryResources(contextName, repositoryName);
+ }
+
+ @XmlElement
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @XmlElement
+ public RepositoryResources getResources() {
+ return resources;
+ }
+
+ public void setResources(RepositoryResources resources) {
+ this.resources = resources;
+ }
+}
Property changes on:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/RepositoryEntry.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/RepositoryResources.java
(from rev 1210,
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/RepositoryResources.java)
===================================================================
---
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/RepositoryResources.java
(rev 0)
+++
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/RepositoryResources.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -0,0 +1,48 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.web.jcr.rest.model;
+
+import javax.xml.bind.annotation.XmlElement;
+
+public class RepositoryResources {
+ private String baseUri;
+
+ public RepositoryResources() {
+ }
+
+ public RepositoryResources( String contextName,
+ String repositoryName ) {
+ this.baseUri = contextName + "/" + repositoryName;
+ }
+
+ @XmlElement( name = "workspaces" )
+ public String getWorkspaces() {
+ return baseUri;
+ }
+
+ public void setWorkspaces(String workspaces) {
+ this.baseUri = workspaces;
+ }
+}
+
Property changes on:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/RepositoryResources.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/WorkspaceEntry.java
(from rev 1210,
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/WorkspaceEntry.java)
===================================================================
---
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/WorkspaceEntry.java
(rev 0)
+++
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/WorkspaceEntry.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -0,0 +1,65 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.web.jcr.rest.model;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement( name = "workspace" )
+public class WorkspaceEntry {
+
+ private String name;
+ private WorkspaceResources resources;
+
+ public WorkspaceEntry() {
+
+ }
+
+ public WorkspaceEntry( String contextName,
+ String repositoryName,
+ String workspaceName ) {
+ this.name = workspaceName;
+
+ resources = new WorkspaceResources(contextName, repositoryName, workspaceName);
+ }
+
+ @XmlElement
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @XmlElement
+ public WorkspaceResources getResources() {
+ return resources;
+ }
+
+ public void setResources(WorkspaceResources resources) {
+ this.resources = resources;
+ }
+}
+
Property changes on:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/WorkspaceEntry.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/WorkspaceResources.java
(from rev 1210,
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/WorkspaceResources.java)
===================================================================
---
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/WorkspaceResources.java
(rev 0)
+++
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/WorkspaceResources.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -0,0 +1,49 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.web.jcr.rest.model;
+
+import javax.xml.bind.annotation.XmlElement;
+
+public class WorkspaceResources {
+ private String baseUri;
+
+ public WorkspaceResources() {
+ }
+
+ public WorkspaceResources( String contextName,
+ String repositoryName,
+ String workspaceName ) {
+ this.baseUri = contextName + "/" + repositoryName + "/" +
workspaceName;
+ }
+
+ @XmlElement( name = "items" )
+ public String getWorkspaces() {
+ return baseUri + "/items";
+ }
+
+ public void setWorkspaces(String workspaces) {
+ this.baseUri = workspaces;
+ }
+}
+
Property changes on:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/WorkspaceResources.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/package-info.java
(from rev 1210,
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/package-info.java)
===================================================================
---
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/package-info.java
(rev 0)
+++
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/package-info.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -0,0 +1,28 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+/**
+ * Models for the DNA interface to faciliate serving basic information as XML or JSON in
the future.
+ */
+package org.jboss.dna.web.jcr.rest.model;
+
Property changes on:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/model/package-info.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/package-info.java
(from rev 1210,
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/package-info.java)
===================================================================
--- trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/package-info.java
(rev 0)
+++
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/package-info.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -0,0 +1,36 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+/**
+ * This package contains the core components for the DNA REST server implementation.
+ * <p>
+ * The key classes are:
+ * <ul>
+ * <li>{@link JcrResources} - the class that handles requests for valid
URIs</li>
+ * <li>{@link JcrApplication} - the JAX-RS application class that indicates that
JcrResources should be used to handle URIs</li>
+ * <li>{@link RepositoryFactory} - the interface to the DNA JCR SPI</li>
+ * </ul>
+ * </p>
+ */
+package org.jboss.dna.web.jcr.rest;
+
Property changes on:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/package-info.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/DnaJcrRepositoryProvider.java
(from rev 1210,
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/DnaJcrRepositoryProvider.java)
===================================================================
---
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/DnaJcrRepositoryProvider.java
(rev 0)
+++
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/DnaJcrRepositoryProvider.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -0,0 +1,124 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.web.jcr.rest.spi;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.Set;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.jcr.JcrConfiguration;
+import org.jboss.dna.jcr.JcrEngine;
+import org.jboss.dna.jcr.SecurityContextCredentials;
+import org.jboss.dna.web.jcr.rest.ServletSecurityContext;
+import org.jboss.resteasy.spi.NotFoundException;
+import org.jboss.resteasy.spi.UnauthorizedException;
+import org.xml.sax.SAXException;
+
+/**
+ * Repository provider backed by the DNA JCR implementation.
+ * <p>
+ * The provider instantiates a {@link JcrEngine} that is {@link
JcrConfiguration#loadFrom(InputStream) configured from} the file
+ * in the location specified by the servlet context parameter {@code
org.jboss.dna.web.jcr.rest.CONFIG_FILE}. This location must
+ * be accessible by the classloader for this class.
+ * </p>
+ *
+ * @see RepositoryProvider
+ * @see Class#getResourceAsStream(String)
+ */
+@ThreadSafe
+public class DnaJcrRepositoryProvider implements RepositoryProvider {
+
+ public static final String CONFIG_FILE =
"org.jboss.dna.web.jcr.rest.CONFIG_FILE";
+
+ private JcrEngine jcrEngine;
+
+ public DnaJcrRepositoryProvider() {
+ }
+
+ public Set<String> getJcrRepositoryNames() {
+ return new HashSet<String>(jcrEngine.getRepositoryNames());
+ }
+
+ private Repository getRepository( String repositoryName ) throws RepositoryException
{
+ return jcrEngine.getRepository(repositoryName);
+ }
+
+ public void startup( ServletContext context ) {
+ String configFile = context.getInitParameter(CONFIG_FILE);
+
+ try {
+ InputStream configFileInputStream =
getClass().getResourceAsStream(configFile);
+ jcrEngine = new JcrConfiguration().loadFrom(configFileInputStream).build();
+ jcrEngine.start();
+ } catch (IOException ioe) {
+ throw new IllegalStateException(ioe);
+ } catch (SAXException saxe) {
+ throw new IllegalStateException(saxe);
+ }
+
+ }
+
+ public void shutdown() {
+ jcrEngine.shutdown();
+ }
+
+ /**
+ * Returns an active session for the given workspace name in the named repository.
+ *
+ * @param request the servlet request; may not be null or unauthenticated
+ * @param repositoryName the name of the repository in which the session is created
+ * @param workspaceName the name of the workspace to which the session should be
connected
+ * @return an active session with the given workspace in the named repository
+ * @throws RepositoryException if any other error occurs
+ */
+ public Session getSession( HttpServletRequest request,
+ String repositoryName,
+ String workspaceName ) throws RepositoryException {
+ assert request != null;
+ assert request.getUserPrincipal() != null : "Request must be
authorized";
+
+ // Sanity check in case assertions are disabled
+ if (request.getUserPrincipal() == null) {
+ throw new UnauthorizedException("Client is not authorized");
+ }
+
+ Repository repository;
+
+ try {
+ repository = getRepository(repositoryName);
+
+ } catch (RepositoryException re) {
+ throw new NotFoundException(re.getMessage(), re);
+ }
+
+ return repository.login(new SecurityContextCredentials(new
ServletSecurityContext(request)), workspaceName);
+
+ }
+}
Property changes on:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/DnaJcrRepositoryProvider.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/RepositoryProvider.java
(from rev 1210,
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/RepositoryProvider.java)
===================================================================
---
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/RepositoryProvider.java
(rev 0)
+++
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/RepositoryProvider.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -0,0 +1,81 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.web.jcr.rest.spi;
+
+import java.util.Set;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * Interface for any class that provides access to one or more local JCR repositories.
+ * <p>
+ * Repository providers must provide a public, no-argument constructor and be
thread-safe.
+ * </p>
+ */
+public interface RepositoryProvider {
+
+ /**
+ * Returns an active session for the given workspace name in the named repository.
+ * <p>
+ * JCR implementations that do not support multiple repositories on the same server
can ignore the repositoryName parameter.
+ * </p>
+ *
+ * @param request the servlet request; may not be null or unauthenticated
+ * @param repositoryName the name of the repository in which the session is created
+ * @param workspaceName the name of the workspace to which the session should be
connected
+ * @return an active session with the given workspace in the named repository
+ * @throws RepositoryException if any other error occurs
+ */
+ public Session getSession( HttpServletRequest request,
+ String repositoryName,
+ String workspaceName ) throws RepositoryException;
+
+ /**
+ * Returns the available repository names
+ * <p>
+ * JCR implementations that do not support multiple repositories on the same server
should provide a singleton set containing
+ * some default repository name.
+ * </p>
+ *
+ * @return the available repository names; may not be null or empty
+ */
+ Set<String> getJcrRepositoryNames();
+
+ /**
+ * Signals the repository provider that it should initialize itself based on the
provided {@link ServletContext servlet
+ * context} and begin accepting connections.
+ *
+ * @param context the servlet context for the REST servlet
+ */
+ void startup( ServletContext context );
+
+ /**
+ * Signals the repository provider that it should complete any pending transactions,
shutdown, and release any external
+ * resource held.
+ */
+ void shutdown();
+
+}
Property changes on:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/RepositoryProvider.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/package-info.java
(from rev 1210,
trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/package-info.java)
===================================================================
---
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/package-info.java
(rev 0)
+++
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/package-info.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -0,0 +1,42 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+/**
+ * Service provider interface (SPI) for the JCR implementation that backs the DNA JCR
REST server.
+ * <p>
+ * Service providers must provide a thread-safe implementation of the {@link
RepositoryProvider} interface
+ * which is then bundled in the server WAR. The REST server can be configured to use the
provider by specifying
+ * the fully-qualified name (FQN) of the custom repository provider class in the {@code
org.jboss.dna.web.jcr.rest.REPOSITORY_PROVIDER} context parameter
+ * in the web configuration file (web.xml).
+ * </p>
+ * <p>
+ * Custom repository providers for JCR implementations that do not support hosting
multiple repositories in the same server
+ * can context can ignore the {@code repositoryName} parameter for {@link
RepositoryProvider#getSession(javax.servlet.http.HttpServletRequest, String, String)},
+ * but must always return a non-empty, non-null set containing some default repository
name from {@link RepositoryProvider#getJcrRepositoryNames()}.
+ * </p>
+ *
+ * @see org.jboss.dna.web.jcr.rest.RepositoryFactory
+ * @see org.jboss.dna.web.jcr.rest.spi.RepositoryProvider
+ */
+package org.jboss.dna.web.jcr.rest.spi;
+
Property changes on:
trunk/web/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/spi/package-info.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: trunk/web/dna-web-jcr-rest-war/.classpath (from rev 1210,
trunk/extensions/dna-web-jcr-rest-war/.classpath)
===================================================================
--- trunk/web/dna-web-jcr-rest-war/.classpath (rev 0)
+++ trunk/web/dna-web-jcr-rest-war/.classpath 2009-09-11 20:48:26 UTC (rev 1211)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/test-classes"
path="src/test/java"/>
+ <classpathentry excluding="**" kind="src"
output="target/test-classes" path="src/test/resources"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con"
path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER">
+ <attributes>
+ <attribute name="org.eclipse.jst.component.dependency"
value="/WEB-INF/lib"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con"
path="org.eclipse.jst.j2ee.internal.web.container"/>
+ <classpathentry kind="con"
path="org.eclipse.jst.j2ee.internal.module.container"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Property changes on: trunk/web/dna-web-jcr-rest-war/.classpath
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: trunk/web/dna-web-jcr-rest-war/.project (from rev 1210,
trunk/extensions/dna-web-jcr-rest-war/.project)
===================================================================
--- trunk/web/dna-web-jcr-rest-war/.project (rev 0)
+++ trunk/web/dna-web-jcr-rest-war/.project 2009-09-11 20:48:26 UTC (rev 1211)
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>dna-web-jcr-rest-war</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.wst.common.project.facet.core.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.wst.validation.validationbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
+ <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
+ <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
+ </natures>
+</projectDescription>
Property changes on: trunk/web/dna-web-jcr-rest-war/.project
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: trunk/web/dna-web-jcr-rest-war/.settings/.jsdtscope (from rev 1210,
trunk/extensions/dna-web-jcr-rest-war/.settings/.jsdtscope)
===================================================================
--- trunk/web/dna-web-jcr-rest-war/.settings/.jsdtscope (rev 0)
+++ trunk/web/dna-web-jcr-rest-war/.settings/.jsdtscope 2009-09-11 20:48:26 UTC (rev
1211)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con"
path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con"
path="org.eclipse.wst.jsdt.launching.WebProject">
+ <attributes>
+ <attribute name="hide" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con"
path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
+ <classpathentry kind="output" path=""/>
+</classpath>
Copied: trunk/web/dna-web-jcr-rest-war/.settings/org.eclipse.wst.common.component (from
rev 1210,
trunk/extensions/dna-web-jcr-rest-war/.settings/org.eclipse.wst.common.component)
===================================================================
--- trunk/web/dna-web-jcr-rest-war/.settings/org.eclipse.wst.common.component
(rev 0)
+++ trunk/web/dna-web-jcr-rest-war/.settings/org.eclipse.wst.common.component 2009-09-11
20:48:26 UTC (rev 1211)
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project-modules id="moduleCoreId" project-version="1.5.0">
+ <wb-module deploy-name="dna-web-jcr-rest-war">
+ <wb-resource deploy-path="/"
source-path="/src/main/webapp"/>
+ <wb-resource deploy-path="/WEB-INF/classes"
source-path="/src/test/java"/>
+ <wb-resource deploy-path="/WEB-INF/classes"
source-path="/src/test/resources"/>
+ <dependent-module deploy-path="/WEB-INF/lib"
handle="module:/resource/dna-web-jcr-rest/dna-web-jcr-rest">
+ <dependency-type>uses</dependency-type>
+ </dependent-module>
+ <dependent-module deploy-path="/WEB-INF/lib"
handle="module:/resource/dna-jcr/dna-jcr">
+ <dependency-type>uses</dependency-type>
+ </dependent-module>
+ <dependent-module deploy-path="/WEB-INF/lib"
handle="module:/resource/dna-common/dna-common">
+ <dependency-type>uses</dependency-type>
+ </dependent-module>
+ <dependent-module deploy-path="/WEB-INF/lib"
handle="module:/resource/dna-graph/dna-graph">
+ <dependency-type>uses</dependency-type>
+ </dependent-module>
+ <dependent-module deploy-path="/WEB-INF/lib"
handle="module:/resource/dna-repository/dna-repository">
+ <dependency-type>uses</dependency-type>
+ </dependent-module>
+ <dependent-module deploy-path="/WEB-INF/lib"
handle="module:/resource/dna-connector-federation/dna-connector-federation">
+ <dependency-type>uses</dependency-type>
+ </dependent-module>
+ <dependent-module deploy-path="/WEB-INF/lib"
handle="module:/resource/dna-cnd/dna-cnd">
+ <dependency-type>uses</dependency-type>
+ </dependent-module>
+ <property name="context-root"
value="dna-web-jcr-rest-war"/>
+ <property name="java-output-path"/>
+ </wb-module>
+</project-modules>
Copied:
trunk/web/dna-web-jcr-rest-war/.settings/org.eclipse.wst.common.project.facet.core.xml
(from rev 1210,
trunk/extensions/dna-web-jcr-rest-war/.settings/org.eclipse.wst.common.project.facet.core.xml)
===================================================================
---
trunk/web/dna-web-jcr-rest-war/.settings/org.eclipse.wst.common.project.facet.core.xml
(rev 0)
+++
trunk/web/dna-web-jcr-rest-war/.settings/org.eclipse.wst.common.project.facet.core.xml 2009-09-11
20:48:26 UTC (rev 1211)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<faceted-project>
+ <installed facet="jst.java" version="5.0"/>
+ <installed facet="jst.web" version="2.3"/>
+</faceted-project>
Property changes on:
trunk/web/dna-web-jcr-rest-war/.settings/org.eclipse.wst.common.project.facet.core.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied:
trunk/web/dna-web-jcr-rest-war/.settings/org.eclipse.wst.jsdt.ui.superType.container (from
rev 1210,
trunk/extensions/dna-web-jcr-rest-war/.settings/org.eclipse.wst.jsdt.ui.superType.container)
===================================================================
--- trunk/web/dna-web-jcr-rest-war/.settings/org.eclipse.wst.jsdt.ui.superType.container
(rev 0)
+++
trunk/web/dna-web-jcr-rest-war/.settings/org.eclipse.wst.jsdt.ui.superType.container 2009-09-11
20:48:26 UTC (rev 1211)
@@ -0,0 +1 @@
+org.eclipse.wst.jsdt.launching.baseBrowserLibrary
\ No newline at end of file
Copied: trunk/web/dna-web-jcr-rest-war/.settings/org.eclipse.wst.jsdt.ui.superType.name
(from rev 1210,
trunk/extensions/dna-web-jcr-rest-war/.settings/org.eclipse.wst.jsdt.ui.superType.name)
===================================================================
--- trunk/web/dna-web-jcr-rest-war/.settings/org.eclipse.wst.jsdt.ui.superType.name
(rev 0)
+++
trunk/web/dna-web-jcr-rest-war/.settings/org.eclipse.wst.jsdt.ui.superType.name 2009-09-11
20:48:26 UTC (rev 1211)
@@ -0,0 +1 @@
+Window
\ No newline at end of file
Copied: trunk/web/dna-web-jcr-rest-war/.settings/org.maven.ide.eclipse.prefs (from rev
1210, trunk/extensions/dna-web-jcr-rest-war/.settings/org.maven.ide.eclipse.prefs)
===================================================================
--- trunk/web/dna-web-jcr-rest-war/.settings/org.maven.ide.eclipse.prefs
(rev 0)
+++ trunk/web/dna-web-jcr-rest-war/.settings/org.maven.ide.eclipse.prefs 2009-09-11
20:48:26 UTC (rev 1211)
@@ -0,0 +1,9 @@
+#Wed May 27 16:41:08 EDT 2009
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+includeModules=true
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+skipCompilerPlugin=true
+version=1
Copied: trunk/web/dna-web-jcr-rest-war/pom.xml (from rev 1210,
trunk/extensions/dna-web-jcr-rest-war/pom.xml)
===================================================================
--- trunk/web/dna-web-jcr-rest-war/pom.xml (rev 0)
+++ trunk/web/dna-web-jcr-rest-war/pom.xml 2009-09-11 20:48:26 UTC (rev 1211)
@@ -0,0 +1,96 @@
+<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>
+ <artifactId>dna</artifactId>
+ <groupId>org.jboss.dna</groupId>
+ <version>0.6-SNAPSHOT</version>
+ <relativePath>../..</relativePath>
+ </parent>
+ <artifactId>dna-web-jcr-rest-war</artifactId>
+ <packaging>war</packaging>
+ <name>JBoss DNA JCR REST Servlet</name>
+ <description>JBoss DNA servlet that provides RESTful access to JCR
items</description>
+ <
url>http://labs.jboss.org/dna</url>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-web-jcr-rest</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.5.8</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <!-- TESTING DEPENDENCIES -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit-dep</artifactId>
+ <version>4.4</version>
+ <scope>integration-test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <finalName>resources</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.cargo</groupId>
+ <artifactId>cargo-maven2-plugin</artifactId>
+ <!-- >version>1.0.1-SNAPSHOT</version -->
+ <executions>
+ <execution>
+ <id>start-container</id>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>start</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>stop-container</id>
+ <phase>post-integration-test</phase>
+ <goals>
+ <goal>stop</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <configuration>
+ <properties>
+ <cargo.logging>low</cargo.logging>
+ <cargo.servlet.users>dnauser:password:connect,readwrite|unauthorized:password:bogus</cargo.servlet.users>
+ </properties>
+ </configuration>
+ <wait>false</wait>
+ </configuration>
+ </plugin>
+ <!--
+ Override the default Surefire behavior to run during
+ integration-test phase
+ -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ <executions>
+ <execution>
+ <id>surefire-it</id>
+ <phase>integration-test</phase>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+
+ </build>
+
+</project>
Property changes on: trunk/web/dna-web-jcr-rest-war/pom.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: trunk/web/dna-web-jcr-rest-war/src/main/resources/configRepository.xml (from rev
1210, trunk/extensions/dna-web-jcr-rest-war/src/main/resources/configRepository.xml)
===================================================================
--- trunk/web/dna-web-jcr-rest-war/src/main/resources/configRepository.xml
(rev 0)
+++ trunk/web/dna-web-jcr-rest-war/src/main/resources/configRepository.xml 2009-09-11
20:48:26 UTC (rev 1211)
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ JBoss DNA (
http://www.jboss.org/dna)
+ ~
+ ~ See the COPYRIGHT.txt file distributed with this work for information
+ ~ regarding copyright ownership. Some portions may be licensed
+ ~ to Red Hat, Inc. under one or more contributor license agreements.
+ ~ See the AUTHORS.txt file in the distribution for a full listing of
+ ~ individual contributors.
+ ~
+ ~ JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ ~ is licensed to you under the terms of the GNU Lesser General Public License as
+ ~ published by the Free Software Foundation; either version 2.1 of
+ ~ the License, or (at your option) any later version.
+ ~
+ ~ JBoss DNA is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ -->
+<configuration
xmlns="http://www.jboss.org/dna/1.0"
xmlns:jcr="http://www.jcp.org/jcr/1.0">
+ <!-- Define the sources from which content is made available -->
+ <sources jcr:primaryType="nt:unstructured">
+ <source jcr:name="repositorySource"
classname="org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource"
retryLimit="3" defaultWorkspaceName="default"/>
+ </sources>
+ <!-- Define the JCR repositories -->
+ <repositories>
+ <!-- Specify the source that should be used for the repository -->
+ <repository jcr:name="repository"
sourceName="repositorySource">
+ <source>repositorySource</source>
+ <!-- Define the options for the JCR repository, using camelcase version of
JcrRepository.Option names
+-->
+ <options jcr:primaryType="dna:options">
+ <projectNodeTypes jcr:primaryType="dna:option"
value="false"/>
+ <jaasLoginConfigName jcr:primaryType="dna:option"
value="dna-jcr"/>
+ </options>
+ <!-- Define any custom node types. Importing CND files via
JcrConfiguration is equivalent to specifying here.
+-->
+ <nodeTypes jcr:primaryType="dna:nodeTypes"/>
+ <!-- Define any namespaces for this repository, other than those already
defined by JCR or DNA
+-->
+ <namespaces jcr:primaryType="dna:namespaces" />
+ </repository>
+ </repositories>
+</configuration>
\ No newline at end of file
Property changes on:
trunk/web/dna-web-jcr-rest-war/src/main/resources/configRepository.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: trunk/web/dna-web-jcr-rest-war/src/main/resources/log4j.properties (from rev 1210,
trunk/extensions/dna-web-jcr-rest-war/src/main/resources/log4j.properties)
===================================================================
--- trunk/web/dna-web-jcr-rest-war/src/main/resources/log4j.properties
(rev 0)
+++ trunk/web/dna-web-jcr-rest-war/src/main/resources/log4j.properties 2009-09-11 20:48:26
UTC (rev 1211)
@@ -0,0 +1,13 @@
+log4j.rootLogger = INFO, stdout
+
+log4j.category.org.apache=DEBUG
+log4j.category.org.jboss.resteasy=DEBUG
+log4j.category.org.mortbay.jetty.security=ERROR
+log4j.category.org.slf4j.impl.JCLLoggerAdapter=DEBUG
+log4j.category.org.springframework=INFO
+
+log4j.appender.stdout = org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Threshold = INFO
+log4j.appender.stdout.Target = System.out
+log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern = [%-5p] [%C] : %m%n [%F:%L]
Copied: trunk/web/dna-web-jcr-rest-war/src/main/webapp/META-INF/MANIFEST.MF (from rev
1210, trunk/extensions/dna-web-jcr-rest-war/src/main/webapp/META-INF/MANIFEST.MF)
===================================================================
--- trunk/web/dna-web-jcr-rest-war/src/main/webapp/META-INF/MANIFEST.MF
(rev 0)
+++ trunk/web/dna-web-jcr-rest-war/src/main/webapp/META-INF/MANIFEST.MF 2009-09-11
20:48:26 UTC (rev 1211)
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path:
+
Copied: trunk/web/dna-web-jcr-rest-war/src/main/webapp/WEB-INF/web.xml (from rev 1210,
trunk/extensions/dna-web-jcr-rest-war/src/main/webapp/WEB-INF/web.xml)
===================================================================
--- trunk/web/dna-web-jcr-rest-war/src/main/webapp/WEB-INF/web.xml
(rev 0)
+++ trunk/web/dna-web-jcr-rest-war/src/main/webapp/WEB-INF/web.xml 2009-09-11 20:48:26 UTC
(rev 1211)
@@ -0,0 +1,116 @@
+<?xml version="1.0"?>
+<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application
2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd">
+ <!--
+ JBoss DNA (
http://www.jboss.org/dna) See the COPYRIGHT.txt file
+ distributed with this work for information regarding copyright
+ ownership. Some portions may be licensed to Red Hat, Inc. under one or
+ more contributor license agreements. See the AUTHORS.txt file in the
+ distribution for a full listing of individual contributors. JBoss DNA
+ is free software. Unless otherwise indicated, all code in JBoss DNA is
+ licensed to you under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either version
+ 2.1 of the License, or (at your option) any later version. JBoss DNA
+ is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details. You should have received a copy of the GNU
+ Lesser General Public License along with this software; if not, write
+ to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ Boston, MA 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ -->
+<web-app>
+ <display-name>JBoss DNA JCR RESTful Interface</display-name>
+
+ <!--
+ This parameter provides the fully-qualified name of a class that implements
+ the o.j.d.web.jcr.rest.spi.RepositoryProvider interface. It is required
+ by the DnaJcrDeployer that controls the lifecycle for the DNA REST server.
+ -->
+ <context-param>
+ <param-name>org.jboss.dna.web.jcr.rest.REPOSITORY_PROVIDER</param-name>
+ <param-value>org.jboss.dna.web.jcr.rest.spi.DnaJcrRepositoryProvider</param-value>
+ </context-param>
+
+ <!--
+ This parameter, specific to the DnaJcrRepositoryProvider implementation, specifies
+ the name of the configuration file to initialize the repository or repositories.
+ This configuration file must be on the classpath and is given as a classpath-relative
+ directory.
+ -->
+ <context-param>
+ <param-name>org.jboss.dna.web.jcr.rest.CONFIG_FILE</param-name>
+ <param-value>/configRepository.xml</param-value>
+ </context-param>
+
+ <!--
+ This parameter defines the JAX-RS application class, which is really just a metadata
class
+ that lets the JAX-RS engine (RESTEasy in this case) know which classes implement
pieces
+ of the JAX-RS specification like exception handling and resource serving.
+
+ This should not be modified.
+ -->
+ <context-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.jboss.dna.web.jcr.rest.JcrApplication</param-value>
+ </context-param>
+
+ <!-- Required parameter for RESTEasy - should not be modified -->
+ <listener>
+ <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
+ </listener>
+
+ <!-- Required parameter for JBoss DNA REST - should not be modified -->
+ <listener>
+ <listener-class>org.jboss.dna.web.jcr.rest.DnaJcrDeployer</listener-class>
+ </listener>
+
+ <!-- Required parameter for RESTEasy - should not be modified -->
+ <servlet>
+ <servlet-name>Resteasy</servlet-name>
+ <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
+ </servlet>
+
+ <!-- Required parameter for JBoss DNA REST - should not be modified -->
+ <servlet-mapping>
+ <servlet-name>Resteasy</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+
+ <!--
+ The JBoss DNA REST implementation leverages the HTTP credentials to for authentication
and authorization
+ within the JCR repository. It makes no sense to try to log into the JCR repository
without credentials,
+ so this constraint helps lock down the repository.
+
+ This should generally not be modified.
+ -->
+ <security-constraint>
+ <display-name>DNA REST</display-name>
+ <web-resource-collection>
+ <web-resource-name>RestEasy</web-resource-name>
+ <url-pattern>/*</url-pattern>
+ </web-resource-collection>
+ <auth-constraint>
+ <!--
+ A user must be assigned this role to connect to any JCR repository, in addition to
needing the READONLY
+ or READWRITE roles to actually read or modify the data. This is not used internally,
so another
+ role could be substituted here.
+ -->
+ <role-name>connect</role-name>
+ </auth-constraint>
+ </security-constraint>
+
+ <!--
+ Any auth-method will work for JBoss DNA. BASIC is used this example for simplicity.
+ -->
+ <login-config>
+ <auth-method>BASIC</auth-method>
+ </login-config>
+
+ <!--
+ This must match the role-name in the auth-constraint above.
+ -->
+ <security-role>
+ <role-name>connect</role-name>
+ </security-role>
+</web-app>
Property changes on: trunk/web/dna-web-jcr-rest-war/src/main/webapp/WEB-INF/web.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied:
trunk/web/dna-web-jcr-rest-war/src/test/java/org/jboss/dna/web/jcr/rest/JcrResourcesTest.java
(from rev 1210,
trunk/extensions/dna-web-jcr-rest-war/src/test/java/org/jboss/dna/web/jcr/rest/JcrResourcesTest.java)
===================================================================
---
trunk/web/dna-web-jcr-rest-war/src/test/java/org/jboss/dna/web/jcr/rest/JcrResourcesTest.java
(rev 0)
+++
trunk/web/dna-web-jcr-rest-war/src/test/java/org/jboss/dna/web/jcr/rest/JcrResourcesTest.java 2009-09-11
20:48:26 UTC (rev 1211)
@@ -0,0 +1,968 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.web.jcr.rest;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.Authenticator;
+import java.net.HttpURLConnection;
+import java.net.PasswordAuthentication;
+import java.net.URL;
+import java.util.HashSet;
+import java.util.Set;
+import javax.ws.rs.core.MediaType;
+import org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONObject;
+import org.jboss.dna.common.util.Base64;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test of the DNA JCR REST resource. Note that this test case uses a very low-level API
to construct requests and deconstruct the
+ * responses. Users are encouraged to use a higher-level library to communicate with the
REST server (e.g., Apache HTTP Commons).
+ */
+public class JcrResourcesTest {
+
+ private static final String SERVER_CONTEXT = "/resources";
+ private static final String SERVER_URL = "http://localhost:8080" +
SERVER_CONTEXT;
+
+ @Before
+ public void beforeEach() {
+
+ // Configured in pom
+ final String login = "dnauser";
+ final String password = "password";
+
+ Authenticator.setDefault(new Authenticator() {
+ @Override
+ protected PasswordAuthentication getPasswordAuthentication() {
+ return new PasswordAuthentication(login, password.toCharArray());
+ }
+ });
+ }
+
+ private String getResponseFor( HttpURLConnection connection ) throws IOException {
+ StringBuffer buff = new StringBuffer();
+
+ InputStream stream = connection.getInputStream();
+ int bytesRead;
+ byte[] bytes = new byte[1024];
+ while (-1 != (bytesRead = stream.read(bytes, 0, 1024))) {
+ buff.append(new String(bytes, 0, bytesRead));
+ }
+
+ return buff.toString();
+ }
+
+ @Test
+ public void shouldNotServeContentToUnauthorizedUser() throws Exception {
+
+ final String login = "dnauser";
+ final String password = "invalidpassword";
+
+ Authenticator.setDefault(new Authenticator() {
+ @Override
+ protected PasswordAuthentication getPasswordAuthentication() {
+ return new PasswordAuthentication(login, password.toCharArray());
+ }
+ });
+
+ URL postUrl = new URL(SERVER_URL + "/");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ assertThat(connection.getResponseCode(),
is(HttpURLConnection.HTTP_UNAUTHORIZED));
+ connection.disconnect();
+
+ }
+
+ @Test
+ public void shouldNotServeContentToUserWithoutConnectRole() throws Exception {
+
+ // Configured in pom
+ final String login = "unauthorizeduser";
+ final String password = "password";
+
+ Authenticator.setDefault(new Authenticator() {
+ @Override
+ protected PasswordAuthentication getPasswordAuthentication() {
+ return new PasswordAuthentication(login, password.toCharArray());
+ }
+ });
+
+ URL postUrl = new URL(SERVER_URL + "/");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ assertThat(connection.getResponseCode(),
is(HttpURLConnection.HTTP_UNAUTHORIZED));
+ connection.disconnect();
+
+ }
+
+ @Test
+ public void shouldServeContentAtRoot() throws Exception {
+ URL postUrl = new URL(SERVER_URL + "/");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+ String body = getResponseFor(connection);
+
+ JSONObject objFromResponse = new JSONObject(body);
+ JSONObject expected = new JSONObject(
+
"{\"dna%3arepository\":{\"repository\":{\"name\":\"dna%3arepository\",\"resources\":{\"workspaces\":\"/resources/dna%3arepository\"}}}}");
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
+ assertThat(objFromResponse.toString(), is(expected.toString()));
+ connection.disconnect();
+ }
+
+ @Test
+ public void shouldServeListOfWorkspacesForValidRepository() throws Exception {
+ URL postUrl = new URL(SERVER_URL + "/dna%3arepository");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+ String body = getResponseFor(connection);
+
+ JSONObject objFromResponse = new JSONObject(body);
+ JSONObject expected = new JSONObject(
+
"{\"default\":{\"workspace\":{\"name\":\"default\",\"resources\":{\"items\":\"/resources/dna%3arepository/default/items\"}}}}");
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
+ assertThat(objFromResponse.toString(), is(expected.toString()));
+ connection.disconnect();
+ }
+
+ @Test
+ public void shouldReturnErrorForInvalidWorkspace() throws Exception {
+ URL postUrl = new URL(SERVER_URL + "/XXX");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_NOT_FOUND));
+ connection.disconnect();
+ }
+
+ @Test
+ public void shouldRetrieveRootNodeForValidRepository() throws Exception {
+ URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ JSONObject body = new JSONObject(getResponseFor(connection));
+ assertThat(body.length(), is(2));
+
+ JSONObject properties = body.getJSONObject("properties");
+ assertThat(properties, is(notNullValue()));
+ assertThat(properties.length(), is(2));
+ assertThat(properties.getString("jcr:primaryType"),
is("dna:root"));
+ assertThat(properties.get("jcr:uuid"), is(notNullValue()));
+
+ JSONArray children = body.getJSONArray("children");
+ assertThat(children.length(), is(1));
+ assertThat(children.getString(0), is("jcr:system"));
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
+ connection.disconnect();
+ }
+
+ @Test
+ public void shouldRetrieveRootNodeAndChildrenWhenDepthSet() throws Exception {
+ URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items?dna:depth=1");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+ JSONObject body = new JSONObject(getResponseFor(connection));
+ assertThat(body.length(), is(2));
+
+ JSONObject properties = body.getJSONObject("properties");
+ assertThat(properties, is(notNullValue()));
+ assertThat(properties.length(), is(2));
+ assertThat(properties.getString("jcr:primaryType"),
is("dna:root"));
+ assertThat(properties.get("jcr:uuid"), is(notNullValue()));
+
+ JSONObject children = body.getJSONObject("children");
+ assertThat(children.length(), is(1));
+
+ JSONObject system = children.getJSONObject("jcr:system");
+ assertThat(system.length(), is(2));
+
+ properties = system.getJSONObject("properties");
+ assertThat(properties.length(), is(1));
+ assertThat(properties.getString("jcr:primaryType"),
is("dna:system"));
+
+ JSONArray namespaces = system.getJSONArray("children");
+ assertThat(namespaces.length(), is(1));
+ assertThat(namespaces.getString(0), is("dna:namespaces"));
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
+ connection.disconnect();
+ }
+
+ @Test
+ public void shouldRetrieveNodeAndChildrenWhenDepthSet() throws Exception {
+ URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/jcr:system?dna:depth=1");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+ JSONObject body = new JSONObject(getResponseFor(connection));
+ assertThat(body.length(), is(2));
+
+ JSONObject properties = body.getJSONObject("properties");
+ assertThat(properties, is(notNullValue()));
+ assertThat(properties.length(), is(1));
+ assertThat(properties.getString("jcr:primaryType"),
is("dna:system"));
+
+ JSONObject children = body.getJSONObject("children");
+ assertThat(children.length(), is(1));
+
+ JSONObject namespaces = children.getJSONObject("dna:namespaces");
+ assertThat(namespaces.length(), is(2));
+
+ properties = namespaces.getJSONObject("properties");
+ assertThat(properties.length(), is(1));
+ assertThat(properties.getString("jcr:primaryType"),
is("dna:namespaces"));
+
+ JSONArray namespace = namespaces.getJSONArray("children");
+ assertThat(namespace.length(), is(10));
+ Set<String> prefixes = new HashSet<String>(namespace.length());
+
+ for (int i = 0; i < namespace.length(); i++) {
+ prefixes.add(namespace.getString(i));
+ }
+
+ String[] expectedNamespaces = new String[] {"dna", "jcr",
"nt", "mix", "sv", "xml", "dnaint",
"xmlns", "xsi", "xsd"};
+ for (int i = 0; i < expectedNamespaces.length; i++) {
+ assertTrue(prefixes.contains(expectedNamespaces[i]));
+ }
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
+ connection.disconnect();
+ }
+
+ @Test
+ public void shouldNotRetrieveNonExistentNode() throws Exception {
+ URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/foo");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_NOT_FOUND));
+ connection.disconnect();
+ }
+
+ @Test
+ public void shouldNotRetrieveNonExistentProperty() throws Exception {
+ URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/jcr:system/foobar");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_NOT_FOUND));
+ connection.disconnect();
+ }
+
+ @Test
+ public void shouldRetrieveProperty() throws Exception {
+ URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/jcr:system/jcr:primaryType");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ String body = getResponseFor(connection);
+ assertThat(body,
is("{\"jcr:primaryType\":\"dna:system\"}"));
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
+ connection.disconnect();
+ }
+
+ @Test
+ public void shouldPostNodeToValidPathWithPrimaryType() throws Exception {
+ URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nodeA");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("POST");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ String payload = "{ \"properties\":
{\"jcr:primaryType\": \"nt:unstructured\", \"testProperty\":
\"testValue\", \"multiValuedProperty\": [\"value1\",
\"value2\"]}}";
+ connection.getOutputStream().write(payload.getBytes());
+
+ JSONObject body = new JSONObject(getResponseFor(connection));
+ assertThat(body.length(), is(1));
+
+ JSONObject properties = body.getJSONObject("properties");
+ assertThat(properties, is(notNullValue()));
+ assertThat(properties.length(), is(3));
+ assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
+ assertThat(properties.getString("testProperty"),
is("testValue"));
+ assertThat(properties.get("multiValuedProperty"),
instanceOf(JSONArray.class));
+
+ JSONArray values = properties.getJSONArray("multiValuedProperty");
+ assertThat(values, is(notNullValue()));
+ assertThat(values.length(), is(2));
+ assertThat(values.getString(0), is("value1"));
+ assertThat(values.getString(1), is("value2"));
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_CREATED));
+ connection.disconnect();
+ }
+
+ @Test
+ public void shouldPostNodeToValidPathWithoutPrimaryType() throws Exception {
+ URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/noPrimaryType");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("POST");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ String payload = "{}";
+ connection.getOutputStream().write(payload.getBytes());
+
+ JSONObject body = new JSONObject(getResponseFor(connection));
+ assertThat(body.length(), is(1));
+
+ JSONObject properties = body.getJSONObject("properties");
+ assertThat(properties, is(notNullValue()));
+ assertThat(properties.length(), is(1));
+ assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_CREATED));
+ connection.disconnect();
+ }
+
+ @Test
+ public void shouldPostNodeToValidPathWithMixinTypes() throws Exception {
+ URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/withMixinType");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("POST");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ String payload = "{ \"properties\": {\"jcr:mixinTypes\":
\"mix:referenceable\"}}";
+ connection.getOutputStream().write(payload.getBytes());
+
+ JSONObject body = new JSONObject(getResponseFor(connection));
+ assertThat(body.length(), is(1));
+
+ JSONObject properties = body.getJSONObject("properties");
+ assertThat(properties, is(notNullValue()));
+ assertThat(properties.length(), is(3));
+ assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
+ assertThat(properties.getString("jcr:uuid"), is(notNullValue()));
+
+ JSONArray values = properties.getJSONArray("jcr:mixinTypes");
+ assertThat(values, is(notNullValue()));
+ assertThat(values.length(), is(1));
+ assertThat(values.getString(0), is("mix:referenceable"));
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_CREATED));
+ connection.disconnect();
+
+ postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/withMixinType");
+ connection = (HttpURLConnection)postUrl.openConnection();
+
+ // Make sure that we can retrieve the node with a GET
+ connection.setDoOutput(true);
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+ body = new JSONObject(getResponseFor(connection));
+
+ assertThat(body.length(), is(1));
+
+ properties = body.getJSONObject("properties");
+ assertThat(properties, is(notNullValue()));
+ assertThat(properties.length(), is(3));
+ assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
+ assertThat(properties.getString("jcr:uuid"), is(notNullValue()));
+
+ values = properties.getJSONArray("jcr:mixinTypes");
+ assertThat(values, is(notNullValue()));
+ assertThat(values.length(), is(1));
+ assertThat(values.getString(0), is("mix:referenceable"));
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
+ connection.disconnect();
+
+ }
+
+ @Test
+ public void shouldNotPostNodeAtInvalidParentPath() throws Exception {
+ URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/foo/bar");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_NOT_FOUND));
+ connection.disconnect();
+
+ }
+
+ @Test
+ public void shouldNotPostNodeWithInvalidPrimaryType() throws Exception {
+ URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/invalidPrimaryType");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("POST");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ String payload = "{ \"properties\":
{\"jcr:primaryType\": \"invalidType\", \"testProperty\":
\"testValue\", \"multiValuedProperty\": [\"value1\",
\"value2\"]}}";
+ connection.getOutputStream().write(payload.getBytes());
+
+ assertThat(connection.getResponseCode(),
is(HttpURLConnection.HTTP_BAD_REQUEST));
+ connection.disconnect();
+
+ postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/invalidPrimaryType");
+ connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_NOT_FOUND));
+ connection.disconnect();
+
+ }
+
+ @Test
+ public void shouldPostNodeHierarchy() throws Exception {
+ URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nestedPost");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("POST");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ String payload = "{ \"properties\":
{\"jcr:primaryType\": \"nt:unstructured\", \"testProperty\":
\"testValue\", \"multiValuedProperty\": [\"value1\",
\"value2\"]},"
+ + " \"children\": { \"childNode\" : {
\"properties\": {\"nestedProperty\":
\"nestedValue\"}}}}";
+
+ connection.getOutputStream().write(payload.getBytes());
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_CREATED));
+ connection.disconnect();
+
+ postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nestedPost?dna:depth=1");
+ connection = (HttpURLConnection)postUrl.openConnection();
+
+ // Make sure that we can retrieve the node with a GET
+ connection.setDoOutput(true);
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+ JSONObject body = new JSONObject(getResponseFor(connection));
+
+ assertThat(body.length(), is(2));
+
+ JSONObject properties = body.getJSONObject("properties");
+ assertThat(properties, is(notNullValue()));
+ assertThat(properties.length(), is(3));
+ assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
+ assertThat(properties.getString("testProperty"),
is("testValue"));
+ assertThat(properties.get("multiValuedProperty"),
instanceOf(JSONArray.class));
+
+ JSONArray values = properties.getJSONArray("multiValuedProperty");
+ assertThat(values, is(notNullValue()));
+ assertThat(values.length(), is(2));
+ assertThat(values.getString(0), is("value1"));
+ assertThat(values.getString(1), is("value2"));
+
+ JSONObject children = body.getJSONObject("children");
+ assertThat(children, is(notNullValue()));
+ assertThat(children.length(), is(1));
+
+ JSONObject child = children.getJSONObject("childNode");
+ assertThat(child, is(notNullValue()));
+ assertThat(child.length(), is(1));
+
+ properties = child.getJSONObject("properties");
+ assertThat(properties, is(notNullValue()));
+ assertThat(properties.length(), is(2));
+ // Parent primary type is nt:unstructured, so this should default to
nt:unstructured primary type
+ assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
+ assertThat(properties.getString("nestedProperty"),
is("nestedValue"));
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
+ connection.disconnect();
+
+ }
+
+ @Test
+ public void shouldFailWholeTransactionIfOneNodeIsBad() throws Exception {
+ URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/invalidNestedPost");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("POST");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ String payload = "{ \"properties\":
{\"jcr:primaryType\": \"nt:unstructured\", \"testProperty\":
\"testValue\", \"multiValuedProperty\": [\"value1\",
\"value2\"]},"
+ + " \"children\": { \"childNode\" : {
\"properties\": {\"jcr:primaryType\":
\"invalidType\"}}}}";
+ connection.getOutputStream().write(payload.getBytes());
+
+ assertThat(connection.getResponseCode(),
is(HttpURLConnection.HTTP_BAD_REQUEST));
+ connection.disconnect();
+
+ postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/invalidNestedPost?dna:depth=1");
+ connection = (HttpURLConnection)postUrl.openConnection();
+
+ // Make sure that we can retrieve the node with a GET
+ connection.setDoOutput(true);
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_NOT_FOUND));
+ connection.disconnect();
+
+ }
+
+ @Test
+ public void shouldNotDeleteNonExistentItem() throws Exception {
+ URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/invalidItemForDelete");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("DELETE");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_NOT_FOUND));
+ connection.disconnect();
+ }
+
+ @Test
+ public void shouldDeleteExtantNode() throws Exception {
+
+ // Create the node
+ URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nodeForDeletion");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("POST");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ String payload = "{ \"properties\":
{\"jcr:primaryType\": \"nt:unstructured\", \"testProperty\":
\"testValue\", \"multiValuedProperty\": [\"value1\",
\"value2\"]}}";
+ connection.getOutputStream().write(payload.getBytes());
+
+ JSONObject body = new JSONObject(getResponseFor(connection));
+ assertThat(body.length(), is(1));
+
+ JSONObject properties = body.getJSONObject("properties");
+ assertThat(properties, is(notNullValue()));
+ assertThat(properties.length(), is(3));
+ assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
+ assertThat(properties.getString("testProperty"),
is("testValue"));
+ assertThat(properties.get("multiValuedProperty"),
instanceOf(JSONArray.class));
+
+ JSONArray values = properties.getJSONArray("multiValuedProperty");
+ assertThat(values, is(notNullValue()));
+ assertThat(values.length(), is(2));
+ assertThat(values.getString(0), is("value1"));
+ assertThat(values.getString(1), is("value2"));
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_CREATED));
+ connection.disconnect();
+
+ // Confirm that it exists
+ postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nodeForDeletion");
+ connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
+ connection.disconnect();
+
+ // Delete the node
+ postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nodeForDeletion");
+ connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("DELETE");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_NO_CONTENT));
+ connection.disconnect();
+
+ // Confirm that it no longer exists
+ postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nodeForDeletion");
+ connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_NOT_FOUND));
+ connection.disconnect();
+ }
+
+ @Test
+ public void shouldDeleteExtantProperty() throws Exception {
+ URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/propertyForDeletion");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("POST");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ String payload = "{ \"properties\":
{\"jcr:primaryType\": \"nt:unstructured\", \"testProperty\":
\"testValue\", \"multiValuedProperty\": [\"value1\",
\"value2\"]}}";
+ connection.getOutputStream().write(payload.getBytes());
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_CREATED));
+ connection.disconnect();
+
+ // Confirm that it exists
+ postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/propertyForDeletion");
+ connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ JSONObject body = new JSONObject(getResponseFor(connection));
+ assertThat(body.length(), is(1));
+
+ JSONObject properties = body.getJSONObject("properties");
+ assertThat(properties, is(notNullValue()));
+ assertThat(properties.length(), is(3));
+ assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
+ assertThat(properties.getString("testProperty"),
is("testValue"));
+ assertThat(properties.get("multiValuedProperty"),
instanceOf(JSONArray.class));
+
+ JSONArray values = properties.getJSONArray("multiValuedProperty");
+ assertThat(values, is(notNullValue()));
+ assertThat(values.length(), is(2));
+ assertThat(values.getString(0), is("value1"));
+ assertThat(values.getString(1), is("value2"));
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
+ connection.disconnect();
+
+ // Delete the property
+ postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/propertyForDeletion/multiValuedProperty");
+ connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("DELETE");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_NO_CONTENT));
+ connection.disconnect();
+
+ // Confirm that it no longer exists
+ postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/propertyForDeletion");
+ connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ body = new JSONObject(getResponseFor(connection));
+ assertThat(body.length(), is(1));
+
+ properties = body.getJSONObject("properties");
+ assertThat(properties, is(notNullValue()));
+ assertThat(properties.length(), is(2));
+ assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
+ assertThat(properties.getString("testProperty"),
is("testValue"));
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
+ connection.disconnect();
+
+ }
+
+ @Test
+ public void shouldNotBeAbleToPutAtInvalidPath() throws Exception {
+
+ URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nonexistantNode");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("PUT");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ String payload = "{ \"firstProperty\": \"someValue\"
}";
+ connection.getOutputStream().write(payload.getBytes());
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_NOT_FOUND));
+ connection.disconnect();
+ }
+
+ @Test
+ public void shouldBeAbleToPutValueToProperty() throws Exception {
+ URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nodeForPutProperty");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("POST");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ String payload = "{ \"properties\":
{\"jcr:primaryType\": \"nt:unstructured\", \"testProperty\":
\"testValue\" }}";
+ connection.getOutputStream().write(payload.getBytes());
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_CREATED));
+ connection.disconnect();
+
+ postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nodeForPutProperty/testProperty");
+ connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("PUT");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ payload = "{\"testProperty\":\"someOtherValue\"}";
+ connection.getOutputStream().write(payload.getBytes());
+
+ JSONObject body = new JSONObject(getResponseFor(connection));
+ assertThat(body.length(), is(1));
+
+ JSONObject properties = body.getJSONObject("properties");
+ assertThat(properties, is(notNullValue()));
+ assertThat(properties.length(), is(2));
+ assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
+ assertThat(properties.getString("testProperty"),
is("someOtherValue"));
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
+ connection.disconnect();
+
+ }
+
+ @Test
+ public void shouldBeAbleToPutBinaryValueToProperty() throws Exception {
+ URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nodeForPutBinaryProperty");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("POST");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ // Base64-encode a value ...
+ String encodedValue =
Base64.encodeBytes("propertyValue".getBytes("UTF-8"));
+
+ String payload = "{ \"properties\":
{\"jcr:primaryType\": \"nt:unstructured\",
\"testProperty/base64/\": \""
+ + encodedValue + "\" }}";
+ connection.getOutputStream().write(payload.getBytes());
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_CREATED));
+ connection.disconnect();
+
+ URL putUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nodeForPutBinaryProperty/testProperty");
+ connection = (HttpURLConnection)putUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("PUT");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ String otherValue = "someOtherValue";
+ payload = "{\"testProperty/base64/\":\"" +
Base64.encodeBytes(otherValue.getBytes("UTF-8")) + "\"}";
+ connection.getOutputStream().write(payload.getBytes());
+
+ JSONObject body = new JSONObject(getResponseFor(connection));
+ assertThat(body.length(), is(1));
+
+ JSONObject properties = body.getJSONObject("properties");
+ assertThat(properties, is(notNullValue()));
+ assertThat(properties.length(), is(2));
+ assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
+ String responseEncodedValue =
properties.getString("testProperty/base64/");
+ String decodedValue = new String(Base64.decode(responseEncodedValue),
"UTF-8");
+ assertThat(decodedValue, is(otherValue));
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
+ connection.disconnect();
+
+ // Try putting a non-binary value ...
+ connection = (HttpURLConnection)putUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("PUT");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ String anotherValue = "yetAnotherValue";
+ payload = "{\"testProperty\":\"" + anotherValue +
"\"}";
+ connection.getOutputStream().write(payload.getBytes());
+
+ body = new JSONObject(getResponseFor(connection));
+ assertThat(body.length(), is(1));
+
+ properties = body.getJSONObject("properties");
+ assertThat(properties, is(notNullValue()));
+ assertThat(properties.length(), is(2));
+ assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
+ assertThat(properties.getString("testProperty"), is(anotherValue));
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
+ connection.disconnect();
+ }
+
+ @Test
+ public void shouldBeAbleToPutPropertiesToNode() throws Exception {
+
+ URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nodeForPutProperties");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("POST");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ String payload = "{ \"properties\":
{\"jcr:primaryType\": \"nt:unstructured\" }}";
+ connection.getOutputStream().write(payload.getBytes());
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_CREATED));
+ connection.disconnect();
+
+ postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nodeForPutProperties");
+ connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("PUT");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ payload = "{\"testProperty\": \"testValue\",
\"multiValuedProperty\": [\"value1\", \"value2\"]}";
+ connection.getOutputStream().write(payload.getBytes());
+
+ JSONObject body = new JSONObject(getResponseFor(connection));
+ assertThat(body.length(), is(1));
+
+ JSONObject properties = body.getJSONObject("properties");
+ assertThat(properties, is(notNullValue()));
+ assertThat(properties.length(), is(3));
+ assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
+ assertThat(properties.getString("testProperty"),
is("testValue"));
+ assertThat(properties.get("multiValuedProperty"),
instanceOf(JSONArray.class));
+
+ JSONArray values = properties.getJSONArray("multiValuedProperty");
+ assertThat(values, is(notNullValue()));
+ assertThat(values.length(), is(2));
+ assertThat(values.getString(0), is("value1"));
+ assertThat(values.getString(1), is("value2"));
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
+ connection.disconnect();
+
+ }
+
+ @Test
+ public void shouldBeAbleToAddAndRemoveMixinTypes() throws Exception {
+
+ URL postUrl = new URL(SERVER_URL +
"/dna%3arepository/default/items/nodeWithNoMixins");
+ HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("POST");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ String payload = "{ \"properties\":
{\"jcr:primaryType\": \"nt:unstructured\" }}";
+ connection.getOutputStream().write(payload.getBytes());
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_CREATED));
+ connection.disconnect();
+
+ connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("PUT");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ payload = "{\"jcr:mixinTypes\":
\"mix:referenceable\"}";
+ connection.getOutputStream().write(payload.getBytes());
+
+ JSONObject body = new JSONObject(getResponseFor(connection));
+ assertThat(body.length(), is(1));
+
+ JSONObject properties = body.getJSONObject("properties");
+ assertThat(properties, is(notNullValue()));
+
+ assertThat(properties.length(), is(3));
+ assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
+ JSONArray mixinTypes = properties.getJSONArray("jcr:mixinTypes");
+ assertThat(mixinTypes, is(notNullValue()));
+ assertThat(mixinTypes.length(), is(1));
+ assertThat(mixinTypes.getString(0), is("mix:referenceable"));
+ assertThat(properties.getString("jcr:uuid"), is(notNullValue()));
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
+ connection.disconnect();
+
+ connection = (HttpURLConnection)postUrl.openConnection();
+
+ connection.setDoOutput(true);
+ connection.setRequestMethod("PUT");
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON);
+
+ payload = "{\"jcr:mixinTypes\": []}";
+ connection.getOutputStream().write(payload.getBytes());
+
+ body = new JSONObject(getResponseFor(connection));
+ assertThat(body.length(), is(1));
+
+ properties = body.getJSONObject("properties");
+ assertThat(properties, is(notNullValue()));
+ assertThat(properties.length(), is(2));
+ assertThat(properties.getString("jcr:primaryType"),
is("nt:unstructured"));
+
+ // removeMixin doesn't currently null out this value
+ mixinTypes = properties.getJSONArray("jcr:mixinTypes");
+ assertThat(mixinTypes, is(notNullValue()));
+ assertThat(mixinTypes.length(), is(0));
+
+ assertThat(connection.getResponseCode(), is(HttpURLConnection.HTTP_OK));
+ connection.disconnect();
+
+ }
+
+}
Property changes on:
trunk/web/dna-web-jcr-rest-war/src/test/java/org/jboss/dna/web/jcr/rest/JcrResourcesTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: trunk/web/dna-web-jcr-rest-war/src/test/resources/log4j.properties (from rev 1210,
trunk/extensions/dna-web-jcr-rest-war/src/test/resources/log4j.properties)
===================================================================
--- trunk/web/dna-web-jcr-rest-war/src/test/resources/log4j.properties
(rev 0)
+++ trunk/web/dna-web-jcr-rest-war/src/test/resources/log4j.properties 2009-09-11 20:48:26
UTC (rev 1211)
@@ -0,0 +1,13 @@
+log4j.rootLogger = DEBUG, stdout
+
+log4j.category.org.apache=DEBUG
+log4j.category.org.jboss.resteasy=DEBUG
+log4j.category.org.mortbay.jetty.security=ERROR
+log4j.category.org.slf4j.impl.JCLLoggerAdapter=DEBUG
+log4j.category.org.springframework=INFO
+
+log4j.appender.stdout = org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Threshold = DEBUG
+log4j.appender.stdout.Target = System.out
+log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern = [%-5p] [%C] : %m%n [%F:%L]