You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ch...@apache.org on 2017/03/08 07:35:38 UTC
svn commit: r1785921 - in /jackrabbit/oak/branches/1.6: ./
oak-examples/standalone/src/main/java/org/apache/jackrabbit/oak/standalone/RemotingInitializer.java
Author: chetanm
Date: Wed Mar 8 07:35:38 2017
New Revision: 1785921
URL: http://svn.apache.org/viewvc?rev=1785921&view=rev
Log:
OAK-5500 - Oak Standalone throws ClassNotFoundException: remoting/protectedHandlersConfig.xml
Merging 1785919
Modified:
jackrabbit/oak/branches/1.6/ (props changed)
jackrabbit/oak/branches/1.6/oak-examples/standalone/src/main/java/org/apache/jackrabbit/oak/standalone/RemotingInitializer.java
Propchange: jackrabbit/oak/branches/1.6/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Mar 8 07:35:38 2017
@@ -1,3 +1,3 @@
/jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1781068,1781075,1781248,1781386,1781846,1781907,1782000,1782029,1782196,1782447,1782770,1782945,1782973,1782990,1783061,1783066,1783089,1783104-1783105,1783619,1783731,1783733,1783742,1783855,1783891,1784023,1784130,1784162,1784251,1784401,1784551,1784574,1785095,1785108,1785283,1785838
+/jackrabbit/oak/trunk:1781068,1781075,1781248,1781386,1781846,1781907,1782000,1782029,1782196,1782447,1782770,1782945,1782973,1782990,1783061,1783066,1783089,1783104-1783105,1783619,1783731,1783733,1783742,1783855,1783891,1784023,1784130,1784162,1784251,1784401,1784551,1784574,1785095,1785108,1785283,1785838,1785919
/jackrabbit/trunk:1345480
Modified: jackrabbit/oak/branches/1.6/oak-examples/standalone/src/main/java/org/apache/jackrabbit/oak/standalone/RemotingInitializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-examples/standalone/src/main/java/org/apache/jackrabbit/oak/standalone/RemotingInitializer.java?rev=1785921&r1=1785920&r2=1785921&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.6/oak-examples/standalone/src/main/java/org/apache/jackrabbit/oak/standalone/RemotingInitializer.java (original)
+++ jackrabbit/oak/branches/1.6/oak-examples/standalone/src/main/java/org/apache/jackrabbit/oak/standalone/RemotingInitializer.java Wed Mar 8 07:35:38 2017
@@ -19,9 +19,13 @@
package org.apache.jackrabbit.oak.standalone;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
import javax.jcr.Repository;
+import javax.servlet.ServletContext;
-import org.apache.jackrabbit.server.remoting.davex.DavexServletService;
import org.apache.jackrabbit.server.remoting.davex.JcrRemotingServlet;
import org.apache.jackrabbit.webdav.simple.SimpleWebdavServlet;
import org.springframework.beans.factory.annotation.Autowired;
@@ -29,6 +33,8 @@ import org.springframework.beans.factory
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
/**
* Configures the Webdav and Davex servlet to enabled remote
@@ -43,6 +49,8 @@ public class RemotingInitializer {
@Autowired
private Repository repository;
+ @Autowired
+ private ServletContext servletContext;
@Bean
public ServletRegistrationBean webDavServlet() {
@@ -51,10 +59,15 @@ public class RemotingInitializer {
public Repository getRepository() {
return repository;
}
+
+ @Override
+ public ServletContext getServletContext() {
+ return RemotingInitializer.this.getServletContext();
+ }
}, "/repository/*");
bean.addInitParameter(SimpleWebdavServlet.INIT_PARAM_RESOURCE_PATH_PREFIX, "/repository");
- bean.addInitParameter(SimpleWebdavServlet.INIT_PARAM_RESOURCE_CONFIG, "remoting/webdav-config.xml");
+ bean.addInitParameter(SimpleWebdavServlet.INIT_PARAM_RESOURCE_CONFIG, "/remoting/webdav-config.xml");
return bean;
}
@@ -66,17 +79,43 @@ public class RemotingInitializer {
public Repository getRepository() {
return repository;
}
+
+ @Override
+ public ServletContext getServletContext() {
+ return RemotingInitializer.this.getServletContext();
+ }
}, "/server/*");
bean.addInitParameter(JcrRemotingServlet.INIT_PARAM_RESOURCE_PATH_PREFIX, "/server");
- bean.addInitParameter(JcrRemotingServlet.INIT_PARAM_BATCHREAD_CONFIG, "remoting/batchread.properties");
+ bean.addInitParameter(JcrRemotingServlet.INIT_PARAM_BATCHREAD_CONFIG, "/remoting/batchread.properties");
- //TODO By docs this is meant to point to a file which gets loaded
- //but servlet always reads it as File not via input stream. Hence using
- //actual class
bean.addInitParameter(JcrRemotingServlet.INIT_PARAM_PROTECTED_HANDLERS_CONFIG,
- "remoting/protectedHandlersConfig.xml");
+ "/remoting/protectedHandlersConfig.xml");
bean.addInitParameter(JcrRemotingServlet.INIT_PARAM_HOME, davHome);
return bean;
}
+
+ /**
+ * Creates a proxy ServletContext which delegates the resource loading to Spring Resource support
+ * Without this default embedded server ServletContext based resource loading was failing
+ */
+ private ServletContext getServletContext(){
+ return (ServletContext) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{ServletContext.class},
+ new InvocationHandler(){
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ if ("getResourceAsStream".equals(method.getName())){
+ return getResource((String) args[0]).getInputStream();
+ }
+ if ("getResource".equals(method.getName())){
+ return getResource((String) args[0]).getURL();
+ }
+ return method.invoke(servletContext, args);
+ }
+ });
+ }
+
+ private Resource getResource(String path) {
+ return new ClassPathResource(path);
+ }
}