[WW-5064] Move XWork Spring support into struts2-spring-plugin

This commit is contained in:
Stefaan Dutry
2021-09-24 11:40:16 +02:00
parent dd807e78a8
commit f1ca6d0e2a
31 changed files with 544 additions and 311 deletions
+2 -33
View File
@@ -207,7 +207,6 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<!-- File upload -->
@@ -235,42 +234,12 @@
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<optional>true</optional>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
@@ -1,21 +0,0 @@
<!--
/*
* 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.
*/
-->
<body>Spring specific interceptor classes.</body>
@@ -1,21 +0,0 @@
<!--
/*
* 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.
*/
-->
<body>Spring ObjectFactory classes.</body>
@@ -1,71 +0,0 @@
/*
* 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.spring;
/**
* @author Mike
*/
public class Bar {
private Foo foo;
private String thing;
private int value;
/**
* @return Returns the foo.
*/
public Foo getFoo() {
return foo;
}
/**
* @param foo The foo to set.
*/
public void setFoo(Foo foo) {
this.foo = foo;
}
/**
* @return Returns the thing.
*/
public String getThing() {
return thing;
}
/**
* @param thing The thing to set.
*/
public void setThing(String thing) {
this.thing = thing;
}
/**
* @return Returns the value.
*/
public int getValue() {
return value;
}
/**
* @param value The value to set.
*/
public void setValue(int value) {
this.value = value;
}
}
@@ -0,0 +1,7 @@
package com.opensymphony.xwork2.util;
import com.opensymphony.xwork2.ObjectFactory;
public class DummyObjectFactory extends ObjectFactory {
}
@@ -19,7 +19,6 @@
package com.opensymphony.xwork2.util;
import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.spring.SpringObjectFactory;
import junit.framework.TestCase;
import java.net.URL;
@@ -33,16 +32,16 @@ public class ResolverUtilTest extends TestCase {
Set<Class<? extends ObjectFactory>> impls = resolver.getClasses();
assertTrue(impls.contains(ObjectFactory.class));
assertTrue(impls.contains(SpringObjectFactory.class));
assertTrue(impls.contains(DummyObjectFactory.class));
}
public void testMissingSomeFind() throws Exception {
ResolverUtil<ObjectFactory> resolver = new ResolverUtil<>();
resolver.findImplementations(ObjectFactory.class, "com.opensymphony.xwork2.spring");
resolver.findImplementations(ObjectFactory.class, "com.opensymphony.xwork2.util");
Set<Class<? extends ObjectFactory>> impls = resolver.getClasses();
assertFalse(impls.contains(ObjectFactory.class));
assertTrue(impls.contains(SpringObjectFactory.class));
assertTrue(impls.contains(DummyObjectFactory.class));
}
public void testFindNamedResource() throws Exception {
@@ -1,26 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/*
* 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.
*/
-->
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="spring-object-factory" class="com.opensymphony.xwork2.spring.SpringObjectFactory"/>
</beans>
@@ -1,31 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/*
* 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.
*/
-->
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="myFoo" class="com.opensymphony.xwork2.spring.Foo">
<property name="name"><value>Little Foo</value></property>
</bean>
<bean id="myBar" class="com.opensymphony.xwork2.spring.Bar" autowire="byType">
<property name="value"><value>16</value></property>
</bean>
</beans>
@@ -1,49 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/*
* 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.
*/
-->
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<bean type="com.opensymphony.xwork2.ActionProxyFactory" name="default"
class="com.opensymphony.xwork2.DefaultActionProxyFactory"/>
<bean type="com.opensymphony.xwork2.ObjectFactory" name="default"
class="com.opensymphony.xwork2.spring.SpringObjectFactory"/>
<constant name="applicationContextPath" value="com/opensymphony/xwork2/spring/actionContext-spring.xml"/>
<package name="default">
<result-types>
<result-type name="null"
class="com.opensymphony.xwork2.result.NullResult" default="true"/>
</result-types>
<interceptors>
<interceptor name="autowire" class="com.opensymphony.xwork2.spring.interceptor.ActionAutowiringInterceptor">
<param name="autowireStrategy">
@org.springframework.beans.factory.config.AutowireCapableBeanFactory@AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE
</param>
</interceptor>
</interceptors>
<default-interceptor-ref name="autowire"/>
<action name="simpleAction" class="com.opensymphony.xwork2.SimpleAction"/>
</package>
</struts>
+18
View File
@@ -51,6 +51,18 @@
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
@@ -68,6 +80,12 @@
<artifactId>commons-jci-fam</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
@@ -16,30 +16,33 @@
* specific language governing permissions and limitations
* under the License.
*/
package com.opensymphony.xwork2.spring;
package com.opensymphony.xwork2;
/**
* @author Mike
* ModelDrivenAction
*
* @author Jason Carreira
* Created Apr 8, 2003 6:27:29 PM
*/
public class Foo
{
String name = null;
public Foo() {
name = "not set";
}
public Foo(String name) {
this.name = name;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public class ModelDrivenAction extends ActionSupport implements ModelDriven {
private String foo;
private TestBean model = new TestBean();
public void setFoo(String foo) {
this.foo = foo;
}
public String getFoo() {
return foo;
}
/**
* @return the model to be pushed onto the ValueStack after the Action itself
*/
public Object getModel() {
return model;
}
}
@@ -0,0 +1,284 @@
/*
* 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;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Result;
import com.opensymphony.xwork2.config.Configuration;
import com.opensymphony.xwork2.inject.Inject;
import java.util.*;
/**
* DOCUMENT ME!
*
* @author $author$
* @version $Revision$
*/
public class SimpleAction extends ActionSupport {
public static final String COMMAND_RETURN_CODE = "com.opensymphony.xwork2.SimpleAction.CommandInvoked";
private ArrayList<String> someList = new ArrayList<>();
private Date date = new Date();
private Properties settings = new Properties();
private String blah;
private String name;
private TestBean bean = new TestBean();
private boolean throwException;
private int bar;
private int baz;
private int foo;
private long longFoo;
private short shortFoo;
private double percentage;
private Map<Integer, String> indexedProps = new HashMap<>();
private String aliasSource;
private String aliasDest;
private Map<String, String> protectedMap = new HashMap<>();
private Map<String, String> existingMap = new HashMap<>();
private List<TestBean> beanList;
public static boolean resultCalled;
public SimpleAction() {
resultCalled = false;
existingMap.put("existingKey", "value");
}
public Map<String,String> getTheProtectedMap() {
return protectedMap;
}
protected Map<String,String> getTheSemiProtectedMap() {
return protectedMap;
}
public void setExistingMap(Map<String,String> map) {
this.existingMap = map;
}
public Map<String,String> getTheExistingMap() {
return existingMap;
}
public void setBar(int bar) {
this.bar = bar;
}
public int getBar() {
return bar;
}
public double getPercentage() {
return percentage;
}
public void setPercentage(double percentage) {
this.percentage = percentage;
}
public void setBaz(int baz) {
this.baz = baz;
}
public int getBaz() {
return baz;
}
public void setBean(TestBean bean) {
this.bean = bean;
}
public TestBean getBean() {
return bean;
}
public void setBlah(String blah) {
this.blah = blah;
}
public String getBlah() {
return blah;
}
public Boolean getBool(String b) {
return new Boolean(b);
}
public boolean[] getBools() {
return new boolean[]{true, false, false, true};
}
public void setDate(Date date) {
this.date = date;
}
public Date getDate() {
return date;
}
public void setFoo(int foo) {
this.foo = foo;
}
public int getFoo() {
return foo;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setSettings(Properties settings) {
this.settings = settings;
}
public Properties getSettings() {
return settings;
}
public String getAliasDest() {
return aliasDest;
}
public void setAliasDest(String aliasDest) {
this.aliasDest = aliasDest;
}
public String getAliasSource() {
return aliasSource;
}
public void setAliasSource(String aliasSource) {
this.aliasSource = aliasSource;
}
public void setSomeList(ArrayList<String> someList) {
this.someList = someList;
}
public ArrayList<String> getSomeList() {
return someList;
}
public String getIndexedProp(int index) {
return indexedProps.get(index);
}
public void setIndexedProp(int index, String val) {
indexedProps.put(index, val);
}
public void setThrowException(boolean throwException) {
this.throwException = throwException;
}
public String commandMethod() throws Exception {
return COMMAND_RETURN_CODE;
}
public Result resultAction() throws Exception {
return new Result() {
public Configuration configuration;
@Inject
public void setConfiguration(Configuration config) {
this.configuration = config;
}
public void execute(ActionInvocation invocation) throws Exception {
if (configuration != null)
resultCalled = true;
}
};
}
public String exceptionMethod() throws Exception {
if (throwException) {
throw new Exception("We're supposed to throw this");
}
return "OK";
}
public String nullMethod() {
return null;
}
@Override
public String execute() throws Exception {
if (foo == bar) {
return ERROR;
}
baz = foo + bar;
name = "HelloWorld";
settings.put("foo", "bar");
settings.put("black", "white");
someList.add("jack");
someList.add("bill");
someList.add("kerry");
return SUCCESS;
}
public long getLongFoo() {
return longFoo;
}
public void setLongFoo(long longFoo) {
this.longFoo = longFoo;
}
public short getShortFoo() {
return shortFoo;
}
public void setShortFoo(short shortFoo) {
this.shortFoo = shortFoo;
}
public List<TestBean> getBeanList() {
return beanList;
}
public void setBeanList(List<TestBean> beanList) {
this.beanList = beanList;
}
}
@@ -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;
import java.util.Date;
/**
* TestBean
*
* @author Jason Carreira
* Created Aug 4, 2003 12:39:53 AM
*/
public class TestBean {
private Date birth;
private String name;
private int count;
private TestChildBean child = new TestChildBean();
public TestBean() {
}
public void setBirth(Date birth) {
this.birth = birth;
}
public Date getBirth() {
return birth;
}
public void setCount(int count) {
this.count = count;
}
public int getCount() {
return count;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public TestChildBean getChild() {
return child;
}
public void setChild(TestChildBean child) {
this.child = child;
}
}
@@ -16,49 +16,50 @@
* specific language governing permissions and limitations
* under the License.
*/
package com.opensymphony.xwork2.spring;
package com.opensymphony.xwork2;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import com.opensymphony.xwork2.Action;
/**
* @author Mike
* TestBean
*/
public class ExternalReferenceAction implements Action
{
private Foo foo;
private Bar bar;
public class TestChildBean {
public String execute() throws Exception {
return SUCCESS;
private Date birth;
private String name;
private int count;
public TestChildBean() {
Calendar cal = new GregorianCalendar(1900, 01, 01);
setBirth(cal.getTime());
}
/**
* @return Returns the foo.
*/
public Foo getFoo() {
return foo;
public void setBirth(Date birth) {
this.birth = birth;
}
/**
* @param foo
* The foo to set.
*/
public void setFoo(Foo foo) {
this.foo = foo;
public Date getBirth() {
return birth;
}
/**
* @return Returns the bar.
*/
public Bar getBar() {
return bar;
public void setCount(int count) {
this.count = count;
}
/**
* @param bar
* The bar to set.
*/
public void setBar(Bar bar) {
this.bar = bar;
public int getCount() {
return count;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
@@ -0,0 +1,87 @@
/*
* 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.mock;
import com.opensymphony.xwork2.TextProvider;
import com.opensymphony.xwork2.util.ValueStack;
import java.util.List;
import java.util.ResourceBundle;
public class DummyTextProvider implements TextProvider {
@Override
public boolean hasKey(String key) {
return false;
}
@Override
public String getText(String key) {
return null;
}
@Override
public String getText(String key, String defaultValue) {
return null;
}
@Override
public String getText(String key, String defaultValue, String obj) {
return null;
}
@Override
public String getText(String key, List<?> args) {
return null;
}
@Override
public String getText(String key, String[] args) {
return null;
}
@Override
public String getText(String key, String defaultValue, List<?> args) {
return null;
}
@Override
public String getText(String key, String defaultValue, String[] args) {
return null;
}
@Override
public String getText(String key, String defaultValue, List<?> args, ValueStack stack) {
return null;
}
@Override
public String getText(String key, String defaultValue, String[] args, ValueStack stack) {
return null;
}
@Override
public ResourceBundle getTexts(String bundleName) {
return null;
}
@Override
public ResourceBundle getTexts() {
return null;
}
}
@@ -18,7 +18,16 @@
*/
package com.opensymphony.xwork2.spring;
import com.opensymphony.xwork2.*;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionChainResult;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ModelDrivenAction;
import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.Result;
import com.opensymphony.xwork2.SimpleAction;
import com.opensymphony.xwork2.TestBean;
import com.opensymphony.xwork2.TextProvider;
import com.opensymphony.xwork2.XWorkTestCase;
import com.opensymphony.xwork2.config.ConfigurationException;
import com.opensymphony.xwork2.config.entities.ActionConfig;
import com.opensymphony.xwork2.config.entities.InterceptorConfig;