mirror of
https://github.com/apache/struts.git
synced 2026-08-07 15:46:57 +00:00
Minor code improvements's in the cdi, convention, jasperreports, junit, rest and sitemesh plugin
- Use Java 7 features like diamond operator - Improve some logging message and don't check LOG.isXxx if not necessary - Fix some typos - Use BooleanUtils.toBoolean(string) instead of "true".isEquals to be more robust
This commit is contained in:
@@ -21,8 +21,8 @@ package org.apache.struts2.cdi;
|
||||
|
||||
import com.opensymphony.xwork2.ObjectFactory;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.enterprise.context.spi.CreationalContext;
|
||||
import javax.enterprise.inject.spi.BeanManager;
|
||||
@@ -114,14 +114,10 @@ public class CdiObjectFactory extends ObjectFactory {
|
||||
bm = lookup(initialContext, CDI_JNDIKEY_BEANMANAGER_COMP_ENV);
|
||||
}
|
||||
if (bm == null) {
|
||||
if (LOG.isErrorEnabled()) {
|
||||
LOG.error("[findBeanManager]: Could not find BeanManager instance for any given JNDI key, giving up");
|
||||
}
|
||||
LOG.error("[findBeanManager]: Could not find BeanManager instance for any given JNDI key, giving up");
|
||||
}
|
||||
} catch ( NamingException e ) {
|
||||
if (LOG.isErrorEnabled()) {
|
||||
LOG.error("[findBeanManager]: Unable to get InitialContext for BeanManager lookup", e);
|
||||
}
|
||||
LOG.error("[findBeanManager]: Unable to get InitialContext for BeanManager lookup", e);
|
||||
}
|
||||
return bm;
|
||||
}
|
||||
@@ -135,16 +131,12 @@ public class CdiObjectFactory extends ObjectFactory {
|
||||
* @return the BeanManager, if found; <tt>null</tt> if not found or {@link javax.naming.NamingException} was thrown.
|
||||
*/
|
||||
protected BeanManager lookup( Context context, String jndiKeyToCheck ) {
|
||||
if (LOG.isInfoEnabled()) {
|
||||
LOG.info("[lookup]: Checking for BeanManager under JNDI key " + jndiKeyToCheck);
|
||||
}
|
||||
LOG.info("[lookup]: Checking for BeanManager under JNDI key {}", jndiKeyToCheck);
|
||||
BeanManager result = null;
|
||||
try {
|
||||
result = (BeanManager) context.lookup(jndiKeyToCheck);
|
||||
} catch ( NamingException e ) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("[lookup]: BeanManager lookup failed for JNDI key " + jndiKeyToCheck, e);
|
||||
}
|
||||
LOG.debug("[lookup]: BeanManager lookup failed for JNDI key {}", jndiKeyToCheck, e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ package org.apache.struts2.convention;
|
||||
public interface ActionConfigBuilder {
|
||||
/**
|
||||
* Builds all the action configurations and stores them into the XWork configuration instance
|
||||
* via XWork dependency injetion.
|
||||
* via XWork dependency injection.
|
||||
*/
|
||||
void buildActionConfigs();
|
||||
|
||||
|
||||
+8
-6
@@ -23,13 +23,14 @@ package org.apache.struts2.convention;
|
||||
import com.opensymphony.xwork2.config.Configuration;
|
||||
import com.opensymphony.xwork2.config.ConfigurationException;
|
||||
import com.opensymphony.xwork2.config.ConfigurationProvider;
|
||||
import com.opensymphony.xwork2.inject.Container;
|
||||
import com.opensymphony.xwork2.inject.ContainerBuilder;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.inject.Container;
|
||||
import com.opensymphony.xwork2.util.location.LocatableProperties;
|
||||
import org.apache.struts2.dispatcher.DispatcherListener;
|
||||
import org.apache.struts2.dispatcher.Dispatcher;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.struts2.StrutsConstants;
|
||||
import org.apache.struts2.dispatcher.Dispatcher;
|
||||
import org.apache.struts2.dispatcher.DispatcherListener;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -49,20 +50,21 @@ public class ClasspathConfigurationProvider implements ConfigurationProvider, Di
|
||||
|
||||
@Inject(StrutsConstants.STRUTS_DEVMODE)
|
||||
public void setDevMode(String mode) {
|
||||
this.devMode = "true".equals(mode);
|
||||
this.devMode = BooleanUtils.toBoolean(mode);
|
||||
}
|
||||
|
||||
@Inject("struts.convention.classes.reload")
|
||||
public void setReload(String reload) {
|
||||
this.reload = "true".equals(reload);
|
||||
this.reload = BooleanUtils.toBoolean(reload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Not used.
|
||||
*/
|
||||
public void destroy() {
|
||||
if (this.listeningToDispatcher)
|
||||
if (this.listeningToDispatcher) {
|
||||
Dispatcher.removeDispatcherListener(this);
|
||||
}
|
||||
actionConfigBuilder.destroy();
|
||||
}
|
||||
|
||||
|
||||
+18
-42
@@ -20,34 +20,21 @@
|
||||
*/
|
||||
package org.apache.struts2.convention;
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import com.opensymphony.xwork2.ObjectFactory;
|
||||
import com.opensymphony.xwork2.Result;
|
||||
import com.opensymphony.xwork2.UnknownHandler;
|
||||
import com.opensymphony.xwork2.XWorkException;
|
||||
import com.opensymphony.xwork2.*;
|
||||
import com.opensymphony.xwork2.config.Configuration;
|
||||
import com.opensymphony.xwork2.config.ConfigurationException;
|
||||
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.entities.*;
|
||||
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 org.apache.logging.log4j.Logger;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
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;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -172,7 +159,7 @@ public class ConventionUnknownHandler implements UnknownHandler {
|
||||
|
||||
// try to find index action in current namespace or in default one
|
||||
if (actionConfig == null) {
|
||||
LOG.trace("Looking for action named [index] in namespace [#0] or in default namespace", namespace);
|
||||
LOG.trace("Looking for action named [index] in namespace [{}] or in default namespace", namespace);
|
||||
actionConfig = configuration.getRuntimeConfiguration().getActionConfig(namespace, "index");
|
||||
}
|
||||
}
|
||||
@@ -197,9 +184,7 @@ public class ConventionUnknownHandler implements UnknownHandler {
|
||||
return new Resource(canonicalPath, ext);
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
if (LOG.isErrorEnabled()) {
|
||||
LOG.error("Unable to parse path to the web application resource {} skipping...", canonicalPath);
|
||||
}
|
||||
LOG.error("Unable to parse path to the web application resource {} skipping...", canonicalPath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,8 +200,8 @@ public class ConventionUnknownHandler implements UnknownHandler {
|
||||
}
|
||||
|
||||
protected ActionConfig buildActionConfig(String path, ResultTypeConfig resultTypeConfig) {
|
||||
Map<String, ResultConfig> results = new HashMap<String, ResultConfig>();
|
||||
HashMap<String, String> params = new HashMap<String, String>();
|
||||
Map<String, ResultConfig> results = new HashMap<>();
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
if (resultTypeConfig.getParams() != null) {
|
||||
params.putAll(resultTypeConfig.getParams());
|
||||
}
|
||||
@@ -240,7 +225,7 @@ public class ConventionUnknownHandler implements UnknownHandler {
|
||||
if (LOG.isTraceEnabled()) {
|
||||
String fqan = ns + "/" + actionName;
|
||||
LOG.trace("Trying to locate the correct result for the FQ action [{}]"
|
||||
+ " with an file extension of [#1] in the directory [{}] " + "and a result code of [{}]",
|
||||
+ " with an file extension of [{}] in the directory [{}] " + "and a result code of [{}]",
|
||||
fqan, ext, pathPrefix, resultCode);
|
||||
}
|
||||
|
||||
@@ -306,10 +291,7 @@ public class ConventionUnknownHandler implements UnknownHandler {
|
||||
String chainedTo = actionName + nameSeparator + resultCode;
|
||||
ActionConfig chainedToConfig = pkg.getActionConfigs().get(chainedTo);
|
||||
if (chainedToConfig != null) {
|
||||
if (LOG.isTraceEnabled()) {
|
||||
LOG.trace("Action [{}] used as chain result for [{}] and result [{}]", chainedTo, actionName, resultCode);
|
||||
}
|
||||
|
||||
LOG.trace("Action [{}] used as chain result for [{}] and result [{}]", chainedTo, actionName, resultCode);
|
||||
ResultTypeConfig chainResultType = pkg.getAllResultTypeConfigs().get("chain");
|
||||
result = buildResult(chainedTo, resultCode, chainResultType, actionContext);
|
||||
}
|
||||
@@ -321,28 +303,22 @@ public class ConventionUnknownHandler implements UnknownHandler {
|
||||
protected Result findResult(String path, String resultCode, String ext, ActionContext actionContext,
|
||||
Map<String, ResultTypeConfig> resultsByExtension) {
|
||||
try {
|
||||
boolean traceEnabled = LOG.isTraceEnabled();
|
||||
if (traceEnabled)
|
||||
LOG.trace("Checking ServletContext for {}", path);
|
||||
LOG.trace("Checking ServletContext for {}", path);
|
||||
|
||||
if (servletContext.getResource(path) != null) {
|
||||
if (traceEnabled)
|
||||
LOG.trace("Found");
|
||||
LOG.trace("Found");
|
||||
return buildResult(path, resultCode, resultsByExtension.get(ext), actionContext);
|
||||
}
|
||||
|
||||
if (traceEnabled)
|
||||
LOG.trace("Checking ClasLoader for {}", path);
|
||||
LOG.trace("Checking ClassLoader for {}", path);
|
||||
|
||||
String classLoaderPath = path.startsWith("/") ? path.substring(1, path.length()) : path;
|
||||
if (ClassLoaderUtil.getResource(classLoaderPath, getClass()) != null) {
|
||||
if (traceEnabled)
|
||||
LOG.trace("Found");
|
||||
LOG.trace("Found");
|
||||
return buildResult(path, resultCode, resultsByExtension.get(ext), actionContext);
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
if (LOG.isErrorEnabled())
|
||||
LOG.error("Unable to parse template path: {} skipping...", path);
|
||||
LOG.error("Unable to parse template path: {} skipping...", path);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -351,7 +327,7 @@ public class ConventionUnknownHandler implements UnknownHandler {
|
||||
protected Result buildResult(String path, String resultCode, ResultTypeConfig config, ActionContext invocationContext) {
|
||||
String resultClass = config.getClassName();
|
||||
|
||||
Map<String, String> params = new LinkedHashMap<String, String>();
|
||||
Map<String, String> params = new LinkedHashMap<>();
|
||||
if (config.getParams() != null) {
|
||||
params.putAll(config.getParams());
|
||||
}
|
||||
@@ -389,7 +365,7 @@ public class ConventionUnknownHandler implements UnknownHandler {
|
||||
finalPrefix += "/";
|
||||
}
|
||||
|
||||
if (namespace == null || "/".equals(namespace)) {
|
||||
if (StringUtils.equals(namespace,"/" )) {
|
||||
namespace = "";
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -107,7 +107,7 @@ public class ConventionsServiceImpl implements ConventionsService {
|
||||
public Map<String, ResultTypeConfig> getResultTypesByExtension(PackageConfig packageConfig) {
|
||||
Map<String, ResultTypeConfig> results = packageConfig.getAllResultTypeConfigs();
|
||||
|
||||
Map<String, ResultTypeConfig> resultsByExtension = new HashMap<String, ResultTypeConfig>();
|
||||
Map<String, ResultTypeConfig> resultsByExtension = new HashMap<>();
|
||||
resultsByExtension.put("jsp", results.get("dispatcher"));
|
||||
resultsByExtension.put("jspf", results.get("dispatcher"));
|
||||
resultsByExtension.put("jspx", results.get("dispatcher"));
|
||||
|
||||
+9
-17
@@ -27,8 +27,8 @@ import com.opensymphony.xwork2.config.entities.PackageConfig;
|
||||
import com.opensymphony.xwork2.config.providers.InterceptorBuilder;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.util.AnnotationUtils;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.struts2.convention.annotation.Action;
|
||||
import org.apache.struts2.convention.annotation.InterceptorRef;
|
||||
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
||||
@@ -50,7 +50,7 @@ public class DefaultInterceptorMapBuilder implements InterceptorMapBuilder {
|
||||
|
||||
public List<InterceptorMapping> build(Class<?> actionClass, PackageConfig.Builder builder,
|
||||
String actionName, Action annotation) {
|
||||
List<InterceptorMapping> interceptorList = new ArrayList<InterceptorMapping>(
|
||||
List<InterceptorMapping> interceptorList = new ArrayList<>(
|
||||
10);
|
||||
|
||||
//from @InterceptorRefs annotation
|
||||
@@ -75,27 +75,19 @@ public class DefaultInterceptorMapBuilder implements InterceptorMapBuilder {
|
||||
}
|
||||
|
||||
protected List<InterceptorMapping> build(InterceptorRef[] interceptors, String actionName, PackageConfig.Builder builder) {
|
||||
List<InterceptorMapping> interceptorList = new ArrayList<InterceptorMapping>(
|
||||
10);
|
||||
List<InterceptorMapping> interceptorList = new ArrayList<>(10);
|
||||
for (InterceptorRef interceptor : interceptors) {
|
||||
if (LOG.isTraceEnabled())
|
||||
LOG.trace("Adding interceptor [{}] to [{}]",
|
||||
interceptor.value(), actionName);
|
||||
Map<String, String> params = StringTools.createParameterMap(interceptor
|
||||
.params());
|
||||
interceptorList.addAll(buildInterceptorList(builder,
|
||||
interceptor, params));
|
||||
LOG.trace("Adding interceptor [{}] to [{}]", interceptor.value(), actionName);
|
||||
Map<String, String> params = StringTools.createParameterMap(interceptor.params());
|
||||
interceptorList.addAll(buildInterceptorList(builder, interceptor, params));
|
||||
}
|
||||
|
||||
return interceptorList;
|
||||
}
|
||||
|
||||
protected List<InterceptorMapping> buildInterceptorList(
|
||||
PackageConfig.Builder builder, InterceptorRef ref, Map params) {
|
||||
return InterceptorBuilder.constructInterceptorReference(builder, ref
|
||||
.value(), params, builder.build().getLocation(),
|
||||
configuration.getContainer().getInstance(
|
||||
ObjectFactory.class));
|
||||
protected List<InterceptorMapping> buildInterceptorList(PackageConfig.Builder builder, InterceptorRef ref, Map params) {
|
||||
return InterceptorBuilder.constructInterceptorReference(builder, ref.value(), params, builder.build().getLocation(),
|
||||
configuration.getContainer().getInstance(ObjectFactory.class));
|
||||
}
|
||||
|
||||
@Inject
|
||||
|
||||
+7
-11
@@ -32,21 +32,17 @@ import com.opensymphony.xwork2.util.finder.ClassLoaderInterface;
|
||||
import com.opensymphony.xwork2.util.finder.ClassLoaderInterfaceDelegate;
|
||||
import com.opensymphony.xwork2.util.finder.ResourceFinder;
|
||||
import com.opensymphony.xwork2.util.finder.Test;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.struts2.convention.annotation.Result;
|
||||
import org.apache.struts2.convention.annotation.Results;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -135,7 +131,7 @@ public class DefaultResultMapBuilder implements ResultMapBuilder {
|
||||
public DefaultResultMapBuilder(ServletContext servletContext, Container container,
|
||||
@Inject("struts.convention.relative.result.types") String relativeResultTypes) {
|
||||
this.servletContext = servletContext;
|
||||
this.relativeResultTypes = new HashSet<String>(Arrays.asList(relativeResultTypes.split("\\s*[,]\\s*")));
|
||||
this.relativeResultTypes = new HashSet<>(Arrays.asList(relativeResultTypes.split("\\s*[,]\\s*")));
|
||||
this.conventionsService = container.getInstance(ConventionsService.class, container.getInstance(String.class, ConventionConstants.CONVENTION_CONVENTIONS_SERVICE));
|
||||
}
|
||||
|
||||
@@ -184,7 +180,7 @@ public class DefaultResultMapBuilder implements ResultMapBuilder {
|
||||
String resultPrefix = defaultResultPath + actionName;
|
||||
|
||||
//results from files
|
||||
Map<String, ResultConfig> results = new HashMap<String, ResultConfig>();
|
||||
Map<String, ResultConfig> results = new HashMap<>();
|
||||
Map<String, ResultTypeConfig> resultsByExtension = conventionsService.getResultTypesByExtension(packageConfig);
|
||||
createFromResources(actionClass, results, defaultResultPath, resultPrefix, actionName,
|
||||
packageConfig, resultsByExtension);
|
||||
@@ -318,7 +314,7 @@ public class DefaultResultMapBuilder implements ResultMapBuilder {
|
||||
if (ctx != null)
|
||||
classLoaderInterface = (ClassLoaderInterface) ctx.get(ClassLoaderInterface.CLASS_LOADER_INTERFACE);
|
||||
|
||||
return (ClassLoaderInterface) ObjectUtils.defaultIfNull(classLoaderInterface, new ClassLoaderInterfaceDelegate(Thread.currentThread().getContextClassLoader()));
|
||||
return ObjectUtils.defaultIfNull(classLoaderInterface, new ClassLoaderInterfaceDelegate(Thread.currentThread().getContextClassLoader()));
|
||||
|
||||
}
|
||||
|
||||
@@ -448,7 +444,7 @@ public class DefaultResultMapBuilder implements ResultMapBuilder {
|
||||
}
|
||||
|
||||
// Add the default parameters for the result type config (if any)
|
||||
HashMap<String, String> params = new HashMap<String, String>();
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
if (resultTypeConfig.getParams() != null) {
|
||||
params.putAll(resultTypeConfig.getParams());
|
||||
}
|
||||
|
||||
+63
-90
@@ -26,52 +26,28 @@ import com.opensymphony.xwork2.FileManagerFactory;
|
||||
import com.opensymphony.xwork2.ObjectFactory;
|
||||
import com.opensymphony.xwork2.config.Configuration;
|
||||
import com.opensymphony.xwork2.config.ConfigurationException;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.config.entities.ExceptionMappingConfig;
|
||||
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.*;
|
||||
import com.opensymphony.xwork2.inject.Container;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.util.AnnotationUtils;
|
||||
import com.opensymphony.xwork2.util.TextParseUtil;
|
||||
import com.opensymphony.xwork2.util.WildcardHelper;
|
||||
import com.opensymphony.xwork2.util.classloader.ReloadingClassLoader;
|
||||
import com.opensymphony.xwork2.util.finder.ClassFinder;
|
||||
import com.opensymphony.xwork2.util.finder.ClassFinderFactory;
|
||||
import com.opensymphony.xwork2.util.finder.DefaultClassFinder;
|
||||
import com.opensymphony.xwork2.util.finder.ClassLoaderInterface;
|
||||
import com.opensymphony.xwork2.util.finder.ClassLoaderInterfaceDelegate;
|
||||
import com.opensymphony.xwork2.util.finder.Test;
|
||||
import com.opensymphony.xwork2.util.finder.UrlSet;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import com.opensymphony.xwork2.util.finder.*;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.struts2.StrutsConstants;
|
||||
import org.apache.struts2.StrutsException;
|
||||
import org.apache.struts2.convention.annotation.Action;
|
||||
import org.apache.struts2.convention.annotation.Actions;
|
||||
import org.apache.struts2.convention.annotation.DefaultInterceptorRef;
|
||||
import org.apache.struts2.convention.annotation.ExceptionMapping;
|
||||
import org.apache.struts2.convention.annotation.ExceptionMappings;
|
||||
import org.apache.struts2.convention.annotation.Namespace;
|
||||
import org.apache.struts2.convention.annotation.Namespaces;
|
||||
import org.apache.struts2.convention.annotation.ParentPackage;
|
||||
import org.apache.struts2.convention.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
@@ -101,7 +77,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
private String actionSuffix = "Action";
|
||||
private boolean checkImplementsAction = true;
|
||||
private boolean mapAllMatches = false;
|
||||
private Set<String> loadedFileUrls = new HashSet<String>();
|
||||
private Set<String> loadedFileUrls = new HashSet<>();
|
||||
private boolean devMode;
|
||||
private ReloadingClassLoader reloadingClassLoader;
|
||||
private boolean reload;
|
||||
@@ -151,7 +127,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
|
||||
@Inject(StrutsConstants.STRUTS_DEVMODE)
|
||||
public void setDevMode(String mode) {
|
||||
this.devMode = "true".equals(mode);
|
||||
this.devMode = BooleanUtils.toBoolean(mode);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,13 +136,13 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
*/
|
||||
@Inject("struts.convention.classes.reload")
|
||||
public void setReload(String reload) {
|
||||
this.reload = "true".equals(reload);
|
||||
this.reload = BooleanUtils.toBoolean(reload);
|
||||
}
|
||||
|
||||
|
||||
@Inject(StrutsConstants.STRUTS_ENABLE_SLASHES_IN_ACTION_NAMES)
|
||||
public void setSlashesInActionNames(String slashesInActionNames) {
|
||||
this.slashesInActionNames = "true".equals(slashesInActionNames);
|
||||
this.slashesInActionNames = BooleanUtils.toBoolean(slashesInActionNames);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,7 +150,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
*/
|
||||
@Inject("struts.convention.exclude.parentClassLoader")
|
||||
public void setExcludeParentClassLoader(String exclude) {
|
||||
this.excludeParentClassLoader = "true".equals(exclude);
|
||||
this.excludeParentClassLoader = BooleanUtils.toBoolean(exclude);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,7 +159,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
*/
|
||||
@Inject("struts.convention.action.alwaysMapExecute")
|
||||
public void setAlwaysMapExecute(String alwaysMapExecute) {
|
||||
this.alwaysMapExecute = "true".equals(alwaysMapExecute);
|
||||
this.alwaysMapExecute = BooleanUtils.toBoolean(alwaysMapExecute);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -202,7 +178,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
*/
|
||||
@Inject(value = "struts.convention.action.disableScanning", required = false)
|
||||
public void setDisableActionScanning(String disableActionScanning) {
|
||||
this.disableActionScanning = "true".equals(disableActionScanning);
|
||||
this.disableActionScanning = BooleanUtils.toBoolean(disableActionScanning);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -219,7 +195,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
*/
|
||||
@Inject(value = "struts.convention.package.locators.disable", required = false)
|
||||
public void setDisablePackageLocatorsScanning(String disablePackageLocatorsScanning) {
|
||||
this.disablePackageLocatorsScanning = "true".equals(disablePackageLocatorsScanning);
|
||||
this.disablePackageLocatorsScanning = BooleanUtils.toBoolean(disablePackageLocatorsScanning);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -239,7 +215,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
*/
|
||||
@Inject(value = "struts.convention.action.checkImplementsAction", required = false)
|
||||
public void setCheckImplementsAction(String checkImplementsAction) {
|
||||
this.checkImplementsAction = "true".equals(checkImplementsAction);
|
||||
this.checkImplementsAction = BooleanUtils.toBoolean(checkImplementsAction);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -288,7 +264,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
*/
|
||||
@Inject(value = "struts.convention.action.mapAllMatches", required = false)
|
||||
public void setMapAllMatches(String mapAllMatches) {
|
||||
this.mapAllMatches = "true".equals(mapAllMatches);
|
||||
this.mapAllMatches = BooleanUtils.toBoolean(mapAllMatches);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -297,7 +273,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
*/
|
||||
@Inject(value = "struts.convention.action.eagerLoading", required = false)
|
||||
public void setEagerLoading(String eagerLoading) {
|
||||
this.eagerLoading = "true".equals(eagerLoading);
|
||||
this.eagerLoading = BooleanUtils.toBoolean(eagerLoading);
|
||||
}
|
||||
|
||||
@Inject
|
||||
@@ -343,12 +319,15 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
|
||||
if (LOG.isTraceEnabled()) {
|
||||
LOG.trace("Loading action configurations");
|
||||
if (actionPackages != null)
|
||||
LOG.trace("Actions being loaded from action packages " + Arrays.asList(actionPackages));
|
||||
if (packageLocators != null)
|
||||
LOG.trace("Actions being loaded using package locators " + Arrays.asList(packageLocators));
|
||||
if (excludePackages != null)
|
||||
LOG.trace("Excluding actions from packages " + Arrays.asList(excludePackages));
|
||||
if (actionPackages != null) {
|
||||
LOG.trace("Actions being loaded from action packages: {}", actionPackages);
|
||||
}
|
||||
if (packageLocators != null) {
|
||||
LOG.trace("Actions being loaded using package locator's: {}", packageLocators);
|
||||
}
|
||||
if (excludePackages != null) {
|
||||
LOG.trace("Excluding actions from packages: {}", excludePackages);
|
||||
}
|
||||
}
|
||||
|
||||
Set<Class> classes = findActions();
|
||||
@@ -357,8 +336,9 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
}
|
||||
|
||||
protected ClassLoaderInterface getClassLoaderInterface() {
|
||||
if (isReloadEnabled())
|
||||
if (isReloadEnabled()) {
|
||||
return new ClassLoaderInterfaceDelegate(this.reloadingClassLoader);
|
||||
}
|
||||
else {
|
||||
/*
|
||||
if there is a ClassLoaderInterface in the context, use it, otherwise
|
||||
@@ -370,9 +350,9 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
*/
|
||||
ClassLoaderInterface classLoaderInterface = null;
|
||||
ActionContext ctx = ActionContext.getContext();
|
||||
if (ctx != null)
|
||||
if (ctx != null) {
|
||||
classLoaderInterface = (ClassLoaderInterface) ctx.get(ClassLoaderInterface.CLASS_LOADER_INTERFACE);
|
||||
|
||||
}
|
||||
return ObjectUtils.defaultIfNull(classLoaderInterface, new ClassLoaderInterfaceDelegate(getClassLoader()));
|
||||
}
|
||||
}
|
||||
@@ -383,7 +363,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Set<Class> findActions() {
|
||||
Set<Class> classes = new HashSet<Class>();
|
||||
Set<Class> classes = new HashSet<>();
|
||||
try {
|
||||
if (actionPackages != null || (packageLocators != null && !disablePackageLocatorsScanning)) {
|
||||
|
||||
@@ -400,8 +380,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
classes.addAll(finder.findClasses(test));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
if (LOG.isErrorEnabled())
|
||||
LOG.error("Unable to scan named packages", ex);
|
||||
LOG.error("Unable to scan named packages", ex);
|
||||
}
|
||||
|
||||
return classes;
|
||||
@@ -418,7 +397,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
}
|
||||
|
||||
private List<URL> readUrls() throws IOException {
|
||||
List<URL> resourceUrls = new ArrayList<URL>();
|
||||
List<URL> resourceUrls = new ArrayList<>();
|
||||
// Usually the "classes" dir.
|
||||
ArrayList<URL> classesList = Collections.list(getClassLoaderInterface().getResources(""));
|
||||
for (URL url : classesList) {
|
||||
@@ -437,7 +416,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
//exclude parent of classloaders
|
||||
ClassLoaderInterface parent = classLoaderInterface.getParent();
|
||||
//if reload is enabled, we need to step up one level, otherwise the UrlSet will be empty
|
||||
//this happens because the parent of the realoding class loader is the web app classloader
|
||||
//this happens because the parent of the reloading class loader is the web app classloader
|
||||
if (parent != null && isReloadEnabled())
|
||||
parent = parent.getParent();
|
||||
|
||||
@@ -450,8 +429,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
urlSet = urlSet.exclude(new ClassLoaderInterfaceDelegate(systemClassLoader.getParent()));
|
||||
|
||||
} catch (SecurityException e) {
|
||||
if (LOG.isWarnEnabled())
|
||||
LOG.warn("Could not get the system classloader due to security constraints, there may be improper urls left to scan");
|
||||
LOG.warn("Could not get the system classloader due to security constraints, there may be improper urls left to scan");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -469,8 +447,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
urlSet = urlSet.excludeJavaHome();
|
||||
} catch (NullPointerException e) {
|
||||
// This happens in GAE since the sandbox contains no java.home directory
|
||||
if (LOG.isWarnEnabled())
|
||||
LOG.warn("Could not exclude JAVA_HOME, is this a sandbox jvm?");
|
||||
LOG.warn("Could not exclude JAVA_HOME, is this a sandbox jvm?");
|
||||
}
|
||||
urlSet = urlSet.excludePaths(System.getProperty("sun.boot.class.path", ""));
|
||||
urlSet = urlSet.exclude(".*/JavaVM.framework/.*");
|
||||
@@ -482,12 +459,12 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
LOG.debug("jar urls regexes were specified: {}", Arrays.asList(includeJars));
|
||||
}
|
||||
List<URL> rawIncludedUrls = urlSet.getUrls();
|
||||
Set<URL> includeUrls = new HashSet<URL>();
|
||||
Set<URL> includeUrls = new HashSet<>();
|
||||
boolean[] patternUsed = new boolean[includeJars.length];
|
||||
|
||||
for (URL url : rawIncludedUrls) {
|
||||
if (fileProtocols.contains(url.getProtocol())) {
|
||||
//it is a jar file, make sure it macthes at least a url regex
|
||||
//it is a jar file, make sure it matches at least a url regex
|
||||
for (int i = 0; i < includeJars.length; i++) {
|
||||
String includeJar = includeJars[i];
|
||||
if (Pattern.matches(includeJar, url.toExternalForm())) {
|
||||
@@ -544,7 +521,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
WildcardHelper wildcardHelper = new WildcardHelper();
|
||||
|
||||
//we really don't care about the results, just the boolean
|
||||
Map<String, String> matchMap = new HashMap<String, String>();
|
||||
Map<String, String> matchMap = new HashMap<>();
|
||||
|
||||
for(String packageExclude : excludePackages) {
|
||||
int[] packagePattern = wildcardHelper.compilePattern(packageExclude);
|
||||
@@ -566,9 +543,9 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
if (actionPackages != null) {
|
||||
for (String packageName : actionPackages) {
|
||||
String strictPackageName = packageName + ".";
|
||||
if (classPackageName.equals(packageName)
|
||||
|| classPackageName.startsWith(strictPackageName))
|
||||
if (classPackageName.equals(packageName) || classPackageName.startsWith(strictPackageName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -587,8 +564,9 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
for (String packageLocator : packageLocators) {
|
||||
String[] splitted = classPackageName.split("\\.");
|
||||
|
||||
if (StringTools.contains(splitted, packageLocator, false))
|
||||
if (StringTools.contains(splitted, packageLocator, false)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -638,7 +616,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
try {
|
||||
return inPackage && (nameMatches || (checkImplementsAction && com.opensymphony.xwork2.Action.class.isAssignableFrom(classInfo.get())));
|
||||
} catch (ClassNotFoundException ex) {
|
||||
LOG.error("Unable to load class [{}]", ex, classInfo.getName());
|
||||
LOG.error("Unable to load class [{}]", classInfo.getName(), ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -647,7 +625,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void buildConfiguration(Set<Class> classes) {
|
||||
Map<String, PackageConfig.Builder> packageConfigs = new HashMap<String, PackageConfig.Builder>();
|
||||
Map<String, PackageConfig.Builder> packageConfigs = new HashMap<>();
|
||||
|
||||
for (Class<?> actionClass : classes) {
|
||||
Actions actionsAnnotation = actionClass.getAnnotation(Actions.class);
|
||||
@@ -664,16 +642,14 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
try {
|
||||
objectFactory.getClassInstance(actionClass.getName());
|
||||
} catch (ClassNotFoundException e) {
|
||||
LOG.error("Object Factory was unable to load class [{}]", e, actionClass.getName());
|
||||
LOG.error("Object Factory was unable to load class [{}]", actionClass.getName(), e);
|
||||
throw new StrutsException("Object Factory was unable to load class " + actionClass.getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
// Determine the action package
|
||||
String actionPackage = actionClass.getPackage().getName();
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Processing class [{}] in package [{}]", actionClass.getName(), actionPackage);
|
||||
}
|
||||
LOG.debug("Processing class [{}] in package [{}]", actionClass.getName(), actionPackage);
|
||||
|
||||
// Determine the default namespace and action name
|
||||
List<String> namespaces = determineActionNamespace(actionClass);
|
||||
@@ -685,7 +661,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
// Verify that the annotations have no errors and also determine if the default action
|
||||
// configuration should still be built or not.
|
||||
Map<String, List<Action>> map = getActionAnnotations(actionClass);
|
||||
Set<String> actionNames = new HashSet<String>();
|
||||
Set<String> actionNames = new HashSet<>();
|
||||
boolean hasDefaultMethod = ReflectionTools.containsMethod(actionClass, DEFAULT_METHOD);
|
||||
if (!map.containsKey(DEFAULT_METHOD)
|
||||
&& hasDefaultMethod
|
||||
@@ -781,7 +757,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
* @return The namespace or an empty string.
|
||||
*/
|
||||
protected List<String> determineActionNamespace(Class<?> actionClass) {
|
||||
List<String> namespaces = new ArrayList<String>();
|
||||
List<String> namespaces = new ArrayList<>();
|
||||
|
||||
// Check if there is a class or package level annotation for the namespace
|
||||
//single namespace
|
||||
@@ -803,8 +779,9 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
LOG.trace("Using non-default action namespaces from Namespaces annotation of [{}]", sb.toString());
|
||||
}
|
||||
|
||||
for (Namespace namespace : namespacesAnnotation.value())
|
||||
for (Namespace namespace : namespacesAnnotation.value()) {
|
||||
namespaces.add(namespace.value());
|
||||
}
|
||||
}
|
||||
|
||||
//don't use default if there are annotations
|
||||
@@ -869,7 +846,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
*/
|
||||
protected Map<String, List<Action>> getActionAnnotations(Class<?> actionClass) {
|
||||
Method[] methods = actionClass.getMethods();
|
||||
Map<String, List<Action>> map = new HashMap<String, List<Action>>();
|
||||
Map<String, List<Action>> map = new HashMap<>();
|
||||
for (Method method : methods) {
|
||||
Actions actionsAnnotation = method.getAnnotation(Actions.class);
|
||||
if (actionsAnnotation != null) {
|
||||
@@ -894,13 +871,12 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
protected List<Action> checkActionsAnnotation(Actions actionsAnnotation) {
|
||||
Action[] actionArray = actionsAnnotation.value();
|
||||
boolean valuelessSeen = false;
|
||||
List<Action> actions = new ArrayList<Action>();
|
||||
List<Action> actions = new ArrayList<>();
|
||||
for (Action ann : actionArray) {
|
||||
if (ann.value().equals(Action.DEFAULT_VALUE) && !valuelessSeen) {
|
||||
valuelessSeen = true;
|
||||
} else if (ann.value().equals(Action.DEFAULT_VALUE)) {
|
||||
throw new ConfigurationException("You may only add a single Action " +
|
||||
"annotation that has no value parameter.");
|
||||
throw new ConfigurationException("You may only add a single Action annotation that has no value parameter.");
|
||||
}
|
||||
|
||||
actions.add(ann);
|
||||
@@ -980,7 +956,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
}
|
||||
|
||||
protected List<ExceptionMappingConfig> buildExceptionMappings(ExceptionMapping[] exceptions, String actionName) {
|
||||
List<ExceptionMappingConfig> exceptionMappings = new ArrayList<ExceptionMappingConfig>();
|
||||
List<ExceptionMappingConfig> exceptionMappings = new ArrayList<>();
|
||||
|
||||
for (ExceptionMapping exceptionMapping : exceptions) {
|
||||
LOG.trace("Mapping exception [{}] to result [{}] for action [{}]", exceptionMapping.exception(),
|
||||
@@ -1062,7 +1038,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
* @param packageConfigs Used to store the actions.
|
||||
*/
|
||||
protected void buildIndexActions(Map<String, PackageConfig.Builder> packageConfigs) {
|
||||
Map<String, PackageConfig.Builder> byNamespace = new HashMap<String, PackageConfig.Builder>();
|
||||
Map<String, PackageConfig.Builder> byNamespace = new HashMap<>();
|
||||
Collection<PackageConfig.Builder> values = packageConfigs.values();
|
||||
for (PackageConfig.Builder packageConfig : values) {
|
||||
byNamespace.put(packageConfig.getNamespace(), packageConfig);
|
||||
@@ -1095,18 +1071,15 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
if (parent.build().getAllActionConfigs().get(parentAction) == null) {
|
||||
parent.addActionConfig(parentAction, indexActionConfig);
|
||||
}
|
||||
} else if (LOG.isTraceEnabled()) {
|
||||
LOG.trace("The parent namespace [{}] already contains " +
|
||||
"an action [{}]", parentNamespace, parentAction);
|
||||
} else {
|
||||
LOG.trace("The parent namespace [{}] already contains an action [{}]", parentNamespace, parentAction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Step #3
|
||||
if (pkgConfig.build().getAllActionConfigs().get("") == null) {
|
||||
LOG.trace("Creating index ActionConfig with an action name of [] for the action " +
|
||||
"class [{}]", indexActionConfig.getClassName());
|
||||
|
||||
LOG.trace("Creating index ActionConfig with an action name of [] for the action class [{}]", indexActionConfig.getClassName());
|
||||
pkgConfig.addActionConfig("", indexActionConfig);
|
||||
}
|
||||
}
|
||||
@@ -1120,15 +1093,15 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
if (devMode && reload) {
|
||||
for (String url : loadedFileUrls) {
|
||||
if (fileManager.fileNeedsReloading(url)) {
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("File [{}] changed, configuration will be reloaded", url);
|
||||
LOG.debug("File [{}] changed, configuration will be reloaded", url);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} else
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ package org.apache.struts2.convention;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -34,14 +34,14 @@ public class ReflectionTools {
|
||||
/**
|
||||
* Determines if the class given contains the method.
|
||||
*
|
||||
* @param klass The class to check for the method.
|
||||
* @param clazz The class to check for the method.
|
||||
* @param method The method name.
|
||||
* @param parameterTypes The parameter types of the method.
|
||||
* @return True if the method exists, false if not.
|
||||
*/
|
||||
public static boolean containsMethod(Class<?> klass, String method, Class<?>... parameterTypes) {
|
||||
public static boolean containsMethod(Class<?> clazz, String method, Class<?>... parameterTypes) {
|
||||
try {
|
||||
klass.getMethod(method, parameterTypes);
|
||||
clazz.getMethod(method, parameterTypes);
|
||||
return true;
|
||||
} catch (NoSuchMethodException e) {
|
||||
return false;
|
||||
@@ -51,14 +51,14 @@ public class ReflectionTools {
|
||||
/**
|
||||
* Retrieves the annotation from the given method in the given class.
|
||||
*
|
||||
* @param klass The class.
|
||||
* @param clazz The class.
|
||||
* @param methodName The method.
|
||||
* @param annotationClass The annotation to get.
|
||||
* @return The annotation or null if it doesn't exist.
|
||||
*/
|
||||
public static <T extends Annotation> T getAnnotation(Class<?> klass, String methodName, Class<T> annotationClass) {
|
||||
public static <T extends Annotation> T getAnnotation(Class<?> clazz, String methodName, Class<T> annotationClass) {
|
||||
try {
|
||||
Method method = klass.getMethod(methodName);
|
||||
Method method = clazz.getMethod(methodName);
|
||||
return method.getAnnotation(annotationClass);
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -71,7 +71,7 @@ public class ReflectionTools {
|
||||
* @return hierarchy of classes
|
||||
*/
|
||||
public static List<Class<?>> getClassHierarchy(Class<?> clazz) {
|
||||
List<Class<?>> classes = new ArrayList<Class<?>>();
|
||||
List<Class<?>> classes = new ArrayList<>();
|
||||
while (clazz != null) {
|
||||
classes.add(0, clazz);
|
||||
clazz = clazz.getSuperclass();
|
||||
|
||||
@@ -42,9 +42,9 @@ public class StringTools {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Map<String, String> createParameterMap(String[] parms) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
int subtract = parms.length % 2;
|
||||
public static Map<String, String> createParameterMap(String[] params) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
int subtract = params.length % 2;
|
||||
if (subtract != 0) {
|
||||
throw new ConfigurationException(
|
||||
"'params' is a string array "
|
||||
@@ -53,9 +53,9 @@ public class StringTools {
|
||||
+ " (e.g. params = {\"key\", \"value\"})");
|
||||
}
|
||||
|
||||
for (int i = 0; i < parms.length; i = i + 2) {
|
||||
String key = parms[i];
|
||||
String value = parms[i + 1];
|
||||
for (int i = 0; i < params.length; i = i + 2) {
|
||||
String key = params[i];
|
||||
String value = params[i + 1];
|
||||
map.put(key, value);
|
||||
}
|
||||
|
||||
|
||||
+2
-6
@@ -38,11 +38,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.createNiceMock;
|
||||
import static org.easymock.classextension.EasyMock.createStrictMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.easymock.classextension.EasyMock.verify;
|
||||
import static org.easymock.classextension.EasyMock.*;
|
||||
|
||||
public class ConventionUnknownHandlerTest extends TestCase {
|
||||
|
||||
@@ -161,7 +157,7 @@ public class ConventionUnknownHandlerTest extends TestCase {
|
||||
|
||||
ActionConfig actionConfig = null;
|
||||
expect(service.determineResultPath(actionConfig)).andReturn("");
|
||||
Map<String, ResultTypeConfig> results = new HashMap<String, ResultTypeConfig>();
|
||||
Map<String, ResultTypeConfig> results = new HashMap<>();
|
||||
results.put("jsp", new ResultTypeConfig.Builder("dispatcher", ServletDispatcherResult.class.getName()).build());
|
||||
expect(service.getResultTypesByExtension(packageConfiguration)).andReturn(results);
|
||||
|
||||
|
||||
+14
-23
@@ -26,16 +26,7 @@ import com.opensymphony.xwork2.config.entities.ResultTypeConfig;
|
||||
import com.opensymphony.xwork2.inject.Container;
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.struts2.convention.actions.NoAnnotationAction;
|
||||
import org.apache.struts2.convention.actions.result.ActionLevelResultAction;
|
||||
import org.apache.struts2.convention.actions.result.ActionLevelResultsAction;
|
||||
import org.apache.struts2.convention.actions.result.ClassLevelResultAction;
|
||||
import org.apache.struts2.convention.actions.result.ClassLevelResultsAction;
|
||||
import org.apache.struts2.convention.actions.result.GlobalResultAction;
|
||||
import org.apache.struts2.convention.actions.result.GlobalResultOverrideAction;
|
||||
import org.apache.struts2.convention.actions.result.InheritedResultExtends;
|
||||
import org.apache.struts2.convention.actions.result.InheritedResultsExtends;
|
||||
import org.apache.struts2.convention.actions.result.OverrideInheritedResultExtends;
|
||||
import org.apache.struts2.convention.actions.result.OverrideResultAction;
|
||||
import org.apache.struts2.convention.actions.result.*;
|
||||
import org.apache.struts2.convention.actions.resultpath.ClassLevelResultPathAction;
|
||||
import org.apache.struts2.convention.annotation.Action;
|
||||
import org.apache.struts2.dispatcher.ServletDispatcherResult;
|
||||
@@ -121,7 +112,7 @@ public class DefaultResultMapBuilderTest extends TestCase {
|
||||
ServletContext context = EasyMock.createStrictMock(ServletContext.class);
|
||||
String resultPath = "/WEB-INF/location";
|
||||
// Setup some mock jsps
|
||||
Set<String> resources = new HashSet<String>();
|
||||
Set<String> resources = new HashSet<>();
|
||||
resources.add(resultPath + "/namespace/action.jsp");
|
||||
resources.add(resultPath + "/namespace/action-success.jsp");
|
||||
resources.add(resultPath + "/namespace/action-error.jsp");
|
||||
@@ -179,7 +170,7 @@ public class DefaultResultMapBuilderTest extends TestCase {
|
||||
ServletContext context = EasyMock.createStrictMock(ServletContext.class);
|
||||
|
||||
// Setup some mock jsps
|
||||
Set<String> resources = new HashSet<String>();
|
||||
Set<String> resources = new HashSet<>();
|
||||
resources.add("/WEB-INF/location/namespace/.something");
|
||||
resources.add("/WEB-INF/location/namespace/.somethingelse/");
|
||||
EasyMock.expect(context.getResourcePaths("/WEB-INF/location/namespace/")).andReturn(resources);
|
||||
@@ -199,7 +190,7 @@ public class DefaultResultMapBuilderTest extends TestCase {
|
||||
ServletContext context = EasyMock.createStrictMock(ServletContext.class);
|
||||
|
||||
// Setup some mock jsps
|
||||
Set<String> resources = new HashSet<String>();
|
||||
Set<String> resources = new HashSet<>();
|
||||
resources.add("/WEB-INF/location/namespace/no-annotation.ftl");
|
||||
resources.add("/WEB-INF/location/namespace/no-annotation-success.jsp");
|
||||
resources.add("/WEB-INF/location/namespace/no-annotation-failure.jsp");
|
||||
@@ -233,7 +224,7 @@ public class DefaultResultMapBuilderTest extends TestCase {
|
||||
ServletContext context = EasyMock.createStrictMock(ServletContext.class);
|
||||
|
||||
// Setup some mock jsps
|
||||
Set<String> resources = new HashSet<String>();
|
||||
Set<String> resources = new HashSet<>();
|
||||
resources.add("/WEB-INF/location/namespace/no-annotation/index.ftl");
|
||||
resources.add("/WEB-INF/location/namespace/no-annotation/success.jsp");
|
||||
resources.add("/WEB-INF/location/namespace/no-annotation/failure.jsp");
|
||||
@@ -269,7 +260,7 @@ public class DefaultResultMapBuilderTest extends TestCase {
|
||||
ServletContext context = EasyMock.createStrictMock(ServletContext.class);
|
||||
|
||||
// Setup some mock jsps
|
||||
Set<String> resources = new HashSet<String>();
|
||||
Set<String> resources = new HashSet<>();
|
||||
resources.add("/WEB-INF/location/namespace/no-annotation/.svn");
|
||||
resources.add("/WEB-INF/location/namespace/no-annotation-success.jsp");
|
||||
EasyMock.expect(context.getResourcePaths("/WEB-INF/location/namespace/")).andReturn(resources);
|
||||
@@ -293,7 +284,7 @@ public class DefaultResultMapBuilderTest extends TestCase {
|
||||
ServletContext context = EasyMock.createStrictMock(ServletContext.class);
|
||||
|
||||
// Setup some mock jsps
|
||||
Set<String> resources = new HashSet<String>();
|
||||
Set<String> resources = new HashSet<>();
|
||||
EasyMock.expect(context.getResourcePaths("/WEB-INF/location/namespace/")).andReturn(resources);
|
||||
EasyMock.replay(context);
|
||||
|
||||
@@ -316,7 +307,7 @@ public class DefaultResultMapBuilderTest extends TestCase {
|
||||
ServletContext context = EasyMock.createStrictMock(ServletContext.class);
|
||||
|
||||
// Setup some mock jsps
|
||||
Set<String> resources = new HashSet<String>();
|
||||
Set<String> resources = new HashSet<>();
|
||||
EasyMock.expect(context.getResourcePaths("/WEB-INF/location/namespace/")).andReturn(resources);
|
||||
EasyMock.replay(context);
|
||||
|
||||
@@ -339,7 +330,7 @@ public class DefaultResultMapBuilderTest extends TestCase {
|
||||
ServletContext context = EasyMock.createStrictMock(ServletContext.class);
|
||||
|
||||
// Setup some mock jsps
|
||||
Set<String> resources = new HashSet<String>();
|
||||
Set<String> resources = new HashSet<>();
|
||||
EasyMock.expect(context.getResourcePaths("/WEB-INF/location/namespace/")).andReturn(resources);
|
||||
EasyMock.replay(context);
|
||||
|
||||
@@ -364,7 +355,7 @@ public class DefaultResultMapBuilderTest extends TestCase {
|
||||
ServletContext context = EasyMock.createStrictMock(ServletContext.class);
|
||||
|
||||
// Setup some mock jsps
|
||||
Set<String> resources = new HashSet<String>();
|
||||
Set<String> resources = new HashSet<>();
|
||||
EasyMock.expect(context.getResourcePaths("/WEB-INF/location/namespace/")).andReturn(resources);
|
||||
EasyMock.replay(context);
|
||||
|
||||
@@ -403,7 +394,7 @@ public class DefaultResultMapBuilderTest extends TestCase {
|
||||
ServletContext context = EasyMock.createStrictMock(ServletContext.class);
|
||||
|
||||
// Setup some mock jsps
|
||||
Set<String> resources = new HashSet<String>();
|
||||
Set<String> resources = new HashSet<>();
|
||||
EasyMock.expect(context.getResourcePaths("/WEB-INF/location/namespace/")).andReturn(resources);
|
||||
EasyMock.replay(context);
|
||||
|
||||
@@ -442,7 +433,7 @@ public class DefaultResultMapBuilderTest extends TestCase {
|
||||
ServletContext context = EasyMock.createStrictMock(ServletContext.class);
|
||||
|
||||
// Setup some mock jsps
|
||||
Set<String> resources = new HashSet<String>();
|
||||
Set<String> resources = new HashSet<>();
|
||||
EasyMock.expect(context.getResourcePaths("/WEB-INF/location/namespace/")).andReturn(resources);
|
||||
EasyMock.replay(context);
|
||||
|
||||
@@ -465,7 +456,7 @@ public class DefaultResultMapBuilderTest extends TestCase {
|
||||
ServletContext context = EasyMock.createStrictMock(ServletContext.class);
|
||||
|
||||
// Setup some mock jsps
|
||||
Set<String> resources = new HashSet<String>();
|
||||
Set<String> resources = new HashSet<>();
|
||||
EasyMock.expect(context.getResourcePaths("/WEB-INF/location/namespace/")).andReturn(resources);
|
||||
EasyMock.replay(context);
|
||||
|
||||
@@ -544,7 +535,7 @@ public class DefaultResultMapBuilderTest extends TestCase {
|
||||
ServletContext context = EasyMock.createStrictMock(ServletContext.class);
|
||||
|
||||
// Setup some mock jsps
|
||||
Set<String> resources = new HashSet<String>();
|
||||
Set<String> resources = new HashSet<>();
|
||||
resources.add(resultPath + "/namespace/action.jsp");
|
||||
resources.add(resultPath + "/namespace/action-success.jsp");
|
||||
resources.add(resultPath + "/namespace/action-failure.jsp");
|
||||
|
||||
+9
-45
@@ -20,21 +20,9 @@
|
||||
*/
|
||||
package org.apache.struts2.convention;
|
||||
|
||||
import com.opensymphony.xwork2.ActionChainResult;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.FileManager;
|
||||
import com.opensymphony.xwork2.FileManagerFactory;
|
||||
import com.opensymphony.xwork2.ObjectFactory;
|
||||
import com.opensymphony.xwork2.Result;
|
||||
import com.opensymphony.xwork2.*;
|
||||
import com.opensymphony.xwork2.config.Configuration;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.config.entities.ExceptionMappingConfig;
|
||||
import com.opensymphony.xwork2.config.entities.InterceptorConfig;
|
||||
import com.opensymphony.xwork2.config.entities.InterceptorMapping;
|
||||
import com.opensymphony.xwork2.config.entities.InterceptorStackConfig;
|
||||
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.entities.*;
|
||||
import com.opensymphony.xwork2.config.impl.DefaultConfiguration;
|
||||
import com.opensymphony.xwork2.factory.DefaultInterceptorFactory;
|
||||
import com.opensymphony.xwork2.factory.DefaultResultFactory;
|
||||
@@ -48,16 +36,7 @@ import junit.framework.TestCase;
|
||||
import org.apache.struts2.convention.actions.DefaultResultPathAction;
|
||||
import org.apache.struts2.convention.actions.NoAnnotationAction;
|
||||
import org.apache.struts2.convention.actions.Skip;
|
||||
import org.apache.struts2.convention.actions.action.ActionNameAction;
|
||||
import org.apache.struts2.convention.actions.action.ActionNamesAction;
|
||||
import org.apache.struts2.convention.actions.action.ClassLevelAnnotationAction;
|
||||
import org.apache.struts2.convention.actions.action.ClassLevelAnnotationDefaultMethodAction;
|
||||
import org.apache.struts2.convention.actions.action.ClassLevelAnnotationsAction;
|
||||
import org.apache.struts2.convention.actions.action.ClassLevelAnnotationsDefaultMethodAction;
|
||||
import org.apache.struts2.convention.actions.action.ClassNameAction;
|
||||
import org.apache.struts2.convention.actions.action.SingleActionNameAction;
|
||||
import org.apache.struts2.convention.actions.action.TestAction;
|
||||
import org.apache.struts2.convention.actions.action.TestExtends;
|
||||
import org.apache.struts2.convention.actions.action.*;
|
||||
import org.apache.struts2.convention.actions.chain.ChainedAction;
|
||||
import org.apache.struts2.convention.actions.defaultinterceptor.SingleActionNameAction2;
|
||||
import org.apache.struts2.convention.actions.exception.ExceptionsActionLevelAction;
|
||||
@@ -78,14 +57,7 @@ import org.apache.struts2.convention.actions.parentpackage.ClassLevelParentPacka
|
||||
import org.apache.struts2.convention.actions.parentpackage.PackageLevelParentPackageAction;
|
||||
import org.apache.struts2.convention.actions.parentpackage.sub.ClassLevelParentPackageChildAction;
|
||||
import org.apache.struts2.convention.actions.parentpackage.sub.PackageLevelParentPackageChildAction;
|
||||
import org.apache.struts2.convention.actions.result.ActionLevelResultAction;
|
||||
import org.apache.struts2.convention.actions.result.ActionLevelResultsAction;
|
||||
import org.apache.struts2.convention.actions.result.ClassLevelResultAction;
|
||||
import org.apache.struts2.convention.actions.result.ClassLevelResultsAction;
|
||||
import org.apache.struts2.convention.actions.result.GlobalResultAction;
|
||||
import org.apache.struts2.convention.actions.result.GlobalResultOverrideAction;
|
||||
import org.apache.struts2.convention.actions.result.InheritedResultExtends;
|
||||
import org.apache.struts2.convention.actions.result.OverrideResultAction;
|
||||
import org.apache.struts2.convention.actions.result.*;
|
||||
import org.apache.struts2.convention.actions.resultpath.ClassLevelResultPathAction;
|
||||
import org.apache.struts2.convention.actions.resultpath.PackageLevelResultPathAction;
|
||||
import org.apache.struts2.convention.actions.skip.Index;
|
||||
@@ -98,18 +70,10 @@ import org.easymock.EasyMock;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import static org.apache.struts2.convention.ReflectionTools.getAnnotation;
|
||||
import static org.easymock.EasyMock.checkOrder;
|
||||
import static org.easymock.EasyMock.createStrictMock;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
import static org.easymock.EasyMock.*;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -144,13 +108,13 @@ public class PackageBasedActionConfigBuilderTest extends TestCase {
|
||||
|
||||
private void run(String actionPackages, String packageLocators, String excludePackages) throws MalformedURLException {
|
||||
//setup interceptors
|
||||
List<InterceptorConfig> defaultInterceptors = new ArrayList<InterceptorConfig>();
|
||||
List<InterceptorConfig> defaultInterceptors = new ArrayList<>();
|
||||
defaultInterceptors.add(makeInterceptorConfig("interceptor-1"));
|
||||
defaultInterceptors.add(makeInterceptorConfig("interceptor-2"));
|
||||
defaultInterceptors.add(makeInterceptorConfig("interceptor-3"));
|
||||
|
||||
//setup interceptor stacks
|
||||
List<InterceptorStackConfig> defaultInterceptorStacks = new ArrayList<InterceptorStackConfig>();
|
||||
List<InterceptorStackConfig> defaultInterceptorStacks = new ArrayList<>();
|
||||
InterceptorMapping interceptor1 = new InterceptorMapping("interceptor-1", new TestInterceptor());
|
||||
InterceptorMapping interceptor2 = new InterceptorMapping("interceptor-2", new TestInterceptor());
|
||||
defaultInterceptorStacks.add(makeInterceptorStackConfig("stack-1", interceptor1, interceptor2));
|
||||
@@ -224,7 +188,7 @@ public class PackageBasedActionConfigBuilderTest extends TestCase {
|
||||
|
||||
ResultMapBuilder resultMapBuilder = createStrictMock(ResultMapBuilder.class);
|
||||
checkOrder(resultMapBuilder, false);
|
||||
Map<String, ResultConfig> results = new HashMap<String, ResultConfig>();
|
||||
Map<String, ResultConfig> results = new HashMap<>();
|
||||
|
||||
/* org.apache.struts2.convention.actions.action */
|
||||
expect(resultMapBuilder.build(ActionNameAction.class, getAnnotation(ActionNameAction.class, "run1", Action.class), "action1", actionPkg)).andReturn(results);
|
||||
|
||||
+12
-30
@@ -23,25 +23,12 @@ package org.apache.struts2.views.jasperreports;
|
||||
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import net.sf.jasperreports.engine.JRException;
|
||||
import net.sf.jasperreports.engine.JRExporter;
|
||||
import net.sf.jasperreports.engine.JRExporterParameter;
|
||||
import net.sf.jasperreports.engine.JRParameter;
|
||||
import net.sf.jasperreports.engine.JasperFillManager;
|
||||
import net.sf.jasperreports.engine.JasperPrint;
|
||||
import net.sf.jasperreports.engine.JasperReport;
|
||||
import net.sf.jasperreports.engine.export.JRCsvExporter;
|
||||
import net.sf.jasperreports.engine.export.JRCsvExporterParameter;
|
||||
import net.sf.jasperreports.engine.export.JRHtmlExporter;
|
||||
import net.sf.jasperreports.engine.export.JRHtmlExporterParameter;
|
||||
import net.sf.jasperreports.engine.export.JRPdfExporter;
|
||||
import net.sf.jasperreports.engine.export.JRRtfExporter;
|
||||
import net.sf.jasperreports.engine.export.JRXlsExporter;
|
||||
import net.sf.jasperreports.engine.export.JRXmlExporter;
|
||||
import net.sf.jasperreports.engine.*;
|
||||
import net.sf.jasperreports.engine.export.*;
|
||||
import net.sf.jasperreports.engine.util.JRLoader;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.dispatcher.StrutsResultSupport;
|
||||
|
||||
@@ -249,9 +236,7 @@ public class JasperReportsResult extends StrutsResultSupport implements JasperRe
|
||||
// Will throw a runtime exception if no "datasource" property. TODO Best place for that is...?
|
||||
initializeProperties(invocation);
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Creating JasperReport for dataSource = " + dataSource + ", format = " + format);
|
||||
}
|
||||
LOG.debug("Creating JasperReport for dataSource = {}, format = {}", dataSource, format);
|
||||
|
||||
HttpServletRequest request = (HttpServletRequest) invocation.getInvocationContext().get(ServletActionContext.HTTP_REQUEST);
|
||||
HttpServletResponse response = (HttpServletResponse) invocation.getInvocationContext().get(ServletActionContext.HTTP_RESPONSE);
|
||||
@@ -311,9 +296,7 @@ public class JasperReportsResult extends StrutsResultSupport implements JasperRe
|
||||
// Add any report parameters from action to param map.
|
||||
Map reportParams = (Map) stack.findValue(reportParameters);
|
||||
if (reportParams != null) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Found report parameters; adding to parameters...");
|
||||
}
|
||||
parameters.putAll(reportParams);
|
||||
}
|
||||
|
||||
@@ -323,12 +306,14 @@ public class JasperReportsResult extends StrutsResultSupport implements JasperRe
|
||||
// Fill the report and produce a print object
|
||||
try {
|
||||
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(systemId);
|
||||
if (conn == null)
|
||||
if (conn == null) {
|
||||
jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, stackDataSource);
|
||||
else
|
||||
}
|
||||
else {
|
||||
jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);
|
||||
}
|
||||
} catch (JRException e) {
|
||||
LOG.error("Error building report for uri " + systemId, e);
|
||||
LOG.error("Error building report for uri {}", systemId, e);
|
||||
throw new ServletException(e.getMessage(), e);
|
||||
}
|
||||
|
||||
@@ -386,16 +371,13 @@ public class JasperReportsResult extends StrutsResultSupport implements JasperRe
|
||||
|
||||
Map exportParams = (Map) stack.findValue(exportParameters);
|
||||
if (exportParams != null) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Found export parameters; adding to exporter parameters...");
|
||||
}
|
||||
LOG.debug("Found export parameters; adding to exporter parameters...");
|
||||
exporter.getParameters().putAll(exportParams);
|
||||
}
|
||||
|
||||
output = exportReportToBytes(jasperPrint, exporter);
|
||||
} catch (JRException e) {
|
||||
String message = "Error producing " + format + " report for uri " + systemId;
|
||||
LOG.error(message, e);
|
||||
LOG.error("Error producing {} report for uri {}", format, systemId, e);
|
||||
throw new ServletException(e.getMessage(), e);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ public class ValueStackShadowMap extends HashMap {
|
||||
* Implementation of containsKey(), overriding HashMap implementation.
|
||||
*
|
||||
* @param key - The key to check in HashMap and if not found to check on valueStack.
|
||||
* @return <tt>true</tt>, if conatins key, <tt>false</tt> otherwise.
|
||||
* @return <tt>true</tt>, if contains key, <tt>false</tt> otherwise.
|
||||
* @see java.util.HashMap#containsKey
|
||||
*/
|
||||
public boolean containsKey(Object key) {
|
||||
|
||||
@@ -21,16 +21,11 @@
|
||||
|
||||
package org.apache.struts2;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionProxy;
|
||||
import com.opensymphony.xwork2.ActionProxyFactory;
|
||||
import com.opensymphony.xwork2.ValidationAware;
|
||||
import com.opensymphony.xwork2.XWorkJUnit4TestCase;
|
||||
import com.opensymphony.xwork2.*;
|
||||
import com.opensymphony.xwork2.config.Configuration;
|
||||
import com.opensymphony.xwork2.interceptor.annotations.After;
|
||||
import com.opensymphony.xwork2.interceptor.annotations.Before;
|
||||
import com.opensymphony.xwork2.util.logging.LoggerFactory;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import com.opensymphony.xwork2.util.logging.jdk.JdkLoggerFactory;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.struts2.dispatcher.Dispatcher;
|
||||
@@ -53,11 +48,7 @@ import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.ConsoleHandler;
|
||||
import java.util.logging.Formatter;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.*;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
@@ -242,7 +233,7 @@ public abstract class StrutsJUnit4TestCase<T> extends XWorkJUnit4TestCase {
|
||||
|
||||
protected void initDispatcherParams() {
|
||||
if (StringUtils.isNotBlank(getConfigPath())) {
|
||||
dispatcherInitParams = new HashMap<String, String>();
|
||||
dispatcherInitParams = new HashMap<>();
|
||||
dispatcherInitParams.put("config", "struts-default.xml," + getConfigPath());
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -42,9 +42,9 @@ import java.util.Set;
|
||||
public class DefaultContentTypeHandlerManager implements ContentTypeHandlerManager {
|
||||
|
||||
/** ContentTypeHandlers keyed by the extension */
|
||||
Map<String,ContentTypeHandler> handlersByExtension = new HashMap<String,ContentTypeHandler>();
|
||||
Map<String,ContentTypeHandler> handlersByExtension = new HashMap<>();
|
||||
/** ContentTypeHandlers keyed by the content-type */
|
||||
Map<String,ContentTypeHandler> handlersByContentType = new HashMap<String,ContentTypeHandler>();
|
||||
Map<String,ContentTypeHandler> handlersByContentType = new HashMap<>();
|
||||
|
||||
private String defaultExtension;
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* Type-safe rest-related informtion to apply to a response
|
||||
* Type-safe rest-related information to apply to a response
|
||||
*/
|
||||
public interface HttpHeaders {
|
||||
|
||||
|
||||
@@ -21,19 +21,15 @@
|
||||
|
||||
package org.apache.struts2.rest;
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.DefaultActionInvocation;
|
||||
import com.opensymphony.xwork2.ModelDriven;
|
||||
import com.opensymphony.xwork2.Result;
|
||||
import com.opensymphony.xwork2.ValidationAware;
|
||||
import com.opensymphony.xwork2.*;
|
||||
import com.opensymphony.xwork2.config.ConfigurationException;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.config.entities.ResultConfig;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import com.opensymphony.xwork2.util.profiling.UtilTimerStack;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.dispatcher.HttpHeaderResult;
|
||||
import org.apache.struts2.rest.handler.ContentTypeHandler;
|
||||
@@ -71,29 +67,29 @@ public class RestActionInvocation extends DefaultActionInvocation {
|
||||
}
|
||||
|
||||
@Inject("struts.rest.logger")
|
||||
public void setLogger(String value) {
|
||||
logger = Boolean.valueOf(value);
|
||||
public void setLogger(String logger) {
|
||||
this.logger = BooleanUtils.toBoolean(logger);
|
||||
}
|
||||
|
||||
@Inject("struts.rest.defaultErrorResultName")
|
||||
public void setDefaultErrorResultName(String value) {
|
||||
defaultErrorResultName = value;
|
||||
public void setDefaultErrorResultName(String defaultErrorResultName) {
|
||||
this.defaultErrorResultName = defaultErrorResultName;
|
||||
}
|
||||
|
||||
/**
|
||||
* If set to true (by default) blocks returning content from any other methods than GET,
|
||||
* if set to false, the content can be returned for any kind of method
|
||||
*
|
||||
* @param value true or false
|
||||
* @param restrictToGet true or false
|
||||
*/
|
||||
@Inject(value = "struts.rest.content.restrictToGET", required = false)
|
||||
public void setRestrictToGet(String value) {
|
||||
restrictToGet = "true".equalsIgnoreCase(value);
|
||||
public void setRestrictToGet(String restrictToGet) {
|
||||
this.restrictToGet = BooleanUtils.toBoolean(restrictToGet);
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setMimeTypeHandlerSelector(ContentTypeHandlerManager sel) {
|
||||
this.handlerSelector = sel;
|
||||
public void setMimeTypeHandlerSelector(ContentTypeHandlerManager selector) {
|
||||
this.handlerSelector = selector;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,7 +145,7 @@ public class RestActionInvocation extends DefaultActionInvocation {
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
// Error proccesing the result
|
||||
// Error processing the result
|
||||
LOG.error("Exception processing the result.", e);
|
||||
|
||||
if (!ServletActionContext.getResponse().isCommitted()) {
|
||||
@@ -196,9 +192,7 @@ public class RestActionInvocation extends DefaultActionInvocation {
|
||||
if (httpHeaders.getStatus() != HttpServletResponse.SC_NOT_MODIFIED ) {
|
||||
executeResult();
|
||||
} else {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Result not processed because the status code is not modified.");
|
||||
}
|
||||
LOG.debug("Result not processed because the status code is not modified.");
|
||||
}
|
||||
|
||||
} finally {
|
||||
@@ -229,20 +223,15 @@ public class RestActionInvocation extends DefaultActionInvocation {
|
||||
if (handler != null && !(handler instanceof HtmlHandler)) {
|
||||
|
||||
// Specific representation (json, xml...)
|
||||
resultCode = handlerSelector.handleResult(
|
||||
this.getProxy().getConfig(), httpHeaders, target);
|
||||
|
||||
resultCode = handlerSelector.handleResult(this.getProxy().getConfig(), httpHeaders, target);
|
||||
} else {
|
||||
|
||||
// Normal struts execution (html o other struts result)
|
||||
findResult();
|
||||
if (result != null) {
|
||||
this.result.execute(this);
|
||||
|
||||
} else {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("No result returned for action " + getAction().getClass().getName()
|
||||
+ " at " + proxy.getConfig().getLocation());
|
||||
LOG.debug("No result returned for action {} at {}", getAction().getClass().getName(), proxy.getConfig().getLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -289,9 +278,7 @@ public class RestActionInvocation extends DefaultActionInvocation {
|
||||
ResultConfig resultConfig = this.proxy.getConfig().getResults().get(defaultErrorResultName);
|
||||
if (resultConfig != null) {
|
||||
this.result = objectFactory.buildResult(resultConfig, invocationContext.getContextMap());
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Found default error result.");
|
||||
}
|
||||
LOG.debug("Found default error result.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,9 @@ import com.opensymphony.xwork2.config.Configuration;
|
||||
import com.opensymphony.xwork2.config.ConfigurationManager;
|
||||
import com.opensymphony.xwork2.config.entities.PackageConfig;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.struts2.RequestUtils;
|
||||
import org.apache.struts2.StrutsConstants;
|
||||
import org.apache.struts2.dispatcher.mapper.ActionMapping;
|
||||
@@ -97,7 +98,15 @@ import java.util.HashMap;
|
||||
public class RestActionMapper extends DefaultActionMapper {
|
||||
|
||||
protected static final Logger LOG = LogManager.getLogger(RestActionMapper.class);
|
||||
|
||||
public static final String HTTP_METHOD_PARAM = "_method";
|
||||
|
||||
private static final String GET = "get";
|
||||
private static final String POST = "post";
|
||||
private static final String PUT = "put";
|
||||
private static final String DELETE = "delete";
|
||||
private static final String OPTIONS = "options";
|
||||
|
||||
private String idParameterName = "id";
|
||||
private String indexMethodName = "index";
|
||||
private String getMethodName = "show";
|
||||
@@ -201,7 +210,7 @@ public class RestActionMapper extends DefaultActionMapper {
|
||||
|
||||
String fullName = mapping.getName();
|
||||
// Only try something if the action name is specified
|
||||
if (fullName != null && fullName.length() > 0) {
|
||||
if (StringUtils.isNotEmpty(fullName)) {
|
||||
|
||||
// cut off any ;jsessionid= type appendix but allow the rails-like ;edit
|
||||
int scPos = fullName.indexOf(';');
|
||||
@@ -282,7 +291,7 @@ public class RestActionMapper extends DefaultActionMapper {
|
||||
if (id != null) {
|
||||
if (!"new".equals(id)) {
|
||||
if (mapping.getParams() == null) {
|
||||
mapping.setParams(new HashMap());
|
||||
mapping.setParams(new HashMap<String, Object>());
|
||||
}
|
||||
mapping.getParams().put(idParameterName, new String[]{id});
|
||||
}
|
||||
@@ -317,8 +326,7 @@ public class RestActionMapper extends DefaultActionMapper {
|
||||
* @param mapping
|
||||
* The action mapping to populate
|
||||
*/
|
||||
protected void parseNameAndNamespace(String uri, ActionMapping mapping,
|
||||
ConfigurationManager configManager) {
|
||||
protected void parseNameAndNamespace(String uri, ActionMapping mapping, ConfigurationManager configManager) {
|
||||
String namespace, name;
|
||||
int lastSlash = uri.lastIndexOf("/");
|
||||
if (lastSlash == -1) {
|
||||
@@ -353,31 +361,23 @@ public class RestActionMapper extends DefaultActionMapper {
|
||||
}
|
||||
|
||||
protected boolean isGet(HttpServletRequest request) {
|
||||
return "get".equalsIgnoreCase(request.getMethod());
|
||||
return GET.equalsIgnoreCase(request.getMethod());
|
||||
}
|
||||
|
||||
protected boolean isPost(HttpServletRequest request) {
|
||||
return "post".equalsIgnoreCase(request.getMethod());
|
||||
return POST.equalsIgnoreCase(request.getMethod());
|
||||
}
|
||||
|
||||
protected boolean isPut(HttpServletRequest request) {
|
||||
if ("put".equalsIgnoreCase(request.getMethod())) {
|
||||
return true;
|
||||
} else {
|
||||
return isPost(request) && "put".equalsIgnoreCase(request.getParameter(HTTP_METHOD_PARAM));
|
||||
}
|
||||
return PUT.equalsIgnoreCase(request.getMethod()) || isPost(request) && PUT.equalsIgnoreCase(request.getParameter(HTTP_METHOD_PARAM));
|
||||
}
|
||||
|
||||
protected boolean isDelete(HttpServletRequest request) {
|
||||
if ("delete".equalsIgnoreCase(request.getMethod())) {
|
||||
return true;
|
||||
} else {
|
||||
return "delete".equalsIgnoreCase(request.getParameter(HTTP_METHOD_PARAM));
|
||||
}
|
||||
return DELETE.equalsIgnoreCase(request.getMethod()) || DELETE.equalsIgnoreCase(request.getParameter(HTTP_METHOD_PARAM));
|
||||
}
|
||||
|
||||
protected boolean isOptions(HttpServletRequest request) {
|
||||
return "options".equalsIgnoreCase(request.getMethod());
|
||||
return OPTIONS.equalsIgnoreCase(request.getMethod());
|
||||
}
|
||||
|
||||
protected boolean isExpectContinue(HttpServletRequest request) {
|
||||
|
||||
@@ -27,15 +27,16 @@ import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.ValidationAware;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.dispatcher.mapper.ActionMapping;
|
||||
|
||||
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
|
||||
|
||||
/**
|
||||
* <!-- START SNIPPET: description -->
|
||||
*
|
||||
@@ -200,9 +201,7 @@ public class RestWorkflowInterceptor extends MethodFilterInterceptor {
|
||||
ValidationAware validationAwareAction = (ValidationAware) action;
|
||||
|
||||
if (validationAwareAction.hasErrors()) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Errors on action "+validationAwareAction+", returning result name 'input'");
|
||||
}
|
||||
LOG.debug("Errors on action {}, returning result name 'input'", validationAwareAction);
|
||||
ActionMapping mapping = (ActionMapping) ActionContext.getContext().get(ServletActionContext.ACTION_MAPPING);
|
||||
String method = inputResultName;
|
||||
if (postMethodName.equals(mapping.getMethod())) {
|
||||
@@ -217,7 +216,7 @@ public class RestWorkflowInterceptor extends MethodFilterInterceptor {
|
||||
.renderResult(method)
|
||||
.withStatus(validationFailureStatusCode);
|
||||
|
||||
Map errors = new HashMap();
|
||||
Map<String, Object> errors = new HashMap<>();
|
||||
|
||||
errors.put("actionErrors", validationAwareAction.getActionErrors());
|
||||
errors.put("fieldErrors", validationAwareAction.getFieldErrors());
|
||||
|
||||
+14
-17
@@ -23,14 +23,9 @@ package org.apache.struts2.sitemesh;
|
||||
import com.opensymphony.module.sitemesh.HTMLPage;
|
||||
import com.opensymphony.module.sitemesh.RequestConstants;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import freemarker.core.InvalidReferenceException;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.ObjectWrapper;
|
||||
import freemarker.template.SimpleHash;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateException;
|
||||
import freemarker.template.TemplateModel;
|
||||
import freemarker.template.*;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
@@ -74,17 +69,15 @@ public class FreemarkerDecoratorServlet extends freemarker.ext.servlet.Freemarke
|
||||
public void init() throws ServletException {
|
||||
try {
|
||||
Dispatcher dispatcher = (Dispatcher) getServletContext().getAttribute(StrutsStatics.SERVLET_DISPATCHER);
|
||||
if (dispatcher == null)
|
||||
if (dispatcher == null) {
|
||||
throw new IllegalStateException("Unable to find the Dispatcher in the Servlet Context. Is '" + StrutsListener.class.getName() + "' missing in web.xml?");
|
||||
|
||||
}
|
||||
freemarkerManager = dispatcher.getContainer().getInstance(FreemarkerManager.class);
|
||||
config = createConfiguration();
|
||||
|
||||
// Process object_wrapper init-param out of order:
|
||||
wrapper = config.getObjectWrapper();
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Using object wrapper of class " + wrapper.getClass().getName());
|
||||
}
|
||||
LOG.debug("Using object wrapper of class {}", wrapper.getClass().getName());
|
||||
|
||||
// Process all other init-params:
|
||||
Enumeration initpnames = getServletConfig().getInitParameterNames();
|
||||
@@ -92,10 +85,10 @@ public class FreemarkerDecoratorServlet extends freemarker.ext.servlet.Freemarke
|
||||
String name = (String) initpnames.nextElement();
|
||||
String value = getInitParameter(name);
|
||||
if (name == null) {
|
||||
throw new ServletException("init-param without param-name. " + "Maybe the web.xml is not well-formed?");
|
||||
throw new ServletException("init-param without param-name. Maybe the web.xml is not well-formed?");
|
||||
}
|
||||
if (value == null) {
|
||||
throw new ServletException("init-param without param-value. " + "Maybe the web.xml is not well-formed?");
|
||||
throw new ServletException("init-param without param-value. Maybe the web.xml is not well-formed?");
|
||||
}
|
||||
|
||||
// template path is already handled!
|
||||
@@ -132,7 +125,7 @@ public class FreemarkerDecoratorServlet extends freemarker.ext.servlet.Freemarke
|
||||
log("Requested template: " + path);
|
||||
}
|
||||
|
||||
Template template = null;
|
||||
Template template;
|
||||
try {
|
||||
template = config.getTemplate(path, deduceLocale(path, request, response));
|
||||
} catch (FileNotFoundException e) {
|
||||
@@ -176,11 +169,15 @@ public class FreemarkerDecoratorServlet extends freemarker.ext.servlet.Freemarke
|
||||
// this exception is thrown if there is an error processing a reference. We want to report these!
|
||||
HttpServletRequest req = ((StrutsRequestWrapper) ActionContext.getContext().get("com.opensymphony.xwork2.dispatcher.HttpServletRequest"));
|
||||
String resultCode = ActionContext.getContext().getActionInvocation().getResultCode();
|
||||
if (req == null) req = request;
|
||||
if (req == null){
|
||||
req = request;
|
||||
}
|
||||
|
||||
StringBuilder msgBuf = new StringBuilder("Error applying freemarker template to\n request: ");
|
||||
msgBuf.append(req.getRequestURL());
|
||||
if (req.getQueryString() != null) msgBuf.append("?").append(req.getQueryString());
|
||||
if (req.getQueryString() != null){
|
||||
msgBuf.append("?").append(req.getQueryString());
|
||||
}
|
||||
msgBuf.append(" with resultCode: ").append(resultCode).append(".\n\n").append(x.getMessage());
|
||||
String msg = msgBuf.toString();
|
||||
LOG.error(msg, x);
|
||||
|
||||
+3
-5
@@ -21,9 +21,9 @@ package org.apache.struts2.sitemesh;
|
||||
import com.opensymphony.module.sitemesh.Config;
|
||||
import com.opensymphony.module.sitemesh.factory.DefaultFactory;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
|
||||
@@ -45,9 +45,7 @@ public class StrutsSiteMeshFactory extends DefaultFactory {
|
||||
|
||||
private boolean isInsideActionTag() {
|
||||
if(ActionContext.getContext() == null) {
|
||||
if (LOG.isTraceEnabled()) {
|
||||
LOG.trace("ActionContext is null! Not a user request?");
|
||||
}
|
||||
LOG.trace("ActionContext is null! Not a user request?");
|
||||
return false;
|
||||
}
|
||||
Object attribute = ServletActionContext.getRequest().getAttribute(StrutsStatics.STRUTS_ACTION_TAG_INVOCATION);
|
||||
|
||||
+7
-7
@@ -71,8 +71,9 @@ public class VelocityDecoratorServlet extends VelocityViewServlet {
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
super.init(config);
|
||||
Dispatcher dispatcher = (Dispatcher) getServletContext().getAttribute(StrutsStatics.SERVLET_DISPATCHER);
|
||||
if (dispatcher == null)
|
||||
if (dispatcher == null) {
|
||||
throw new IllegalStateException("Unable to find the Dispatcher in the Servlet Context. Is '" + StrutsListener.class.getName() + "' missing in web.xml?");
|
||||
}
|
||||
velocityManager = dispatcher.getContainer().getInstance(VelocityManager.class);
|
||||
velocityManager.init(config.getServletContext());
|
||||
|
||||
@@ -81,9 +82,9 @@ public class VelocityDecoratorServlet extends VelocityViewServlet {
|
||||
toolboxManager = velocityManager.getToolboxManager();
|
||||
|
||||
// we can get these now that velocity is initialized
|
||||
defaultContentType = (String) getVelocityProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE);
|
||||
defaultContentType = getVelocityProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE);
|
||||
|
||||
String encoding = (String) getVelocityProperty(RuntimeConstants.OUTPUT_ENCODING, DEFAULT_OUTPUT_ENCODING);
|
||||
String encoding = getVelocityProperty(RuntimeConstants.OUTPUT_ENCODING, DEFAULT_OUTPUT_ENCODING);
|
||||
|
||||
// For non Latin-1 encodings, ensure that the charset is
|
||||
// included in the Content-Type header.
|
||||
@@ -107,7 +108,7 @@ public class VelocityDecoratorServlet extends VelocityViewServlet {
|
||||
String template;
|
||||
|
||||
context.put("base", request.getContextPath());
|
||||
// For backwards compatability with apps that used the old VelocityDecoratorServlet
|
||||
// For backwards compatibility with apps that used the old VelocityDecoratorServlet
|
||||
// that extended VelocityServlet instead of VelocityViewServlet
|
||||
context.put("req", request);
|
||||
context.put("res", response);
|
||||
@@ -140,8 +141,7 @@ public class VelocityDecoratorServlet extends VelocityViewServlet {
|
||||
|
||||
private DecoratorMapper getDecoratorMapper() {
|
||||
Factory factory = Factory.getInstance(new Config(getServletConfig()));
|
||||
DecoratorMapper decoratorMapper = factory.getDecoratorMapper();
|
||||
return decoratorMapper;
|
||||
return factory.getDecoratorMapper();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,7 +160,7 @@ public class VelocityDecoratorServlet extends VelocityViewServlet {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the content type of the response. This is available to be overriden
|
||||
* Sets the content type of the response. This is available to be overridden
|
||||
* by a derived class.
|
||||
* <p/>
|
||||
* <p>The default implementation is :
|
||||
|
||||
Reference in New Issue
Block a user