mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
Merges Struts 2 ClassLoaderUtils into XWork 2 ClassLoaderUtil
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1302821 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -21,19 +21,18 @@
|
||||
|
||||
package org.apache.struts2.config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.struts2.StrutsException;
|
||||
import org.apache.struts2.util.ClassLoaderUtils;
|
||||
|
||||
import com.opensymphony.xwork2.util.ClassLoaderUtil;
|
||||
import com.opensymphony.xwork2.util.location.LocatableProperties;
|
||||
import com.opensymphony.xwork2.util.location.Location;
|
||||
import com.opensymphony.xwork2.util.location.LocationImpl;
|
||||
import com.opensymphony.xwork2.util.logging.Logger;
|
||||
import com.opensymphony.xwork2.util.logging.LoggerFactory;
|
||||
import org.apache.struts2.StrutsException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
/**
|
||||
@@ -54,7 +53,7 @@ class PropertiesSettings extends Settings {
|
||||
*/
|
||||
public PropertiesSettings(String name) {
|
||||
|
||||
URL settingsUrl = ClassLoaderUtils.getResource(name + ".properties", getClass());
|
||||
URL settingsUrl = ClassLoaderUtil.getResource(name + ".properties", getClass());
|
||||
|
||||
if (settingsUrl == null) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
|
||||
@@ -26,7 +26,6 @@ import com.opensymphony.xwork2.util.logging.Logger;
|
||||
import com.opensymphony.xwork2.util.logging.LoggerFactory;
|
||||
import org.apache.struts2.StrutsConstants;
|
||||
import org.apache.struts2.dispatcher.ng.HostConfig;
|
||||
import org.apache.struts2.util.ClassLoaderUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -242,7 +241,7 @@ public class DefaultStaticContentLoader implements StaticContentLoader {
|
||||
String factoryName = filterConfig.getInitParameter("loggerFactory");
|
||||
if (factoryName != null) {
|
||||
try {
|
||||
Class cls = ClassLoaderUtils.loadClass(factoryName, this.getClass());
|
||||
Class cls = ClassLoaderUtil.loadClass(factoryName, this.getClass());
|
||||
LoggerFactory fac = (LoggerFactory)cls.newInstance();
|
||||
LoggerFactory.setLoggerFactory(fac);
|
||||
} catch (InstantiationException e) {
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.opensymphony.xwork2.inject.Container;
|
||||
import com.opensymphony.xwork2.inject.ContainerBuilder;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.interceptor.Interceptor;
|
||||
import com.opensymphony.xwork2.util.ClassLoaderUtil;
|
||||
import com.opensymphony.xwork2.util.FileManager;
|
||||
import com.opensymphony.xwork2.util.LocalizedTextUtil;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
@@ -61,7 +62,6 @@ import org.apache.struts2.dispatcher.mapper.ActionMapping;
|
||||
import org.apache.struts2.dispatcher.multipart.MultiPartRequest;
|
||||
import org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper;
|
||||
import org.apache.struts2.util.AttributeMap;
|
||||
import org.apache.struts2.util.ClassLoaderUtils;
|
||||
import org.apache.struts2.util.ObjectFactoryDestroyable;
|
||||
import org.apache.struts2.views.freemarker.FreemarkerManager;
|
||||
|
||||
@@ -73,6 +73,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -80,7 +81,6 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* A utility class the actual dispatcher delegates most of its tasks to. Each instance
|
||||
@@ -347,7 +347,7 @@ public class Dispatcher {
|
||||
String[] classes = configProvs.split("\\s*[,]\\s*");
|
||||
for (String cname : classes) {
|
||||
try {
|
||||
Class cls = ClassLoaderUtils.loadClass(cname, this.getClass());
|
||||
Class cls = ClassLoaderUtil.loadClass(cname, this.getClass());
|
||||
ConfigurationProvider prov = (ConfigurationProvider)cls.newInstance();
|
||||
configurationManager.addContainerProvider(prov);
|
||||
} catch (InstantiationException e) {
|
||||
|
||||
@@ -21,10 +21,21 @@
|
||||
|
||||
package org.apache.struts2.dispatcher;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.config.Configuration;
|
||||
import com.opensymphony.xwork2.config.ConfigurationProvider;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.util.ClassLoaderUtil;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import com.opensymphony.xwork2.util.ValueStackFactory;
|
||||
import com.opensymphony.xwork2.util.logging.Logger;
|
||||
import com.opensymphony.xwork2.util.logging.LoggerFactory;
|
||||
import com.opensymphony.xwork2.util.profiling.UtilTimerStack;
|
||||
import org.apache.struts2.RequestUtils;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.dispatcher.mapper.ActionMapper;
|
||||
import org.apache.struts2.dispatcher.mapper.ActionMapping;
|
||||
import org.apache.struts2.dispatcher.ng.filter.FilterHostConfig;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
@@ -35,23 +46,10 @@ import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.struts2.RequestUtils;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.dispatcher.mapper.ActionMapper;
|
||||
import org.apache.struts2.dispatcher.mapper.ActionMapping;
|
||||
import org.apache.struts2.dispatcher.ng.filter.FilterHostConfig;
|
||||
import org.apache.struts2.util.ClassLoaderUtils;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.config.Configuration;
|
||||
import com.opensymphony.xwork2.config.ConfigurationProvider;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import com.opensymphony.xwork2.util.ValueStackFactory;
|
||||
import com.opensymphony.xwork2.util.logging.Logger;
|
||||
import com.opensymphony.xwork2.util.logging.LoggerFactory;
|
||||
import com.opensymphony.xwork2.util.profiling.UtilTimerStack;
|
||||
import java.io.IOException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Master filter for Struts that handles four distinct
|
||||
@@ -205,7 +203,7 @@ public class FilterDispatcher implements StrutsStatics, Filter {
|
||||
String factoryName = filterConfig.getInitParameter("loggerFactory");
|
||||
if (factoryName != null) {
|
||||
try {
|
||||
Class cls = ClassLoaderUtils.loadClass(factoryName, this.getClass());
|
||||
Class cls = ClassLoaderUtil.loadClass(factoryName, this.getClass());
|
||||
LoggerFactory fac = (LoggerFactory) cls.newInstance();
|
||||
LoggerFactory.setLoggerFactory(fac);
|
||||
} catch (InstantiationException e) {
|
||||
|
||||
@@ -20,14 +20,19 @@
|
||||
*/
|
||||
package org.apache.struts2.dispatcher.ng;
|
||||
|
||||
import com.opensymphony.xwork2.util.logging.LoggerFactory;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.util.ClassLoaderUtil;
|
||||
import com.opensymphony.xwork2.util.logging.LoggerFactory;
|
||||
import org.apache.struts2.StrutsConstants;
|
||||
import org.apache.struts2.dispatcher.Dispatcher;
|
||||
import org.apache.struts2.dispatcher.StaticContentLoader;
|
||||
import org.apache.struts2.util.ClassLoaderUtils;
|
||||
import org.apache.struts2.StrutsConstants;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
@@ -45,7 +50,7 @@ public class InitOperations {
|
||||
String factoryName = filterConfig.getInitParameter("loggerFactory");
|
||||
if (factoryName != null) {
|
||||
try {
|
||||
Class cls = ClassLoaderUtils.loadClass(factoryName, this.getClass());
|
||||
Class cls = ClassLoaderUtil.loadClass(factoryName, this.getClass());
|
||||
LoggerFactory fac = (LoggerFactory) cls.newInstance();
|
||||
LoggerFactory.setLoggerFactory(fac);
|
||||
} catch ( InstantiationException e ) {
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.struts2.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
|
||||
/**
|
||||
* This class is extremely useful for loading resources and classes in a fault tolerant manner
|
||||
* that works across different applications servers.
|
||||
* <p/>
|
||||
* It has come out of many months of frustrating use of multiple application servers at Atlassian,
|
||||
* please don't change things unless you're sure they're not going to break in one server or another!
|
||||
*
|
||||
*/
|
||||
public class ClassLoaderUtils {
|
||||
|
||||
/**
|
||||
* Load a given resource.
|
||||
* <p/>
|
||||
* This method will try to load the resource using the following methods (in order):
|
||||
* <ul>
|
||||
* <li>From {@link Thread#getContextClassLoader() Thread.currentThread().getContextClassLoader()}
|
||||
* <li>From {@link Class#getClassLoader() ClassLoaderUtil.class.getClassLoader()}
|
||||
* <li>From the {@link Class#getClassLoader() callingClass.getClassLoader() }
|
||||
* </ul>
|
||||
*
|
||||
* @param resourceName The name of the resource to load
|
||||
* @param callingClass The Class object of the calling object
|
||||
*/
|
||||
public static URL getResource(String resourceName, Class callingClass) {
|
||||
URL url = null;
|
||||
|
||||
url = Thread.currentThread().getContextClassLoader().getResource(resourceName);
|
||||
|
||||
if (url == null) {
|
||||
url = ClassLoaderUtils.class.getClassLoader().getResource(resourceName);
|
||||
}
|
||||
|
||||
if (url == null) {
|
||||
url = callingClass.getClassLoader().getResource(resourceName);
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a convenience method to load a resource as a stream.
|
||||
* <p/>
|
||||
* The algorithm used to find the resource is given in getResource()
|
||||
*
|
||||
* @param resourceName The name of the resource to load
|
||||
* @param callingClass The Class object of the calling object
|
||||
*/
|
||||
public static InputStream getResourceAsStream(String resourceName, Class callingClass) {
|
||||
URL url = getResource(resourceName, callingClass);
|
||||
|
||||
try {
|
||||
return (url != null) ? url.openStream() : null;
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a class with a given name.
|
||||
* <p/>
|
||||
* It will try to load the class in the following order:
|
||||
* <ul>
|
||||
* <li>From {@link Thread#getContextClassLoader() Thread.currentThread().getContextClassLoader()}
|
||||
* <li>Using the basic {@link Class#forName(java.lang.String) }
|
||||
* <li>From {@link Class#getClassLoader() ClassLoaderUtil.class.getClassLoader()}
|
||||
* <li>From the {@link Class#getClassLoader() callingClass.getClassLoader() }
|
||||
* </ul>
|
||||
*
|
||||
* @param className The name of the class to load
|
||||
* @param callingClass The Class object of the calling object
|
||||
* @throws ClassNotFoundException If the class cannot be found anywhere.
|
||||
*/
|
||||
public static Class loadClass(String className, Class callingClass) throws ClassNotFoundException {
|
||||
try {
|
||||
return Thread.currentThread().getContextClassLoader().loadClass(className);
|
||||
} catch (ClassNotFoundException e) {
|
||||
try {
|
||||
return Class.forName(className);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
try {
|
||||
return ClassLoaderUtils.class.getClassLoader().loadClass(className);
|
||||
} catch (ClassNotFoundException exc) {
|
||||
return callingClass.getClassLoader().loadClass(className);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the current classloader hierarchy - useful for debugging.
|
||||
*/
|
||||
public static void printClassLoader() {
|
||||
System.out.println("ClassLoaderUtils.printClassLoader");
|
||||
printClassLoader(Thread.currentThread().getContextClassLoader());
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the classloader hierarchy from a given classloader - useful for debugging.
|
||||
*/
|
||||
public static void printClassLoader(ClassLoader cl) {
|
||||
System.out.println("ClassLoaderUtils.printClassLoader(cl = " + cl + ")");
|
||||
|
||||
if (cl != null) {
|
||||
printClassLoader(cl.getParent());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ package org.apache.struts2.util;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ObjectFactory;
|
||||
import com.opensymphony.xwork2.inject.Container;
|
||||
import com.opensymphony.xwork2.util.ClassLoaderUtil;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import com.opensymphony.xwork2.util.logging.Logger;
|
||||
import com.opensymphony.xwork2.util.logging.LoggerFactory;
|
||||
@@ -78,7 +79,7 @@ public class StrutsUtil {
|
||||
Class c = (Class) classes.get(name);
|
||||
|
||||
if (c == null) {
|
||||
c = ClassLoaderUtils.loadClass(name, StrutsUtil.class);
|
||||
c = ClassLoaderUtil.loadClass(name, StrutsUtil.class);
|
||||
classes.put(name, c);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,12 +21,12 @@
|
||||
|
||||
package org.apache.struts2.views.velocity;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.struts2.util.ClassLoaderUtils;
|
||||
import com.opensymphony.xwork2.util.ClassLoaderUtil;
|
||||
import org.apache.velocity.exception.ResourceNotFoundException;
|
||||
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
|
||||
/**
|
||||
* Loads resource from the Thread's context ClassLoader.
|
||||
@@ -44,7 +44,7 @@ public class StrutsResourceLoader extends ClasspathResourceLoader {
|
||||
}
|
||||
|
||||
try {
|
||||
return ClassLoaderUtils.getResourceAsStream(name, StrutsResourceLoader.class);
|
||||
return ClassLoaderUtil.getResourceAsStream(name, StrutsResourceLoader.class);
|
||||
} catch (Exception e) {
|
||||
throw new ResourceNotFoundException(e.getMessage());
|
||||
}
|
||||
|
||||
@@ -21,26 +21,23 @@
|
||||
|
||||
package org.apache.struts2.views.xslt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.mock.MockActionInvocation;
|
||||
import com.opensymphony.xwork2.util.ClassLoaderUtil;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.StrutsTestCase;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.URIResolver;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.StrutsTestCase;
|
||||
import org.apache.struts2.util.ClassLoaderUtils;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.mock.MockActionInvocation;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import com.opensymphony.xwork2.util.ValueStackFactory;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Unit test for {@link XSLTResult}.
|
||||
@@ -138,7 +135,7 @@ public class XSLTResultTest extends StrutsTestCase {
|
||||
protected URIResolver getURIResolver() {
|
||||
return new URIResolver() {
|
||||
public Source resolve(String href, String base) throws TransformerException {
|
||||
return new StreamSource(ClassLoaderUtils.getResourceAsStream(href, this.getClass()));
|
||||
return new StreamSource(ClassLoaderUtil.getResourceAsStream(href, this.getClass()));
|
||||
}
|
||||
|
||||
};
|
||||
@@ -159,7 +156,7 @@ public class XSLTResultTest extends StrutsTestCase {
|
||||
protected URIResolver getURIResolver() {
|
||||
return new URIResolver() {
|
||||
public Source resolve(String href, String base) throws TransformerException {
|
||||
return new StreamSource(ClassLoaderUtils.getResourceAsStream(href, this.getClass()));
|
||||
return new StreamSource(ClassLoaderUtil.getResourceAsStream(href, this.getClass()));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
+13
-4
@@ -21,15 +21,24 @@
|
||||
|
||||
package org.apache.struts2.codebehind;
|
||||
|
||||
import com.opensymphony.xwork2.*;
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ObjectFactory;
|
||||
import com.opensymphony.xwork2.Result;
|
||||
import com.opensymphony.xwork2.UnknownHandler;
|
||||
import com.opensymphony.xwork2.XWorkException;
|
||||
import com.opensymphony.xwork2.config.Configuration;
|
||||
import com.opensymphony.xwork2.config.ConfigurationException;
|
||||
import com.opensymphony.xwork2.config.entities.*;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.config.entities.InterceptorLocator;
|
||||
import com.opensymphony.xwork2.config.entities.PackageConfig;
|
||||
import com.opensymphony.xwork2.config.entities.ResultConfig;
|
||||
import com.opensymphony.xwork2.config.entities.ResultTypeConfig;
|
||||
import com.opensymphony.xwork2.config.providers.InterceptorBuilder;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.util.ClassLoaderUtil;
|
||||
import com.opensymphony.xwork2.util.logging.Logger;
|
||||
import com.opensymphony.xwork2.util.logging.LoggerFactory;
|
||||
import org.apache.struts2.util.ClassLoaderUtils;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import java.net.MalformedURLException;
|
||||
@@ -253,7 +262,7 @@ public class CodebehindUnknownHandler implements UnknownHandler {
|
||||
LOG.debug("Loaded template '" + path + "' from servlet context.");
|
||||
}
|
||||
} else {
|
||||
template = ClassLoaderUtils.getResource(stripLeadingSlash(path), getClass());
|
||||
template = ClassLoaderUtil.getResource(stripLeadingSlash(path), getClass());
|
||||
if (template != null && LOG.isDebugEnabled()) {
|
||||
LOG.debug("Loaded template '" + stripLeadingSlash(path) + "' from class path.");
|
||||
}
|
||||
|
||||
+2
-2
@@ -24,9 +24,9 @@ package org.apache.struts2.config_browser;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.util.ClassLoaderUtil;
|
||||
import com.opensymphony.xwork2.validator.ActionValidatorManager;
|
||||
import com.opensymphony.xwork2.validator.Validator;
|
||||
import org.apache.struts2.util.ClassLoaderUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -92,7 +92,7 @@ public class ListValidatorsAction extends ActionSupport {
|
||||
|
||||
private Class getClassInstance() {
|
||||
try {
|
||||
return ClassLoaderUtils.loadClass(clazz, ActionContext.getContext().getClass());
|
||||
return ClassLoaderUtil.loadClass(clazz, ActionContext.getContext().getClass());
|
||||
} catch (Exception e) {
|
||||
LOG.error("Class '" + clazz + "' not found...",e);
|
||||
}
|
||||
|
||||
+17
-11
@@ -20,15 +20,6 @@
|
||||
*/
|
||||
package org.apache.struts2.convention;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.*;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import com.opensymphony.xwork2.config.entities.*;
|
||||
import com.opensymphony.xwork2.config.providers.InterceptorBuilder;
|
||||
import org.apache.struts2.util.ClassLoaderUtils;
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
@@ -38,11 +29,26 @@ import com.opensymphony.xwork2.UnknownHandler;
|
||||
import com.opensymphony.xwork2.XWorkException;
|
||||
import com.opensymphony.xwork2.config.Configuration;
|
||||
import com.opensymphony.xwork2.config.ConfigurationException;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.config.entities.InterceptorMapping;
|
||||
import com.opensymphony.xwork2.config.entities.PackageConfig;
|
||||
import com.opensymphony.xwork2.config.entities.ResultConfig;
|
||||
import com.opensymphony.xwork2.config.entities.ResultTypeConfig;
|
||||
import com.opensymphony.xwork2.config.providers.InterceptorBuilder;
|
||||
import com.opensymphony.xwork2.inject.Container;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.util.ClassLoaderUtil;
|
||||
import com.opensymphony.xwork2.util.logging.Logger;
|
||||
import com.opensymphony.xwork2.util.logging.LoggerFactory;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This class is the default unknown handler for all of the Convention
|
||||
@@ -328,7 +334,7 @@ public class ConventionUnknownHandler implements UnknownHandler {
|
||||
LOG.trace("Checking ClasLoader for #0", path);
|
||||
|
||||
String classLoaderPath = path.startsWith("/") ? path.substring(1, path.length()) : path;
|
||||
if (ClassLoaderUtils.getResource(classLoaderPath, getClass()) != null) {
|
||||
if (ClassLoaderUtil.getResource(classLoaderPath, getClass()) != null) {
|
||||
if (traceEnabled)
|
||||
LOG.trace("Found");
|
||||
return buildResult(path, resultCode, resultsByExtension.get(ext), actionContext);
|
||||
|
||||
+8
-9
@@ -20,19 +20,18 @@
|
||||
*/
|
||||
package org.apache.struts2.convention;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import org.apache.struts2.convention.annotation.AnnotationTools;
|
||||
import org.apache.struts2.convention.annotation.ResultPath;
|
||||
import org.apache.struts2.util.ClassLoaderUtils;
|
||||
|
||||
import com.opensymphony.xwork2.config.ConfigurationException;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.config.entities.PackageConfig;
|
||||
import com.opensymphony.xwork2.config.entities.ResultTypeConfig;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.util.ClassLoaderUtil;
|
||||
import org.apache.struts2.convention.annotation.AnnotationTools;
|
||||
import org.apache.struts2.convention.annotation.ResultPath;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -95,7 +94,7 @@ public class ConventionsServiceImpl implements ConventionsService {
|
||||
}
|
||||
|
||||
try {
|
||||
return determineResultPath(ClassLoaderUtils.loadClass(actionConfig.getClassName(), this.getClass()));
|
||||
return determineResultPath(ClassLoaderUtil.loadClass(actionConfig.getClassName(), this.getClass()));
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException("Invalid action class configuration that references an unknown " +
|
||||
"class named [" + actionConfig.getClassName() + "]", e);
|
||||
|
||||
@@ -21,12 +21,14 @@
|
||||
|
||||
package org.apache.struts2.jsf;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.config.entities.ResultConfig;
|
||||
import com.opensymphony.xwork2.interceptor.Interceptor;
|
||||
import com.opensymphony.xwork2.util.ClassLoaderUtil;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.StrutsException;
|
||||
|
||||
import javax.faces.FactoryFinder;
|
||||
import javax.faces.application.Application;
|
||||
@@ -41,16 +43,12 @@ import javax.faces.el.VariableResolver;
|
||||
import javax.faces.event.ActionListener;
|
||||
import javax.faces.lifecycle.Lifecycle;
|
||||
import javax.faces.lifecycle.LifecycleFactory;
|
||||
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.StrutsException;
|
||||
import org.apache.struts2.util.ClassLoaderUtils;
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.config.entities.ResultConfig;
|
||||
import com.opensymphony.xwork2.interceptor.Interceptor;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* * Initializes the JSF context for this request.
|
||||
@@ -301,7 +299,7 @@ public class FacesSetupInterceptor extends FacesSupport implements Interceptor {
|
||||
Class implClass = null;
|
||||
|
||||
try {
|
||||
implClass = ClassLoaderUtils.loadClass(implClassName, this
|
||||
implClass = ClassLoaderUtil.loadClass(implClassName, this
|
||||
.getClass());
|
||||
} catch (ClassNotFoundException e1) {
|
||||
throw new IllegalArgumentException("Class " + implClassName
|
||||
|
||||
@@ -24,17 +24,12 @@ import java.util.*;
|
||||
/**
|
||||
* This class is extremely useful for loading resources and classes in a fault tolerant manner
|
||||
* that works across different applications servers.
|
||||
*
|
||||
* <p/>
|
||||
* It has come out of many months of frustrating use of multiple application servers at Atlassian,
|
||||
* please don't change things unless you're sure they're not going to break in one server or another!
|
||||
*
|
||||
* It was brought in from oscore trunk revision 147.
|
||||
*
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
*/
|
||||
public class ClassLoaderUtil {
|
||||
//~ Methods ////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Load all resources with a given name, potentially aggregating all results
|
||||
@@ -77,18 +72,18 @@ public class ClassLoaderUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a given resource.
|
||||
*
|
||||
* This method will try to load the resource using the following methods (in order):
|
||||
* <ul>
|
||||
* <li>From Thread.currentThread().getContextClassLoader()
|
||||
* <li>From ClassLoaderUtil.class.getClassLoader()
|
||||
* <li>callingClass.getClassLoader()
|
||||
* </ul>
|
||||
*
|
||||
* @param resourceName The name IllegalStateException("Unable to call ")of the resource to load
|
||||
* @param callingClass The Class object of the calling object
|
||||
*/
|
||||
* Load a given resource.
|
||||
* <p/>
|
||||
* This method will try to load the resource using the following methods (in order):
|
||||
* <ul>
|
||||
* <li>From {@link Thread#getContextClassLoader() Thread.currentThread().getContextClassLoader()}
|
||||
* <li>From {@link Class#getClassLoader() ClassLoaderUtil.class.getClassLoader()}
|
||||
* <li>From the {@link Class#getClassLoader() callingClass.getClassLoader() }
|
||||
* </ul>
|
||||
*
|
||||
* @param resourceName The name of the resource to load
|
||||
* @param callingClass The Class object of the calling object
|
||||
*/
|
||||
public static URL getResource(String resourceName, Class callingClass) {
|
||||
URL url = Thread.currentThread().getContextClassLoader().getResource(resourceName);
|
||||
|
||||
@@ -130,20 +125,20 @@ public class ClassLoaderUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a class with a given name.
|
||||
*
|
||||
* It will try to load the class in the following order:
|
||||
* <ul>
|
||||
* <li>From Thread.currentThread().getContextClassLoader()
|
||||
* <li>Using the basic Class.forName()
|
||||
* <li>From ClassLoaderUtil.class.getClassLoader()
|
||||
* <li>From the callingClass.getClassLoader()
|
||||
* </ul>
|
||||
*
|
||||
* @param className The name of the class to load
|
||||
* @param callingClass The Class object of the calling object
|
||||
* @throws ClassNotFoundException If the class cannot be found anywhere.
|
||||
*/
|
||||
* Load a class with a given name.
|
||||
* <p/>
|
||||
* It will try to load the class in the following order:
|
||||
* <ul>
|
||||
* <li>From {@link Thread#getContextClassLoader() Thread.currentThread().getContextClassLoader()}
|
||||
* <li>Using the basic {@link Class#forName(java.lang.String) }
|
||||
* <li>From {@link Class#getClassLoader() ClassLoaderUtil.class.getClassLoader()}
|
||||
* <li>From the {@link Class#getClassLoader() callingClass.getClassLoader() }
|
||||
* </ul>
|
||||
*
|
||||
* @param className The name of the class to load
|
||||
* @param callingClass The Class object of the calling object
|
||||
* @throws ClassNotFoundException If the class cannot be found anywhere.
|
||||
*/
|
||||
public static Class loadClass(String className, Class callingClass) throws ClassNotFoundException {
|
||||
try {
|
||||
return Thread.currentThread().getContextClassLoader().loadClass(className);
|
||||
@@ -160,6 +155,25 @@ public class ClassLoaderUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the current classloader hierarchy - useful for debugging.
|
||||
*/
|
||||
public static void printClassLoader() {
|
||||
System.out.println("ClassLoaderUtils.printClassLoader");
|
||||
printClassLoader(Thread.currentThread().getContextClassLoader());
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the classloader hierarchy from a given classloader - useful for debugging.
|
||||
*/
|
||||
public static void printClassLoader(ClassLoader cl) {
|
||||
System.out.println("ClassLoaderUtils.printClassLoader(cl = " + cl + ")");
|
||||
|
||||
if (cl != null) {
|
||||
printClassLoader(cl.getParent());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggregates Enumeration instances into one iterator and filters out duplicates. Always keeps one
|
||||
* ahead of the enumerator to protect against returning duplicates.
|
||||
|
||||
Reference in New Issue
Block a user