ALFCOM-2816: Changes for JBoss v5.0.1.GA compatibility

- All code that resolves classpath resources goes through JBossEnabledResourceLoader with VFS support
- JBossEnabledResourcePatternResolver can handle recursion within VFS directory structures
- Reflection used to avoid runtime dependency on JBoss classes
- resource-ref declared in jboss-web.xml 
- Work around incorrect treatment of env-entry-value tag in web.xml

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14106 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Dave Ward
2009-04-28 14:07:52 +00:00
parent f743983dcb
commit e1d365e545
7 changed files with 98 additions and 66 deletions

View File

@@ -25,18 +25,18 @@
package org.alfresco.filesys.alfresco; package org.alfresco.filesys.alfresco;
import java.io.File; import java.io.File;
import java.io.UnsupportedEncodingException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.URL;
import java.net.URLDecoder;
import org.alfresco.config.ConfigElement; import org.alfresco.config.ConfigElement;
import org.alfresco.jlan.server.filesys.DiskSharedDevice; import org.alfresco.jlan.server.filesys.DiskSharedDevice;
import org.alfresco.jlan.server.filesys.pseudo.LocalPseudoFile; import org.alfresco.jlan.server.filesys.pseudo.LocalPseudoFile;
import org.alfresco.jlan.server.filesys.pseudo.PseudoFile; import org.alfresco.jlan.server.filesys.pseudo.PseudoFile;
import org.alfresco.service.ServiceRegistry; import org.alfresco.service.ServiceRegistry;
import org.alfresco.util.ResourceFinder;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.Resource;
/** /**
* Desktop Action Class * Desktop Action Class
@@ -409,28 +409,31 @@ public abstract class DesktopAction {
throw new DesktopActionException("Desktop action executable path not specified"); throw new DesktopActionException("Desktop action executable path not specified");
// Check that the application exists on the local filesystem // Check that the application exists on the local filesystem
Resource resource = new ResourceFinder().getResource(m_path);
URL appURL = this.getClass().getClassLoader().getResource(m_path); if (!resource.exists())
if ( appURL == null) {
throw new DesktopActionException("Failed to find drag and drop application, " + m_path); throw new DesktopActionException("Failed to find drag and drop application, " + m_path);
}
// Decode the URL path, it might contain escaped characters // Decode the URL path, it might contain escaped characters
String appURLPath = null;
try
{
appURLPath = URLDecoder.decode( appURL.getFile(), "UTF-8");
}
catch ( UnsupportedEncodingException ex)
{
throw new DesktopActionException("Failed to decode drag/drop path, " + ex.getMessage());
}
// Check that the drag/drop file exists // Check that the drag/drop file exists
File appFile;
try
{
appFile = resource.getFile();
File appFile = new File(appURLPath); if (!appFile.exists())
if ( appFile.exists() == false) {
throw new DesktopActionException("Drag and drop application not found, " + appFile); throw new DesktopActionException("Drag and drop application not found, " + appFile);
}
}
catch (IOException e)
{
throw new DesktopActionException("Unable to resolve drag and drop application as a file, "
+ resource.getDescription());
}
// Create the pseudo file for the action // Create the pseudo file for the action

View File

@@ -27,9 +27,6 @@ import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLDecoder;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.StringTokenizer; import java.util.StringTokenizer;
@@ -44,6 +41,8 @@ import org.alfresco.filesys.alfresco.DesktopResponse;
import org.alfresco.jlan.server.filesys.DiskSharedDevice; import org.alfresco.jlan.server.filesys.DiskSharedDevice;
import org.alfresco.scripts.ScriptException; import org.alfresco.scripts.ScriptException;
import org.alfresco.service.cmr.repository.ScriptService; import org.alfresco.service.cmr.repository.ScriptService;
import org.alfresco.util.ResourceFinder;
import org.springframework.core.io.Resource;
/** /**
* Javascript Desktop Action Class * Javascript Desktop Action Class
@@ -155,28 +154,25 @@ public class JavaScriptDesktopAction extends DesktopAction {
} }
// Check if the script exists on the classpath // Check if the script exists on the classpath
Resource resource = new ResourceFinder().getResource(m_scriptName);
URL scriptURL = this.getClass().getClassLoader().getResource(m_scriptName); if (!resource.exists())
if ( scriptURL == null) {
throw new DesktopActionException("Failed to find script on classpath, " + getScriptName()); throw new DesktopActionException("Failed to find script on classpath, " + getScriptName());
// Decode the URL path, it might contain escaped characters
String scriptURLPath = null;
try
{
scriptURLPath = URLDecoder.decode( scriptURL.getFile(), "UTF-8");
}
catch ( UnsupportedEncodingException ex)
{
throw new DesktopActionException("Failed to decode script path, " + ex.getMessage());
} }
// Check that the script file exists // Check that the script file exists
File scriptFile;
File scriptFile = new File(scriptURLPath); try
{
scriptFile = resource.getFile();
if (scriptFile.exists() == false) if (scriptFile.exists() == false)
throw new DesktopActionException("Script file not found, " + m_scriptName); throw new DesktopActionException("Script file not found, " + m_scriptName);
}
catch (IOException e)
{
throw new DesktopActionException("Unable to resolve script as a file, " + resource.getDescription());
}
m_scriptPath = scriptFile.getAbsolutePath(); m_scriptPath = scriptFile.getAbsolutePath();
m_lastModified =scriptFile.lastModified(); m_lastModified =scriptFile.lastModified();

View File

@@ -31,8 +31,12 @@ import java.util.List;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
/** /**
* Initialises Log4j's HierarchyDynamicMBean (refer to core-services-context.xml) and any overriding log4.properties files. * Initialises Log4j's HierarchyDynamicMBean (refer to core-services-context.xml) and any overriding log4.properties files.
@@ -62,10 +66,11 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
* WEB - INF / classes / alfresco / module / org.alfresco.module.avmCompare / log4j.properties * WEB - INF / classes / alfresco / module / org.alfresco.module.avmCompare / log4j.properties
* </pre> * </pre>
*/ */
public class Log4JHierarchyInit public class Log4JHierarchyInit implements ApplicationContextAware
{ {
private static Log logger = LogFactory.getLog(Log4JHierarchyInit.class); private static Log logger = LogFactory.getLog(Log4JHierarchyInit.class);
private List<String> extraLog4jUrls; private List<String> extraLog4jUrls;
private ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
public Log4JHierarchyInit() public Log4JHierarchyInit()
{ {
@@ -86,6 +91,16 @@ public class Log4JHierarchyInit
} }
} }
/* (non-Javadoc)
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
*/
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
{
this.resolver = applicationContext;
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void init() public void init()
{ {
@@ -120,7 +135,6 @@ public class Log4JHierarchyInit
private void importLogSettings(Method method, String springUrl) private void importLogSettings(Method method, String springUrl)
{ {
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources = null; Resource[] resources = null;
try try

View File

@@ -133,8 +133,7 @@ public class SchemaBootstrap extends AbstractLifecycleBean
public static final int DEFAULT_MAX_STRING_LENGTH = 1024; public static final int DEFAULT_MAX_STRING_LENGTH = 1024;
private static volatile int maxStringLength = DEFAULT_MAX_STRING_LENGTH; private static volatile int maxStringLength = DEFAULT_MAX_STRING_LENGTH;
private ResourcePatternResolver rpr = new PathMatchingResourcePatternResolver(this.getClass().getClassLoader());
/** /**
@@ -838,7 +837,6 @@ public class SchemaBootstrap extends AbstractLifecycleBean
// replace the dialect placeholder // replace the dialect placeholder
String dialectScriptUrl = scriptUrl.replaceAll(PLACEHOLDER_SCRIPT_DIALECT, dialectClazz.getName()); String dialectScriptUrl = scriptUrl.replaceAll(PLACEHOLDER_SCRIPT_DIALECT, dialectClazz.getName());
// get a handle on the resource // get a handle on the resource
ResourcePatternResolver rpr = new PathMatchingResourcePatternResolver(this.getClass().getClassLoader());
Resource resource = rpr.getResource(dialectScriptUrl); Resource resource = rpr.getResource(dialectScriptUrl);
if (!resource.exists()) if (!resource.exists())
{ {
@@ -1147,6 +1145,9 @@ public class SchemaBootstrap extends AbstractLifecycleBean
@Override @Override
protected synchronized void onBootstrap(ApplicationEvent event) protected synchronized void onBootstrap(ApplicationEvent event)
{ {
// Use the application context to load resources
rpr = (ApplicationContext)event.getSource();
// do everything in a transaction // do everything in a transaction
Session session = getSessionFactory().openSession(); Session session = getSessionFactory().openSession();
Connection connection = null; Connection connection = null;

View File

@@ -30,6 +30,7 @@ import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import org.alfresco.config.JBossEnabledResourcePatternResolver;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
@@ -43,6 +44,7 @@ import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourcePatternResolver;
/** /**
* A factory allowing initialization of an entire 'subsystem' in a child application context. As with other * A factory allowing initialization of an entire 'subsystem' in a child application context. As with other
@@ -309,7 +311,20 @@ public class ChildApplicationContextFactory extends AbstractPropertyBackedBean i
+ ChildApplicationContextFactory.CONTEXT_SUFFIX, + ChildApplicationContextFactory.CONTEXT_SUFFIX,
ChildApplicationContextFactory.EXTENSION_CLASSPATH_PREFIX + getCategory() + '/' + getTypeName() + '/' ChildApplicationContextFactory.EXTENSION_CLASSPATH_PREFIX + getCategory() + '/' + getTypeName() + '/'
+ getId() + '/' + ChildApplicationContextFactory.CONTEXT_SUFFIX + getId() + '/' + ChildApplicationContextFactory.CONTEXT_SUFFIX
}, false, this.parent); }, false, this.parent)
{
/*
* (non-Javadoc)
* @see org.springframework.context.support.AbstractApplicationContext#getResourcePatternResolver()
*/
@Override
protected ResourcePatternResolver getResourcePatternResolver()
{
return new JBossEnabledResourcePatternResolver(this);
}
};
// Add a property placeholder configurer, with the subsystem-scoped default properties // Add a property placeholder configurer, with the subsystem-scoped default properties
PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();

View File

@@ -43,8 +43,12 @@ import org.alfresco.service.cmr.module.ModuleService;
import org.alfresco.service.descriptor.DescriptorService; import org.alfresco.service.descriptor.DescriptorService;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
/** /**
* This component controls the execution of * This component controls the execution of
@@ -63,7 +67,7 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
* @author Derek Hulley * @author Derek Hulley
* @since 2.0 * @since 2.0
*/ */
public class ModuleServiceImpl implements ModuleService public class ModuleServiceImpl implements ApplicationContextAware, ModuleService
{ {
/** Error messages **/ /** Error messages **/
private static final String ERR_UNABLE_TO_OPEN_MODULE_PROPETIES = "module.err.unable_to_open_module_properties"; private static final String ERR_UNABLE_TO_OPEN_MODULE_PROPETIES = "module.err.unable_to_open_module_properties";
@@ -78,6 +82,8 @@ public class ModuleServiceImpl implements ModuleService
/** A cache of module details by module ID */ /** A cache of module details by module ID */
private Map<String, ModuleDetails> moduleDetailsById; private Map<String, ModuleDetails> moduleDetailsById;
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
/** Default constructor */ /** Default constructor */
public ModuleServiceImpl() public ModuleServiceImpl()
{ {
@@ -109,6 +115,16 @@ public class ModuleServiceImpl implements ModuleService
this.moduleComponentHelper.setTenantAdminService(tenantAdminService); this.moduleComponentHelper.setTenantAdminService(tenantAdminService);
} }
/* (non-Javadoc)
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
*/
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
{
this.resolver = applicationContext;
}
/** /**
* @see ModuleComponentHelper#registerComponent(ModuleComponent) * @see ModuleComponentHelper#registerComponent(ModuleComponent)
*/ */
@@ -169,7 +185,6 @@ public class ModuleServiceImpl implements ModuleService
{ {
moduleDetailsById = new HashMap<String, ModuleDetails>(13); moduleDetailsById = new HashMap<String, ModuleDetails>(13);
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources = resolver.getResources(MODULE_CONFIG_SEARCH_ALL); Resource[] resources = resolver.getResources(MODULE_CONFIG_SEARCH_ALL);
// Read each resource // Read each resource

View File

@@ -29,33 +29,21 @@ import java.util.Arrays;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.alfresco.config.JBossEnabledResourcePatternResolver;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
/** /**
* Can be used in Spring configuration to search for all resources matching an array of patterns. * Can be used in Spring configuration to search for all resources matching an array of patterns.
* *
* @author dward * @author dward
*/ */
public class ResourceFinder extends PathMatchingResourcePatternResolver public class ResourceFinder extends JBossEnabledResourcePatternResolver
{ {
/**
* Instantiates a new resource finder.
*/
public ResourceFinder() public ResourceFinder()
{ {
} super(new DefaultResourceLoader());
/**
* The Constructor.
*
* @param classLoader
* the class loader
*/
public ResourceFinder(ClassLoader classLoader)
{
super(classLoader);
} }
/** /**