Skip to content

Commit

Permalink
WW-5078 Removes support for <xwork> DTDs
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed Nov 29, 2020
1 parent a72d1a8 commit b4bc5dc
Show file tree
Hide file tree
Showing 94 changed files with 1,043 additions and 1,020 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import com.opensymphony.xwork2.config.impl.DefaultConfiguration;
import com.opensymphony.xwork2.config.providers.XWorkConfigurationProvider;
import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.StrutsConstants;
Expand Down Expand Up @@ -102,7 +101,6 @@ public List<ContainerProvider> getContainerProviders() {
try {
if (containerProviders.size() == 0) {
containerProviders.add(new XWorkConfigurationProvider());
containerProviders.add(new XmlConfigurationProvider("xwork.xml", false));
}

return containerProviders;
Expand Down Expand Up @@ -160,7 +158,7 @@ private void clearContainerProvider(ContainerProvider containerProvider) {
*/
public synchronized void destroyConfiguration() {
clearContainerProviders(); // let's destroy the ConfigurationProvider first
containerProviders = new CopyOnWriteArrayList<ContainerProvider>();
containerProviders = new CopyOnWriteArrayList<>();
if (configuration != null)
configuration.destroy(); // let's destroy it first, before nulling it.
configuration = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,22 @@
* @author Neo
* @version $Revision$
*/
public class XmlConfigurationProvider implements ConfigurationProvider {
public abstract class XmlConfigurationProvider implements ConfigurationProvider {

private static final Logger LOG = LogManager.getLogger(XmlConfigurationProvider.class);

private final String configFileName;
private final Set<String> loadedFileUrls = new HashSet<>();
private final Map<String, Element> declaredPackages = new HashMap<>();

private List<Document> documents;
private Set<String> includedFileNames;
private String configFileName;
private ObjectFactory objectFactory;

private final Set<String> loadedFileUrls = new HashSet<>();
private boolean errorIfMissing;
private Map<String, String> dtdMappings;
private Map<String, String> dtdMappings = new HashMap<>();
private Configuration configuration;

private boolean throwExceptionOnDuplicateBeans = true;
private final Map<String, Element> declaredPackages = new HashMap<>();

private FileManager fileManager;
private ValueSubstitutor valueSubstitutor;
Expand All @@ -112,21 +113,8 @@ public XmlConfigurationProvider(String filename) {
this(filename, true);
}

public XmlConfigurationProvider(String filename, boolean errorIfMissing) {
public XmlConfigurationProvider(String filename, @Deprecated boolean notUsed) {
this.configFileName = filename;
this.errorIfMissing = errorIfMissing;

Map<String, String> mappings = new HashMap<>();
mappings.put("-//Apache Struts//XWork 2.6//EN", "xwork-2.6.dtd");
mappings.put("-//Apache Struts//XWork 2.5//EN", "xwork-2.5.dtd");
mappings.put("-//Apache Struts//XWork 2.3//EN", "xwork-2.3.dtd");
mappings.put("-//Apache Struts//XWork 2.1.3//EN", "xwork-2.1.3.dtd");
mappings.put("-//Apache Struts//XWork 2.1//EN", "xwork-2.1.dtd");
mappings.put("-//Apache Struts//XWork 2.0//EN", "xwork-2.0.dtd");
mappings.put("-//Apache Struts//XWork 1.1.1//EN", "xwork-1.1.1.dtd");
mappings.put("-//Apache Struts//XWork 1.1//EN", "xwork-1.1.dtd");
mappings.put("-//Apache Struts//XWork 1.0//EN", "xwork-1.0.dtd");
setDtdMappings(mappings);
}

public void setThrowExceptionOnDuplicateBeans(boolean val) {
Expand Down Expand Up @@ -1078,12 +1066,7 @@ private List<Document> loadConfigurationFiles(String fileName, Element includeEl
}

if (urls == null || !urls.hasNext()) {
if (errorIfMissing) {
throw new ConfigurationException("Could not open files of the name " + fileName, ioException);
} else {
LOG.trace("Unable to locate configuration files of the name {}, skipping", fileName);
return docs;
}
throw new ConfigurationException("Could not open file: " + fileName, ioException);
}

URL url = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ public StrutsXmlConfigurationProvider(boolean errorIfMissing) {
this("struts.xml", errorIfMissing, null);
}

/**
* Constructs the configuration provider based on the provided config file
*
* @param filename file with Struts configuration
*/
public StrutsXmlConfigurationProvider(String filename) {
this(filename, false, null);
}

/**
* Constructs the configuration provider
*
Expand Down
11 changes: 5 additions & 6 deletions core/src/main/resources/xwork-default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
* under the License.
*/
-->
<!DOCTYPE xwork PUBLIC
"-//Apache Struts//XWork 2.0//EN"
"http://struts.apache.org/dtds/xwork-2.0.dtd">

<xwork>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<package name="xwork-default" abstract="true">

<!-- START SNIPPET: xwork2-default-result-types -->
Expand Down Expand Up @@ -84,4 +83,4 @@
<default-class-ref class="com.opensymphony.xwork2.ActionSupport"/>

</package>
</xwork>
</struts>
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@

import com.opensymphony.xwork2.config.entities.ActionConfig;
import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
import com.opensymphony.xwork2.mock.MockResult;
import org.apache.struts2.StrutsException;
import org.apache.struts2.config.StrutsXmlConfigurationProvider;
import org.apache.struts2.dispatcher.HttpParameters;
import com.opensymphony.xwork2.mock.MockResult;

import java.util.HashMap;

Expand All @@ -34,38 +35,40 @@ public class ActionInvocationTest extends XWorkTestCase {

public void testCommandInvocation() throws Exception {
ActionProxy baseActionProxy = actionProxyFactory.createActionProxy(
"baz", "commandTest", null, null);
"baz", "commandTest", null, null);
assertEquals("success", baseActionProxy.execute());

ActionProxy commandActionProxy = actionProxyFactory.createActionProxy(
"baz", "myCommand", null, null);
"baz", "myCommand", null, null);
assertEquals(SimpleAction.COMMAND_RETURN_CODE, commandActionProxy.execute());
}

public void testCommandInvocationDoMethod() throws Exception {
ActionProxy baseActionProxy = actionProxyFactory.createActionProxy(
"baz", "doMethodTest", null, null);
"baz", "doMethodTest", null, null);
assertEquals("input", baseActionProxy.execute());
}

public void testCommandInvocationUnknownHandler() throws Exception {

UnknownHandler unknownHandler = new UnknownHandler() {
public ActionConfig handleUnknownAction(String namespace, String actionName) throws StrutsException {
public ActionConfig handleUnknownAction(String namespace, String actionName) throws StrutsException {
return new ActionConfig.Builder("test", actionName, ActionSupport.class.getName())
.addAllowedMethod("unknownmethod")
.build();
.addAllowedMethod("unknownmethod")
.build();
}

public Result handleUnknownResult(ActionContext actionContext, String actionName, ActionConfig actionConfig, String resultCode) throws StrutsException {
return new MockResult();
}

public Object handleUnknownActionMethod(Object action, String methodName) {
if (methodName.equals("unknownmethod")) {
return "found";
} else {
return null;
}
}
public Result handleUnknownResult(ActionContext actionContext, String actionName, ActionConfig actionConfig, String resultCode) throws StrutsException {
return new MockResult();
}
public Object handleUnknownActionMethod(Object action, String methodName) {
if (methodName.equals("unknownmethod")) {
return "found";
} else {
return null;
}
}
};

UnknownHandlerManagerMock uhm = new UnknownHandlerManagerMock();
Expand All @@ -74,16 +77,16 @@ public Object handleUnknownActionMethod(Object action, String methodName) {
loadButAdd(UnknownHandlerManager.class, uhm);

DefaultActionProxy baseActionProxy = (DefaultActionProxy) actionProxyFactory.createActionProxy(
"baz", "unknownMethodTest", "unknownmethod", null);
"baz", "unknownMethodTest", "unknownmethod", null);

((DefaultActionInvocation)baseActionProxy.getInvocation()).setUnknownHandlerManager(uhm);
((DefaultActionInvocation) baseActionProxy.getInvocation()).setUnknownHandlerManager(uhm);

assertEquals("found", baseActionProxy.execute());
}

public void testResultReturnInvocationAndWired() throws Exception {
ActionProxy baseActionProxy = actionProxyFactory.createActionProxy(
"baz", "resultAction", null, null);
"baz", "resultAction", null, null);
assertNull(baseActionProxy.execute());
assertTrue(SimpleAction.resultCalled);
}
Expand All @@ -96,7 +99,7 @@ public void testSimple() {
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());

try {
ActionProxy proxy = actionProxyFactory.createActionProxy( "", "Foo", null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", "Foo", null, extraContext);
proxy.execute();
assertEquals("this is blah", proxy.getInvocation().getStack().findValue("[1].blah"));
} catch (Exception e) {
Expand All @@ -105,11 +108,12 @@ public void testSimple() {
}
}

@Override protected void setUp() throws Exception {
@Override
protected void setUp() throws Exception {
super.setUp();

// ensure we're using the default configuration, not simple config
XmlConfigurationProvider configurationProvider = new XmlConfigurationProvider("xwork-sample.xml");
XmlConfigurationProvider configurationProvider = new StrutsXmlConfigurationProvider("xwork-sample.xml");
container.inject(configurationProvider);
loadConfigurationProviders(configurationProvider);
}
Expand Down
15 changes: 8 additions & 7 deletions core/src/test/java/com/opensymphony/xwork2/ChainResultTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.opensymphony.xwork2.util.ValueStack;
import junit.framework.TestCase;
import org.apache.struts2.StrutsException;
import org.apache.struts2.config.StrutsXmlConfigurationProvider;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -38,7 +39,7 @@ protected void setUp() throws Exception {
super.setUp();

// ensure we're using the default configuration, not simple config
XmlConfigurationProvider configurationProvider = new XmlConfigurationProvider("xwork-sample.xml");
XmlConfigurationProvider configurationProvider = new StrutsXmlConfigurationProvider("xwork-sample.xml");
container.inject(configurationProvider);
loadConfigurationProviders(configurationProvider);
}
Expand Down Expand Up @@ -124,9 +125,9 @@ public void testRecursiveChain() throws Exception {
}

private class NamespaceActionNameTestActionProxyFactory implements ActionProxyFactory {
private ActionProxy returnVal;
private String expectedActionName;
private String expectedNamespace;
private final ActionProxy returnVal;
private final String expectedActionName;
private final String expectedNamespace;

NamespaceActionNameTestActionProxyFactory(String expectedNamespace, String expectedActionName, ActionProxy returnVal) {
this.expectedNamespace = expectedNamespace;
Expand Down Expand Up @@ -156,14 +157,14 @@ public ActionProxy createActionProxy(String namespace, String actionName, Map<St
}

public ActionProxy createActionProxy(String namespace, String actionName, String methodName, Map<String, Object> extraContext, boolean executeResult, boolean cleanupContext) {
TestCase.assertEquals(expectedNamespace, namespace);
TestCase.assertEquals(expectedNamespace, namespace);
TestCase.assertEquals(expectedActionName, actionName);

return returnVal;
}

public ActionProxy createActionProxy(ActionInvocation actionInvocation, String namespace, String actionName, String methodName, boolean executeResult, boolean cleanupContext) {
TestCase.assertEquals(expectedNamespace, namespace);
TestCase.assertEquals(expectedNamespace, namespace);
TestCase.assertEquals(expectedActionName, actionName);

return returnVal;
Expand All @@ -177,7 +178,7 @@ public ActionProxy createActionProxy(String namespace, String actionName, String
}

public ActionProxy createActionProxy(ActionInvocation inv, String namespace, String actionName,
Map<String, Object> extraContext, boolean executeResult, boolean cleanupContext) throws Exception {
Map<String, Object> extraContext, boolean executeResult, boolean cleanupContext) throws Exception {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.opensymphony.xwork2.ognl.OgnlUtil;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.ValueStackFactory;
import org.apache.struts2.config.StrutsXmlConfigurationProvider;
import org.apache.struts2.dispatcher.HttpParameters;

import java.util.ArrayList;
Expand Down Expand Up @@ -304,7 +305,7 @@ public void testInvokeWithLazyParams() throws Exception {
DefaultActionInvocation defaultActionInvocation = new DefaultActionInvocation(extraContext, true);
container.inject(defaultActionInvocation);

ActionProxy actionProxy = actionProxyFactory.createActionProxy( "", "LazyFoo", null, extraContext);
ActionProxy actionProxy = actionProxyFactory.createActionProxy("", "LazyFoo", null, extraContext);
defaultActionInvocation.init(actionProxy);
defaultActionInvocation.invoke();

Expand All @@ -322,6 +323,7 @@ public void testInvokeWithAsyncManager() throws Exception {
lock.acquire();
dai.setAsyncManager(new AsyncManager() {
Object asyncActionResult;

@Override
public boolean hasAsyncActionResult() {
return asyncActionResult != null;
Expand Down Expand Up @@ -384,7 +386,7 @@ public void beforeResult(ActionInvocation invocation, String resultCode) {
assertFalse("invocation should not be executed", dai.executed);
assertNull("a null result should be passed to upper and wait for the async result", dai.resultCode);

if(lock.tryAcquire(1500L, TimeUnit.MILLISECONDS)) {
if (lock.tryAcquire(1500L, TimeUnit.MILLISECONDS)) {
try {
dai.invoke();
assertTrue("preResultListener should be executed", preResultExecuted[0]);
Expand All @@ -402,7 +404,7 @@ public void beforeResult(ActionInvocation invocation, String resultCode) {

public void testActionEventListener() throws Exception {
ActionProxy actionProxy = actionProxyFactory.createActionProxy("",
"ExceptionFoo", "exceptionMethod", new HashMap<String, Object>());
"ExceptionFoo", "exceptionMethod", new HashMap<String, Object>());
DefaultActionInvocation defaultActionInvocation = (DefaultActionInvocation) actionProxy.getInvocation();

SimpleActionEventListener actionEventListener = new SimpleActionEventListener("prepared", "exceptionHandled");
Expand All @@ -428,7 +430,7 @@ public boolean hasUnknownHandlers() {

public void testActionChainResult() throws Exception {
ActionProxy actionProxy = actionProxyFactory.createActionProxy("", "Foo", null,
new HashMap<String, Object>());
new HashMap<String, Object>());
DefaultActionInvocation defaultActionInvocation = (DefaultActionInvocation) actionProxy.getInvocation();
defaultActionInvocation.init(actionProxy);

Expand All @@ -446,7 +448,7 @@ public void testActionChainResult() throws Exception {

public void testNoResultDefined() throws Exception {
ActionProxy actionProxy = actionProxyFactory.createActionProxy("", "Foo", null,
new HashMap<String, Object>());
new HashMap<String, Object>());
DefaultActionInvocation defaultActionInvocation = (DefaultActionInvocation) actionProxy.getInvocation();
defaultActionInvocation.init(actionProxy);

Expand All @@ -459,7 +461,7 @@ public void testNoResultDefined() throws Exception {

public void testNullResultPossible() throws Exception {
ActionProxy actionProxy = actionProxyFactory.createActionProxy("",
"NullFoo", "nullMethod", new HashMap<String, Object>());
"NullFoo", "nullMethod", new HashMap<String, Object>());
DefaultActionInvocation defaultActionInvocation = (DefaultActionInvocation) actionProxy.getInvocation();
defaultActionInvocation.init(actionProxy);

Expand All @@ -473,16 +475,16 @@ protected void setUp() throws Exception {
super.setUp();

// ensure we're using the default configuration, not simple config
XmlConfigurationProvider configurationProvider = new XmlConfigurationProvider("xwork-sample.xml");
XmlConfigurationProvider configurationProvider = new StrutsXmlConfigurationProvider("xwork-sample.xml");
container.inject(configurationProvider);
loadConfigurationProviders(configurationProvider);
}


private class SimpleActionEventListener implements ActionEventListener {

private String name;
private String result;
private final String name;
private final String result;

SimpleActionEventListener(String name, String result) {

Expand All @@ -492,7 +494,7 @@ private class SimpleActionEventListener implements ActionEventListener {

@Override
public Object prepare(Object action, ValueStack stack) {
((SimpleAction)action).setName(name);
((SimpleAction) action).setName(name);
return action;
}

Expand Down
Loading

0 comments on commit b4bc5dc

Please sign in to comment.