Merge branch 'master' into jackson-2.9.6

This commit is contained in:
Yasser Zamani
2018-10-07 15:23:35 +03:30
committed by GitHub
41 changed files with 1352 additions and 303 deletions
+110
View File
@@ -0,0 +1,110 @@
/*
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.
*/
import java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.Properties;
public class MavenWrapperDownloader {
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL =
"https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar";
/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";
/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";
/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if(mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if(mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: : " + url);
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if(!outputFile.getParentFile().exists()) {
if(!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}
}
BIN
View File
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip
+20 -18
View File
@@ -28,9 +28,9 @@ The Apache Struts web framework is a free open-source solution for creating Java
## Documentation
More information can be found on the [homepage](https://struts.apache.org/). Please read the [Security Guide](https://struts.apache.org/security/)
More information can be found on the [homepage](https://struts.apache.org/). Please read the [Security Guide](https://struts.apache.org/security/),
and the [JavaDocs](https://struts.apache.org/maven/struts2-core/apidocs/index.html) can be browsed.
Questions related to the usage of the Apache Struts should be posted to the [user mailing list](https://struts.apache.org/mail.html).
Questions related to the usage of Apache Struts should be posted to the [user mailing list](https://struts.apache.org/mail.html).
## Description
@@ -43,13 +43,15 @@ In practice, we find that unless these concerns are separated, larger applicatio
One way to separate concerns in a software application is to use a Model-View-Controller (MVC) architecture. The Model
represents the business or database code, the View represents the page design code, and the Controller represents
the navigational code. The Struts framework is designed to help developers create web applications that utilize
a MVC architecture.
an MVC architecture.
The framework provides three key components:
A “request” handler provided by the application developer that is mapped to a standard URI. A “response” handler that
transfers control to another resource which completes the response. A tag library that helps developers create interactive
form-based applications with server pages. The frameworks architecture and tags are buzzword compliant. Struts works well
- A “request” handler provided by the application developer that is mapped to a standard URI.
- A “response” handler that transfers control to another resource which completes the response.
- A tag library that helps developers create interactive form-based applications with server pages.
The frameworks architecture and tags are buzzword compliant. Struts works well
with conventional REST applications and with technologies like SOAP and AJAX.
## The Apache Struts Project
@@ -65,7 +67,7 @@ platform into a coherent whole. Our goal is to leverage existing standards by pr
enterprise-grade applications that are easy to maintain over time.
The Apache Struts Project offered two major versions of the Struts framework. Currently we are only maintaining the Struts 2
version. It is recommended to upgrade all Struts 1.x application to Struts 2. Please do not start new application development
version. It is recommended to upgrade all Struts 1.x applications to Struts 2. Please do not start new application development
using Struts 1.x, as we are no longer issuing security patches.
Struts 2 was originally known as WebWork 2. After working independently for several years, the WebWork and Struts
@@ -74,25 +76,25 @@ to difficult problems.
## Why should you use Apache Struts?
Apache Struts is a modern, maintained and full-featured web framework. It has been there for years and give the huge user
base it is unlikely it will go away anytime soon in the future. Not only that we have dedicated users and developers
on the project. Apache Struts is licensed to the Apache License 2.0 and this will not change. We maintain a clean IP
Apache Struts is a modern, maintained and full-featured web framework. As it has been around for years and grown a huge user
base it is unlikely it will go away anytime soon. Not only that, we have dedicated users and developers
on the project. Apache Struts is licensed under the Apache License 2.0 and this will not change. We maintain a clean IP
and you are “safe” to use the project. Sometimes you are not “safe” to use a project when a company controls the SCM.
Access to Source Code doesnt mean it is free. With Apache Struts, you are not only free to “do what you want with it”,
you can even contribute (which is not always the case). And best of it: you can become a part of the core team too.
you can even contribute (which is not always the case). And best of all: you can become a part of the core team too.
It is usually very easy to integrate other technologies with Apache Struts. If you are using an ORM like Apache Cayenne,
Hibernate or JDBC you will not have any restrictions. Apache Struts is not even tied too much to a frontend technology.
Hibernate or JDBC, you will not have any restrictions. Apache Struts is not even tied too much to a frontend technology.
In old days it was JSP, then came Velocity and Freemarker. Nowadays you might build your web application with just static
HTML and AngularJS. Or you want to use Sitemesh or Tiles. This all is no problem due to Struts elegant and easy to use
HTML and AngularJS. Or you might want to use Sitemesh or Tiles. This all is no problem due to Struts' elegant and easy-to-use
extension mechanisms.
Unlike other, component oriented frameworks, we do not aim to hide the stateless nature of the web. We think it is
Unlike other, component-oriented frameworks, we do not aim to hide the stateless nature of the web. We think it is
perfectly acceptable to build upon a Request/Response cycle. We also think the MVC pattern is not so bad, just because
it is old. In fact, we believe the Apache Struts architecture is clean and easy to understand.
Of course, if you wish to build components on the server side which render on the front end side, you are most likely
wrong with Struts. This is a different approach which promises to reduce the amount of HTML/JavaScript knowledge needed
Of course, if you wish to build components on the server side which render on the front end side, you will most likely
not want Struts. This is a different approach which promises to reduce the amount of HTML/JavaScript knowledge needed
and to create reusable components for the view layer. Projects like Wicket and Tapestry serve this purpose very well.
As with every framework you need to decide if it makes sense for you to build components or if you are better with
the Struts-approach.
As with every framework, you need to decide if it makes sense for you to build components or if you prefer
the Struts approach.
+1 -1
View File
@@ -111,7 +111,7 @@
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>attached</goal>
<goal>single</goal>
</goals>
</execution>
</executions>
+6 -6
View File
@@ -1,6 +1,6 @@
http://struts.apache.org/getting-started/
http://struts.apache.org/security/
http://struts.apache.org/core-developers/
http://struts.apache.org/tag-developers/
http://struts.apache.org/maven-archetypes/
http://struts.apache.org/plugins/
https://struts.apache.org/getting-started/
https://struts.apache.org/security/
https://struts.apache.org/core-developers/
https://struts.apache.org/tag-developers/
https://struts.apache.org/maven-archetypes/
https://struts.apache.org/plugins/
-19
View File
@@ -178,25 +178,6 @@
</plugins>
</build>
</profile>
<profile>
<id>default-tools.jar</id>
<activation>
<property>
<name>java.vendor</name>
<value>Sun Microsystems Inc.</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</profile>
</profiles>
@@ -201,13 +201,10 @@ public class ActionChainResult implements Result {
* @param invocation the DefaultActionInvocation calling the action call stack
*/
public void execute(ActionInvocation invocation) throws Exception {
// if the finalNamespace wasn't explicitly defined, assume the current one
if (this.namespace == null) {
this.namespace = invocation.getProxy().getNamespace();
}
ValueStack stack = ActionContext.getContext().getValueStack();
String finalNamespace = TextParseUtil.translateVariables(namespace, stack);
String finalNamespace = this.namespace != null
? TextParseUtil.translateVariables(namespace, stack)
: invocation.getProxy().getNamespace();
String finalActionName = TextParseUtil.translateVariables(actionName, stack);
String finalMethodName = this.methodName != null
? TextParseUtil.translateVariables(this.methodName, stack)
@@ -21,7 +21,6 @@ package com.opensymphony.xwork2.conversion.impl;
import com.opensymphony.xwork2.conversion.ObjectTypeDeterminer;
import com.opensymphony.xwork2.conversion.TypeConverter;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.XWorkList;
import java.lang.reflect.Member;
import java.util.Collection;
@@ -16,13 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
package com.opensymphony.xwork2.util;
package com.opensymphony.xwork2.conversion.impl;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.XWorkException;
import com.opensymphony.xwork2.conversion.TypeConverter;
import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -150,8 +150,8 @@ public class PrefixMethodInvocationUtil {
public static Method getPrefixedMethod(String[] prefixes, String methodName, Object action) {
assert(prefixes != null);
String capitalizedMethodName = capitalizeMethodName(methodName);
for (String prefixe : prefixes) {
String prefixedMethodName = prefixe + capitalizedMethodName;
for (String prefix : prefixes) {
String prefixedMethodName = prefix + capitalizedMethodName;
try {
return action.getClass().getMethod(prefixedMethodName, EMPTY_CLASS_ARRAY);
}
@@ -61,14 +61,20 @@ public class OgnlUtil {
private boolean enableExpressionCache = true;
private boolean enableEvalExpression;
private Set<Class<?>> excludedClasses = Collections.emptySet();
private Set<Pattern> excludedPackageNamePatterns = Collections.emptySet();
private Set<String> excludedPackageNames = Collections.emptySet();
private Set<Class<?>> excludedClasses;
private Set<Pattern> excludedPackageNamePatterns;
private Set<String> excludedPackageNames;
private Container container;
private boolean allowStaticMethodAccess;
private boolean disallowProxyMemberAccess;
public OgnlUtil() {
excludedClasses = new HashSet<>();
excludedPackageNamePatterns = new HashSet<>();
excludedPackageNames = new HashSet<>();
}
@Inject
public void setXWorkConverter(XWorkConverter conv) {
this.defaultConverter = new OgnlTypeConverterWrapper(conv);
@@ -95,6 +101,13 @@ public class OgnlUtil {
@Inject(value = StrutsConstants.STRUTS_EXCLUDED_CLASSES, required = false)
public void setExcludedClasses(String commaDelimitedClasses) {
Set<Class<?>> excludedClasses = new HashSet<>();
excludedClasses.addAll(this.excludedClasses);
excludedClasses.addAll(parseExcludedClasses(commaDelimitedClasses));
this.excludedClasses = Collections.unmodifiableSet(excludedClasses);
}
private Set<Class<?>> parseExcludedClasses(String commaDelimitedClasses) {
Set<String> classNames = TextParseUtil.commaDelimitedStringToSet(commaDelimitedClasses);
Set<Class<?>> classes = new HashSet<>();
@@ -106,11 +119,18 @@ public class OgnlUtil {
}
}
excludedClasses = Collections.unmodifiableSet(classes);
return classes;
}
@Inject(value = StrutsConstants.STRUTS_EXCLUDED_PACKAGE_NAME_PATTERNS, required = false)
public void setExcludedPackageNamePatterns(String commaDelimitedPackagePatterns) {
Set<Pattern> excludedPackageNamePatterns = new HashSet<>();
excludedPackageNamePatterns.addAll(this.excludedPackageNamePatterns);
excludedPackageNamePatterns.addAll(parseExcludedPackageNamePatterns(commaDelimitedPackagePatterns));
this.excludedPackageNamePatterns = Collections.unmodifiableSet(excludedPackageNamePatterns);
}
private Set<Pattern> parseExcludedPackageNamePatterns(String commaDelimitedPackagePatterns) {
Set<String> packagePatterns = TextParseUtil.commaDelimitedStringToSet(commaDelimitedPackagePatterns);
Set<Pattern> packageNamePatterns = new HashSet<>();
@@ -118,12 +138,19 @@ public class OgnlUtil {
packageNamePatterns.add(Pattern.compile(pattern));
}
excludedPackageNamePatterns = Collections.unmodifiableSet(packageNamePatterns);
return packageNamePatterns;
}
@Inject(value = StrutsConstants.STRUTS_EXCLUDED_PACKAGE_NAMES, required = false)
public void setExcludedPackageNames(String commaDelimitedPackageNames) {
excludedPackageNames = Collections.unmodifiableSet(TextParseUtil.commaDelimitedStringToSet(commaDelimitedPackageNames));
Set<String> excludedPackageNames = new HashSet<>();
excludedPackageNames.addAll(this.excludedPackageNames);
excludedPackageNames.addAll(parseExcludedPackageNames(commaDelimitedPackageNames));
this.excludedPackageNames = Collections.unmodifiableSet(excludedPackageNames);
}
private Set<String> parseExcludedPackageNames(String commaDelimitedPackageNames) {
return TextParseUtil.commaDelimitedStringToSet(commaDelimitedPackageNames);
}
public Set<Class<?>> getExcludedClasses() {
@@ -81,29 +81,31 @@ public class SecurityMemberAccess implements MemberAccess {
@Override
public boolean isAccessible(Map context, Object target, Member member, String propertyName) {
LOG.debug("Checking access for [target: {}, member: {}, property: {}]", target, member, propertyName);
Class targetClass = target.getClass();
Class memberClass = member.getDeclaringClass();
if (checkEnumAccess(target, member)) {
LOG.trace("Allowing access to enum: {}", target);
LOG.trace("Allowing access to enum: target class [{}] of target [{}], member [{}]", targetClass, target, member);
return true;
}
Class targetClass = target.getClass();
Class memberClass = member.getDeclaringClass();
if (Modifier.isStatic(member.getModifiers()) && allowStaticMethodAccess) {
LOG.debug("Support for accessing static methods [target: {}, member: {}, property: {}] is deprecated!", target, member, propertyName);
LOG.debug("Support for accessing static methods [target: {}, targetClass: {}, member: {}, property: {}] is deprecated!",
target, targetClass, member, propertyName);
if (!isClassExcluded(member.getDeclaringClass())) {
targetClass = member.getDeclaringClass();
}
}
if (isPackageExcluded(targetClass.getPackage(), memberClass.getPackage())) {
LOG.warn("Package of target [{}] or package of member [{}] are excluded!", target, member);
LOG.warn("Package [{}] of target class [{}] of target [{}] or package [{}] of member [{}] are excluded!", targetClass.getPackage(), targetClass,
target, memberClass.getPackage(), member);
return false;
}
if (isClassExcluded(targetClass)) {
LOG.warn("Target class [{}] is excluded!", target);
LOG.warn("Target class [{}] of target [{}] is excluded!", targetClass, target);
return false;
}
@@ -113,7 +115,7 @@ public class SecurityMemberAccess implements MemberAccess {
}
if (disallowProxyMemberAccess && ProxyUtil.isProxyMember(member, target)) {
LOG.warn("Access to proxy [{}] is blocked!", member);
LOG.warn("Access to proxy is blocked! Target class [{}] of target [{}], member [{}]", targetClass, target, member);
return false;
}
@@ -154,9 +156,9 @@ public class SecurityMemberAccess implements MemberAccess {
if (targetPackage == null || memberPackage == null) {
LOG.warn("The use of the default (unnamed) package is discouraged!");
}
final String targetPackageName = targetPackage == null ? "" : targetPackage.getName();
final String memberPackageName = memberPackage == null ? "" : memberPackage.getName();
String targetPackageName = targetPackage == null ? "" : targetPackage.getName();
String memberPackageName = memberPackage == null ? "" : memberPackage.getName();
for (Pattern pattern : excludedPackageNamePatterns) {
if (pattern.matcher(targetPackageName).matches() || pattern.matcher(memberPackageName).matches()) {
@@ -164,9 +166,11 @@ public class SecurityMemberAccess implements MemberAccess {
}
}
for (String packageName : excludedPackageNames) {
if (targetPackageName.startsWith(packageName) || targetPackageName.equals(packageName)
|| memberPackageName.startsWith(packageName) || memberPackageName.equals(packageName)) {
targetPackageName = targetPackageName + ".";
memberPackageName = memberPackageName + ".";
for (String packageName: excludedPackageNames) {
if (targetPackageName.startsWith(packageName) || memberPackageName.startsWith(packageName)) {
return true;
}
}
@@ -70,7 +70,9 @@ public class DefaultFileManager implements FileManager {
return null;
}
InputStream is = openFile(fileUrl);
monitorFile(fileUrl);
if (reloadingConfigs) {
monitorFile(fileUrl);
}
return is;
}
@@ -37,9 +37,7 @@ public class JarEntryRevision extends Revision {
private long lastModified;
public static Revision build(URL fileUrl, FileManager fileManager) {
StrutsJarURLConnection conn = null;
try {
conn = StrutsJarURLConnection.openConnection(fileUrl);
try (StrutsJarURLConnection conn = StrutsJarURLConnection.openConnection(fileUrl)) {
conn.setUseCaches(false);
URL url = fileManager.normalizeToFileProtocol(fileUrl);
if (url != null) {
@@ -51,14 +49,6 @@ public class JarEntryRevision extends Revision {
LOG.warn("Could not create JarEntryRevision for [{}]!", fileUrl, e);
return null;
}
finally {
if(null != conn) {
try {
conn.getInputStream().close();
} catch (IOException ignored) {
}
}
}
}
private JarEntryRevision(URL jarFileURL, long lastModified) {
@@ -70,21 +60,12 @@ public class JarEntryRevision extends Revision {
}
public boolean needsReloading() {
StrutsJarURLConnection conn = null;
long lastLastModified = lastModified;
try {
conn = StrutsJarURLConnection.openConnection(jarFileURL);
try (StrutsJarURLConnection conn = StrutsJarURLConnection.openConnection(jarFileURL)) {
conn.setUseCaches(false);
lastLastModified = conn.getJarEntry().getTime();
} catch (IOException ignored) {
}
finally {
if(null != conn) {
try {
conn.getInputStream().close();
} catch (IOException ignored) {
}
}
} catch (Throwable e) {
LOG.warn("Could not check if needsReloading for [{}]!", jarFileURL, e);
}
return lastModified < lastLastModified;
@@ -44,7 +44,7 @@ import java.util.jar.JarFile;
* While {@link JarURLConnection#parseSpecs(URL)} is private, then we had to extend {@link URLConnection} instead
* @since 2.5.15
*/
class StrutsJarURLConnection extends URLConnection {
class StrutsJarURLConnection extends URLConnection implements AutoCloseable {
private static final String FILE_URL_PREFIX = "file:";
private JarURLConnection jarURLConnection;
@@ -123,8 +123,8 @@ class StrutsJarURLConnection extends URLConnection {
Path tmpFile = Files.createTempFile("jar_cache", null);
try {
Files.copy(in, tmpFile, StandardCopyOption.REPLACE_EXISTING);
JarFile jarFile = new JarFile(tmpFile.toFile(), true, JarFile.OPEN_READ);
tmpFile.toFile().deleteOnExit();
JarFile jarFile = new JarFile(tmpFile.toFile(), true, JarFile.OPEN_READ
| JarFile.OPEN_DELETE);
return jarFile;
} catch (Throwable thr) {
try {
@@ -171,6 +171,20 @@ class StrutsJarURLConnection extends URLConnection {
}
}
@Override
public void close() throws Exception {
try {
getInputStream().close();
} catch (IOException ignored) {
}
if (jarURLConnection == null) {
try {
jarFile.close();
} catch (IOException ignored) {
}
}
}
static StrutsJarURLConnection openConnection(URL url) throws IOException {
return new StrutsJarURLConnection(url);
}
@@ -282,6 +282,11 @@ public final class StrutsConstants {
public static final String STRUTS_EXPRESSION_PARSER = "struts.expression.parser";
/** namespaces names' whitelist **/
public static final String STRUTS_ALLOWED_NAMESPACE_NAMES = "struts.allowed.namespace.names";
/** default namespace name to use when namespace didn't match the whitelist **/
public static final String STRUTS_DEFAULT_NAMESPACE_NAME = "struts.default.namespace.name";
/** actions names' whitelist **/
public static final String STRUTS_ALLOWED_ACTION_NAMES = "struts.allowed.action.names";
/** default action name to use when action didn't match the whitelist **/
@@ -31,7 +31,6 @@ import org.apache.logging.log4j.Logger;
import org.apache.struts2.RequestUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.StrutsException;
import org.apache.struts2.util.PrefixTrie;
import javax.servlet.http.HttpServletRequest;
@@ -117,6 +116,10 @@ public class DefaultActionMapper implements ActionMapper {
protected boolean allowSlashesInActionNames = false;
protected boolean alwaysSelectFullNamespace = false;
protected PrefixTrie prefixTrie = null;
protected Pattern allowedNamespaceNames = Pattern.compile("[a-zA-Z0-9._/\\-]*");
protected String defaultNamespaceName = "/";
protected Pattern allowedActionNames = Pattern.compile("[a-zA-Z0-9._!/\\-]*");
protected String defaultActionName = "index";
@@ -202,6 +205,16 @@ public class DefaultActionMapper implements ActionMapper {
this.alwaysSelectFullNamespace = BooleanUtils.toBoolean(alwaysSelectFullNamespace);
}
@Inject(value = StrutsConstants.STRUTS_ALLOWED_NAMESPACE_NAMES, required = false)
public void setAllowedNamespaceNames(String allowedNamespaceNames) {
this.allowedNamespaceNames = Pattern.compile(allowedNamespaceNames);
}
@Inject(value = StrutsConstants.STRUTS_DEFAULT_NAMESPACE_NAME, required = false)
public void setDefaultNamespaceName(String defaultNamespaceName) {
this.defaultNamespaceName = defaultNamespaceName;
}
@Inject(value = StrutsConstants.STRUTS_ALLOWED_ACTION_NAMES, required = false)
public void setAllowedActionNames(String allowedActionNames) {
this.allowedActionNames = Pattern.compile(allowedActionNames);
@@ -389,10 +402,28 @@ public class DefaultActionMapper implements ActionMapper {
}
}
mapping.setNamespace(namespace);
mapping.setNamespace(cleanupNamespaceName(namespace));
mapping.setName(cleanupActionName(name));
}
/**
* Checks namespace name against allowed pattern if not matched returns default namespace
*
* @param rawNamespace name extracted from URI
* @return safe namespace name
*/
protected String cleanupNamespaceName(final String rawNamespace) {
if (allowedNamespaceNames.matcher(rawNamespace).matches()) {
return rawNamespace;
} else {
LOG.warn(
"{} did not match allowed namespace names {} - default namespace {} will be used!",
rawNamespace, allowedNamespaceNames, defaultNamespaceName
);
return defaultNamespaceName;
}
}
/**
* Checks action name against allowed pattern if not matched returns default action name
*
@@ -134,6 +134,7 @@ public class PostbackResult extends StrutsResultSupport {
if (actionName != null) {
actionName = conditionalParse(actionName, invocation);
parseLocation = false;
if (namespace == null) {
namespace = invocation.getProxy().getNamespace();
} else {
@@ -159,6 +159,7 @@ public class ServletActionRedirectResult extends ServletRedirectResult implement
*/
public void execute(ActionInvocation invocation) throws Exception {
actionName = conditionalParse(actionName, invocation);
parseLocation = false;
if (namespace == null) {
namespace = invocation.getProxy().getNamespace();
} else {
@@ -122,6 +122,8 @@ public abstract class StrutsResultSupport implements Result, StrutsStatics {
/** use UTF-8 as this is the recommended encoding by W3C to avoid incompatibilities. */
public static final String DEFAULT_URL_ENCODING = "UTF-8";
protected boolean parseLocation = true;
private boolean parse;
private boolean encode;
private String location;
@@ -200,7 +202,7 @@ public abstract class StrutsResultSupport implements Result, StrutsStatics {
* @throws Exception if an error occurs while executing the result.
*/
public void execute(ActionInvocation invocation) throws Exception {
lastFinalLocation = conditionalParse(location, invocation);
lastFinalLocation = parseLocation ? conditionalParse(location, invocation) : location;
doExecute(lastFinalLocation, invocation);
}
+5 -10
View File
@@ -45,11 +45,6 @@
java.lang.ClassLoader,
java.lang.Shutdown,
java.lang.ProcessBuilder,
ognl.OgnlContext,
ognl.ClassResolver,
ognl.TypeConverter,
ognl.MemberAccess,
com.opensymphony.xwork2.ognl.SecurityMemberAccess,
com.opensymphony.xwork2.ActionContext" />
<!-- this must be valid regex, each '.' in package name must be escaped! -->
@@ -59,16 +54,16 @@
<!-- this is simpler version of the above used with string comparison -->
<constant name="struts.excludedPackageNames"
value="
java.lang.,
ognl.,
javax,
javax.,
freemarker.core.,
freemarker.template.,
freemarker.ext.rhino.,
freemarker.ext.beans.,
sun.misc.,
sun.reflect.,
javassist." />
javassist.,
com.opensymphony.xwork2.ognl.,
com.opensymphony.xwork2.security.,
com.opensymphony.xwork2.util." />
<bean class="com.opensymphony.xwork2.ObjectFactory" name="struts"/>
<bean type="com.opensymphony.xwork2.factory.ResultFactory" name="struts" class="org.apache.struts2.factory.StrutsResultFactory" />
@@ -72,6 +72,41 @@ public class ChainResultTest extends XWorkTestCase {
}
}
public void testWithNoNamespace() throws Exception {
ActionChainResult result = new ActionChainResult();
result.setActionName("${actionName}");
String expectedActionName = "testActionName";
String expectedNamespace = "${1-1}";
Map<String, Object> values = new HashMap<>();
values.put("actionName", expectedActionName);
ValueStack stack = ActionContext.getContext().getValueStack();
stack.push(values);
Mock actionProxyMock = new Mock(ActionProxy.class);
actionProxyMock.expect("execute");
actionProxyMock.expectAndReturn("getNamespace", expectedNamespace);
actionProxyMock.expectAndReturn("getActionName", expectedActionName);
actionProxyMock.expectAndReturn("getMethod", null);
ActionProxy actionProxy = (ActionProxy) actionProxyMock.proxy();
ActionProxyFactory testActionProxyFactory = new NamespaceActionNameTestActionProxyFactory(expectedNamespace, expectedActionName, actionProxy);
result.setActionProxyFactory(testActionProxyFactory);
Mock invocationMock = new Mock(ActionInvocation.class);
invocationMock.matchAndReturn("getProxy", actionProxy);
try {
ActionContext testContext = new ActionContext(stack.getContext());
ActionContext.setContext(testContext);
result.execute((ActionInvocation) invocationMock.proxy());
actionProxyMock.verify();
} finally {
ActionContext.setContext(null);
}
}
public void testRecursiveChain() throws Exception {
ActionProxy proxy = actionProxyFactory.createActionProxy("", "InfiniteRecursionChain", null, null);
@@ -88,7 +123,7 @@ public class ChainResultTest extends XWorkTestCase {
private String expectedActionName;
private String expectedNamespace;
public NamespaceActionNameTestActionProxyFactory(String expectedNamespace, String expectedActionName, ActionProxy returnVal) {
NamespaceActionNameTestActionProxyFactory(String expectedNamespace, String expectedActionName, ActionProxy returnVal) {
this.expectedNamespace = expectedNamespace;
this.expectedActionName = expectedActionName;
this.returnVal = returnVal;
@@ -78,12 +78,14 @@ public class XmlConfigurationProviderTest extends ConfigurationTestBase {
}
public void testNeedsReload() throws Exception {
container.getInstance(FileManagerFactory.class).setReloadingConfigs("true");
final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-actions.xml";
ConfigurationProvider provider = buildConfigurationProvider(filename);
container.getInstance(FileManagerFactory.class).setReloadingConfigs("true");
ConfigurationProvider provider = new XmlConfigurationProvider(filename, true);
container.getInstance(FileManagerFactory.class).getFileManager().setReloadingConfigs(true);
container.inject(provider);
provider.init(configuration);
provider.loadPackages();
assertTrue(!provider.needsReload()); // Revision exists and timestamp didn't change
assertFalse(provider.needsReload()); // Revision exists and timestamp didn't change
File file = new File(getClass().getResource("/" + filename).toURI());
assertTrue("not exists: " + file.toString(), file.exists());
@@ -92,6 +94,24 @@ public class XmlConfigurationProviderTest extends ConfigurationTestBase {
assertTrue(provider.needsReload());
}
public void testNeedsReloadNotReloadingConfigs() throws Exception {
final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-actions.xml";
buildConfigurationProvider(filename);
ConfigurationProvider provider = new XmlConfigurationProvider(filename, true);
container.getInstance(FileManagerFactory.class).getFileManager().setReloadingConfigs(false);
container.inject(provider);
provider.init(configuration);
provider.loadPackages();
assertFalse(provider.needsReload()); // Revision exists and timestamp didn't change
File file = new File(getClass().getResource("/" + filename).toURI());
assertTrue("not exists: " + file.toString(), file.exists());
changeFileTime(file);
assertFalse(provider.needsReload());
}
public void testInheritence() throws Exception {
final String filename = "com/opensymphony/xwork2/config/providers/xwork-include-parent.xml";
ConfigurationProvider provider = buildConfigurationProvider(filename);
@@ -155,10 +175,13 @@ public class XmlConfigurationProviderTest extends ConfigurationTestBase {
public void testEmptySpaces() throws Exception {
final String filename = "com/opensymphony/xwork2/config/providers/xwork- test.xml";
ConfigurationProvider provider = new XmlConfigurationProvider(filename, true);
container.getInstance(FileManagerFactory.class).getFileManager().setReloadingConfigs(true);
container.inject(provider);
provider.init(configuration);
provider.loadPackages();
ConfigurationProvider provider = buildConfigurationProvider(filename);
assertTrue(!provider.needsReload());
assertFalse(provider.needsReload());
URI uri = ClassLoaderUtil.getResource(filename, ConfigurationProvider.class).toURI();
@@ -170,6 +193,27 @@ public class XmlConfigurationProviderTest extends ConfigurationTestBase {
assertTrue(provider.needsReload());
}
public void testEmptySpacesNotReloadingConfigs() throws Exception {
final String filename = "com/opensymphony/xwork2/config/providers/xwork- test.xml";
buildConfigurationProvider(filename);
ConfigurationProvider provider = new XmlConfigurationProvider(filename, true);
container.getInstance(FileManagerFactory.class).getFileManager().setReloadingConfigs(false);
container.inject(provider);
provider.init(configuration);
provider.loadPackages();
assertFalse(provider.needsReload());
URI uri = ClassLoaderUtil.getResource(filename, ConfigurationProvider.class).toURI();
File file = new File(uri);
assertTrue(file.exists());
changeFileTime(file);
assertFalse(provider.needsReload());
}
public void testConfigsInJarFiles() throws Exception {
container.getInstance(FileManagerFactory.class).getFileManager().setReloadingConfigs(true);
testProvider("xwork-jar.xml");
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package com.opensymphony.xwork2.util;
package com.opensymphony.xwork2.conversion.impl;
import com.opensymphony.xwork2.XWorkTestCase;
@@ -0,0 +1,75 @@
/*
* 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 com.opensymphony.xwork2.ognl;
import com.opensymphony.xwork2.test.TestArrayBean;
import org.apache.struts2.StrutsInternalTestCase;
public class OgnlUtilStrutsTest extends StrutsInternalTestCase {
private OgnlUtil ognlUtil;
@Override
public void setUp() throws Exception {
super.setUp();
ognlUtil = container.getInstance(OgnlUtil.class);
}
public void testDefaultExcludes() {
ognlUtil.setExcludedClasses("");
ognlUtil.setExcludedPackageNames("");
ognlUtil.setExcludedPackageNamePatterns("");
assertTrue(ognlUtil.getExcludedClasses().size() > 0);
assertTrue(ognlUtil.getExcludedPackageNames().size() > 0);
try {
ognlUtil.getExcludedClasses().clear();
fail("Missing the expected Exception");
} catch (Exception ex) {
assertTrue(ex instanceof UnsupportedOperationException);
}
try {
ognlUtil.getExcludedPackageNames().clear();
fail("Missing the expected Exception");
} catch (Exception ex) {
assertTrue(ex instanceof UnsupportedOperationException);
}
try {
ognlUtil.getExcludedPackageNamePatterns().clear();
fail("Missing the expected Exception");
} catch (Exception ex) {
assertTrue(ex instanceof UnsupportedOperationException);
}
}
public void testAccessToSizeMethod() throws Exception {
// given
TestArrayBean bean = new TestArrayBean();
bean.getPersons().add("Alice");
bean.getPersons().add("Mich");
// when
Object value = ognlUtil.getValue("persons.size() > 0", ognlUtil.createDefaultContext(bean), bean);
// then
assertTrue(value instanceof Boolean);
assertTrue((Boolean) value);
}
}
@@ -41,7 +41,7 @@ public class OgnlUtilTest extends XWorkTestCase {
ognlUtil = container.getInstance(OgnlUtil.class);
}
public void testCanSetADependentObject() throws Exception {
public void testCanSetADependentObject() {
String dogName = "fido";
OgnlRuntime.setNullHandler(Owner.class, new NullHandler() {
@@ -22,7 +22,6 @@ import com.opensymphony.xwork2.util.TextParseUtil;
import junit.framework.TestCase;
import java.lang.reflect.Member;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -62,7 +61,7 @@ public class SecurityMemberAccessTest extends TestCase {
String propertyName = "stringField";
Member member = FooBar.class.getDeclaredMethod("get" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1));
Set<Class<?>> excluded = new HashSet<Class<?>>();
Set<Class<?>> excluded = new HashSet<>();
excluded.add(FooBar.class);
sma.setExcludedClasses(excluded);
@@ -108,7 +107,7 @@ public class SecurityMemberAccessTest extends TestCase {
String propertyName = "barLogic";
Member member = BarInterface.class.getMethod(propertyName);
Set<Class<?>> excluded = new HashSet<Class<?>>();
Set<Class<?>> excluded = new HashSet<>();
excluded.add(BarInterface.class);
sma.setExcludedClasses(excluded);
@@ -126,7 +125,7 @@ public class SecurityMemberAccessTest extends TestCase {
String propertyName = "fooLogic";
Member member = FooBar.class.getMethod(propertyName);
Set<Class<?>> excluded = new HashSet<Class<?>>();
Set<Class<?>> excluded = new HashSet<>();
excluded.add(BarInterface.class);
sma.setExcludedClasses(excluded);
@@ -158,7 +157,7 @@ public class SecurityMemberAccessTest extends TestCase {
String propertyName = "barLogic";
Member member = BarInterface.class.getMethod(propertyName);
Set<Class<?>> excluded = new HashSet<Class<?>>();
Set<Class<?>> excluded = new HashSet<>();
excluded.add(FooBarInterface.class);
sma.setExcludedClasses(excluded);
@@ -173,7 +172,7 @@ public class SecurityMemberAccessTest extends TestCase {
// given
SecurityMemberAccess sma = new SecurityMemberAccess(false);
Set<Pattern> excluded = new HashSet<Pattern>();
Set<Pattern> excluded = new HashSet<>();
excluded.add(Pattern.compile("^" + FooBar.class.getPackage().getName().replaceAll("\\.", "\\\\.") + ".*"));
sma.setExcludedPackageNamePatterns(excluded);
@@ -191,7 +190,7 @@ public class SecurityMemberAccessTest extends TestCase {
// given
SecurityMemberAccess sma = new SecurityMemberAccess(false);
Set<String> excluded = new HashSet<String>();
Set<String> excluded = new HashSet<>();
excluded.add(FooBar.class.getPackage().getName());
sma.setExcludedPackageNames(excluded);
@@ -205,11 +204,11 @@ public class SecurityMemberAccessTest extends TestCase {
assertFalse("stringField is accessible!", actual);
}
public void testDefaultPackageExclusion() throws Exception {
public void testDefaultPackageExclusion() {
// given
SecurityMemberAccess sma = new SecurityMemberAccess(false);
Set<Pattern> excluded = new HashSet<Pattern>();
Set<Pattern> excluded = new HashSet<>();
excluded.add(Pattern.compile("^" + FooBar.class.getPackage().getName().replaceAll("\\.", "\\\\.") + ".*"));
sma.setExcludedPackageNamePatterns(excluded);
@@ -220,11 +219,11 @@ public class SecurityMemberAccessTest extends TestCase {
assertFalse("default package is excluded!", actual);
}
public void testDefaultPackageExclusion2() throws Exception {
public void testDefaultPackageExclusion2() {
// given
SecurityMemberAccess sma = new SecurityMemberAccess(false);
Set<Pattern> excluded = new HashSet<Pattern>();
Set<Pattern> excluded = new HashSet<>();
excluded.add(Pattern.compile("^$"));
sma.setExcludedPackageNamePatterns(excluded);
@@ -317,10 +316,10 @@ public class SecurityMemberAccessTest extends TestCase {
public void testAccessPrimitiveDoubleWithNames() throws Exception {
// given
SecurityMemberAccess sma = new SecurityMemberAccess(false);
sma.setExcludedPackageNames(TextParseUtil.commaDelimitedStringToSet("java.lang.,ognl,javax"));
sma.setExcludedPackageNames(TextParseUtil.commaDelimitedStringToSet("ognl.,javax."));
Set<Class<?>> excluded = new HashSet<Class<?>>();
Set<Class<?>> excluded = new HashSet<>();
excluded.add(Object.class);
excluded.add(Runtime.class);
excluded.add(System.class);
@@ -369,7 +368,7 @@ public class SecurityMemberAccessTest extends TestCase {
public void testAccessPrimitiveDoubleWithPackageRegExs() throws Exception {
// given
SecurityMemberAccess sma = new SecurityMemberAccess(false);
Set<Pattern> patterns = new HashSet<Pattern>();
Set<Pattern> patterns = new HashSet<>();
patterns.add(Pattern.compile("^java\\.lang\\..*"));
sma.setExcludedPackageNamePatterns(patterns);
@@ -386,7 +385,7 @@ public class SecurityMemberAccessTest extends TestCase {
public void testAccessMemberAccessIsAccessible() throws Exception {
// given
SecurityMemberAccess sma = new SecurityMemberAccess(false);
Set<Class<?>> excluded = new HashSet<Class<?>>();
Set<Class<?>> excluded = new HashSet<>();
excluded.add(ognl.MemberAccess.class);
sma.setExcludedClasses(excluded);
@@ -404,7 +403,7 @@ public class SecurityMemberAccessTest extends TestCase {
public void testAccessMemberAccessIsBlocked() throws Exception {
// given
SecurityMemberAccess sma = new SecurityMemberAccess(false);
Set<Class<?>> excluded = new HashSet<Class<?>>();
Set<Class<?>> excluded = new HashSet<>();
excluded.add(SecurityMemberAccess.class);
sma.setExcludedClasses(excluded);
@@ -419,6 +418,21 @@ public class SecurityMemberAccessTest extends TestCase {
assertFalse(accessible);
}
public void testPackageNameExclusionAsCommaDelimited() {
// given
SecurityMemberAccess sma = new SecurityMemberAccess(false);
sma.setExcludedPackageNames(TextParseUtil.commaDelimitedStringToSet("java.lang."));
// when
boolean actual = sma.isPackageExcluded(String.class.getPackage(), null);
actual &= sma.isPackageExcluded(null, String.class.getPackage());
// then
assertTrue("package java.lang. is accessible!", actual);
}
}
class FooBar implements FooBarInterface {
@@ -0,0 +1,35 @@
/*
* 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 com.opensymphony.xwork2.test;
import java.util.ArrayList;
import java.util.List;
public class TestArrayBean {
private List<String> persons = new ArrayList<>();
public void setPersons(List<String> persons) {
this.persons = persons;
}
public List<String> getPersons() {
return persons;
}
}
@@ -21,16 +21,9 @@ package com.opensymphony.xwork2.util;
import com.opensymphony.xwork2.FileManager;
import com.opensymphony.xwork2.FileManagerFactory;
import com.opensymphony.xwork2.XWorkTestCase;
import com.opensymphony.xwork2.util.fs.DefaultFileManager;
import org.apache.struts2.util.fs.JBossFileManager;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import java.net.URLStreamHandlerFactory;
import java.net.*;
/**
* FileManager Tester.
@@ -49,23 +42,40 @@ public class DefaultFileManagerTest extends XWorkTestCase {
fileManager = container.getInstance(FileManagerFactory.class).getFileManager();
}
public void disabled_testGetFileInJar() throws Exception {
testLoadFile("xwork-jar.xml");
testLoadFile("xwork - jar.xml");
testLoadFile("xwork-zip.xml");
testLoadFile("xwork - zip.xml");
testLoadFile("xwork-jar2.xml");
testLoadFile("xwork - jar2.xml");
testLoadFile("xwork-zip2.xml");
testLoadFile("xwork - zip2.xml");
public void testGetFileInJar() throws Exception {
testLoadFile("xwork-jar.xml", false);
testLoadFile("xwork - jar.xml", false);
testLoadFile("xwork-zip.xml", false);
testLoadFile("xwork - zip.xml", false);
testLoadFile("xwork-jar2.xml", false);
testLoadFile("xwork - jar2.xml", false);
testLoadFile("xwork-zip2.xml", false);
testLoadFile("xwork - zip2.xml", false);
testLoadFile("xwork-jar.xml", true);
testLoadFile("xwork - jar.xml", true);
testLoadFile("xwork-zip.xml", true);
testLoadFile("xwork - zip.xml", true);
testLoadFile("xwork-jar2.xml", true);
testLoadFile("xwork - jar2.xml", true);
testLoadFile("xwork-zip2.xml", true);
testLoadFile("xwork - zip2.xml", true);
}
private void testLoadFile(String fileName) {
fileManager.setReloadingConfigs(true);
private void testLoadFile(String fileName, boolean reloadConfigs) throws Exception {
fileManager.setReloadingConfigs(reloadConfigs);
URL url = ClassLoaderUtil.getResource(fileName, DefaultFileManagerTest.class);
InputStream file = fileManager.loadFile(url);
assertNotNull(file);
assertTrue(fileManager.fileNeedsReloading(fileName));
file.close();
assertFalse(fileManager.fileNeedsReloading(url.toString()));
long now = System.currentTimeMillis();
JarURLConnection conn = (JarURLConnection) url.openConnection();
conn.getJarEntry().setTime(now + 60000);
conn.getInputStream().close();
assertEquals(reloadConfigs, fileManager.fileNeedsReloading(url.toString()));
}
public void testReloadingConfigs() throws Exception {
@@ -21,7 +21,9 @@ package com.opensymphony.xwork2.util.fs;
import com.opensymphony.xwork2.FileManager;
import com.opensymphony.xwork2.FileManagerFactory;
import com.opensymphony.xwork2.XWorkTestCase;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.filefilter.WildcardFileFilter;
import java.io.File;
import java.io.FileOutputStream;
@@ -30,6 +32,8 @@ import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.jar.Attributes;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
@@ -113,6 +117,20 @@ public class JarEntryRevisionTest extends XWorkTestCase {
assertTrue(entry.needsReloading());
}
@Override
protected void tearDown() throws Exception {
Path tmpFile = Files.createTempFile("jar_cache", null);
Path tmpFolder = tmpFile.getParent();
int count = FileUtils.listFiles(tmpFolder.toFile(), new WildcardFileFilter("jar_cache*"),
null).size();
if (tmpFile.toFile().delete()) {
count--;
}
assertEquals(0, count);
super.tearDown();
}
/**
* WW-4901 Simulating container implementation of {@link URL#openConnection()}
@@ -47,6 +47,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
@@ -134,7 +135,7 @@ public class DispatcherTest extends StrutsInternalTestCase {
assertEquals("utf-8", req.getCharacterEncoding());
}
public void testPrepareMultipartRequest() throws Exception {
MockHttpServletRequest req = new MockHttpServletRequest();
MockHttpServletResponse res = new MockHttpServletResponse();
@@ -175,9 +176,9 @@ public class DispatcherTest extends StrutsInternalTestCase {
}
public void testDispatcherListener() throws Exception {
final DispatcherListenerState state = new DispatcherListenerState();
Dispatcher.addDispatcherListener(new DispatcherListener() {
public void dispatcherDestroyed(Dispatcher du) {
state.isDestroyed = true;
@@ -186,21 +187,21 @@ public class DispatcherTest extends StrutsInternalTestCase {
state.isInitialized = true;
}
});
assertFalse(state.isDestroyed);
assertFalse(state.isInitialized);
Dispatcher du = initDispatcher(new HashMap<String, String>() );
assertTrue(state.isInitialized);
du.cleanup();
assertTrue(state.isDestroyed);
}
public void testConfigurationManager() {
Dispatcher du;
final InternalConfigurationManager configurationManager = new InternalConfigurationManager(Container.DEFAULT_NAME);
@@ -208,26 +209,42 @@ public class DispatcherTest extends StrutsInternalTestCase {
du = new MockDispatcher(new MockServletContext(), new HashMap<String, String>(), configurationManager);
du.init();
Dispatcher.setInstance(du);
assertFalse(configurationManager.destroyConfiguration);
du.cleanup();
assertTrue(configurationManager.destroyConfiguration);
}
finally {
Dispatcher.setInstance(null);
}
}
public void testInitLoadsDefaultConfig() {
Dispatcher du = new Dispatcher(new MockServletContext(), new HashMap<String, String>());
du.init();
Configuration config = du.getConfigurationManager().getConfiguration();
assertNotNull(config);
HashSet<String> expected = new HashSet<String>();
expected.add("struts-default.xml");
expected.add("struts-plugin.xml");
expected.add("struts.xml");
assertEquals(expected, config.getLoadedFileNames());
assertTrue(config.getPackageConfigs().size() > 0);
PackageConfig packageConfig = config.getPackageConfig("struts-default");
assertTrue(packageConfig.getInterceptorConfigs().size() > 0);
assertTrue(packageConfig.getResultTypeConfigs().size() > 0);
}
public void testObjectFactoryDestroy() throws Exception {
ConfigurationManager cm = new ConfigurationManager(Container.DEFAULT_NAME);
Dispatcher du = new MockDispatcher(new MockServletContext(), new HashMap<String, String>(), cm);
Mock mockConfiguration = new Mock(Configuration.class);
cm.setConfiguration((Configuration)mockConfiguration.proxy());
Mock mockContainer = new Mock(Container.class);
String reloadConfigs = container.getInstance(String.class, StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD);
mockContainer.expectAndReturn("getInstance", C.args(C.eq(String.class), C.eq(StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD)),
@@ -248,18 +265,18 @@ public class DispatcherTest extends StrutsInternalTestCase {
mockConfiguration.verify();
mockContainer.verify();
}
public void testInterceptorDestroy() throws Exception {
public void testInterceptorDestroy() throws Exception {
Mock mockInterceptor = new Mock(Interceptor.class);
mockInterceptor.matchAndReturn("hashCode", 0);
mockInterceptor.expect("destroy");
InterceptorMapping interceptorMapping = new InterceptorMapping("test", (Interceptor) mockInterceptor.proxy());
InterceptorStackConfig isc = new InterceptorStackConfig.Builder("test").addInterceptor(interceptorMapping).build();
PackageConfig packageConfig = new PackageConfig.Builder("test").addInterceptorStackConfig(isc).build();
Map<String, PackageConfig> packageConfigs = new HashMap<String, PackageConfig>();
packageConfigs.put("test", packageConfig);
@@ -273,14 +290,14 @@ public class DispatcherTest extends StrutsInternalTestCase {
mockConfiguration.matchAndReturn("getPackageConfigs", packageConfigs);
mockConfiguration.matchAndReturn("getContainer", mockContainer.proxy());
mockConfiguration.expect("destroy");
ConfigurationManager configurationManager = new ConfigurationManager(Container.DEFAULT_NAME);
configurationManager.setConfiguration((Configuration) mockConfiguration.proxy());
Dispatcher dispatcher = new MockDispatcher(new MockServletContext(), new HashMap<String, String>(), configurationManager);
dispatcher.init();
dispatcher.cleanup();
mockInterceptor.verify();
mockContainer.verify();
mockConfiguration.verify();
@@ -363,8 +380,8 @@ public class DispatcherTest extends StrutsInternalTestCase {
destroyConfiguration = true;
}
}
class DispatcherListenerState {
public boolean isInitialized = false;
public boolean isDestroyed = false;
@@ -27,12 +27,12 @@ import com.opensymphony.xwork2.config.entities.PackageConfig;
import com.opensymphony.xwork2.config.impl.DefaultConfiguration;
import com.opensymphony.xwork2.inject.Container;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsException;
import org.apache.struts2.StrutsInternalTestCase;
import org.apache.struts2.result.StrutsResultSupport;
import org.apache.struts2.views.jsp.StrutsMockHttpServletRequest;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -65,7 +65,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
};
}
public void testGetMapping() throws Exception {
public void testGetMapping() {
req.setupGetRequestURI("/my/namespace/actionName.action");
req.setupGetServletPath("/my/namespace/actionName.action");
req.setupGetAttribute(null);
@@ -79,7 +79,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertNull(mapping.getMethod());
}
public void testGetMappingWithMethod() throws Exception {
public void testGetMappingWithMethod() {
req.setupGetParameterMap(new HashMap());
req.setupGetRequestURI("/my/namespace/actionName!add.action");
req.setupGetServletPath("/my/namespace/actionName!add.action");
@@ -95,7 +95,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("add", mapping.getMethod());
}
public void testGetMappingWithSlashedName() throws Exception {
public void testGetMappingWithSlashedName() {
req.setupGetRequestURI("/my/foo/actionName.action");
req.setupGetServletPath("/my/foo/actionName.action");
@@ -111,7 +111,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertNull(mapping.getMethod());
}
public void testGetMappingWithSlashedNameAtRootButNoSlashPackage() throws Exception {
public void testGetMappingWithSlashedNameAtRootButNoSlashPackage() {
req.setupGetRequestURI("/foo/actionName.action");
req.setupGetServletPath("/foo/actionName.action");
@@ -127,7 +127,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertNull(mapping.getMethod());
}
public void testGetMappingWithSlashedNameAtRoot() throws Exception {
public void testGetMappingWithSlashedNameAtRoot() {
config = new DefaultConfiguration();
PackageConfig pkg = new PackageConfig.Builder("myns")
.namespace("/my/namespace").build();
@@ -158,7 +158,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
public void testGetMappingWithNamespaceSlash() throws Exception {
public void testGetMappingWithNamespaceSlash() {
req.setupGetRequestURI("/my-hh/abc.action");
req.setupGetServletPath("/my-hh/abc.action");
@@ -181,7 +181,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("my-hh/abc", mapping.getName());
}
public void testGetMappingWithUnknownNamespace() throws Exception {
public void testGetMappingWithUnknownNamespace() {
req.setupGetRequestURI("/bo/foo/actionName.action");
req.setupGetServletPath("/bo/foo/actionName.action");
req.setupGetAttribute(null);
@@ -195,7 +195,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertNull(mapping.getMethod());
}
public void testGetMappingWithUnknownNamespaceButFullNamespaceSelect() throws Exception {
public void testGetMappingWithUnknownNamespaceButFullNamespaceSelect() {
req.setupGetRequestURI("/bo/foo/actionName.action");
req.setupGetServletPath("/bo/foo/actionName.action");
req.setupGetAttribute(null);
@@ -210,7 +210,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertNull(mapping.getMethod());
}
public void testGetMappingWithActionName_methodAndName() throws Exception {
public void testGetMappingWithActionName_methodAndName() {
DefaultActionMapper mapper = new DefaultActionMapper();
mapper.setAllowDynamicMethodCalls("true");
ActionMapping mapping = mapper.getMappingFromActionName("actionName!add");
@@ -218,24 +218,24 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("add", mapping.getMethod());
}
public void testGetMappingWithActionName_name() throws Exception {
public void testGetMappingWithActionName_name() {
DefaultActionMapper mapper = new DefaultActionMapper();
ActionMapping mapping = mapper.getMappingFromActionName("actionName");
assertEquals("actionName", mapping.getName());
assertEquals(null, mapping.getMethod());
assertNull(mapping.getMethod());
}
public void testGetMappingWithActionName_noDynamicMethod() throws Exception {
public void testGetMappingWithActionName_noDynamicMethod() {
DefaultActionMapper mapper = new DefaultActionMapper();
mapper.setAllowDynamicMethodCalls("false");
ActionMapping mapping = mapper.getMappingFromActionName("actionName!add");
assertEquals("actionName!add", mapping.getName());
assertEquals(null, mapping.getMethod());
assertNull(mapping.getMethod());
}
public void testGetMappingWithActionName_noDynamicMethodColonPrefix() throws Exception {
public void testGetMappingWithActionName_noDynamicMethodColonPrefix() {
Map parameterMap = new HashMap();
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put(DefaultActionMapper.METHOD_PREFIX + "someMethod", "");
StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
@@ -247,16 +247,16 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
ActionMapping actionMapping = defaultActionMapper.getMapping(request, configManager);
assertEquals("someServletPath", actionMapping.getName());
assertEquals(null, actionMapping.getMethod());
assertNull(actionMapping.getMethod());
}
public void testGetMappingWithActionName_null() throws Exception {
public void testGetMappingWithActionName_null() {
DefaultActionMapper mapper = new DefaultActionMapper();
ActionMapping mapping = mapper.getMappingFromActionName(null);
assertNull(mapping);
}
public void testGetUri() throws Exception {
public void testGetUri() {
req.setupGetParameterMap(new HashMap());
req.setupGetRequestURI("/my/namespace/actionName.action");
req.setupGetServletPath("/my/namespace/actionName.action");
@@ -268,7 +268,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("/my/namespace/actionName.action", mapper.getUriFromActionMapping(mapping));
}
public void testGetUriWithSemicolonPresent() throws Exception {
public void testGetUriWithSemicolonPresent() {
req.setupGetParameterMap(new HashMap());
req.setupGetRequestURI("/my/namespace/actionName.action;abc=123rty56");
req.setupGetServletPath("/my/namespace/actionName.action;abc=123rty56");
@@ -280,7 +280,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("/my/namespace/actionName.action", mapper.getUriFromActionMapping(mapping));
}
public void testGetUriWithMethod() throws Exception {
public void testGetUriWithMethod() {
req.setupGetParameterMap(new HashMap());
req.setupGetRequestURI("/my/namespace/actionName!add.action");
req.setupGetServletPath("/my/namespace/actionName!add.action");
@@ -293,8 +293,8 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("/my/namespace/actionName!add.action", mapper.getUriFromActionMapping(mapping));
}
public void testGetUriWithOriginalExtension() throws Exception {
ActionMapping mapping = new ActionMapping("actionName", "/ns", null, new HashMap());
public void testGetUriWithOriginalExtension() {
ActionMapping mapping = new ActionMapping("actionName", "/ns", null, new HashMap<String, Object>());
ActionMapping orig = new ActionMapping();
orig.setExtension("foo");
@@ -304,7 +304,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("/ns/actionName.foo", mapper.getUriFromActionMapping(mapping));
}
public void testGetMappingWithNoExtension() throws Exception {
public void testGetMappingWithNoExtension() {
req.setupGetParameterMap(new HashMap());
req.setupGetRequestURI("/my/namespace/actionName");
req.setupGetServletPath("/my/namespace/actionName");
@@ -320,7 +320,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertNull(mapping.getMethod());
}
public void testGetMappingWithNoExtensionButUriHasExtension() throws Exception {
public void testGetMappingWithNoExtensionButUriHasExtension() {
req.setupGetParameterMap(new HashMap());
req.setupGetRequestURI("/my/namespace/actionName.html");
req.setupGetServletPath("/my/namespace/actionName.html");
@@ -340,7 +340,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
// === test name & namespace ===
// =============================
public void testParseNameAndNamespace1() throws Exception {
public void testParseNameAndNamespace1() {
ActionMapping actionMapping = new ActionMapping();
DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
@@ -350,7 +350,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals(actionMapping.getNamespace(), "");
}
public void testParseNameAndNamespace2() throws Exception {
public void testParseNameAndNamespace2() {
ActionMapping actionMapping = new ActionMapping();
DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
@@ -360,7 +360,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals(actionMapping.getNamespace(), "/");
}
public void testParseNameAndNamespace3() throws Exception {
public void testParseNameAndNamespace3() {
ActionMapping actionMapping = new ActionMapping();
DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
@@ -370,7 +370,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals(actionMapping.getNamespace(), "/my");
}
public void testParseNameAndNamespace_NoSlashes() throws Exception {
public void testParseNameAndNamespace_NoSlashes() {
ActionMapping actionMapping = new ActionMapping();
DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
@@ -381,7 +381,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals(actionMapping.getNamespace(), "");
}
public void testParseNameAndNamespace_AllowSlashes() throws Exception {
public void testParseNameAndNamespace_AllowSlashes() {
ActionMapping actionMapping = new ActionMapping();
DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
@@ -397,8 +397,8 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
// === test special prefix ===
// ===========================
public void testActionPrefixWhenDisabled() throws Exception {
Map parameterMap = new HashMap();
public void testActionPrefixWhenDisabled() {
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put(DefaultActionMapper.ACTION_PREFIX + "myAction", "");
StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
@@ -411,8 +411,8 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("someServletPath", actionMapping.getName());
}
public void testActionPrefixWhenEnabled() throws Exception {
Map parameterMap = new HashMap();
public void testActionPrefixWhenEnabled() {
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put(DefaultActionMapper.ACTION_PREFIX + "myAction", "");
StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
@@ -426,8 +426,8 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("myAction", actionMapping.getName());
}
public void testActionPrefixWhenSlashesAndCrossNamespaceDisabled() throws Exception {
Map parameterMap = new HashMap();
public void testActionPrefixWhenSlashesAndCrossNamespaceDisabled() {
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put(DefaultActionMapper.ACTION_PREFIX + "my/Action", "");
StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
@@ -442,8 +442,8 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("my/Action", actionMapping.getName());
}
public void testActionPrefixWhenSlashesButSlashesDisabledAndCrossNamespaceDisabled() throws Exception {
Map parameterMap = new HashMap();
public void testActionPrefixWhenSlashesButSlashesDisabledAndCrossNamespaceDisabled() {
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put(DefaultActionMapper.ACTION_PREFIX + "my/Action", "");
StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
@@ -458,8 +458,8 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("Action", actionMapping.getName());
}
public void testActionPrefixWhenSlashesButSlashesDisabledAndCrossNamespace() throws Exception {
Map parameterMap = new HashMap();
public void testActionPrefixWhenSlashesButSlashesDisabledAndCrossNamespace() {
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put(DefaultActionMapper.ACTION_PREFIX + "my/Action", "");
StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
@@ -475,8 +475,8 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("my/Action", actionMapping.getName());
}
public void testActionPrefixWhenCrossNamespace() throws Exception {
Map parameterMap = new HashMap();
public void testActionPrefixWhenCrossNamespace() {
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put(DefaultActionMapper.ACTION_PREFIX + "/my/Action", "");
StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
@@ -491,8 +491,8 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("/my/Action", actionMapping.getName());
}
public void testActionPrefix_fromImageButton() throws Exception {
Map parameterMap = new HashMap();
public void testActionPrefix_fromImageButton() {
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put(DefaultActionMapper.ACTION_PREFIX + "myAction", "");
parameterMap.put(DefaultActionMapper.ACTION_PREFIX + "myAction.x", "");
parameterMap.put(DefaultActionMapper.ACTION_PREFIX + "myAction.y", "");
@@ -508,8 +508,8 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("myAction", actionMapping.getName());
}
public void testActionPrefix_fromIEImageButton() throws Exception {
Map parameterMap = new HashMap();
public void testActionPrefix_fromIEImageButton() {
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put(DefaultActionMapper.ACTION_PREFIX + "myAction.x", "");
parameterMap.put(DefaultActionMapper.ACTION_PREFIX + "myAction.y", "");
@@ -524,8 +524,8 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("myAction", actionMapping.getName());
}
public void testRedirectPrefix() throws Exception {
Map parameterMap = new HashMap();
public void testRedirectPrefix() {
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put("redirect:" + "http://www.google.com", "");
StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
@@ -540,8 +540,8 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertNull(result);
}
public void testUnsafeRedirectPrefix() throws Exception {
Map parameterMap = new HashMap();
public void testUnsafeRedirectPrefix() {
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put("redirect:" + "http://%{3*4}", "");
StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
@@ -556,8 +556,8 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertNull(result);
}
public void testRedirectActionPrefix() throws Exception {
Map parameterMap = new HashMap();
public void testRedirectActionPrefix() {
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put("redirectAction:" + "myAction", "");
StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
@@ -573,8 +573,8 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertNull(result);
}
public void testUnsafeRedirectActionPrefix() throws Exception {
Map parameterMap = new HashMap();
public void testUnsafeRedirectActionPrefix() {
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put("redirectAction:" + "%{3*4}", "");
StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
@@ -590,8 +590,8 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertNull(result);
}
public void testRedirectActionPrefixWithEmptyExtension() throws Exception {
Map parameterMap = new HashMap();
public void testRedirectActionPrefixWithEmptyExtension() {
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put("redirectAction:" + "myAction", "");
StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
@@ -608,8 +608,8 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertNull(result);
}
public void testCustomActionPrefix() throws Exception {
Map parameterMap = new HashMap();
public void testCustomActionPrefix() {
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put("foo:myAction", "");
final StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
@@ -627,39 +627,39 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals(actionMapping.getName(), "myAction");
}
public void testDropExtension() throws Exception {
public void testDropExtension() {
DefaultActionMapper mapper = new DefaultActionMapper();
String name = mapper.dropExtension("foo.action", new ActionMapping());
assertTrue("Name not right: "+name, "foo".equals(name));
assertEquals("Name not right: " + name, "foo", name);
name = mapper.dropExtension("foo.action.action", new ActionMapping());
assertTrue("Name not right: "+name, "foo.action".equals(name));
assertEquals("Name not right: " + name, "foo.action", name);
}
public void testDropExtensionWhenBlank() throws Exception {
public void testDropExtensionWhenBlank() {
DefaultActionMapper mapper = new DefaultActionMapper();
mapper.setExtensions("action,,");
String name = mapper.dropExtension("foo.action", new ActionMapping());
assertTrue("Name not right: "+name, "foo".equals(name));
assertEquals("Name not right: " + name, "foo", name);
name = mapper.dropExtension("foo", new ActionMapping());
assertTrue("Name not right: "+name, "foo".equals(name));
assertEquals("Name not right: " + name, "foo", name);
assertNull(mapper.dropExtension("foo.bar", new ActionMapping()));
assertNull(mapper.dropExtension("foo.", new ActionMapping()));
}
public void testDropExtensionEmbeddedDot() throws Exception {
public void testDropExtensionEmbeddedDot() {
DefaultActionMapper mapper = new DefaultActionMapper();
mapper.setExtensions("action,,");
String name = mapper.dropExtension("/foo/bar-1.0/baz.action", new ActionMapping());
assertTrue("Name not right: "+name, "/foo/bar-1.0/baz".equals(name));
assertEquals("Name not right: " + name, "/foo/bar-1.0/baz", name);
name = mapper.dropExtension("/foo/bar-1.0/baz", new ActionMapping());
assertTrue("Name not right: "+name, "/foo/bar-1.0/baz".equals(name));
assertEquals("Name not right: " + name, "/foo/bar-1.0/baz", name);
}
public void testGetUriFromActionMapper1() throws Exception {
public void testGetUriFromActionMapper1() {
DefaultActionMapper mapper = new DefaultActionMapper();
ActionMapping actionMapping = new ActionMapping();
actionMapping.setMethod("myMethod");
@@ -670,7 +670,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("/myNamespace/myActionName!myMethod.action", uri);
}
public void testGetUriFromActionMapper2() throws Exception {
public void testGetUriFromActionMapper2() {
DefaultActionMapper mapper = new DefaultActionMapper();
ActionMapping actionMapping = new ActionMapping();
actionMapping.setMethod("myMethod");
@@ -681,7 +681,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("/myActionName!myMethod.action", uri);
}
public void testGetUriFromActionMapper3() throws Exception {
public void testGetUriFromActionMapper3() {
DefaultActionMapper mapper = new DefaultActionMapper();
ActionMapping actionMapping = new ActionMapping();
actionMapping.setMethod("myMethod");
@@ -693,7 +693,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
}
public void testGetUriFromActionMapper4() throws Exception {
public void testGetUriFromActionMapper4() {
DefaultActionMapper mapper = new DefaultActionMapper();
ActionMapping actionMapping = new ActionMapping();
actionMapping.setName("myActionName");
@@ -703,7 +703,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("/myActionName.action", uri);
}
public void testGetUriFromActionMapper5() throws Exception {
public void testGetUriFromActionMapper5() {
DefaultActionMapper mapper = new DefaultActionMapper();
ActionMapping actionMapping = new ActionMapping();
actionMapping.setName("myActionName");
@@ -714,7 +714,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
}
//
public void testGetUriFromActionMapper6() throws Exception {
public void testGetUriFromActionMapper6() {
DefaultActionMapper mapper = new DefaultActionMapper();
ActionMapping actionMapping = new ActionMapping();
actionMapping.setMethod("myMethod");
@@ -725,7 +725,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("/myNamespace/myActionName!myMethod.action?test=bla", uri);
}
public void testGetUriFromActionMapper7() throws Exception {
public void testGetUriFromActionMapper7() {
DefaultActionMapper mapper = new DefaultActionMapper();
ActionMapping actionMapping = new ActionMapping();
actionMapping.setMethod("myMethod");
@@ -736,7 +736,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("/myActionName!myMethod.action?test=bla", uri);
}
public void testGetUriFromActionMapper8() throws Exception {
public void testGetUriFromActionMapper8() {
DefaultActionMapper mapper = new DefaultActionMapper();
ActionMapping actionMapping = new ActionMapping();
actionMapping.setMethod("myMethod");
@@ -748,7 +748,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
}
public void testGetUriFromActionMapper9() throws Exception {
public void testGetUriFromActionMapper9() {
DefaultActionMapper mapper = new DefaultActionMapper();
ActionMapping actionMapping = new ActionMapping();
actionMapping.setName("myActionName?test=bla");
@@ -758,7 +758,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("/myActionName.action?test=bla", uri);
}
public void testGetUriFromActionMapper10() throws Exception {
public void testGetUriFromActionMapper10() {
DefaultActionMapper mapper = new DefaultActionMapper();
ActionMapping actionMapping = new ActionMapping();
actionMapping.setName("myActionName?test=bla");
@@ -768,7 +768,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("/myActionName.action?test=bla", uri);
}
public void testGetUriFromActionMapper11() throws Exception {
public void testGetUriFromActionMapper11() {
DefaultActionMapper mapper = new DefaultActionMapper();
ActionMapping actionMapping = new ActionMapping();
actionMapping.setName("myActionName.action");
@@ -778,7 +778,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("/myActionName.action", uri);
}
public void testGetUriFromActionMapper12() throws Exception {
public void testGetUriFromActionMapper12() {
DefaultActionMapper mapper = new DefaultActionMapper();
ActionMapping actionMapping = new ActionMapping();
actionMapping.setName("myActionName.action");
@@ -788,7 +788,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("/myActionName.action", uri);
}
public void testGetUriFromActionMapper_justActionAndMethod() throws Exception {
public void testGetUriFromActionMapper_justActionAndMethod() {
DefaultActionMapper mapper = new DefaultActionMapper();
ActionMapping actionMapping = new ActionMapping();
actionMapping.setMethod("myMethod");
@@ -799,7 +799,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("myActionName!myMethod", uri);
}
public void testGetUriFromActionMapperWhenBlankExtension() throws Exception {
public void testGetUriFromActionMapperWhenBlankExtension() {
DefaultActionMapper mapper = new DefaultActionMapper();
mapper.setExtensions(",,");
ActionMapping actionMapping = new ActionMapping();
@@ -811,7 +811,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("/myNamespace/myActionName!myMethod", uri);
}
public void testSetExtension() throws Exception {
public void testSetExtension() {
DefaultActionMapper mapper = new DefaultActionMapper();
mapper.setExtensions("");
assertNull(mapper.extensions);
@@ -828,15 +828,40 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals(Arrays.asList("html", "", "xml"), mapper.extensions);
mapper.setExtensions("xml");
assertEquals(Arrays.asList("xml"), mapper.extensions);
assertEquals(Collections.singletonList("xml"), mapper.extensions);
mapper.setExtensions(",");
assertEquals(Arrays.asList(""), mapper.extensions);
assertEquals(Collections.singletonList(""), mapper.extensions);
}
public void testAllowedActionNames() throws Exception {
public void testAllowedNamespaceNames() {
DefaultActionMapper mapper = new DefaultActionMapper();
String namespace = "/";
assertEquals(namespace, mapper.cleanupNamespaceName(namespace));
namespace = "${namespace}";
assertEquals(mapper.defaultNamespaceName, mapper.cleanupNamespaceName(namespace));
namespace = "${${%{namespace}}}";
assertEquals(mapper.defaultNamespaceName, mapper.cleanupNamespaceName(namespace));
namespace = "${#foo='namespace',#foo}";
assertEquals(mapper.defaultNamespaceName, mapper.cleanupNamespaceName(namespace));
namespace = "/test-namespace/namespace/";
assertEquals("/test-namespace/namespace/", mapper.cleanupNamespaceName(namespace));
namespace = "/test_namespace/namespace-test/";
assertEquals("/test_namespace/namespace-test/", mapper.cleanupNamespaceName(namespace));
namespace = "/test_namespace/namespace.test/";
assertEquals("/test_namespace/namespace.test/", mapper.cleanupActionName(namespace));
}
public void testAllowedActionNames() {
DefaultActionMapper mapper = new DefaultActionMapper();
String actionName = "action";
@@ -861,7 +886,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
assertEquals("test!bar.action", mapper.cleanupActionName(actionName));
}
public void testAllowedMethodNames() throws Exception {
public void testAllowedMethodNames() {
DefaultActionMapper mapper = new DefaultActionMapper();
assertEquals("", mapper.cleanupMethodName(""));
@@ -0,0 +1,96 @@
/*
* 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.result;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.util.ValueStack;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsInternalTestCase;
import org.apache.struts2.dispatcher.mapper.ActionMapper;
import org.easymock.IMocksControl;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import static org.easymock.EasyMock.createControl;
import static org.easymock.EasyMock.expect;
public class PostbackResultTest extends StrutsInternalTestCase {
public void testWithNoNamespace() throws Exception {
ActionContext context = ActionContext.getContext();
ValueStack stack = context.getValueStack();
MockHttpServletRequest req = new MockHttpServletRequest();
MockHttpServletResponse res = new MockHttpServletResponse();
context.put(ServletActionContext.HTTP_REQUEST, req);
context.put(ServletActionContext.HTTP_RESPONSE, res);
PostbackResult result = new PostbackResult();
result.setActionName("myAction${1-1}");
result.setPrependServletContext(false);
IMocksControl control = createControl();
ActionProxy mockActionProxy = control.createMock(ActionProxy.class);
ActionInvocation mockInvocation = control.createMock(ActionInvocation.class);
expect(mockInvocation.getInvocationContext()).andReturn(context).anyTimes();
expect(mockInvocation.getStack()).andReturn(stack).anyTimes();
expect(mockInvocation.getProxy()).andReturn(mockActionProxy);
expect(mockActionProxy.getNamespace()).andReturn("${1-1}");
control.replay();
result.setActionMapper(container.getInstance(ActionMapper.class));
result.execute(mockInvocation);
assertEquals("<!DOCTYPE html><html><body><form action=\"${1-1}/myAction0.action\" method=\"POST\">" +
"<script>setTimeout(function(){document.forms[0].submit();},0);</script></html>", res.getContentAsString());
control.verify();
}
public void testWithNamespace() throws Exception {
ActionContext context = ActionContext.getContext();
ValueStack stack = context.getValueStack();
MockHttpServletRequest req = new MockHttpServletRequest();
MockHttpServletResponse res = new MockHttpServletResponse();
context.put(ServletActionContext.HTTP_REQUEST, req);
context.put(ServletActionContext.HTTP_RESPONSE, res);
PostbackResult result = new PostbackResult();
result.setActionName("myAction${1-1}");
result.setNamespace("myNamespace${1-1}");
result.setPrependServletContext(false);
IMocksControl control = createControl();
ActionInvocation mockInvocation = control.createMock(ActionInvocation.class);
expect(mockInvocation.getInvocationContext()).andReturn(context).anyTimes();
expect(mockInvocation.getStack()).andReturn(stack).anyTimes();
control.replay();
result.setActionMapper(container.getInstance(ActionMapper.class));
result.execute(mockInvocation);
assertEquals("<!DOCTYPE html><html><body><form action=\"myNamespace0/myAction0.action\" method=\"POST\">" +
"<script>setTimeout(function(){document.forms[0].submit();},0);</script></html>", res.getContentAsString());
control.verify();
}
}
@@ -28,7 +28,6 @@ import com.opensymphony.xwork2.util.ValueStack;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsInternalTestCase;
import org.apache.struts2.dispatcher.mapper.ActionMapper;
import org.apache.struts2.result.ServletActionRedirectResult;
import org.apache.struts2.views.util.DefaultUrlHelper;
import org.easymock.IMocksControl;
import org.springframework.mock.web.MockHttpServletRequest;
@@ -41,9 +40,6 @@ import static org.easymock.EasyMock.createControl;
import static org.easymock.EasyMock.expect;
/**
* @version $Date$ $Id$
*/
public class ServletActionRedirectResultTest extends StrutsInternalTestCase {
public void testIncludeParameterInResultWithConditionParseOn() throws Exception {
@@ -76,15 +72,15 @@ public class ServletActionRedirectResultTest extends StrutsInternalTestCase {
context.put(ServletActionContext.HTTP_RESPONSE, res);
Map<String, ResultConfig> results= new HashMap<String, ResultConfig>();
Map<String, ResultConfig> results= new HashMap<>();
results.put("myResult", resultConfig);
ActionConfig actionConfig = new ActionConfig.Builder("", "", "")
.addResultConfigs(results).build();
ServletActionRedirectResult result = new ServletActionRedirectResult();
result.setActionName("myAction");
result.setNamespace("/myNamespace");
result.setActionName("myAction${1-1}");
result.setNamespace("/myNamespace${1-1}");
result.setParse(true);
result.setEncode(false);
result.setPrependServletContext(false);
@@ -103,7 +99,69 @@ public class ServletActionRedirectResultTest extends StrutsInternalTestCase {
control.replay();
result.setActionMapper(container.getInstance(ActionMapper.class));
result.execute(mockInvocation);
assertEquals("/myNamespace/myAction.action?param1=value+1&param2=value+2&param3=value+3#fragment", res.getRedirectedUrl());
assertEquals("/myNamespace0/myAction0.action?param1=value+1&param2=value+2&param3=value+3#fragment", res.getRedirectedUrl());
control.verify();
}
public void testIncludeParameterInResultWithConditionParseOnWithNoNamespace() throws Exception {
ResultConfig resultConfig = new ResultConfig.Builder("", "")
.addParam("actionName", "someActionName")
.addParam("namespace", "someNamespace")
.addParam("encode", "true")
.addParam("parse", "true")
.addParam("location", "someLocation")
.addParam("prependServletContext", "true")
.addParam("method", "someMethod")
.addParam("statusCode", "333")
.addParam("param1", "${#value1}")
.addParam("param2", "${#value2}")
.addParam("param3", "${#value3}")
.addParam("anchor", "${#fragment}")
.build();
ActionContext context = ActionContext.getContext();
ValueStack stack = context.getValueStack();
context.getContextMap().put("value1", "value 1");
context.getContextMap().put("value2", "value 2");
context.getContextMap().put("value3", "value 3");
MockHttpServletRequest req = new MockHttpServletRequest();
MockHttpServletResponse res = new MockHttpServletResponse();
context.put(ServletActionContext.HTTP_REQUEST, req);
context.put(ServletActionContext.HTTP_RESPONSE, res);
Map<String, ResultConfig> results= new HashMap<>();
results.put("myResult", resultConfig);
ActionConfig actionConfig = new ActionConfig.Builder("", "", "")
.addResultConfigs(results).build();
ServletActionRedirectResult result = new ServletActionRedirectResult();
result.setActionName("myAction${1-1}");
result.setParse(true);
result.setEncode(false);
result.setPrependServletContext(false);
result.setAnchor("fragment");
result.setUrlHelper(new DefaultUrlHelper());
IMocksControl control = createControl();
ActionProxy mockActionProxy = control.createMock(ActionProxy.class);
ActionInvocation mockInvocation = control.createMock(ActionInvocation.class);
expect(mockInvocation.getProxy()).andReturn(mockActionProxy).times(2);
expect(mockInvocation.getResultCode()).andReturn("myResult");
expect(mockActionProxy.getConfig()).andReturn(actionConfig);
expect(mockActionProxy.getNamespace()).andReturn("${1-1}");
expect(mockInvocation.getInvocationContext()).andReturn(context);
expect(mockInvocation.getStack()).andReturn(stack).anyTimes();
control.replay();
result.setActionMapper(container.getInstance(ActionMapper.class));
result.execute(mockInvocation);
assertEquals("/${1-1}/myAction0.action?param1=value+1&param2=value+2&param3=value+3#fragment", res.getRedirectedUrl());
control.verify();
}
@@ -131,7 +189,7 @@ public class ServletActionRedirectResultTest extends StrutsInternalTestCase {
context.put(ServletActionContext.HTTP_RESPONSE, res);
Map<String, ResultConfig> results= new HashMap<String, ResultConfig>();
Map<String, ResultConfig> results= new HashMap<>();
results.put("myResult", resultConfig);
ActionConfig actionConfig = new ActionConfig.Builder("", "", "")
@@ -18,17 +18,16 @@
*/
package org.apache.struts2.result;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.struts2.StrutsInternalTestCase;
import org.apache.struts2.result.StrutsResultSupport;
import org.easymock.EasyMock;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.util.ValueStack;
import org.apache.struts2.StrutsInternalTestCase;
import org.easymock.EasyMock;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* Test case for StrutsResultSupport.
@@ -61,6 +60,27 @@ public class StrutsResultSupportTest extends StrutsInternalTestCase {
EasyMock.verify(mockActionInvocation);
}
public void testParseButNotParseLocation() throws Exception {
ValueStack stack = ActionContext.getContext().getValueStack();
ActionInvocation mockActionInvocation = EasyMock.createNiceMock(ActionInvocation.class);
mockActionInvocation.getStack();
EasyMock.expectLastCall().andReturn(stack).anyTimes();
EasyMock.replay(mockActionInvocation);
InternalStrutsResultSupport result = new InternalStrutsResultSupport();
result.setParse(true);
result.setEncode(false);
result.parseLocation = false;
result.setLocation("${1-1}");
result.execute(mockActionInvocation);
assertNotNull(result.getInternalLocation());
assertEquals("${1-1}", result.getInternalLocation());
EasyMock.verify(mockActionInvocation);
}
public void testParseAndEncode() throws Exception {
ValueStack stack = ActionContext.getContext().getValueStack();
stack.push(new ActionSupport() {
@@ -110,7 +130,7 @@ public class StrutsResultSupportTest extends StrutsInternalTestCase {
EasyMock.verify(mockActionInvocation);
}
public void testConditionalParseCollection() throws Exception {
public void testConditionalParseCollection() {
ValueStack stack = ActionContext.getContext().getValueStack();
stack.push(new ActionSupport() {
public List<String> getList() {
@@ -142,11 +162,11 @@ public class StrutsResultSupportTest extends StrutsInternalTestCase {
public static class InternalStrutsResultSupport extends StrutsResultSupport {
private String _internalLocation = null;
protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
protected void doExecute(String finalLocation, ActionInvocation invocation) {
_internalLocation = finalLocation;
}
public String getInternalLocation() {
String getInternalLocation() {
return _internalLocation;
}
}
Vendored Executable
+286
View File
@@ -0,0 +1,286 @@
#!/bin/sh
# ----------------------------------------------------------------------------
# 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.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Maven2 Start Up Batch script
#
# Required ENV vars:
# ------------------
# JAVA_HOME - location of a JDK home dir
#
# Optional ENV vars
# -----------------
# M2_HOME - location of maven2's installed home dir
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------
if [ -z "$MAVEN_SKIP_RC" ] ; then
if [ -f /etc/mavenrc ] ; then
. /etc/mavenrc
fi
if [ -f "$HOME/.mavenrc" ] ; then
. "$HOME/.mavenrc"
fi
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
mingw=false
case "`uname`" in
CYGWIN*) cygwin=true ;;
MINGW*) mingw=true;;
Darwin*) darwin=true
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
if [ -z "$JAVA_HOME" ]; then
if [ -x "/usr/libexec/java_home" ]; then
export JAVA_HOME="`/usr/libexec/java_home`"
else
export JAVA_HOME="/Library/Java/Home"
fi
fi
;;
esac
if [ -z "$JAVA_HOME" ] ; then
if [ -r /etc/gentoo-release ] ; then
JAVA_HOME=`java-config --jre-home`
fi
fi
if [ -z "$M2_HOME" ] ; then
## resolve links - $0 may be a link to maven's home
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
saveddir=`pwd`
M2_HOME=`dirname "$PRG"`/..
# make it fully qualified
M2_HOME=`cd "$M2_HOME" && pwd`
cd "$saveddir"
# echo Using m2 at $M2_HOME
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --unix "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
# For Mingw, ensure paths are in UNIX format before anything is touched
if $mingw ; then
[ -n "$M2_HOME" ] &&
M2_HOME="`(cd "$M2_HOME"; pwd)`"
[ -n "$JAVA_HOME" ] &&
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
# TODO classpath?
fi
if [ -z "$JAVA_HOME" ]; then
javaExecutable="`which javac`"
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=`which readlink`
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
if $darwin ; then
javaHome="`dirname \"$javaExecutable\"`"
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
else
javaExecutable="`readlink -f \"$javaExecutable\"`"
fi
javaHome="`dirname \"$javaExecutable\"`"
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
fi
fi
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="`which java`"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly." >&2
echo " We cannot execute $JAVACMD" >&2
exit 1
fi
if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
if [ -z "$1" ]
then
echo "Path not specified to find_maven_basedir"
return 1
fi
basedir="$1"
wdir="$1"
while [ "$wdir" != '/' ] ; do
if [ -d "$wdir"/.mvn ] ; then
basedir=$wdir
break
fi
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
if [ -d "${wdir}" ]; then
wdir=`cd "$wdir/.."; pwd`
fi
# end of workaround
done
echo "${basedir}"
}
# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
echo "$(tr -s '\n' ' ' < "$1")"
fi
}
BASE_DIR=`find_maven_basedir "$(pwd)"`
if [ -z "$BASE_DIR" ]; then
exit 1;
fi
##########################################################################################
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
# This allows using the maven wrapper in projects that prohibit checking in binary data.
##########################################################################################
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found .mvn/wrapper/maven-wrapper.jar"
fi
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
fi
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"
while IFS="=" read key value; do
case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
esac
done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
if [ "$MVNW_VERBOSE" = true ]; then
echo "Downloading from: $jarUrl"
fi
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
if command -v wget > /dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found wget ... using wget"
fi
wget "$jarUrl" -O "$wrapperJarPath"
elif command -v curl > /dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found curl ... using curl"
fi
curl -o "$wrapperJarPath" "$jarUrl"
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Falling back to using Java to download"
fi
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
if [ -e "$javaClass" ]; then
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Compiling MavenWrapperDownloader.java ..."
fi
# Compiling the Java class
("$JAVA_HOME/bin/javac" "$javaClass")
fi
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
# Running the downloader
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Running MavenWrapperDownloader.java ..."
fi
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
fi
fi
fi
fi
##########################################################################################
# End of extension
##########################################################################################
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
if [ "$MVNW_VERBOSE" = true ]; then
echo $MAVEN_PROJECTBASEDIR
fi
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --path --windows "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
fi
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
exec "$JAVACMD" \
$MAVEN_OPTS \
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
Vendored Executable
+161
View File
@@ -0,0 +1,161 @@
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM http://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Maven2 Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM set title of command window
title %0
@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
@REM ==== END VALIDATION ====
:init
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR%
:findBaseDir
IF EXIST "%WDIR%"\.mvn goto baseDirFound
cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"
FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO (
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
)
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
if exist %WRAPPER_JAR% (
echo Found %WRAPPER_JAR%
) else (
echo Couldn't find %WRAPPER_JAR%, downloading it ...
echo Downloading from: %DOWNLOAD_URL%
powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"
echo Finished downloading %WRAPPER_JAR%
)
@REM End of extension
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
if ERRORLEVEL 1 goto error
goto end
:error
set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%" == "on" pause
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
exit /B %ERROR_CODE%
@@ -172,6 +172,8 @@ public class PortletActionRedirectResult extends PortletResult {
*/
public void execute(ActionInvocation invocation) throws Exception {
actionName = conditionalParse(actionName, invocation);
parseLocation = false;
String portletNamespace = (String)invocation.getInvocationContext().get(PortletConstants.PORTLET_NAMESPACE);
if (portletMode != null) {
Map<PortletMode, String> namespaceMap = getNamespaceMap(invocation);
@@ -364,7 +364,7 @@ public class RestActionMapper extends DefaultActionMapper {
name = uri.substring(namespace.length() + 1);
}
mapping.setNamespace(namespace);
mapping.setNamespace(cleanupNamespaceName(namespace));
mapping.setName(name);
}
+10 -9
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts-master</artifactId>
<version>11</version>
<version>13</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -98,11 +98,11 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.platformVersion>4.3.13.RELEASE</spring.platformVersion>
<ognl.version>3.2.5</ognl.version>
<ognl.version>3.2.6</ognl.version>
<asm.version>5.2</asm.version>
<tiles.version>3.0.8</tiles.version>
<tiles-request.version>1.0.7</tiles-request.version>
<log4j2.version>2.10.0</log4j2.version>
<log4j2.version>2.11.1</log4j2.version>
<jackson.version>2.9.6</jackson.version>
<!-- Site generation -->
@@ -155,7 +155,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
<doclint>none</doclint>
</configuration>
</plugin>
</plugins>
@@ -279,11 +279,12 @@
<useIdeaDefaultExcludes>true</useIdeaDefaultExcludes>
<useDefaultExcludes>true</useDefaultExcludes>
<addDefaultLicenseMatchers>false</addDefaultLicenseMatchers>
<licenseMatchers>
<classNames>
<className>org.apache.rat.analysis.license.ApacheSoftwareLicense20</className>
</classNames>
</licenseMatchers>
<licenses>
<licens implementation="org.apache.rat.analysis.license.ApacheSoftwareLicense20"/>
</licenses>
<licenseFamilies>
<licenseFamily implementation="org.apache.rat.license.Apache20LicenseFamily"/>
</licenseFamilies>
<includes>
<include>pom.xml</include>
<include>src/**</include>