<type>pom</type>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.argeo.commons.security</groupId>
+ <artifactId>org.argeo.security.ui.application</artifactId>
+ <version>${version.argeo-commons}</version>
+ <scope>test</scope>
+ </dependency>
<!-- Tomcat -->
<dependency>
<groupId>org.argeo.commons.server</groupId>
<url-pattern>/remoting/*</url-pattern>
</servlet-mapping>
- <!-- XML rmeoting -->
+ <!-- XML remoting -->
<servlet>
<servlet-name>xmlremoting</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<servlet-mapping>
<servlet-name>webdav</servlet-name>
- <url-pattern>/default/*</url-pattern>
+ <url-pattern>/webdav/*</url-pattern>
</servlet-mapping>
<!-- JCR-MANAGER servlet -->
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
- <bean id="webdavServlet" class="org.argeo.jackrabbit.remote.WebDavServlet">
-<!-- <property name="repository" ref="jcrRepository" />-->
- <property name="resourceConfiguration" value="osgibundle:/WEB-INF/webdav-config.xml" />
- </bean>
-
<bean
class="org.springframework.web.servlet.handler.SimpleServletPostProcessor" />
class="org.springframework.web.servlet.handler.SimpleServletHandlerAdapter" />
<bean id="urlMapping"
- class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
- <property name="mappings">
- <props>
- <prop key="**">webdavServlet</prop>
- </props>
- </property>
+ class="org.argeo.jackrabbit.remote.WebdavHandlerMapping">
+ <property name="repositoryRegister" ref="repositoryRegister" />
+ <property name="configuration" value="osgibundle:/WEB-INF/webdav-config.xml" />
</bean>
</beans>
\ No newline at end of file
org.argeo.jackrabbit.*,
</Export-Package>
<Import-Package>
+ javax.servlet,
org.xml.sax;version="0.0.0",
org.apache.jackrabbit.webdav.jcr,
org.springframework.security.providers.jaas;resolution:="optional",
</dependency>
<dependency>
<groupId>org.argeo.commons.server</groupId>
- <artifactId>org.argeo.server.jcr</artifactId>
+ <artifactId>org.argeo.server.jcr.mvc</artifactId>
<version>0.2.3-SNAPSHOT</version>
</dependency>
import javax.servlet.http.HttpServlet;
import org.apache.jackrabbit.webdav.jcr.JCRWebdavServerServlet;
+import org.argeo.jcr.mvc.MultipleRepositoryHandlerMapping;
public class JcrRemotingHandlerMapping extends MultipleRepositoryHandlerMapping {
protected HttpServlet createServlet(Repository repository, String pathPrefix)
throws ServletException {
- JcrRemotingServlet jcrRemotingServlet = new JcrRemotingServlet(
- repository);
+ JcrRemotingServlet servlet = new JcrRemotingServlet(repository);
Properties initParameters = new Properties();
initParameters.setProperty(
JCRWebdavServerServlet.INIT_PARAM_RESOURCE_PATH_PREFIX,
pathPrefix);
- jcrRemotingServlet.init(new DelegatingServletConfig(pathPrefix.replace(
- '/', '_'), initParameters));
- return jcrRemotingServlet;
+ servlet.init(new DelegatingServletConfig(pathPrefix.replace('/', '_'),
+ initParameters));
+ return servlet;
}
}
+++ /dev/null
-package org.argeo.jackrabbit.remote;
-
-import java.util.Enumeration;
-import java.util.Properties;
-
-import javax.jcr.Repository;
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.ArgeoException;
-import org.argeo.jcr.RepositoryRegister;
-import org.springframework.beans.BeansException;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.web.context.ServletContextAware;
-import org.springframework.web.servlet.HandlerExecutionChain;
-import org.springframework.web.servlet.HandlerMapping;
-
-public abstract class MultipleRepositoryHandlerMapping implements
- HandlerMapping, ApplicationContextAware, ServletContextAware {
- private final static Log log = LogFactory
- .getLog(MultipleRepositoryHandlerMapping.class);
-
- private ConfigurableApplicationContext applicationContext;
- private ServletContext servletContext;
-
- private RepositoryRegister repositoryRegister;
-
- /** Actually creates the servlet to be registered. */
- protected abstract HttpServlet createServlet(Repository repository,
- String pathPrefix) throws ServletException;
-
- public HandlerExecutionChain getHandler(HttpServletRequest request)
- throws Exception {
- if (log.isTraceEnabled()) {
- log.trace("getContextPath=" + request.getContextPath());
- log.trace("getServletPath=" + request.getServletPath());
- log.trace("getPathInfo=" + request.getPathInfo());
- }
-
- String repositoryName = extractRepositoryName(request);
- String pathPrefix = request.getServletPath() + '/' + repositoryName;
- String beanName = pathPrefix;
-
- if (!applicationContext.containsBean(beanName)) {
- Repository repository = repositoryRegister.getRepositories().get(
- repositoryName);
- HttpServlet servlet = createServlet(repository, pathPrefix);
- applicationContext.getBeanFactory().registerSingleton(beanName,
- servlet);
- // TODO: unregister it as well
- }
- HttpServlet remotingServlet = (HttpServlet) applicationContext
- .getBean(beanName);
- return new HandlerExecutionChain(remotingServlet);
- }
-
- /** The repository name is the first part of the path info */
- protected String extractRepositoryName(HttpServletRequest request) {
- String pathInfo = request.getPathInfo();
- // TODO: optimize by checking character by character
- String[] tokens = pathInfo.split("/");
- StringBuffer currName = new StringBuffer("");
- tokens: for (String token : tokens) {
- if (token.equals(""))
- continue tokens;
- currName.append(token);
- if (repositoryRegister.getRepositories().containsKey(
- currName.toString()))
- return currName.toString();
- currName.append('/');
- }
- throw new ArgeoException("No repository can be found for request "
- + pathInfo);
- }
-
- public void setApplicationContext(ApplicationContext applicationContext)
- throws BeansException {
- this.applicationContext = (ConfigurableApplicationContext) applicationContext;
- }
-
- public void setServletContext(ServletContext servletContext) {
- this.servletContext = servletContext;
- }
-
- public void setRepositoryRegister(RepositoryRegister repositoryRegister) {
- this.repositoryRegister = repositoryRegister;
- }
-
- protected class DelegatingServletConfig implements ServletConfig {
- private String name;
- private Properties initParameters;
-
- public DelegatingServletConfig(String name, Properties initParameters) {
- super();
- this.name = name;
- this.initParameters = initParameters;
- }
-
- public String getServletName() {
- return name;
- }
-
- public ServletContext getServletContext() {
- return servletContext;
- }
-
- public String getInitParameter(String paramName) {
- return initParameters.getProperty(paramName);
- }
-
- @SuppressWarnings("rawtypes")
- public Enumeration getInitParameterNames() {
- return initParameters.keys();
- }
- }
-
-}
import java.io.IOException;
import javax.jcr.Repository;
+import javax.jcr.SimpleCredentials;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.server.SessionProvider;
import org.apache.jackrabbit.webdav.simple.ResourceConfig;
import org.apache.jackrabbit.webdav.simple.SimpleWebdavServlet;
import org.argeo.ArgeoException;
private static final long serialVersionUID = 1L;
private final static Log log = LogFactory.getLog(WebDavServlet.class);
- private Repository repository;
- private Resource resourceConfiguration;
-
- public WebDavServlet() {
+ private final Repository repository;
+ private final Resource resourceConfiguration;
+ public WebDavServlet(Repository repository, Resource configuration) {
+ this.repository = repository;
+ this.resourceConfiguration = configuration;
}
@Override
return repository;
}
- public void setRepository(Repository repository) {
- this.repository = repository;
- }
-
- public void setResourceConfiguration(Resource resourceConfig) {
- this.resourceConfiguration = resourceConfig;
+ @Override
+ public SessionProvider getSessionProvider() {
+ return new CachingSessionProvider(new SimpleCredentials("demo",
+ "demo".toCharArray()));
}
}
--- /dev/null
+package org.argeo.jackrabbit.remote;
+
+import java.util.Properties;
+
+import javax.jcr.Repository;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+
+import org.apache.jackrabbit.webdav.jcr.JCRWebdavServerServlet;
+import org.argeo.jcr.mvc.MultipleRepositoryHandlerMapping;
+import org.springframework.core.io.Resource;
+
+public class WebdavHandlerMapping extends MultipleRepositoryHandlerMapping {
+ private Resource configuration;
+
+ protected HttpServlet createServlet(Repository repository, String pathPrefix)
+ throws ServletException {
+
+ WebDavServlet servlet = new WebDavServlet(repository, configuration);
+ Properties initParameters = new Properties();
+ initParameters.setProperty(
+ JCRWebdavServerServlet.INIT_PARAM_RESOURCE_PATH_PREFIX,
+ pathPrefix);
+ servlet.init(new DelegatingServletConfig(pathPrefix.replace('/', '_'),
+ initParameters));
+ return servlet;
+ }
+
+ public void setConfiguration(Resource configuration) {
+ this.configuration = configuration;
+ }
+
+}
-<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">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.argeo.commons.server</groupId>
<Export-Package>
org.argeo.jcr.mvc.*
</Export-Package>
+ <Import-Package>
+ org.springframework.beans.factory,
+ *
+ </Import-Package>
</instructions>
</configuration>
</plugin>
<groupId>org.springframework.ws</groupId>
<artifactId>org.springframework.xml</artifactId>
</dependency>
-
+
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
--- /dev/null
+package org.argeo.jcr.mvc;
+
+import java.util.Enumeration;
+import java.util.Properties;
+
+import javax.jcr.Repository;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.ArgeoException;
+import org.argeo.jcr.RepositoryRegister;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.web.context.ServletContextAware;
+import org.springframework.web.servlet.HandlerExecutionChain;
+import org.springframework.web.servlet.HandlerMapping;
+
+public abstract class MultipleRepositoryHandlerMapping implements
+ HandlerMapping, ApplicationContextAware, ServletContextAware {
+ private final static Log log = LogFactory
+ .getLog(MultipleRepositoryHandlerMapping.class);
+
+ private ConfigurableApplicationContext applicationContext;
+ private ServletContext servletContext;
+
+ private RepositoryRegister repositoryRegister;
+
+ /** Actually creates the servlet to be registered. */
+ protected abstract HttpServlet createServlet(Repository repository,
+ String pathPrefix) throws ServletException;
+
+ public HandlerExecutionChain getHandler(HttpServletRequest request)
+ throws Exception {
+ if (log.isTraceEnabled()) {
+ log.trace("getContextPath=" + request.getContextPath());
+ log.trace("getServletPath=" + request.getServletPath());
+ log.trace("getPathInfo=" + request.getPathInfo());
+ }
+
+ String repositoryName = extractRepositoryName(request);
+ String pathPrefix = request.getServletPath() + '/' + repositoryName;
+ String beanName = pathPrefix;
+
+ if (!applicationContext.containsBean(beanName)) {
+ Repository repository = repositoryRegister.getRepositories().get(
+ repositoryName);
+ HttpServlet servlet = createServlet(repository, pathPrefix);
+ applicationContext.getBeanFactory().registerSingleton(beanName,
+ servlet);
+ // TODO: unregister it as well
+ }
+ HttpServlet remotingServlet = (HttpServlet) applicationContext
+ .getBean(beanName);
+ return new HandlerExecutionChain(remotingServlet);
+ }
+
+ /** The repository name is the first part of the path info */
+ protected String extractRepositoryName(HttpServletRequest request) {
+ String pathInfo = request.getPathInfo();
+ // TODO: optimize by checking character by character
+ String[] tokens = pathInfo.split("/");
+ StringBuffer currName = new StringBuffer("");
+ tokens: for (String token : tokens) {
+ if (token.equals(""))
+ continue tokens;
+ currName.append(token);
+ if (repositoryRegister.getRepositories().containsKey(
+ currName.toString()))
+ return currName.toString();
+ currName.append('/');
+ }
+ throw new ArgeoException("No repository can be found for request "
+ + pathInfo);
+ }
+
+ public void setApplicationContext(ApplicationContext applicationContext)
+ throws BeansException {
+ this.applicationContext = (ConfigurableApplicationContext) applicationContext;
+ }
+
+ public void setServletContext(ServletContext servletContext) {
+ this.servletContext = servletContext;
+ }
+
+ public void setRepositoryRegister(RepositoryRegister repositoryRegister) {
+ this.repositoryRegister = repositoryRegister;
+ }
+
+ protected class DelegatingServletConfig implements ServletConfig {
+ private String name;
+ private Properties initParameters;
+
+ public DelegatingServletConfig(String name, Properties initParameters) {
+ super();
+ this.name = name;
+ this.initParameters = initParameters;
+ }
+
+ public String getServletName() {
+ return name;
+ }
+
+ public ServletContext getServletContext() {
+ return servletContext;
+ }
+
+ public String getInitParameter(String paramName) {
+ return initParameters.getProperty(paramName);
+ }
+
+ @SuppressWarnings("rawtypes")
+ public Enumeration getInitParameterNames() {
+ return initParameters.keys();
+ }
+ }
+
+}