From 56c1291d2fe718dd40062d39fa3ec4f05efbac1d Mon Sep 17 00:00:00 2001 From: Kusal Kithul-Godage Date: Sat, 13 Jul 2024 21:21:52 +1000 Subject: [PATCH 1/6] WW-5440 Deprecate AnnotationParameterFilterInterceptor --- .../xwork2/interceptor/annotations/Allowed.java | 2 ++ .../annotations/AnnotationParameterFilterInterceptor.java | 7 +++++-- .../xwork2/interceptor/annotations/BlockByDefault.java | 2 ++ .../xwork2/interceptor/annotations/Blocked.java | 2 ++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/Allowed.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/Allowed.java index 40c6bdbbd1..39bfdcb26b 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/Allowed.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/Allowed.java @@ -28,9 +28,11 @@ * a HttpRequest parameter. * * @author martin.gilday + * @deprecated since 6.6.0, use {@link org.apache.struts2.interceptor.parameter.StrutsParameter}. */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) +@Deprecated public @interface Allowed { } diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/AnnotationParameterFilterInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/AnnotationParameterFilterInterceptor.java index 8309d61d2b..d1b7260ac4 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/AnnotationParameterFilterInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/AnnotationParameterFilterInterceptor.java @@ -23,13 +23,13 @@ import com.opensymphony.xwork2.interceptor.AbstractInterceptor; import com.opensymphony.xwork2.interceptor.Interceptor; import com.opensymphony.xwork2.interceptor.ParameterFilterInterceptor; -import com.opensymphony.xwork2.interceptor.ParametersInterceptor; import com.opensymphony.xwork2.util.AnnotationUtils; import org.apache.struts2.dispatcher.HttpParameters; +import org.apache.struts2.interceptor.parameter.ParametersInterceptor; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.lang.reflect.Field; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; /** @@ -46,7 +46,10 @@ *

* * @author martin.gilday + * @deprecated since 6.6.0, integrated into {@link ParametersInterceptor} with {@link StrutsParameter} using + * {@code struts.parameters.requireAnnotations=true} */ +@Deprecated public class AnnotationParameterFilterInterceptor extends AbstractInterceptor { /* (non-Javadoc) diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/BlockByDefault.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/BlockByDefault.java index ddb855b3da..e7b4520220 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/BlockByDefault.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/BlockByDefault.java @@ -31,9 +31,11 @@ * To allow access to a field it must be annotated with {@link Allowed} * * @author martin.gilday + * @deprecated since 6.6.0, use {@code struts.parameters.requireAnnotations=true} to block all parameters globally. */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) +@Deprecated public @interface BlockByDefault { } diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/Blocked.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/Blocked.java index 630368a87b..17ec80940d 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/Blocked.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/Blocked.java @@ -28,9 +28,11 @@ * a HttpRequest parameter. * * @author martin.gilday + * @deprecated since 6.6.0, use {@code struts.parameters.requireAnnotations=true} to block all parameters globally. */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) +@Deprecated public @interface Blocked { } From 10edbce8d92cb9909b6685f6ca0b2b39bc27680c Mon Sep 17 00:00:00 2001 From: Kusal Kithul-Godage Date: Sat, 13 Jul 2024 21:22:09 +1000 Subject: [PATCH 2/6] WW-5440 Fix MultipleFileUploadUsingArrayAction --- .../fileupload/MultipleFileUploadUsingArrayAction.java | 6 +++++- apps/showcase/src/main/resources/struts-fileupload.xml | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/fileupload/MultipleFileUploadUsingArrayAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/fileupload/MultipleFileUploadUsingArrayAction.java index 59ea954e21..ff26356131 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/fileupload/MultipleFileUploadUsingArrayAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/fileupload/MultipleFileUploadUsingArrayAction.java @@ -28,12 +28,16 @@ import java.util.List; /** - * Showcase action - mutiple file upload using array. + * Showcase action - multiple file upload using array. */ public class MultipleFileUploadUsingArrayAction extends ActionSupport implements UploadedFilesAware { private List uploadedFiles; + public List getUpload() { + return this.uploadedFiles; + } + public String upload() throws Exception { System.out.println("\n\n upload2"); System.out.println("files:"); diff --git a/apps/showcase/src/main/resources/struts-fileupload.xml b/apps/showcase/src/main/resources/struts-fileupload.xml index 5b500b73f6..e34539fcee 100644 --- a/apps/showcase/src/main/resources/struts-fileupload.xml +++ b/apps/showcase/src/main/resources/struts-fileupload.xml @@ -40,7 +40,7 @@ - /WEB-INF/fileupload/multipleUploadUsingList.jsp + /WEB-INF/fileupload/multipleUploadUsingList.jsp /WEB-INF/fileupload/multiple-success.jsp @@ -50,7 +50,7 @@ - /WEB-INF/fileupload/multipleUploadUsingArray.jsp + /WEB-INF/fileupload/multipleUploadUsingArray.jsp /WEB-INF/fileupload/multiple-success.jsp From f9953938f7313840a7122e4706235c8334fbee4e Mon Sep 17 00:00:00 2001 From: Kusal Kithul-Godage Date: Sat, 13 Jul 2024 19:39:13 +1000 Subject: [PATCH 3/6] WW-5440 Add missing annotations --- .../demo/rest/example/OrdersController.java | 24 +++---- .../org/demo/rest/example/OrdersService.java | 7 +- .../showcase/DynamicTreeSelectAction.java | 3 +- .../LotsOfOptiontransferselectAction.java | 17 ++++- .../showcase/LotsOfRichtexteditorAction.java | 7 +- .../struts2/showcase/MoreSelectsAction.java | 10 ++- .../showcase/ShowAjaxDynamicTreeAction.java | 2 + .../apache/struts2/showcase/UITagExample.java | 8 +++ .../showcase/action/AbstractCRUDAction.java | 11 ++-- .../showcase/action/EmployeeAction.java | 5 +- .../showcase/action/ExampleAction.java | 10 ++- .../showcase/action/JSPEvalAction.java | 8 ++- .../struts2/showcase/action/SkillAction.java | 2 + .../showcase/actionchaining/ActionChain1.java | 3 + .../showcase/actionchaining/ActionChain2.java | 5 +- .../showcase/actionchaining/ActionChain3.java | 8 ++- .../struts2/showcase/ajax/AjaxTestAction.java | 3 +- .../ajax/AutocompleterExampleAction.java | 5 +- .../ajax/Example4ShowPanelAction.java | 3 + .../struts2/showcase/ajax/Example5Action.java | 3 + .../showcase/ajax/tree/GetCategory.java | 3 + .../struts2/showcase/ajax/tree/Toggle.java | 2 + .../showcase/async/ChatRoomAction.java | 13 ++-- .../showcase/chat/ChatLoginAction.java | 5 +- .../struts2/showcase/chat/CrudRoomAction.java | 3 + .../showcase/chat/EnterRoomAction.java | 5 +- .../struts2/showcase/chat/ExitRoomAction.java | 5 +- .../chat/MessagesAvailableInRoomAction.java | 6 +- .../chat/SendMessageToRoomAction.java | 10 +-- .../chat/UsersAvailableInRoomAction.java | 7 +- .../conversion/OperationsEnumAction.java | 3 +- .../freemarker/StandardTagsAction.java | 6 +- .../hangman/GuessCharacterAction.java | 6 +- .../modelDriven/ModelDrivenAction.java | 3 + .../showcase/person/EditPersonAction.java | 6 +- .../showcase/person/ListPeopleAction.java | 3 +- .../showcase/person/NewPersonAction.java | 3 + .../showcase/source/ViewSourceAction.java | 12 +++- .../tag/nonui/actionPrefix/SubmitAction.java | 3 + .../tag/nonui/debugtag/DebugTagAction.java | 3 +- .../iteratortag/AppendIteratorTagDemo.java | 7 +- .../iteratortag/IteratorGeneratorTagDemo.java | 9 +-- .../iteratortag/MergeIteratorTagDemo.java | 9 +-- .../iteratortag/SubsetIteratorTagDemo.java | 13 ++-- .../struts2/showcase/token/TokenAction.java | 2 + .../AbstractValidationActionSupport.java | 1 + .../validation/AjaxFormSubmitAction.java | 31 +++++---- .../BeanValidationExampleAction.java | 13 +++- .../NonFieldValidatorsExampleAction.java | 5 ++ .../showcase/validation/QuizAction.java | 4 ++ .../validation/SubmitApplication.java | 3 + .../VisitorValidatorsExampleAction.java | 3 + .../struts2/showcase/xslt/JVMAction.java | 6 +- .../osgi/admin/actions/BundlesAction.java | 9 +-- .../osgi/admin/actions/ShellAction.java | 15 +++-- .../main/java/actions/osgi/BundlesAction.java | 1 + .../java/actions/osgi/HelloWorldAction.java | 4 +- .../xwork2/ValidationAwareSupport.java | 15 ++--- .../dispatcher/DefaultActionSupport.java | 10 +-- .../xwork2/ActionSupportTest.java | 7 +- .../xwork2/ModelDrivenAction.java | 8 ++- .../xwork2/ModelDrivenAnnotationAction.java | 8 ++- .../xwork2/ProxyInvocationAction.java | 2 + .../com/opensymphony/xwork2/SimpleAction.java | 26 ++++---- .../xwork2/SimpleAnnotationAction.java | 32 +++++++-- .../xwork2/ValidationOrderAction.java | 36 +++++----- .../ModelDrivenInterceptorTest.java | 8 ++- .../ScopedModelDrivenInterceptorTest.java | 10 +++ .../annotations/AllowingByDefaultAction.java | 9 ++- .../annotations/BlockingByDefaultAction.java | 9 ++- .../xwork2/test/ModelDrivenAction2.java | 4 +- .../test/ModelDrivenAnnotationAction2.java | 4 +- .../xwork2/test/SimpleAction2.java | 3 +- .../xwork2/test/SimpleAction3.java | 8 ++- .../xwork2/test/SimpleAnnotationAction2.java | 2 + .../xwork2/test/SimpleAnnotationAction3.java | 8 ++- .../ValidateAnnotatedMethodOnlyAction.java | 3 + .../com/opensymphony/xwork2/util/Bar.java | 5 +- .../util/StrutsLocalizedTextProviderTest.java | 10 +-- .../validator/ActionValidatorManagerTest.java | 5 +- .../validator/AnnotationValidationAction.java | 1 + .../AnnotationValidationExpAction.java | 1 + .../StringLengthFieldValidatorTest.java | 7 ++ .../VisitorValidatorModelAction.java | 3 + .../validator/VisitorValidatorTestAction.java | 7 +- .../struts2/ExecutionCountTestAction.java | 3 +- .../apache/struts2/HttpMethodsTestAction.java | 2 + .../java/org/apache/struts2/TestAction.java | 1 + .../interceptor/CookieInterceptorTest.java | 9 +++ .../FileUploadInterceptorTest.java | 4 +- .../views/jsp/IteratorGeneratorTagTest.java | 13 ++-- .../views/jsp/SortIteratorTagTest.java | 22 +++---- .../views/jsp/SubsetIteratorTagTest.java | 29 ++++----- .../views/jsp/ui/DoubleValidationAction.java | 2 + .../views/jsp/ui/FieldErrorTagTest.java | 13 ++-- .../views/jsp/ui/IntValidationAction.java | 2 + .../beanvalidation/actions/FieldAction.java | 2 + .../actions/FieldMatchAction.java | 5 ++ .../actions/ModelDrivenAction.java | 5 +- .../actions/ValidateGroupAction.java | 7 +- .../config_browser/ActionNamesAction.java | 5 +- .../config_browser/ListValidatorsAction.java | 8 ++- .../config_browser/ShowBeansAction.java | 2 + .../config_browser/ShowConfigAction.java | 25 ++++--- .../config_browser/ShowValidatorAction.java | 24 ++++--- .../src/test/java/actions/MessageAction.java | 2 +- .../json/JSONValidationInterceptorTest.java | 5 ++ .../apache/struts2/junit/JUnitTestAction.java | 2 + .../junit/session/SessionGetAction.java | 1 + .../junit/session/SessionSetAction.java | 1 + .../oval/interceptor/FieldsWithProfiles.java | 4 ++ .../oval/interceptor/MemberObject.java | 8 +-- .../oval/interceptor/ModelDrivenAction.java | 11 ++-- .../struts2/oval/interceptor/SimpleField.java | 5 +- .../oval/interceptor/SimpleFieldI18n.java | 2 + .../SimpleFieldI18nDefaultKey.java | 4 +- .../SimpleFieldJPAAnnotations.java | 2 + .../SimpleFieldOGNLExpression.java | 4 +- .../oval/interceptor/SimpleFieldsXML.java | 4 +- .../interceptor/SimpleFieldsXMLChild.java | 3 + .../oval/interceptor/SimpleMethod.java | 4 +- .../rest/RestActionInvocationTest.java | 65 ++++++++++--------- .../xwork2/ModelDrivenAction.java | 8 ++- 123 files changed, 647 insertions(+), 308 deletions(-) diff --git a/apps/rest-showcase/src/main/java/org/demo/rest/example/OrdersController.java b/apps/rest-showcase/src/main/java/org/demo/rest/example/OrdersController.java index 2184e2b1ec..50d9c8fa65 100644 --- a/apps/rest-showcase/src/main/java/org/demo/rest/example/OrdersController.java +++ b/apps/rest-showcase/src/main/java/org/demo/rest/example/OrdersController.java @@ -18,30 +18,30 @@ */ package org.demo.rest.example; -import java.util.Collection; - +import com.opensymphony.xwork2.ModelDriven; +import com.opensymphony.xwork2.Validateable; +import com.opensymphony.xwork2.ValidationAwareSupport; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.struts2.convention.annotation.Result; +import org.apache.struts2.convention.annotation.Results; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import org.apache.struts2.rest.DefaultHttpHeaders; import org.apache.struts2.rest.HttpHeaders; -import org.apache.struts2.convention.annotation.Results; -import org.apache.struts2.convention.annotation.Result; -import com.opensymphony.xwork2.ModelDriven; -import com.opensymphony.xwork2.Validateable; -import com.opensymphony.xwork2.ValidationAwareSupport; +import java.util.Collection; @Results({ @Result(name="success", type="redirectAction", params = {"actionName" , "orders"}) }) -public class OrdersController extends ValidationAwareSupport implements ModelDriven, Validateable{ +public class OrdersController extends ValidationAwareSupport implements ModelDriven, Validateable { private static final Logger log = LogManager.getLogger(OrdersController.class); private Order model = new Order(); private String id; private Collection list; - private OrdersService ordersService = new OrdersService(); + private final OrdersService ordersService = new OrdersService(); // GET /orders/1 public HttpHeaders show() { @@ -54,7 +54,7 @@ public HttpHeaders index() { return new DefaultHttpHeaders("index") .disableCaching(); } - + // GET /orders/1/edit public String edit() { return "edit"; @@ -101,13 +101,15 @@ public void validate() { } } + @StrutsParameter public void setId(String id) { if (id != null) { this.model = ordersService.get(id); } this.id = id; } - + + @Override public Object getModel() { return (list != null ? list : model); } diff --git a/apps/rest-showcase/src/main/java/org/demo/rest/example/OrdersService.java b/apps/rest-showcase/src/main/java/org/demo/rest/example/OrdersService.java index 321723e3f6..431fdcf57c 100644 --- a/apps/rest-showcase/src/main/java/org/demo/rest/example/OrdersService.java +++ b/apps/rest-showcase/src/main/java/org/demo/rest/example/OrdersService.java @@ -18,11 +18,14 @@ */ package org.demo.rest.example; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; public class OrdersService { - private static Map orders = new HashMap(); + private static final Map orders = new HashMap<>(); private static int nextId = 6; static { orders.put("3", new Order("3", "Bob", 33)); diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/DynamicTreeSelectAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/DynamicTreeSelectAction.java index 422b483cbc..c194ca386c 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/DynamicTreeSelectAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/DynamicTreeSelectAction.java @@ -21,6 +21,7 @@ package org.apache.struts2.showcase; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import org.apache.struts2.showcase.ajax.tree.Category; //START SNIPPET: treeExampleDynamicJavaSelected @@ -30,7 +31,7 @@ public class DynamicTreeSelectAction extends ActionSupport { private long nodeId; private Category currentCategory; - + @StrutsParameter public void setNodeId(long nodeId) { this.nodeId = nodeId; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/LotsOfOptiontransferselectAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/LotsOfOptiontransferselectAction.java index b56618eeba..9d861c9205 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/LotsOfOptiontransferselectAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/LotsOfOptiontransferselectAction.java @@ -21,6 +21,7 @@ package org.apache.struts2.showcase; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -74,6 +75,7 @@ public List getFavouriteCartoonCharacters() { return _favouriteCartoonCharactersKeys; } + @StrutsParameter public void setFavouriteCartoonCharacters(List favouriteCartoonCharacters) { _favouriteCartoonCharactersKeys = favouriteCartoonCharacters; } @@ -82,6 +84,7 @@ public List getNotFavouriteCartoonCharacters() { return _notFavouriteCartoonCharactersKeys; } + @StrutsParameter public void setNotFavouriteCartoonCharacters(List notFavouriteCartoonCharacters) { _notFavouriteCartoonCharactersKeys = notFavouriteCartoonCharacters; } @@ -108,6 +111,7 @@ public List getFavouriteCars() { return _favouriteCarsKeys; } + @StrutsParameter public void setFavouriteCars(List favouriteCars) { _favouriteCarsKeys = favouriteCars; } @@ -116,6 +120,7 @@ public List getNotFavouriteCars() { return _notFavouriteCarsKeys; } + @StrutsParameter public void setNotFavouriteCars(List notFavouriteCars) { _notFavouriteCarsKeys = notFavouriteCars; } @@ -142,6 +147,7 @@ public List getFavouriteMotorcycles() { return _favouriteMotorcyclesKeys; } + @StrutsParameter public void setFavouriteMotorcycles(List favouriteMotorcycles) { _favouriteMotorcyclesKeys = favouriteMotorcycles; } @@ -150,6 +156,7 @@ public List getNotFavouriteMotorcycles() { return _notFavouriteMotorcyclesKeys; } + @StrutsParameter public void setNotFavouriteMotorcycles(List notFavouriteMotorcycles) { _notFavouriteMotorcyclesKeys = notFavouriteMotorcycles; } @@ -176,6 +183,7 @@ public List getFavouriteCountries() { return _favouriteCountriesKeys; } + @StrutsParameter public void setFavouriteCountries(List favouriteCountries) { _favouriteCountriesKeys = favouriteCountries; } @@ -184,6 +192,7 @@ public List getNotFavouriteCountries() { return _notFavouriteCountriesKeys; } + @StrutsParameter public void setNotFavouriteCountries(List notFavouriteCountries) { _notFavouriteCountriesKeys = notFavouriteCountries; } @@ -205,6 +214,7 @@ public List getFavouriteSports() { return _favouriteSportsKeys; } + @StrutsParameter public void setFavouriteSports(List favouriteSportsKeys) { this._favouriteSportsKeys = favouriteSportsKeys; } @@ -213,6 +223,7 @@ public List getNonFavouriteSports() { return _nonFavouriteSportsKeys; } + @StrutsParameter public void setNonFavouriteSports(List notFavouriteSportsKeys) { this._nonFavouriteSportsKeys = notFavouriteSportsKeys; } @@ -222,6 +233,7 @@ public List getPrioritisedFavouriteCartoonCharacters() { return _prioritisedFavouriteCartoonCharacters; } + @StrutsParameter public void setPrioritisedFavouriteCartoonCharacters(List prioritisedFavouriteCartoonCharacters) { _prioritisedFavouriteCartoonCharacters = prioritisedFavouriteCartoonCharacters; } @@ -230,6 +242,7 @@ public List getPrioritisedFavouriteCars() { return _prioritisedFavouriteCars; } + @StrutsParameter public void setPrioritisedFavouriteCars(List prioritisedFavouriteCars) { _prioritisedFavouriteCars = prioritisedFavouriteCars; } @@ -239,6 +252,7 @@ public List getPrioritisedFavouriteCountries() { return _prioritisedFavouriteCountries; } + @StrutsParameter public void setPrioritisedFavouriteCountries(List prioritisedFavouriteCountries) { _prioritisedFavouriteCountries = prioritisedFavouriteCountries; } @@ -264,12 +278,13 @@ public List getFavouriteCities() { return _favouriteCities; } + @StrutsParameter public void setFavouriteCities(List favouriteCities) { this._favouriteCities = favouriteCities; } // actions - + @Override public String input() throws Exception { return SUCCESS; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/LotsOfRichtexteditorAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/LotsOfRichtexteditorAction.java index 1e106691da..ac18342a53 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/LotsOfRichtexteditorAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/LotsOfRichtexteditorAction.java @@ -21,6 +21,7 @@ package org.apache.struts2.showcase; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; /** * @@ -36,6 +37,7 @@ public String getDescription1() { return this.description1; } + @StrutsParameter public void setDescription1(String description1) { this.description1 = description1; } @@ -45,6 +47,7 @@ public String getDescription2() { return this.description2; } + @StrutsParameter public void setDescription2(String description2) { this.description2 = description2; } @@ -54,6 +57,7 @@ public String getDescription3() { return this.description3; } + @StrutsParameter public void setDescription3(String description3) { this.description3 = description3; } @@ -63,11 +67,12 @@ public String getDescription4() { return this.description4; } + @StrutsParameter public void setDescription4(String description4) { this.description4 = description4; } - + @Override public String input() throws Exception { return SUCCESS; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/MoreSelectsAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/MoreSelectsAction.java index 6a5d85f67b..72f554bed3 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/MoreSelectsAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/MoreSelectsAction.java @@ -21,6 +21,7 @@ package org.apache.struts2.showcase; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -75,11 +76,11 @@ public List getDefaultFavouriteNumbers() { return list; } - public List getPrioritisedFavouriteCartoonCharacters() { return _prioritisedFavouriteCartoonCharacters; } + @StrutsParameter public void setPrioritisedFavouriteCartoonCharacters(List prioritisedFavouriteCartoonCharacters) { _prioritisedFavouriteCartoonCharacters = prioritisedFavouriteCartoonCharacters; } @@ -88,15 +89,16 @@ public List getPrioritisedFavouriteCars() { return _prioritisedFavouriteCars; } + @StrutsParameter public void setPrioritisedFavouriteCars(List prioritisedFavouriteCars) { _prioritisedFavouriteCars = prioritisedFavouriteCars; } - public List getPrioritisedFavouriteCountries() { return _prioritisedFavouriteCountries; } + @StrutsParameter public void setPrioritisedFavouriteCountries(List prioritisedFavouriteCountries) { _prioritisedFavouriteCountries = prioritisedFavouriteCountries; } @@ -105,6 +107,7 @@ public List getFavouriteNumbers() { return favouriteNumbers; } + @StrutsParameter public void setFavouriteNumbers(List favouriteNumbers) { this.favouriteNumbers = favouriteNumbers; } @@ -129,12 +132,13 @@ public List getFavouriteCities() { return favouriteCities; } + @StrutsParameter public void setFavouriteCities(List favouriteCities) { this.favouriteCities = favouriteCities; } // actions - + @Override public String input() throws Exception { return SUCCESS; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/ShowAjaxDynamicTreeAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/ShowAjaxDynamicTreeAction.java index 40ec4b72ca..242790c9f8 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/ShowAjaxDynamicTreeAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/ShowAjaxDynamicTreeAction.java @@ -21,6 +21,7 @@ package org.apache.struts2.showcase; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import org.apache.struts2.showcase.ajax.tree.Category; public class ShowAjaxDynamicTreeAction extends ActionSupport { @@ -34,6 +35,7 @@ public int getNodeId() { return nodeId; } + @StrutsParameter public void setNodeId(int nodeId) { this.nodeId = nodeId; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/UITagExample.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/UITagExample.java index 1e87b2193d..c04114c2ed 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/UITagExample.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/UITagExample.java @@ -200,6 +200,7 @@ public String getBestFriend() { return bestFriend; } + @StrutsParameter public void setBestFriend(String bestFriend) { this.bestFriend = bestFriend; } @@ -231,6 +232,7 @@ public void setRegion(String region) { this.region = region; } + @StrutsParameter public void setPicture(File picture) { this.picture = picture; } @@ -239,10 +241,12 @@ public File getPicture() { return this.picture; } + @StrutsParameter public void setPictureContentType(String pictureContentType) { this.pictureContentType = pictureContentType; } + @StrutsParameter public void setPictureFileName(String pictureFileName) { this.pictureFileName = pictureFileName; } @@ -323,6 +327,7 @@ public String getDescription() { return this.description; } + @Override public boolean equals(Object obj) { if (!(obj instanceof VehicalType)) { return false; @@ -331,6 +336,7 @@ public boolean equals(Object obj) { } } + @Override public int hashCode() { return key.hashCode(); } @@ -354,6 +360,7 @@ public String getDescription() { return this.description; } + @Override public boolean equals(Object obj) { if (!(obj instanceof VehicalSpecific)) { return false; @@ -362,6 +369,7 @@ public boolean equals(Object obj) { } } + @Override public int hashCode() { return key.hashCode(); } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/action/AbstractCRUDAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/action/AbstractCRUDAction.java index 4c79c7ea94..2880f36581 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/action/AbstractCRUDAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/action/AbstractCRUDAction.java @@ -21,6 +21,7 @@ import com.opensymphony.xwork2.ActionSupport; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import org.apache.struts2.showcase.dao.Dao; import org.apache.struts2.showcase.model.IdEntity; @@ -40,7 +41,6 @@ public abstract class AbstractCRUDAction extends ActionSupport { protected abstract Dao getDao(); - public Collection getAvailableItems() { return availableItems; } @@ -49,6 +49,7 @@ public String[] getToDelete() { return toDelete; } + @StrutsParameter public void setToDelete(String[] toDelete) { this.toDelete = toDelete; } @@ -64,11 +65,11 @@ public String list() throws Exception { public String delete() throws Exception { if (toDelete != null) { int count = 0; - for (int i = 0, j = toDelete.length; i < j; i++) { - count = count + getDao().delete(toDelete[i]); - } + for (String s : toDelete) { + count = count + getDao().delete(s); + } if (log.isDebugEnabled()) { - log.debug("AbstractCRUDAction - [delete]: " + count + " items deleted."); + log.debug("AbstractCRUDAction - [delete]: {} items deleted.", count); } } return SUCCESS; diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/action/EmployeeAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/action/EmployeeAction.java index af2281f17e..e8a411fe3d 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/action/EmployeeAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/action/EmployeeAction.java @@ -21,6 +21,7 @@ import com.opensymphony.xwork2.Preparable; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import org.apache.struts2.showcase.application.TestDataProvider; import org.apache.struts2.showcase.dao.Dao; import org.apache.struts2.showcase.dao.EmployeeDao; @@ -52,7 +53,7 @@ public class EmployeeAction extends AbstractCRUDAction implements Preparable { public String execute() throws Exception { if (getCurrentEmployee() != null && getCurrentEmployee().getOtherSkills() != null) { - setSelectedSkills(new ArrayList()); + setSelectedSkills(new ArrayList<>()); Iterator it = getCurrentEmployee().getOtherSkills().iterator(); while (it.hasNext()) { getSelectedSkills().add(((Skill) it.next()).getName()); @@ -73,10 +74,12 @@ public Long getEmpId() { return empId; } + @StrutsParameter public void setEmpId(Long empId) { this.empId = empId; } + @StrutsParameter(depth = 2) public Employee getCurrentEmployee() { return currentEmployee; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/action/ExampleAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/action/ExampleAction.java index 35c0715631..771d49cbca 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/action/ExampleAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/action/ExampleAction.java @@ -20,7 +20,11 @@ import com.opensymphony.xwork2.ActionSupport; -import java.util.*; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; public class ExampleAction extends ActionSupport { public static final String CONSTANT = "Struts Rocks!"; @@ -46,7 +50,7 @@ public Book getBook() { } public Map getBooks() { - Map books = new HashMap(); + Map books = new HashMap<>(); books.put("Iliad", new Book("Iliad", "Homer")); books.put("The Republic", new Book("The Replublic", "Plato")); books.put("Thus Spake Zarathustra", new Book("Thus Spake Zarathustra", @@ -79,4 +83,4 @@ public String getAuthor() { public void setAuthor(String author) { this.author = author; } -} \ No newline at end of file +} diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/action/JSPEvalAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/action/JSPEvalAction.java index fed9cd6447..7683a97019 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/action/JSPEvalAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/action/JSPEvalAction.java @@ -21,8 +21,13 @@ import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.interceptor.annotations.After; import org.apache.struts2.ServletActionContext; +import org.apache.struts2.interceptor.parameter.StrutsParameter; -import java.io.*; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.IOException; import java.net.URL; /** @@ -62,6 +67,7 @@ public void cleanUp() throws IOException { } } + @StrutsParameter public void setJsp(String jsp) { this.jsp = jsp; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/action/SkillAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/action/SkillAction.java index 6ba2096915..ce462095b5 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/action/SkillAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/action/SkillAction.java @@ -46,6 +46,7 @@ public class SkillAction extends AbstractCRUDAction implements Preparable { * * @throws Exception thrown if a system level exception occurs. */ + @Override public void prepare() throws Exception { Skill preFetched = (Skill) fetch(getSkillName(), getCurrentSkill()); if (preFetched != null) { @@ -64,6 +65,7 @@ public String getSkillName() { return skillName; } + @StrutsParameter public void setSkillName(String skillName) { this.skillName = skillName; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/actionchaining/ActionChain1.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/actionchaining/ActionChain1.java index e196e2226f..e57006f2bd 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/actionchaining/ActionChain1.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/actionchaining/ActionChain1.java @@ -19,6 +19,7 @@ package org.apache.struts2.showcase.actionchaining; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; public class ActionChain1 extends ActionSupport { @@ -26,6 +27,7 @@ public class ActionChain1 extends ActionSupport { private String actionChain1Property1 = "Property Set In Action Chain 1"; + @Override public String input() throws Exception { return SUCCESS; } @@ -34,6 +36,7 @@ public String getActionChain1Property1() { return actionChain1Property1; } + @StrutsParameter public void setActionChain1Property1(String actionChain1Property1) { this.actionChain1Property1 = actionChain1Property1; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/actionchaining/ActionChain2.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/actionchaining/ActionChain2.java index b973a2b78c..32e7f67676 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/actionchaining/ActionChain2.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/actionchaining/ActionChain2.java @@ -19,6 +19,7 @@ package org.apache.struts2.showcase.actionchaining; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; public class ActionChain2 extends ActionSupport { @@ -27,6 +28,7 @@ public class ActionChain2 extends ActionSupport { private String actionChain1Property1; private String actionChain2Property1 = "Property Set in Action Chain 2"; + @Override public String execute() throws Exception { return SUCCESS; } @@ -35,15 +37,16 @@ public String getActionChain1Property1() { return actionChain1Property1; } + @StrutsParameter public void setActionChain1Property1(String actionChain1Property1) { this.actionChain1Property1 = actionChain1Property1; } - public String getActionChain2Property1() { return actionChain2Property1; } + @StrutsParameter public void setActionChain2Property1(String actionChain2Property1) { this.actionChain2Property1 = actionChain2Property1; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/actionchaining/ActionChain3.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/actionchaining/ActionChain3.java index e22712f8e9..402a1b578c 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/actionchaining/ActionChain3.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/actionchaining/ActionChain3.java @@ -19,6 +19,7 @@ package org.apache.struts2.showcase.actionchaining; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; public class ActionChain3 extends ActionSupport { @@ -28,7 +29,7 @@ public class ActionChain3 extends ActionSupport { private String actionChain2Property1; private String actionChain3Property1 = "Property set in Action Chain 3"; - + @Override public String execute() throws Exception { return SUCCESS; } @@ -37,24 +38,25 @@ public String getActionChain1Property1() { return actionChain1Property1; } + @StrutsParameter public void setActionChain1Property1(String actionChain1Property1) { this.actionChain1Property1 = actionChain1Property1; } - public String getActionChain2Property1() { return actionChain2Property1; } + @StrutsParameter public void setActionChain2Property1(String actionChain2Property1) { this.actionChain2Property1 = actionChain2Property1; } - public String getActionChain3Property1() { return actionChain3Property1; } + @StrutsParameter public void setActionChain3Property1(String actionChain3Property1) { this.actionChain3Property1 = actionChain3Property1; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/AjaxTestAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/AjaxTestAction.java index 6fd2bfecbf..ec146c05d9 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/AjaxTestAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/AjaxTestAction.java @@ -21,10 +21,10 @@ package org.apache.struts2.showcase.ajax; import com.opensymphony.xwork2.Action; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.io.Serializable; - public class AjaxTestAction implements Action, Serializable { private static int counter = 0; @@ -46,6 +46,7 @@ public String getData() { return data; } + @StrutsParameter public void setData(String data) { this.data = data; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/AutocompleterExampleAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/AutocompleterExampleAction.java index 001cffa397..9193ec918a 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/AutocompleterExampleAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/AutocompleterExampleAction.java @@ -21,16 +21,18 @@ package org.apache.struts2.showcase.ajax; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.util.ArrayList; import java.util.List; public class AutocompleterExampleAction extends ActionSupport { private String select; - private List options = new ArrayList(); + private final List options = new ArrayList<>(); private static final long serialVersionUID = -8481638176160014396L; + @Override public String execute() throws Exception { if ("fruits".equals(select)) { options.add("apple"); @@ -49,6 +51,7 @@ public String getSelect() { return select; } + @StrutsParameter public void setSelect(String select) { this.select = select; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/Example4ShowPanelAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/Example4ShowPanelAction.java index 10a2d10dbd..c698da86df 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/Example4ShowPanelAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/Example4ShowPanelAction.java @@ -21,6 +21,7 @@ package org.apache.struts2.showcase.ajax; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.text.SimpleDateFormat; import java.util.Date; @@ -51,6 +52,7 @@ public String getGender() { return gender; } + @StrutsParameter public void setGender(String gender) { this.gender = gender; } @@ -59,6 +61,7 @@ public String getName() { return name; } + @StrutsParameter public void setName(String name) { this.name = name; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/Example5Action.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/Example5Action.java index 4f7d3ed656..d5f7b1c3dc 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/Example5Action.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/Example5Action.java @@ -21,6 +21,7 @@ package org.apache.struts2.showcase.ajax; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; public class Example5Action extends ActionSupport { @@ -37,6 +38,7 @@ public String getName() { return name; } + @StrutsParameter public void setName(String name) { this.name = name; } @@ -45,6 +47,7 @@ public Integer getAge() { return age; } + @StrutsParameter public void setAge(Integer age) { this.age = age; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/tree/GetCategory.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/tree/GetCategory.java index 73362667dc..cbb7ec1e49 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/tree/GetCategory.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/tree/GetCategory.java @@ -21,6 +21,7 @@ package org.apache.struts2.showcase.ajax.tree; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; /** */ @@ -28,6 +29,7 @@ public class GetCategory extends ActionSupport { private long catId; private Category category; + @Override public String execute() throws Exception { if (catId < 1) { // force the root @@ -39,6 +41,7 @@ public String execute() throws Exception { return SUCCESS; } + @StrutsParameter public void setCatId(long catId) { this.catId = catId; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/tree/Toggle.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/tree/Toggle.java index 036719157f..a050054b22 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/tree/Toggle.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/tree/Toggle.java @@ -24,6 +24,8 @@ /** */ public class Toggle extends GetCategory { + + @Override public String execute() throws Exception { super.execute(); diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/async/ChatRoomAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/async/ChatRoomAction.java index 67b27e3b6c..be05ce1a9a 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/async/ChatRoomAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/async/ChatRoomAction.java @@ -50,15 +50,12 @@ public List getNewMessages() { } public Callable receiveNewMessages() throws Exception { - return new Callable() { - @Override - public String call() throws Exception { - while (lastIndex >= messages.size()) { - Thread.sleep(3000); - } - newMessages = messages.subList(lastIndex, messages.size()); - return SUCCESS; + return () -> { + while (lastIndex >= messages.size()) { + Thread.sleep(3000); } + newMessages = messages.subList(lastIndex, messages.size()); + return SUCCESS; }; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatLoginAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatLoginAction.java index 0dcfd8943c..d40232e0ba 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatLoginAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatLoginAction.java @@ -21,11 +21,11 @@ package org.apache.struts2.showcase.chat; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.action.SessionAware; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.util.Map; -import org.apache.struts2.action.SessionAware; - public class ChatLoginAction extends ActionSupport implements SessionAware { private static final long serialVersionUID = 1L; @@ -43,6 +43,7 @@ public String getName() { return this.name; } + @StrutsParameter public void setName(String name) { this.name = name; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/CrudRoomAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/CrudRoomAction.java index f447b073e7..ca546792ab 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/CrudRoomAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/CrudRoomAction.java @@ -21,6 +21,7 @@ package org.apache.struts2.showcase.chat; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; public class CrudRoomAction extends ActionSupport { @@ -36,6 +37,7 @@ public String getDescription() { return description; } + @StrutsParameter public void setDescription(String description) { this.description = description; } @@ -44,6 +46,7 @@ public String getName() { return name; } + @StrutsParameter public void setName(String name) { this.name = name; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/EnterRoomAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/EnterRoomAction.java index 4b3939b0d3..bf5c6df9ad 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/EnterRoomAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/EnterRoomAction.java @@ -21,11 +21,11 @@ package org.apache.struts2.showcase.chat; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.action.SessionAware; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.util.Map; -import org.apache.struts2.action.SessionAware; - public class EnterRoomAction extends ActionSupport implements SessionAware { private static final long serialVersionUID = 1L; @@ -38,6 +38,7 @@ public String getRoomName() { return this.roomName; } + @StrutsParameter public void setRoomName(String roomName) { this.roomName = roomName; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ExitRoomAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ExitRoomAction.java index 7dc14be1d1..e87dfdc950 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ExitRoomAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ExitRoomAction.java @@ -21,11 +21,11 @@ package org.apache.struts2.showcase.chat; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.action.SessionAware; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.util.Map; -import org.apache.struts2.action.SessionAware; - public class ExitRoomAction extends ActionSupport implements SessionAware { private static final long serialVersionUID = 1L; @@ -38,6 +38,7 @@ public String getRoomName() { return roomName; } + @StrutsParameter public void setRoomName(String roomName) { this.roomName = roomName; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/MessagesAvailableInRoomAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/MessagesAvailableInRoomAction.java index a7330e7334..3489bac713 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/MessagesAvailableInRoomAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/MessagesAvailableInRoomAction.java @@ -21,6 +21,7 @@ package org.apache.struts2.showcase.chat; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.util.ArrayList; import java.util.List; @@ -30,13 +31,14 @@ public class MessagesAvailableInRoomAction extends ActionSupport { private static final long serialVersionUID = 1L; private String roomName; - private ChatService chatService; - private List messagesAvailableInRoom = new ArrayList(); + private final ChatService chatService; + private List messagesAvailableInRoom = new ArrayList<>(); public String getRoomName() { return this.roomName; } + @StrutsParameter public void setRoomName(String roomName) { this.roomName = roomName; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/SendMessageToRoomAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/SendMessageToRoomAction.java index 96bfe75c2f..51843179db 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/SendMessageToRoomAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/SendMessageToRoomAction.java @@ -21,16 +21,16 @@ package org.apache.struts2.showcase.chat; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.action.SessionAware; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.util.Map; -import org.apache.struts2.action.SessionAware; - public class SendMessageToRoomAction extends ActionSupport implements SessionAware { private static final long serialVersionUID = 1L; - private ChatService chatService; + private final ChatService chatService; private String roomName; private String message; @@ -45,6 +45,7 @@ public String getRoomName() { return this.roomName; } + @StrutsParameter public void setRoomName(String roomName) { this.roomName = roomName; } @@ -53,11 +54,12 @@ public String getMessage() { return this.message; } + @StrutsParameter public void setMessage(String message) { this.message = message; } - + @Override public String execute() throws Exception { User user = (User) session.get(ChatAuthenticationInterceptor.USER_SESSION_KEY); try { diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/UsersAvailableInRoomAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/UsersAvailableInRoomAction.java index bebd738307..0f97a34010 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/UsersAvailableInRoomAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/UsersAvailableInRoomAction.java @@ -21,6 +21,7 @@ package org.apache.struts2.showcase.chat; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.util.ArrayList; import java.util.List; @@ -29,8 +30,8 @@ public class UsersAvailableInRoomAction extends ActionSupport { private static final long serialVersionUID = 1L; - private ChatService chatService; - private List usersAvailableInRoom = new ArrayList(); + private final ChatService chatService; + private List usersAvailableInRoom = new ArrayList<>(); private String roomName; @@ -43,6 +44,7 @@ public String getRoomName() { return this.roomName; } + @StrutsParameter public void setRoomName(String roomName) { this.roomName = roomName; } @@ -51,6 +53,7 @@ public List getUsersAvailableInRoom() { return usersAvailableInRoom; } + @Override public String execute() throws Exception { try { usersAvailableInRoom = chatService.getUsersAvailableInRoom(roomName); diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/conversion/OperationsEnumAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/conversion/OperationsEnumAction.java index 272c8b6cc2..a3fb3b8277 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/conversion/OperationsEnumAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/conversion/OperationsEnumAction.java @@ -34,7 +34,7 @@ public class OperationsEnumAction extends ActionSupport { private static final long serialVersionUID = -2229489704988870318L; - private List selectedOperations = new LinkedList(); + private List selectedOperations = new LinkedList<>(); public String input() throws Exception { return SUCCESS; @@ -53,7 +53,6 @@ public void setSelectedOperations(List selectedOperations) { this.selectedOperations = selectedOperations; } - public List getAvailableOperations() { return Arrays.asList(OperationsEnum.values()); } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/freemarker/StandardTagsAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/freemarker/StandardTagsAction.java index c23ee156a7..c79480ff06 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/freemarker/StandardTagsAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/freemarker/StandardTagsAction.java @@ -22,6 +22,7 @@ import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.Preparable; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.text.DateFormatSymbols; @@ -34,6 +35,7 @@ public class StandardTagsAction extends ActionSupport implements Preparable { private String[] gender; private String[] months; + @Override public void prepare() { months = new DateFormatSymbols().getMonths(); name = StandardTagsAction.class.getName().substring(StandardTagsAction.class.getName().lastIndexOf(".") + 1); @@ -44,6 +46,7 @@ public String getName() { return name; } + @StrutsParameter public void setName(String name) { this.name = name; } @@ -52,15 +55,16 @@ public String[] getMonths() { return months; } + @StrutsParameter public void setMonths(String[] months) { this.months = months; } - public String[] getGender() { return gender; } + @StrutsParameter public void setGender(String[] gender) { this.gender = gender; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/hangman/GuessCharacterAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/hangman/GuessCharacterAction.java index 67ea15099c..3df913d585 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/hangman/GuessCharacterAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/hangman/GuessCharacterAction.java @@ -21,11 +21,11 @@ package org.apache.struts2.showcase.hangman; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.action.SessionAware; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.util.Map; -import org.apache.struts2.action.SessionAware; - public class GuessCharacterAction extends ActionSupport implements SessionAware { private static final long serialVersionUID = 9050915577007590674L; @@ -34,6 +34,7 @@ public class GuessCharacterAction extends ActionSupport implements SessionAware private Character character; private Hangman hangman; + @Override public String execute() throws Exception { hangman = (Hangman) session.get(HangmanConstants.HANGMAN_SESSION_KEY); hangman.guess(character); @@ -45,6 +46,7 @@ public Hangman getHangman() { return hangman; } + @StrutsParameter public void setCharacter(Character character) { this.character = character; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/modelDriven/ModelDrivenAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/modelDriven/ModelDrivenAction.java index c32cd20031..a491ba7ca6 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/modelDriven/ModelDrivenAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/modelDriven/ModelDrivenAction.java @@ -30,14 +30,17 @@ public class ModelDrivenAction extends ActionSupport implements ModelDriven { private static final long serialVersionUID = 1271130427666936592L; + @Override public String input() throws Exception { return SUCCESS; } + @Override public String execute() throws Exception { return SUCCESS; } + @Override public Object getModel() { return new Gangster(); } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/person/EditPersonAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/person/EditPersonAction.java index 4d102f7806..8fbdee0b21 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/person/EditPersonAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/person/EditPersonAction.java @@ -23,10 +23,10 @@ import com.opensymphony.xwork2.ActionSupport; import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import org.springframework.beans.factory.annotation.Autowired; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; /** @@ -42,13 +42,14 @@ public class EditPersonAction extends ActionSupport { @Autowired private PersonManager personManager; - private List persons = new ArrayList(); + private List persons = new ArrayList<>(); /** * A default implementation that does nothing an returns "success". * * @return {@link #INPUT} */ + @Override public String execute() throws Exception { persons.addAll(personManager.getPeople()); return INPUT; @@ -68,6 +69,7 @@ public String save() throws Exception { return "list"; } + @StrutsParameter(depth = 2) public List getPersons() { return persons; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/person/ListPeopleAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/person/ListPeopleAction.java index e64c199d60..2d21587874 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/person/ListPeopleAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/person/ListPeopleAction.java @@ -35,8 +35,9 @@ public class ListPeopleAction extends ActionSupport { @Autowired private PersonManager personManager; - private List people = new ArrayList(); + private final List people = new ArrayList<>(); + @Override public String execute() { people.addAll(personManager.getPeople()); diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/person/NewPersonAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/person/NewPersonAction.java index eb07bd721c..d5888af857 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/person/NewPersonAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/person/NewPersonAction.java @@ -23,6 +23,7 @@ import com.opensymphony.xwork2.ActionSupport; import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import org.springframework.beans.factory.annotation.Autowired; @@ -38,12 +39,14 @@ public class NewPersonAction extends ActionSupport { private PersonManager personManager; private Person person; + @Override public String execute() { personManager.createPerson(person); return "list"; } + @StrutsParameter(depth = 1) public Person getPerson() { return person; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/source/ViewSourceAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/source/ViewSourceAction.java index ce5b5b9495..bbd4bb54ab 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/source/ViewSourceAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/source/ViewSourceAction.java @@ -23,6 +23,7 @@ import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.util.ClassLoaderUtil; import org.apache.struts2.action.ServletContextAware; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import javax.servlet.ServletContext; import java.io.BufferedReader; @@ -98,8 +99,9 @@ public String execute() throws IOException { /** * @param className the className to set */ + @StrutsParameter public void setClassName(String className) { - if (className != null && className.trim().length() > 0) { + if (className != null && !className.trim().isEmpty()) { this.className = className; } } @@ -107,8 +109,9 @@ public void setClassName(String className) { /** * @param config the config to set */ + @StrutsParameter public void setConfig(String config) { - if (config != null && config.trim().length() > 0) { + if (config != null && !config.trim().isEmpty()) { this.config = config; } } @@ -116,8 +119,9 @@ public void setConfig(String config) { /** * @param page the page to set */ + @StrutsParameter public void setPage(String page) { - if (page != null && page.trim().length() > 0) { + if (page != null && !page.trim().isEmpty()) { this.page = page; } } @@ -125,6 +129,7 @@ public void setPage(String page) { /** * @param padding the padding to set */ + @StrutsParameter public void setPadding(int padding) { this.padding = padding; } @@ -222,6 +227,7 @@ private List read(InputStream in, int targetLineNumber) { return snippet; } + @Override public void withServletContext(ServletContext arg0) { this.servletContext = arg0; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/tag/nonui/actionPrefix/SubmitAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/tag/nonui/actionPrefix/SubmitAction.java index 7ae6257eb0..6e5afa8069 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/tag/nonui/actionPrefix/SubmitAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/tag/nonui/actionPrefix/SubmitAction.java @@ -21,6 +21,7 @@ package org.apache.struts2.showcase.tag.nonui.actionPrefix; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; public class SubmitAction extends ActionSupport { @@ -32,10 +33,12 @@ public String getText() { return text; } + @StrutsParameter public void setText(String text) { this.text = text; } + @Override public String execute() throws Exception { return SUCCESS; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/tag/nonui/debugtag/DebugTagAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/tag/nonui/debugtag/DebugTagAction.java index e3c2681501..4d732fecdc 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/tag/nonui/debugtag/DebugTagAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/tag/nonui/debugtag/DebugTagAction.java @@ -23,8 +23,9 @@ public class DebugTagAction extends ActionSupport { + @Override public String execute() throws Exception { PrepareOperations.overrideDevMode(true); // Just for Showcase, explicitly switch on for this action only return SUCCESS; } -} \ No newline at end of file +} diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/tag/nonui/iteratortag/AppendIteratorTagDemo.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/tag/nonui/iteratortag/AppendIteratorTagDemo.java index f3936a49b7..deca54ab07 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/tag/nonui/iteratortag/AppendIteratorTagDemo.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/tag/nonui/iteratortag/AppendIteratorTagDemo.java @@ -22,6 +22,7 @@ import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.Validateable; +import org.apache.struts2.interceptor.parameter.StrutsParameter; /** * @@ -47,25 +48,25 @@ public void validate() { } } - public String getIteratorValue1() { return iteratorValue1; } + @StrutsParameter public void setIteratorValue1(String iteratorValue1) { this.iteratorValue1 = iteratorValue1; } - public String getIteratorValue2() { return iteratorValue2; } + @StrutsParameter public void setIteratorValue2(String iteratorValue2) { this.iteratorValue2 = iteratorValue2; } - + @Override public String input() throws Exception { return SUCCESS; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/tag/nonui/iteratortag/IteratorGeneratorTagDemo.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/tag/nonui/iteratortag/IteratorGeneratorTagDemo.java index 0e48519bdb..ca66f63de6 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/tag/nonui/iteratortag/IteratorGeneratorTagDemo.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/tag/nonui/iteratortag/IteratorGeneratorTagDemo.java @@ -21,6 +21,7 @@ package org.apache.struts2.showcase.tag.nonui.iteratortag; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; /** */ @@ -37,34 +38,34 @@ public String getValue() { return value; } + @StrutsParameter public void setValue(String value) { this.value = value; } - public Integer getCount() { return count; } + @StrutsParameter public void setCount(Integer count) { this.count = count; } - public String getSeparator() { return this.separator; } + @StrutsParameter public void setSeparator(String separator) { this.separator = separator; } - public String submit() throws Exception { return SUCCESS; } - + @Override public String input() throws Exception { return SUCCESS; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/tag/nonui/iteratortag/MergeIteratorTagDemo.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/tag/nonui/iteratortag/MergeIteratorTagDemo.java index cc8fa28dea..6bb4c9b1cb 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/tag/nonui/iteratortag/MergeIteratorTagDemo.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/tag/nonui/iteratortag/MergeIteratorTagDemo.java @@ -22,6 +22,7 @@ import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.Validateable; +import org.apache.struts2.interceptor.parameter.StrutsParameter; /** @@ -33,7 +34,7 @@ public class MergeIteratorTagDemo extends ActionSupport implements Validateable private String iteratorValue1; private String iteratorValue2; - + @Override public void validate() { if (iteratorValue1 == null || iteratorValue1.trim().length() <= 0) { addFieldError("iteratorValue1", "iterator value 1 cannot be empty"); @@ -47,25 +48,25 @@ public void validate() { } } - public String getIteratorValue1() { return this.iteratorValue1; } + @StrutsParameter public void setIteratorValue1(String iteratorValue1) { this.iteratorValue1 = iteratorValue1; } - public String getIteratorValue2() { return this.iteratorValue2; } + @StrutsParameter public void setIteratorValue2(String iteratorValue2) { this.iteratorValue2 = iteratorValue2; } - + @Override public String input() throws Exception { return SUCCESS; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/tag/nonui/iteratortag/SubsetIteratorTagDemo.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/tag/nonui/iteratortag/SubsetIteratorTagDemo.java index 11b2211374..ccbd310133 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/tag/nonui/iteratortag/SubsetIteratorTagDemo.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/tag/nonui/iteratortag/SubsetIteratorTagDemo.java @@ -22,6 +22,7 @@ import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.Validateable; +import org.apache.struts2.interceptor.parameter.StrutsParameter; /** * @@ -34,7 +35,7 @@ public class SubsetIteratorTagDemo extends ActionSupport implements Validateable private Integer count; private Integer start; - + @Override public void validate() { if (iteratorValue == null || iteratorValue.trim().length() <= 0) { addFieldError("iteratorValue1", "iterator value 1 cannot be empty"); @@ -43,34 +44,34 @@ public void validate() { } } - public String getIteratorValue() { return this.iteratorValue; } + @StrutsParameter public void setIteratorValue(String iteratorValue) { this.iteratorValue = iteratorValue; } - public Integer getCount() { return this.count; } + @StrutsParameter public void setCount(Integer count) { this.count = count; } - public Integer getStart() { return this.start; } + @StrutsParameter public void setStart(Integer start) { this.start = start; } - + @Override public String input() throws Exception { return SUCCESS; } @@ -78,6 +79,4 @@ public String input() throws Exception { public String submit() throws Exception { return SUCCESS; } - - } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/token/TokenAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/token/TokenAction.java index 680fde6492..297c19c754 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/token/TokenAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/token/TokenAction.java @@ -22,6 +22,7 @@ import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.util.Date; @@ -76,6 +77,7 @@ public int getAmount() { return amount; } + @StrutsParameter public void setAmount(int amount) { this.amount = amount; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/AbstractValidationActionSupport.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/AbstractValidationActionSupport.java index 9e04cd0947..53228a952f 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/AbstractValidationActionSupport.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/AbstractValidationActionSupport.java @@ -30,6 +30,7 @@ public String submit() throws Exception { return "success"; } + @Override public String input() throws Exception { return "input"; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/AjaxFormSubmitAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/AjaxFormSubmitAction.java index 7ef478ab46..4c831c754a 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/AjaxFormSubmitAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/AjaxFormSubmitAction.java @@ -18,8 +18,6 @@ */ package org.apache.struts2.showcase.validation; -import java.sql.Date; - import com.opensymphony.xwork2.validator.annotations.DateRangeFieldValidator; import com.opensymphony.xwork2.validator.annotations.EmailValidator; import com.opensymphony.xwork2.validator.annotations.FieldExpressionValidator; @@ -29,6 +27,9 @@ import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator; import com.opensymphony.xwork2.validator.annotations.StringLengthFieldValidator; import com.opensymphony.xwork2.validator.annotations.UrlValidator; +import org.apache.struts2.interceptor.parameter.StrutsParameter; + +import java.sql.Date; /** * @@ -72,9 +73,10 @@ public Date getDateValidatorField() { } @DateRangeFieldValidator( - min="01/01/1990", - max="01/01/2000", + min="01/01/1990", + max="01/01/2000", message="must be a min 01-01-1990 max 01-01-2000 if supplied") + @StrutsParameter public void setDateValidatorField(Date dateValidatorField) { this.dateValidatorField = dateValidatorField; } @@ -84,6 +86,7 @@ public String getEmailValidatorField() { } @EmailValidator(message="must be a valid email if supplied") + @StrutsParameter public void setEmailValidatorField(String emailValidatorField) { this.emailValidatorField = emailValidatorField; } @@ -93,6 +96,7 @@ public Integer getIntegerValidatorField() { } @IntRangeFieldValidator(min="1", max="10", message="must be integer min 1 max 10 if supplied") + @StrutsParameter public void setIntegerValidatorField(Integer integerValidatorField) { this.integerValidatorField = integerValidatorField; } @@ -102,8 +106,9 @@ public String getRegexValidatorField() { } @RegexFieldValidator( - regex="[^<>]+", + regex="[^<>]+", message="regexValidatorField must match a regexp (.*\\.txt) if specified") + @StrutsParameter public void setRegexValidatorField(String regexValidatorField) { this.regexValidatorField = regexValidatorField; } @@ -113,6 +118,7 @@ public String getRequiredStringValidatorField() { } @RequiredStringValidator(trim=true, message="required and must be string") + @StrutsParameter public void setRequiredStringValidatorField(String requiredStringValidatorField) { this.requiredStringValidatorField = requiredStringValidatorField; } @@ -122,6 +128,7 @@ public String getRequiredValidatorField() { } @RequiredFieldValidator(message="required") + @StrutsParameter public void setRequiredValidatorField(String requiredValidatorField) { this.requiredValidatorField = requiredValidatorField; } @@ -131,10 +138,11 @@ public String getStringLengthValidatorField() { } @StringLengthFieldValidator( - minLength="2", - maxLength="4", - trim=true, + minLength="2", + maxLength="4", + trim=true, message="must be a String of a specific greater than 1 less than 5 if specified") + @StrutsParameter public void setStringLengthValidatorField(String stringLengthValidatorField) { this.stringLengthValidatorField = stringLengthValidatorField; } @@ -144,10 +152,10 @@ public String getFieldExpressionValidatorField() { } @FieldExpressionValidator( - expression = "(fieldExpressionValidatorField == requiredValidatorField)", + expression = "(fieldExpressionValidatorField == requiredValidatorField)", message = "must be the same as the Required Validator Field if specified") - public void setFieldExpressionValidatorField( - String fieldExpressionValidatorField) { + @StrutsParameter + public void setFieldExpressionValidatorField(String fieldExpressionValidatorField) { this.fieldExpressionValidatorField = fieldExpressionValidatorField; } @@ -156,6 +164,7 @@ public String getUrlValidatorField() { } @UrlValidator(message="must be a valid url if supplied") + @StrutsParameter public void setUrlValidatorField(String urlValidatorField) { this.urlValidatorField = urlValidatorField; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/BeanValidationExampleAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/BeanValidationExampleAction.java index 4c07f51e97..e4aed74cca 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/BeanValidationExampleAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/BeanValidationExampleAction.java @@ -26,6 +26,7 @@ import org.apache.struts2.convention.annotation.Namespace; import org.apache.struts2.convention.annotation.ParentPackage; import org.apache.struts2.convention.annotation.Result; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import org.apache.struts2.interceptor.validation.SkipValidation; import org.hibernate.validator.constraints.ScriptAssert; import org.hibernate.validator.constraints.URL; @@ -95,6 +96,7 @@ public Date getDateValidatorField() { return dateValidatorField; } + @StrutsParameter public void setDateValidatorField(Date dateValidatorField) { this.dateValidatorField = dateValidatorField; } @@ -103,6 +105,7 @@ public String getEmailValidatorField() { return emailValidatorField; } + @StrutsParameter public void setEmailValidatorField(String emailValidatorField) { this.emailValidatorField = emailValidatorField; } @@ -111,6 +114,7 @@ public Integer getIntegerValidatorField() { return integerValidatorField; } + @StrutsParameter public void setIntegerValidatorField(Integer integerValidatorField) { this.integerValidatorField = integerValidatorField; } @@ -119,6 +123,7 @@ public String getRegexValidatorField() { return regexValidatorField; } + @StrutsParameter public void setRegexValidatorField(String regexValidatorField) { this.regexValidatorField = regexValidatorField; } @@ -127,6 +132,7 @@ public String getRequiredStringValidatorField() { return requiredStringValidatorField; } + @StrutsParameter public void setRequiredStringValidatorField(String requiredStringValidatorField) { this.requiredStringValidatorField = requiredStringValidatorField; } @@ -135,6 +141,7 @@ public String getRequiredValidatorField() { return requiredValidatorField; } + @StrutsParameter public void setRequiredValidatorField(String requiredValidatorField) { this.requiredValidatorField = requiredValidatorField; } @@ -143,6 +150,7 @@ public String getStringLengthValidatorField() { return stringLengthValidatorField; } + @StrutsParameter public void setStringLengthValidatorField(String stringLengthValidatorField) { this.stringLengthValidatorField = stringLengthValidatorField; } @@ -151,8 +159,8 @@ public String getFieldExpressionValidatorField() { return fieldExpressionValidatorField; } - public void setFieldExpressionValidatorField( - String fieldExpressionValidatorField) { + @StrutsParameter + public void setFieldExpressionValidatorField(String fieldExpressionValidatorField) { this.fieldExpressionValidatorField = fieldExpressionValidatorField; } @@ -160,6 +168,7 @@ public String getUrlValidatorField() { return urlValidatorField; } + @StrutsParameter public void setUrlValidatorField(String urlValidatorField) { this.urlValidatorField = urlValidatorField; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/NonFieldValidatorsExampleAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/NonFieldValidatorsExampleAction.java index 2b16d9b769..d263e5db74 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/NonFieldValidatorsExampleAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/NonFieldValidatorsExampleAction.java @@ -20,6 +20,8 @@ */ package org.apache.struts2.showcase.validation; +import org.apache.struts2.interceptor.parameter.StrutsParameter; + /** */ @@ -37,6 +39,7 @@ public String getSomeText() { return someText; } + @StrutsParameter public void setSomeText(String someText) { this.someText = someText; } @@ -45,6 +48,7 @@ public String getSomeTextRetype() { return someTextRetype; } + @StrutsParameter public void setSomeTextRetype(String someTextRetype) { this.someTextRetype = someTextRetype; } @@ -53,6 +57,7 @@ public String getSomeTextRetypeAgain() { return someTextRetypeAgain; } + @StrutsParameter public void setSomeTextRetypeAgain(String someTextRetypeAgain) { this.someTextRetypeAgain = someTextRetypeAgain; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/QuizAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/QuizAction.java index 57a583193f..35fc1c3ca3 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/QuizAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/QuizAction.java @@ -21,6 +21,7 @@ package org.apache.struts2.showcase.validation; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; /** */ @@ -39,6 +40,7 @@ public String getName() { return name; } + @StrutsParameter public void setName(String name) { this.name = name; } @@ -47,6 +49,7 @@ public int getAge() { return age; } + @StrutsParameter public void setAge(int age) { this.age = age; } @@ -55,6 +58,7 @@ public String getAnswer() { return answer; } + @StrutsParameter public void setAnswer(String answer) { this.answer = answer; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/SubmitApplication.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/SubmitApplication.java index 5a990d01aa..ca01f89939 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/SubmitApplication.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/SubmitApplication.java @@ -21,6 +21,7 @@ package org.apache.struts2.showcase.validation; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; /** * @version $Date$ $Id$ @@ -30,6 +31,7 @@ public class SubmitApplication extends ActionSupport { private String name; private Integer age; + @StrutsParameter public void setName(String name) { this.name = name; } @@ -38,6 +40,7 @@ public String getName() { return this.name; } + @StrutsParameter public void setAge(Integer age) { this.age = age; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/VisitorValidatorsExampleAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/VisitorValidatorsExampleAction.java index 7c13f35b69..6cba476128 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/VisitorValidatorsExampleAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/VisitorValidatorsExampleAction.java @@ -23,12 +23,15 @@ // START SNIPPET: visitorValidatorsExample +import org.apache.struts2.interceptor.parameter.StrutsParameter; + public class VisitorValidatorsExampleAction extends AbstractValidationActionSupport { private static final long serialVersionUID = 4375454086939598216L; private User user; + @StrutsParameter(depth = 1) public User getUser() { return user; } diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/xslt/JVMAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/xslt/JVMAction.java index 6472adf62b..aae7d37772 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/xslt/JVMAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/xslt/JVMAction.java @@ -21,11 +21,9 @@ package org.apache.struts2.showcase.xslt; import com.opensymphony.xwork2.ActionSupport; - -import javax.servlet.http.HttpServletRequest; - import org.apache.struts2.action.ServletRequestAware; +import javax.servlet.http.HttpServletRequest; import java.util.Map; import java.util.Properties; @@ -72,7 +70,7 @@ public void setInfo(ImportantInfo info) { this.info = info; } - public class ImportantInfo { + public static class ImportantInfo { private String classpath; private Properties systemProperties; diff --git a/bundles/admin/src/main/java/org/apache/struts2/osgi/admin/actions/BundlesAction.java b/bundles/admin/src/main/java/org/apache/struts2/osgi/admin/actions/BundlesAction.java index 26b7030029..673b218f6e 100644 --- a/bundles/admin/src/main/java/org/apache/struts2/osgi/admin/actions/BundlesAction.java +++ b/bundles/admin/src/main/java/org/apache/struts2/osgi/admin/actions/BundlesAction.java @@ -25,10 +25,11 @@ import com.opensymphony.xwork2.config.Configuration; import com.opensymphony.xwork2.config.entities.PackageConfig; import com.opensymphony.xwork2.inject.Inject; +import org.apache.struts2.action.ServletContextAware; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import org.apache.struts2.osgi.BundleAccessor; -import org.apache.struts2.osgi.host.OsgiHost; import org.apache.struts2.osgi.StrutsOsgiListener; -import org.apache.struts2.action.ServletContextAware; +import org.apache.struts2.osgi.host.OsgiHost; import org.osgi.framework.Bundle; import org.osgi.framework.BundleException; @@ -36,9 +37,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.List; import java.util.Collections; -import java.util.Comparator; +import java.util.List; public class BundlesAction extends ActionSupport implements ServletContextAware { @@ -114,6 +114,7 @@ public String getId() { return id; } + @StrutsParameter public void setId(String id) { this.id = id; } diff --git a/bundles/admin/src/main/java/org/apache/struts2/osgi/admin/actions/ShellAction.java b/bundles/admin/src/main/java/org/apache/struts2/osgi/admin/actions/ShellAction.java index 1870a5b38a..aa87e4d7f5 100644 --- a/bundles/admin/src/main/java/org/apache/struts2/osgi/admin/actions/ShellAction.java +++ b/bundles/admin/src/main/java/org/apache/struts2/osgi/admin/actions/ShellAction.java @@ -21,25 +21,25 @@ package org.apache.struts2.osgi.admin.actions; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; - +import com.opensymphony.xwork2.Action; +import com.opensymphony.xwork2.ActionSupport; import org.apache.felix.shell.ShellService; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import org.apache.struts2.osgi.DefaultBundleAccessor; import org.apache.struts2.osgi.interceptor.BundleContextAware; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; -import com.opensymphony.xwork2.Action; -import com.opensymphony.xwork2.ActionSupport; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; /** * This action executes commands on the Felix Shell. - * + * * The action is BundleContextAware so that if the OSGi interceptor is used the BundleContext * can be provided for configurations where the DefaultBundleAccessor is insufficient. - * + * */ public class ShellAction extends ActionSupport implements BundleContextAware { private String command; @@ -77,6 +77,7 @@ public String getCommand() { return command; } + @StrutsParameter public void setCommand(String command) { this.command = command; } diff --git a/bundles/demo/src/main/java/actions/osgi/BundlesAction.java b/bundles/demo/src/main/java/actions/osgi/BundlesAction.java index 9c5464fcba..a7d5da9cd5 100644 --- a/bundles/demo/src/main/java/actions/osgi/BundlesAction.java +++ b/bundles/demo/src/main/java/actions/osgi/BundlesAction.java @@ -33,6 +33,7 @@ public class BundlesAction extends ActionSupport implements BundleContextAware { private BundleContext bundleContext; + @Override public void withBundleContext(BundleContext bundleContext) { this.bundleContext = bundleContext; } diff --git a/bundles/demo/src/main/java/actions/osgi/HelloWorldAction.java b/bundles/demo/src/main/java/actions/osgi/HelloWorldAction.java index dad0c25a77..6bb927b4e9 100644 --- a/bundles/demo/src/main/java/actions/osgi/HelloWorldAction.java +++ b/bundles/demo/src/main/java/actions/osgi/HelloWorldAction.java @@ -26,6 +26,7 @@ import org.apache.struts2.convention.annotation.Namespace; import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.ResultPath; +import org.apache.struts2.interceptor.parameter.StrutsParameter; @Namespace("/osgi") @ResultPath("/content/osgi") @@ -41,6 +42,7 @@ public String execute() { return SUCCESS; } + @StrutsParameter(depth = 1) public Message getMessage() { return message; } @@ -60,4 +62,4 @@ public String toString() { sb.append("}"); return sb.toString(); } -} \ No newline at end of file +} diff --git a/core/src/main/java/com/opensymphony/xwork2/ValidationAwareSupport.java b/core/src/main/java/com/opensymphony/xwork2/ValidationAwareSupport.java index 378351a79a..385911c612 100644 --- a/core/src/main/java/com/opensymphony/xwork2/ValidationAwareSupport.java +++ b/core/src/main/java/com/opensymphony/xwork2/ValidationAwareSupport.java @@ -21,7 +21,12 @@ import com.opensymphony.xwork2.interceptor.ValidationAware; import java.io.Serializable; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; /** * Provides a default implementation of ValidationAware. Returns new collections for @@ -72,13 +77,7 @@ public synchronized void addActionMessage(String aMessage) { public synchronized void addFieldError(String fieldName, String errorMessage) { final Map> errors = internalGetFieldErrors(); - List thisFieldErrors = errors.get(fieldName); - - if (thisFieldErrors == null) { - thisFieldErrors = new ArrayList<>(); - errors.put(fieldName, thisFieldErrors); - } - + List thisFieldErrors = errors.computeIfAbsent(fieldName, k -> new ArrayList<>()); thisFieldErrors.add(errorMessage); } diff --git a/core/src/main/java/org/apache/struts2/dispatcher/DefaultActionSupport.java b/core/src/main/java/org/apache/struts2/dispatcher/DefaultActionSupport.java index 7fa83fc879..0df1e3e905 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/DefaultActionSupport.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/DefaultActionSupport.java @@ -18,11 +18,11 @@ */ package org.apache.struts2.dispatcher; -import javax.servlet.http.HttpServletRequest; - +import com.opensymphony.xwork2.ActionSupport; import org.apache.struts2.ServletActionContext; +import org.apache.struts2.interceptor.parameter.StrutsParameter; -import com.opensymphony.xwork2.ActionSupport; +import javax.servlet.http.HttpServletRequest; /** * A simple action support class that sets properties to be able to serve @@ -44,6 +44,7 @@ public DefaultActionSupport() { /* (non-Javadoc) * @see com.opensymphony.xwork2.ActionSupport#execute() */ + @Override public String execute() throws Exception { HttpServletRequest request = ServletActionContext.getRequest(); String requestedUrl = request.getPathInfo(); @@ -61,9 +62,8 @@ public String getSuccessResultValue() { /** * @param successResultValue The successResultValue to set. */ + @StrutsParameter public void setSuccessResultValue(String successResultValue) { this.successResultValue = successResultValue; } - - } diff --git a/core/src/test/java/com/opensymphony/xwork2/ActionSupportTest.java b/core/src/test/java/com/opensymphony/xwork2/ActionSupportTest.java index 65c38d38ec..b917aaed43 100644 --- a/core/src/test/java/com/opensymphony/xwork2/ActionSupportTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/ActionSupportTest.java @@ -20,8 +20,12 @@ import com.opensymphony.xwork2.conversion.impl.ConversionData; import com.opensymphony.xwork2.util.ValueStack; +import org.apache.struts2.interceptor.parameter.StrutsParameter; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.ResourceBundle; /** * Unit test for {@link ActionSupport}. @@ -334,6 +338,7 @@ public Double getVal() { return val; } + @StrutsParameter public void setVal(Double val) { this.val = val; } diff --git a/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAction.java b/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAction.java index fabc3ed95b..6ffcad2ff2 100644 --- a/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAction.java +++ b/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAction.java @@ -19,6 +19,8 @@ package com.opensymphony.xwork2; +import org.apache.struts2.interceptor.parameter.StrutsParameter; + /** * ModelDrivenAction * @@ -28,9 +30,9 @@ public class ModelDrivenAction extends ActionSupport implements ModelDriven { private String foo; - private TestBean model = new TestBean(); - + private final TestBean model = new TestBean(); + @StrutsParameter public void setFoo(String foo) { this.foo = foo; } @@ -42,6 +44,8 @@ public String getFoo() { /** * @return the model to be pushed onto the ValueStack after the Action itself */ + @StrutsParameter(depth = 2) + @Override public Object getModel() { return model; } diff --git a/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAnnotationAction.java b/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAnnotationAction.java index a103d7d5cc..5549b60b10 100644 --- a/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAnnotationAction.java +++ b/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAnnotationAction.java @@ -18,6 +18,8 @@ */ package com.opensymphony.xwork2; +import org.apache.struts2.interceptor.parameter.StrutsParameter; + /** * ModelDrivenAnnotationAction * @@ -28,9 +30,9 @@ public class ModelDrivenAnnotationAction extends ActionSupport implements ModelDriven { private String foo; - private AnnotatedTestBean model = new AnnotatedTestBean(); - + private final AnnotatedTestBean model = new AnnotatedTestBean(); + @StrutsParameter public void setFoo(String foo) { this.foo = foo; } @@ -42,6 +44,8 @@ public String getFoo() { /** * @return the model to be pushed onto the ValueStack after the Action itself */ + @StrutsParameter(depth = 2) + @Override public Object getModel() { return model; } diff --git a/core/src/test/java/com/opensymphony/xwork2/ProxyInvocationAction.java b/core/src/test/java/com/opensymphony/xwork2/ProxyInvocationAction.java index ac4e2c36eb..47afb2baa6 100644 --- a/core/src/test/java/com/opensymphony/xwork2/ProxyInvocationAction.java +++ b/core/src/test/java/com/opensymphony/xwork2/ProxyInvocationAction.java @@ -22,6 +22,8 @@ * Need by the ProxyInvocationTest */ public class ProxyInvocationAction extends ActionSupport implements ProxyInvocationInterface { + + @Override public String show() { return "proxyResult"; } diff --git a/core/src/test/java/com/opensymphony/xwork2/SimpleAction.java b/core/src/test/java/com/opensymphony/xwork2/SimpleAction.java index 16b3357b16..51d9fa7f79 100644 --- a/core/src/test/java/com/opensymphony/xwork2/SimpleAction.java +++ b/core/src/test/java/com/opensymphony/xwork2/SimpleAction.java @@ -21,7 +21,12 @@ import com.opensymphony.xwork2.config.Configuration; import com.opensymphony.xwork2.inject.Inject; -import java.util.*; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; /** @@ -56,7 +61,7 @@ public class SimpleAction extends ActionSupport { private Map existingMap = new HashMap<>(); private List beanList; - + public static boolean resultCalled; @@ -64,11 +69,11 @@ public SimpleAction() { resultCalled = false; existingMap.put("existingKey", "value"); } - + public Map getTheProtectedMap() { return protectedMap; } - + protected Map getTheSemiProtectedMap() { return protectedMap; } @@ -81,7 +86,6 @@ public Map getTheExistingMap() { return existingMap; } - public void setBar(int bar) { this.bar = bar; } @@ -187,15 +191,15 @@ public void setSomeList(ArrayList someList) { public ArrayList 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; @@ -204,7 +208,7 @@ public void setThrowException(boolean throwException) { public String commandMethod() throws Exception { return COMMAND_RETURN_CODE; } - + public Result resultAction() throws Exception { return new Result() { public Configuration configuration; @@ -217,7 +221,7 @@ public void execute(ActionInvocation invocation) throws Exception { if (configuration != null) resultCalled = true; } - + }; } @@ -251,7 +255,7 @@ public String execute() throws Exception { return SUCCESS; } - + public long getLongFoo() { return longFoo; } diff --git a/core/src/test/java/com/opensymphony/xwork2/SimpleAnnotationAction.java b/core/src/test/java/com/opensymphony/xwork2/SimpleAnnotationAction.java index 5e21a09849..312e7bc9c2 100644 --- a/core/src/test/java/com/opensymphony/xwork2/SimpleAnnotationAction.java +++ b/core/src/test/java/com/opensymphony/xwork2/SimpleAnnotationAction.java @@ -18,7 +18,18 @@ */ package com.opensymphony.xwork2; -import com.opensymphony.xwork2.validator.annotations.*; +import com.opensymphony.xwork2.validator.annotations.DateRangeFieldValidator; +import com.opensymphony.xwork2.validator.annotations.DoubleRangeFieldValidator; +import com.opensymphony.xwork2.validator.annotations.EmailValidator; +import com.opensymphony.xwork2.validator.annotations.ExpressionValidator; +import com.opensymphony.xwork2.validator.annotations.IntRangeFieldValidator; +import com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator; +import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator; +import com.opensymphony.xwork2.validator.annotations.StringLengthFieldValidator; +import com.opensymphony.xwork2.validator.annotations.UrlValidator; +import com.opensymphony.xwork2.validator.annotations.Validations; +import com.opensymphony.xwork2.validator.annotations.ValidatorType; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.util.ArrayList; import java.util.Date; @@ -49,8 +60,6 @@ public class SimpleAnnotationAction extends ActionSupport { private String aliasSource; private String aliasDest; - - //~ Constructors /////////////////////////////////////////////////////////// @@ -61,6 +70,7 @@ public SimpleAnnotationAction() { @RequiredFieldValidator(type = ValidatorType.FIELD, message = "You must enter a value for bar.") @IntRangeFieldValidator(type = ValidatorType.FIELD, min = "6", max = "10", message = "bar must be between ${min} and ${max}, current value is ${bar}.") + @StrutsParameter public void setBar(int bar) { this.bar = bar; } @@ -70,6 +80,7 @@ public int getBar() { } @IntRangeFieldValidator(min = "0", key = "baz.range", message = "Could not find baz.range!") + @StrutsParameter public void setBaz(int baz) { this.baz = baz; } @@ -83,6 +94,7 @@ public double getPercentage() { } @DoubleRangeFieldValidator(minInclusive = "0.123", key = "baz.range", message = "Could not find percentage.range!") + @StrutsParameter public void setPercentage(double percentage) { this.percentage = percentage; } @@ -91,10 +103,12 @@ public void setBean(AnnotatedTestBean bean) { this.bean = bean; } + @StrutsParameter(depth = 2) public AnnotatedTestBean getBean() { return bean; } + @StrutsParameter public void setBlah(String blah) { this.blah = blah; } @@ -112,6 +126,7 @@ public boolean[] getBools() { } @DateRangeFieldValidator(min = "12/22/2002", max = "12/25/2002", message = "The date must be between 12-22-2002 and 12-25-2002.") + @StrutsParameter public void setDate(Date date) { this.date = date; } @@ -120,6 +135,7 @@ public Date getDate() { return date; } + @StrutsParameter public void setFoo(int foo) { this.foo = foo; } @@ -128,6 +144,7 @@ public int getFoo() { return foo; } + @StrutsParameter public void setName(String name) { this.name = name; } @@ -140,15 +157,16 @@ public void setSettings(Properties settings) { this.settings = settings; } + @StrutsParameter(depth = 1) public Properties getSettings() { return settings; } - public String getAliasDest() { return aliasDest; } + @StrutsParameter public void setAliasDest(String aliasDest) { this.aliasDest = aliasDest; } @@ -157,11 +175,12 @@ public String getAliasSource() { return aliasSource; } + @StrutsParameter public void setAliasSource(String aliasSource) { this.aliasSource = aliasSource; } - + @StrutsParameter public void setSomeList(ArrayList someList) { this.someList = someList; } @@ -170,6 +189,7 @@ public ArrayList getSomeList() { return someList; } + @StrutsParameter public void setThrowException(boolean throwException) { this.throwException = throwException; } @@ -186,7 +206,6 @@ public String exceptionMethod() throws Exception { return "OK"; } - @Override @Validations( requiredFields = {@RequiredFieldValidator(type = ValidatorType.SIMPLE, fieldName = "customfield", message = "You must enter a value for field.")}, @@ -210,6 +229,7 @@ public String exceptionMethod() throws Exception { @ExpressionValidator(expression = "foo > 5", message = "Foo must be greater than Bar 5. Foo = ${foo}, Bar = ${bar}.") } ) + @Override public String execute() throws Exception { if (foo == bar) { return ERROR; diff --git a/core/src/test/java/com/opensymphony/xwork2/ValidationOrderAction.java b/core/src/test/java/com/opensymphony/xwork2/ValidationOrderAction.java index 0928301e32..f5cc1c4e23 100644 --- a/core/src/test/java/com/opensymphony/xwork2/ValidationOrderAction.java +++ b/core/src/test/java/com/opensymphony/xwork2/ValidationOrderAction.java @@ -18,14 +18,16 @@ */ package com.opensymphony.xwork2; +import org.apache.struts2.interceptor.parameter.StrutsParameter; + /** * A sample action to test validation order. - * + * * @author tm_jee * @version $Date$ $Id$ */ public class ValidationOrderAction extends ActionSupport { - + private String username; private String password; private String confirmPassword; @@ -38,9 +40,9 @@ public class ValidationOrderAction extends ActionSupport { private String email; private String website; private String passwordHint; - - - + + + @Override public String execute() throws Exception { return SUCCESS; @@ -53,7 +55,7 @@ public String getCity() { } - + @StrutsParameter public void setCity(String city) { this.city = city; } @@ -65,7 +67,7 @@ public String getConfirmPassword() { } - + @StrutsParameter public void setConfirmPassword(String confirmPassword) { this.confirmPassword = confirmPassword; } @@ -77,7 +79,7 @@ public String getCountry() { } - + @StrutsParameter public void setCountry(String country) { this.country = country; } @@ -89,7 +91,7 @@ public String getEmail() { } - + @StrutsParameter public void setEmail(String email) { this.email = email; } @@ -101,7 +103,7 @@ public String getFirstName() { } - + @StrutsParameter public void setFirstName(String firstName) { this.firstName = firstName; } @@ -113,7 +115,7 @@ public String getLastName() { } - + @StrutsParameter public void setLastName(String lastName) { this.lastName = lastName; } @@ -125,7 +127,7 @@ public String getPassword() { } - + @StrutsParameter public void setPassword(String password) { this.password = password; } @@ -137,7 +139,7 @@ public String getPasswordHint() { } - + @StrutsParameter public void setPasswordHint(String passwordHint) { this.passwordHint = passwordHint; } @@ -149,7 +151,7 @@ public String getPostalCode() { } - + @StrutsParameter public void setPostalCode(String postalCode) { this.postalCode = postalCode; } @@ -161,7 +163,7 @@ public String getProvince() { } - + @StrutsParameter public void setProvince(String province) { this.province = province; } @@ -173,7 +175,7 @@ public String getUsername() { } - + @StrutsParameter public void setUsername(String username) { this.username = username; } @@ -185,7 +187,7 @@ public String getWebsite() { } - + @StrutsParameter public void setWebsite(String website) { this.website = website; } diff --git a/core/src/test/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptorTest.java b/core/src/test/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptorTest.java index 4f3589f9f1..65b21c86d1 100644 --- a/core/src/test/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptorTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptorTest.java @@ -20,7 +20,12 @@ import com.mockobjects.dynamic.ConstraintMatcher; import com.mockobjects.dynamic.Mock; -import com.opensymphony.xwork2.*; +import com.opensymphony.xwork2.Action; +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.ActionSupport; +import com.opensymphony.xwork2.ModelDriven; +import com.opensymphony.xwork2.XWorkTestCase; import com.opensymphony.xwork2.util.ValueStack; import java.util.Date; @@ -175,6 +180,7 @@ protected void tearDown() throws Exception { public class ModelDrivenAction extends ActionSupport implements ModelDriven { + @Override public Object getModel() { return model; } diff --git a/core/src/test/java/com/opensymphony/xwork2/interceptor/ScopedModelDrivenInterceptorTest.java b/core/src/test/java/com/opensymphony/xwork2/interceptor/ScopedModelDrivenInterceptorTest.java index 39358f2648..577f663214 100644 --- a/core/src/test/java/com/opensymphony/xwork2/interceptor/ScopedModelDrivenInterceptorTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/interceptor/ScopedModelDrivenInterceptorTest.java @@ -190,22 +190,27 @@ private class MyUserScopedModelDrivenAction implements ScopedModelDriven, Action private String key; private User model; + @Override public void setModel(Object model) { this.model = (User) model; } + @Override public void setScopeKey(String key) { this.key = key; } + @Override public String getScopeKey() { return key; } + @Override public User getModel() { return model; } + @Override public String execute() throws Exception { return SUCCESS; } @@ -217,22 +222,27 @@ private class MyEquidaeScopedModelDrivenAction implements ScopedModelDriven, Act private String key; private Equidae model; + @Override public void setModel(Object model) { this.model = (Equidae) model; } + @Override public void setScopeKey(String key) { this.key = key; } + @Override public String getScopeKey() { return key; } + @Override public Equidae getModel() { return model; } + @Override public String execute() throws Exception { return SUCCESS; } diff --git a/core/src/test/java/com/opensymphony/xwork2/interceptor/annotations/AllowingByDefaultAction.java b/core/src/test/java/com/opensymphony/xwork2/interceptor/annotations/AllowingByDefaultAction.java index c70fcae442..21ec5462e5 100644 --- a/core/src/test/java/com/opensymphony/xwork2/interceptor/annotations/AllowingByDefaultAction.java +++ b/core/src/test/java/com/opensymphony/xwork2/interceptor/annotations/AllowingByDefaultAction.java @@ -19,21 +19,24 @@ package com.opensymphony.xwork2.interceptor.annotations; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; /** * @author martin.gilday * */ public class AllowingByDefaultAction extends ActionSupport { - + @Blocked private String name; private String job; - + + @StrutsParameter public void setName(String name) { this.name = name; } - + + @StrutsParameter public void setJob(String job) { this.job = job; } diff --git a/core/src/test/java/com/opensymphony/xwork2/interceptor/annotations/BlockingByDefaultAction.java b/core/src/test/java/com/opensymphony/xwork2/interceptor/annotations/BlockingByDefaultAction.java index fa1f7e7427..499fb2c946 100644 --- a/core/src/test/java/com/opensymphony/xwork2/interceptor/annotations/BlockingByDefaultAction.java +++ b/core/src/test/java/com/opensymphony/xwork2/interceptor/annotations/BlockingByDefaultAction.java @@ -19,6 +19,7 @@ package com.opensymphony.xwork2.interceptor.annotations; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; /** * @author martin.gilday @@ -26,15 +27,17 @@ */ @BlockByDefault public class BlockingByDefaultAction extends ActionSupport { - + @Allowed private String name; private String job; - + + @StrutsParameter public void setName(String name) { this.name = name; } - + + @StrutsParameter public void setJob(String job) { this.job = job; } diff --git a/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAction2.java b/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAction2.java index 5bbc2d48ce..0c445860b8 100644 --- a/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAction2.java +++ b/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAction2.java @@ -19,6 +19,7 @@ package com.opensymphony.xwork2.test; import com.opensymphony.xwork2.ModelDrivenAction; +import org.apache.struts2.interceptor.parameter.StrutsParameter; /** @@ -28,12 +29,13 @@ */ public class ModelDrivenAction2 extends ModelDrivenAction { - private TestBean2 model = new TestBean2(); + private final TestBean2 model = new TestBean2(); /** * @return the model to be pushed onto the ValueStack after the Action itself */ + @StrutsParameter(depth = 3) @Override public Object getModel() { return model; diff --git a/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAnnotationAction2.java b/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAnnotationAction2.java index c7aef9315e..7c26dcfabc 100644 --- a/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAnnotationAction2.java +++ b/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAnnotationAction2.java @@ -19,6 +19,7 @@ package com.opensymphony.xwork2.test; import com.opensymphony.xwork2.ModelDrivenAnnotationAction; +import org.apache.struts2.interceptor.parameter.StrutsParameter; /** @@ -29,12 +30,13 @@ */ public class ModelDrivenAnnotationAction2 extends ModelDrivenAnnotationAction { - private AnnotationTestBean2 model = new AnnotationTestBean2(); + private final AnnotationTestBean2 model = new AnnotationTestBean2(); /** * @return the model to be pushed onto the ValueStack after the Action itself */ + @StrutsParameter(depth = 3) @Override public Object getModel() { return model; diff --git a/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction2.java b/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction2.java index d08435464b..1d9540402a 100644 --- a/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction2.java +++ b/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction2.java @@ -19,6 +19,7 @@ package com.opensymphony.xwork2.test; import com.opensymphony.xwork2.SimpleAction; +import org.apache.struts2.interceptor.parameter.StrutsParameter; /** @@ -31,7 +32,7 @@ public class SimpleAction2 extends SimpleAction { private int count; - + @StrutsParameter public void setCount(int count) { this.count = count; } diff --git a/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction3.java b/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction3.java index f4934cd898..40a4c79b2b 100644 --- a/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction3.java +++ b/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction3.java @@ -20,6 +20,7 @@ import com.opensymphony.xwork2.SimpleAction; import com.opensymphony.xwork2.util.Bar; +import org.apache.struts2.interceptor.parameter.StrutsParameter; /** @@ -32,19 +33,24 @@ public class SimpleAction3 extends SimpleAction implements DataAware { private Bar bar; private String data; - + @Override public void setBarObj(Bar b) { bar = b; } + @StrutsParameter(depth = 1) + @Override public Bar getBarObj() { return bar; } + @StrutsParameter + @Override public void setData(String data) { this.data = data; } + @Override public String getData() { return data; } diff --git a/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction2.java b/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction2.java index 1f7d98a162..d5e566e408 100644 --- a/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction2.java +++ b/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction2.java @@ -21,6 +21,7 @@ import com.opensymphony.xwork2.SimpleAnnotationAction; import com.opensymphony.xwork2.validator.annotations.IntRangeFieldValidator; import com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator; +import org.apache.struts2.interceptor.parameter.StrutsParameter; /** * SimpleAction2 @@ -35,6 +36,7 @@ public class SimpleAnnotationAction2 extends SimpleAnnotationAction { @RequiredFieldValidator(message = "You must enter a value for count.") @IntRangeFieldValidator(min = "0", max = "5", message = "count must be between ${min} and ${max}, current value is ${count}.") + @StrutsParameter public void setCount(int count) { this.count = count; } diff --git a/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction3.java b/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction3.java index 929eb4b512..dea337bce9 100644 --- a/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction3.java +++ b/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction3.java @@ -20,6 +20,7 @@ import com.opensymphony.xwork2.SimpleAnnotationAction; import com.opensymphony.xwork2.util.Bar; +import org.apache.struts2.interceptor.parameter.StrutsParameter; /** @@ -33,19 +34,24 @@ public class SimpleAnnotationAction3 extends SimpleAnnotationAction implements A private Bar bar; private String data; - + @Override public void setBarObj(Bar b) { bar = b; } + @StrutsParameter(depth = 1) + @Override public Bar getBarObj() { return bar; } + @StrutsParameter + @Override public void setData(String data) { this.data = data; } + @Override public String getData() { return data; } diff --git a/core/src/test/java/com/opensymphony/xwork2/test/annotations/ValidateAnnotatedMethodOnlyAction.java b/core/src/test/java/com/opensymphony/xwork2/test/annotations/ValidateAnnotatedMethodOnlyAction.java index b57361cd4d..aefaa94a09 100644 --- a/core/src/test/java/com/opensymphony/xwork2/test/annotations/ValidateAnnotatedMethodOnlyAction.java +++ b/core/src/test/java/com/opensymphony/xwork2/test/annotations/ValidateAnnotatedMethodOnlyAction.java @@ -20,6 +20,7 @@ import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.validator.annotations.ExpressionValidator; +import org.apache.struts2.interceptor.parameter.StrutsParameter; /** * ValidateAnnotatedMethodOnlyAction @@ -34,6 +35,7 @@ public String getParam1() { return param1; } + @StrutsParameter public void setParam1(String param1) { this.param1 = param1; } @@ -42,6 +44,7 @@ public String getParam2() { return param2; } + @StrutsParameter public void setParam2(String param2) { this.param2 = param2; } diff --git a/core/src/test/java/com/opensymphony/xwork2/util/Bar.java b/core/src/test/java/com/opensymphony/xwork2/util/Bar.java index 348a28576c..6332a570b1 100644 --- a/core/src/test/java/com/opensymphony/xwork2/util/Bar.java +++ b/core/src/test/java/com/opensymphony/xwork2/util/Bar.java @@ -19,6 +19,7 @@ package com.opensymphony.xwork2.util; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; /** @@ -32,7 +33,7 @@ public class Bar extends ActionSupport { String title; int somethingElse; - + @StrutsParameter public void setId(Long id) { this.id = id; } @@ -41,6 +42,7 @@ public Long getId() { return this.id; } + @StrutsParameter public void setSomethingElse(int somethingElse) { this.somethingElse = somethingElse; } @@ -49,6 +51,7 @@ public int getSomethingElse() { return somethingElse; } + @StrutsParameter public void setTitle(String title) { this.title = title; } diff --git a/core/src/test/java/com/opensymphony/xwork2/util/StrutsLocalizedTextProviderTest.java b/core/src/test/java/com/opensymphony/xwork2/util/StrutsLocalizedTextProviderTest.java index b86923db1a..7bb8af612e 100644 --- a/core/src/test/java/com/opensymphony/xwork2/util/StrutsLocalizedTextProviderTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/util/StrutsLocalizedTextProviderTest.java @@ -32,6 +32,7 @@ import com.opensymphony.xwork2.test.ModelDrivenAction2; import com.opensymphony.xwork2.test.TestBean2; import org.apache.struts2.config.StrutsXmlConfigurationProvider; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.text.DateFormat; import java.text.ParseException; @@ -83,6 +84,7 @@ public void testActionGetTextWithNullObject() throws Exception { public static class MyAction extends ActionSupport { private Bar testBean2; + @StrutsParameter(depth = 1) public Bar getBarObj() { return testBean2; } @@ -460,7 +462,7 @@ public void testGetDefaultMessageWithAlternateKey() { /** * Test the {@link StrutsLocalizedTextProvider#findText(java.lang.Class, java.lang.String, java.util.Locale, java.lang.String, java.lang.Object[], com.opensymphony.xwork2.util.ValueStack) } * method for basic correctness. - * + * * It is the version of the method that will search the class hierarchy resource bundles first, unless {@link StrutsLocalizedTextProvider#searchDefaultBundlesFirst} * is true (in which case it will search the default resource bundles first). No matter the flag setting, it should search until it finds a match, or fails to find * a match and returns the default message parameter that was passed. @@ -611,7 +613,7 @@ public int currentBundlesMapSize() { /** * Attempt to force the resource bundles to be reloaded, even if configuration would otherwise prevent it. - * It will preserve the current reloadBundles state, attempt to force a reload and then restore the + * It will preserve the current reloadBundles state, attempt to force a reload and then restore the * original reloadBundles value. */ public void callReloadBundlesForceReload() { @@ -625,9 +627,9 @@ public void callReloadBundlesForceReload() { } /** - * Returns the value of the resource bundles reloaded state from the context, provided that one was + * Returns the value of the resource bundles reloaded state from the context, provided that one was * previously set. If no value is found, the result will be false (same as if bundles had not been reloaded). - * + * * @return true if resource bundles reloaded indicator is true, false otherwise (including if value was never set). */ public boolean getBundlesReloadedIndicatorValue() { diff --git a/core/src/test/java/com/opensymphony/xwork2/validator/ActionValidatorManagerTest.java b/core/src/test/java/com/opensymphony/xwork2/validator/ActionValidatorManagerTest.java index 385f2ab0a3..0c100babe8 100644 --- a/core/src/test/java/com/opensymphony/xwork2/validator/ActionValidatorManagerTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/validator/ActionValidatorManagerTest.java @@ -25,6 +25,7 @@ import com.opensymphony.xwork2.validator.validators.RequiredFieldValidator; import com.opensymphony.xwork2.validator.validators.RequiredStringValidator; import com.opensymphony.xwork2.validator.validators.VisitorFieldValidator; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.util.ArrayList; import java.util.Collections; @@ -201,8 +202,10 @@ public static class MockAction extends ActionSupport { public void setReferenceNumber(String referenceNumber) { this.referenceNumber = referenceNumber; } public Integer getOrder() { return order; } + @StrutsParameter public void setOrder(Integer order) { this.order = order; } + @StrutsParameter(depth = 2) public Customer getCustomer() { return customer; } public void setCustomer(Customer customer) { this.customer = customer; } } @@ -233,4 +236,4 @@ public static class Address { public String getPobox() { return pobox; } public void setPobox(String pobox) { this.pobox = pobox; } } -} \ No newline at end of file +} diff --git a/core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationAction.java b/core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationAction.java index 3142c45155..b8e6b16013 100644 --- a/core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationAction.java +++ b/core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationAction.java @@ -87,6 +87,7 @@ public class AnnotationValidationAction extends ActionSupport { messageParams = {"one", "two", "three"}) @VisitorFieldValidator(message = "Foo isn't valid!", key = "visitorfield.key", fieldName = "foo", appendPrefix = false, shortCircuit = true, messageParams = {"one", "two", "three"}) + @Override public String execute() { return SUCCESS; } diff --git a/core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationExpAction.java b/core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationExpAction.java index 073ff3bcec..f794391496 100644 --- a/core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationExpAction.java +++ b/core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationExpAction.java @@ -89,6 +89,7 @@ public class AnnotationValidationExpAction extends ActionSupport { messageParams = {"one", "two", "three"}) @VisitorFieldValidator(message = "Foo isn't valid!", key = "visitorfield.key", fieldName = "foo", appendPrefix = false, shortCircuit = true, messageParams = {"one", "two", "three"}) + @Override public String execute() { return SUCCESS; } diff --git a/core/src/test/java/com/opensymphony/xwork2/validator/StringLengthFieldValidatorTest.java b/core/src/test/java/com/opensymphony/xwork2/validator/StringLengthFieldValidatorTest.java index 20d8a2bfca..dc1ee6b12a 100644 --- a/core/src/test/java/com/opensymphony/xwork2/validator/StringLengthFieldValidatorTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/validator/StringLengthFieldValidatorTest.java @@ -24,6 +24,7 @@ import com.opensymphony.xwork2.XWorkTestCase; import com.opensymphony.xwork2.util.ValueStack; import com.opensymphony.xwork2.validator.validators.StringLengthFieldValidator; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.util.Arrays; import java.util.Collection; @@ -220,6 +221,7 @@ public String getMyField() { return this.myField; } + @StrutsParameter public void setMyField(String myField) { this.myField = myField; } @@ -228,6 +230,7 @@ public boolean isTrimValue() { return trimValue; } + @StrutsParameter public void setTrimValue(boolean trimValue) { this.trimValue = trimValue; } @@ -236,6 +239,7 @@ public int getMinLengthValue() { return minLengthValue; } + @StrutsParameter public void setMinLengthValue(int minLengthValue) { this.minLengthValue = minLengthValue; } @@ -244,6 +248,7 @@ public int getMaxLengthValue() { return maxLengthValue; } + @StrutsParameter public void setMaxLengthValue(int maxLengthValue) { this.maxLengthValue = maxLengthValue; } @@ -252,6 +257,7 @@ public String[] getStrings() { return strings; } + @StrutsParameter public void setStrings(String[] strings) { this.strings = strings; } @@ -260,6 +266,7 @@ public Collection getStringCollection() { return stringCollection; } + @StrutsParameter public void setStringCollection(Collection stringCollection) { this.stringCollection = stringCollection; } diff --git a/core/src/test/java/com/opensymphony/xwork2/validator/VisitorValidatorModelAction.java b/core/src/test/java/com/opensymphony/xwork2/validator/VisitorValidatorModelAction.java index fee56451ba..9f5baeee0f 100644 --- a/core/src/test/java/com/opensymphony/xwork2/validator/VisitorValidatorModelAction.java +++ b/core/src/test/java/com/opensymphony/xwork2/validator/VisitorValidatorModelAction.java @@ -19,6 +19,7 @@ package com.opensymphony.xwork2.validator; import com.opensymphony.xwork2.ModelDriven; +import org.apache.struts2.interceptor.parameter.StrutsParameter; /** @@ -32,6 +33,8 @@ public class VisitorValidatorModelAction extends VisitorValidatorTestAction impl /** * @return the model to be pushed onto the ValueStack instead of the Action itself */ + @StrutsParameter(depth = 2) + @Override public Object getModel() { return getBean(); } diff --git a/core/src/test/java/com/opensymphony/xwork2/validator/VisitorValidatorTestAction.java b/core/src/test/java/com/opensymphony/xwork2/validator/VisitorValidatorTestAction.java index 9e672bf489..b7cef86ae9 100644 --- a/core/src/test/java/com/opensymphony/xwork2/validator/VisitorValidatorTestAction.java +++ b/core/src/test/java/com/opensymphony/xwork2/validator/VisitorValidatorTestAction.java @@ -20,6 +20,7 @@ import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.TestBean; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.util.ArrayList; import java.util.Date; @@ -49,15 +50,16 @@ public VisitorValidatorTestAction() { } } - public void setBean(TestBean bean) { this.bean = bean; } + @StrutsParameter(depth = 2) public TestBean getBean() { return bean; } + @StrutsParameter public void setContext(String context) { this.context = context; } @@ -70,6 +72,7 @@ public void setTestBeanArray(TestBean[] testBeanArray) { this.testBeanArray = testBeanArray; } + @StrutsParameter(depth = 3) public TestBean[] getTestBeanArray() { return testBeanArray; } @@ -78,6 +81,7 @@ public void setTestBeanList(List testBeanList) { this.testBeanList = testBeanList; } + @StrutsParameter(depth = 3) public List getTestBeanList() { return testBeanList; } @@ -86,6 +90,7 @@ public Date getBirthday() { return birthday; } + @StrutsParameter public void setBirthday(Date birthday) { this.birthday = birthday; } diff --git a/core/src/test/java/org/apache/struts2/ExecutionCountTestAction.java b/core/src/test/java/org/apache/struts2/ExecutionCountTestAction.java index 1d609e572d..ca8ee077f9 100644 --- a/core/src/test/java/org/apache/struts2/ExecutionCountTestAction.java +++ b/core/src/test/java/org/apache/struts2/ExecutionCountTestAction.java @@ -41,9 +41,10 @@ public int getExecutionCount() { return executionCount; } + @Override public String execute() throws Exception { executionCount++; - LOG.info("executing ExecutionCountTestAction. Current count is " + executionCount); + LOG.info("executing ExecutionCountTestAction. Current count is {}", executionCount); return SUCCESS; } diff --git a/core/src/test/java/org/apache/struts2/HttpMethodsTestAction.java b/core/src/test/java/org/apache/struts2/HttpMethodsTestAction.java index 255044b95f..33921e2204 100644 --- a/core/src/test/java/org/apache/struts2/HttpMethodsTestAction.java +++ b/core/src/test/java/org/apache/struts2/HttpMethodsTestAction.java @@ -68,6 +68,7 @@ public String onDelete() { return "onDelete"; } + @Override public void setMethod(HttpMethod httpMethod) { this.httpMethod = httpMethod; } @@ -76,6 +77,7 @@ public HttpMethod getHttpMethod() { return httpMethod; } + @Override public String getBadRequestResultName() { return resultName; } diff --git a/core/src/test/java/org/apache/struts2/TestAction.java b/core/src/test/java/org/apache/struts2/TestAction.java index b9595de11b..f90f538f20 100644 --- a/core/src/test/java/org/apache/struts2/TestAction.java +++ b/core/src/test/java/org/apache/struts2/TestAction.java @@ -184,6 +184,7 @@ public void setFooInt(Integer fooInt) { this.fooInt = fooInt; } + @Override public String execute() throws Exception { if (result == null) { result = Action.SUCCESS; diff --git a/core/src/test/java/org/apache/struts2/interceptor/CookieInterceptorTest.java b/core/src/test/java/org/apache/struts2/interceptor/CookieInterceptorTest.java index afe18f731a..8e6f6d19d1 100644 --- a/core/src/test/java/org/apache/struts2/interceptor/CookieInterceptorTest.java +++ b/core/src/test/java/org/apache/struts2/interceptor/CookieInterceptorTest.java @@ -27,6 +27,7 @@ import com.opensymphony.xwork2.security.DefaultExcludedPatternsChecker; import org.apache.struts2.ServletActionContext; import org.apache.struts2.StrutsInternalTestCase; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import org.springframework.mock.web.MockHttpServletRequest; import javax.servlet.http.Cookie; @@ -503,6 +504,7 @@ public static class MockActionWithCookieAware extends ActionSupport implements C private String cookie2; private String cookie3; + @Override public void setCookiesMap(Map cookies) { this.cookies = cookies; } @@ -515,6 +517,7 @@ public String getCookie1() { return cookie1; } + @StrutsParameter public void setCookie1(String cookie1) { this.cookie1 = cookie1; } @@ -523,6 +526,7 @@ public String getCookie2() { return cookie2; } + @StrutsParameter public void setCookie2(String cookie2) { this.cookie2 = cookie2; } @@ -531,6 +535,7 @@ public String getCookie3() { return cookie3; } + @StrutsParameter public void setCookie3(String cookie3) { this.cookie3 = cookie3; } @@ -543,6 +548,7 @@ public static class MockActionWithActionCookieAware extends ActionSupport implem private String cookie2; private String cookie3; + @Override public void withCookies(Map cookies) { this.cookies = cookies; } @@ -555,6 +561,7 @@ public String getCookie1() { return cookie1; } + @StrutsParameter public void setCookie1(String cookie1) { this.cookie1 = cookie1; } @@ -563,6 +570,7 @@ public String getCookie2() { return cookie2; } + @StrutsParameter public void setCookie2(String cookie2) { this.cookie2 = cookie2; } @@ -571,6 +579,7 @@ public String getCookie3() { return cookie3; } + @StrutsParameter public void setCookie3(String cookie3) { this.cookie3 = cookie3; } diff --git a/core/src/test/java/org/apache/struts2/interceptor/FileUploadInterceptorTest.java b/core/src/test/java/org/apache/struts2/interceptor/FileUploadInterceptorTest.java index 14bb23c364..cfb3057701 100644 --- a/core/src/test/java/org/apache/struts2/interceptor/FileUploadInterceptorTest.java +++ b/core/src/test/java/org/apache/struts2/interceptor/FileUploadInterceptorTest.java @@ -27,7 +27,6 @@ import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.struts2.ServletActionContext; import org.apache.struts2.StrutsInternalTestCase; -import org.apache.struts2.TestAction; import org.apache.struts2.dispatcher.HttpParameters; import org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest; import org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper; @@ -37,7 +36,6 @@ import javax.servlet.http.HttpServletRequest; import java.io.File; -import java.io.IOException; import java.net.URI; import java.net.URL; import java.nio.charset.StandardCharsets; @@ -595,6 +593,7 @@ private MultiPartRequestWrapper createMultipartRequest(HttpServletRequest req, i return new MultiPartRequestWrapper(jak, req, tempDir.getAbsolutePath(), new DefaultLocaleProvider()); } + @Override protected void setUp() throws Exception { super.setUp(); @@ -605,6 +604,7 @@ protected void setUp() throws Exception { tempDir.mkdirs(); } + @Override protected void tearDown() throws Exception { tempDir.delete(); interceptor.destroy(); diff --git a/core/src/test/java/org/apache/struts2/views/jsp/IteratorGeneratorTagTest.java b/core/src/test/java/org/apache/struts2/views/jsp/IteratorGeneratorTagTest.java index d1748e16fb..a5739b00e8 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/IteratorGeneratorTagTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/IteratorGeneratorTagTest.java @@ -18,13 +18,12 @@ */ package org.apache.struts2.views.jsp; -import java.util.Iterator; - +import com.opensymphony.xwork2.Action; +import com.opensymphony.xwork2.ActionSupport; import org.apache.struts2.util.IteratorGenerator.Converter; import org.apache.struts2.views.jsp.iterator.IteratorGeneratorTag; -import com.opensymphony.xwork2.Action; -import com.opensymphony.xwork2.ActionSupport; +import java.util.Iterator; /** * Test case for IteratorGeneratorTag. @@ -428,11 +427,7 @@ public void testGeneratorWithCount_clearTagStateSet() throws Exception { public Action getAction() { return new ActionSupport() { public Converter getMyConverter() { - return new Converter() { - public Object convert(String value) throws Exception { - return "myConverter-"+value; - } - }; + return value -> "myConverter-"+value; } public int getMyCount() { diff --git a/core/src/test/java/org/apache/struts2/views/jsp/SortIteratorTagTest.java b/core/src/test/java/org/apache/struts2/views/jsp/SortIteratorTagTest.java index f88c2ae816..700e6e80a3 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/SortIteratorTagTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/SortIteratorTagTest.java @@ -18,18 +18,16 @@ */ package org.apache.struts2.views.jsp; +import com.opensymphony.xwork2.Action; +import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.views.jsp.iterator.SortIteratorTag; + +import javax.servlet.jsp.JspException; import java.util.ArrayList; import java.util.Comparator; import java.util.Iterator; import java.util.List; -import javax.servlet.jsp.JspException; - -import org.apache.struts2.views.jsp.iterator.SortIteratorTag; - -import com.opensymphony.xwork2.Action; -import com.opensymphony.xwork2.ActionSupport; - /** * Test case to test SortIteratorTag. * @@ -338,13 +336,11 @@ public void testSortWithIllegalComparator() throws Exception { public Action getAction() { return new ActionSupport() { public Comparator getComparator() { - return new Comparator() { - public int compare(Object o1, Object o2) { - Integer i1 = (Integer) o1; - Integer i2 = (Integer) o2; + return (o1, o2) -> { + Integer i1 = (Integer) o1; + Integer i2 = (Integer) o2; - return (i1.intValue() - i2.intValue()); - } + return (i1 - i2); }; } diff --git a/core/src/test/java/org/apache/struts2/views/jsp/SubsetIteratorTagTest.java b/core/src/test/java/org/apache/struts2/views/jsp/SubsetIteratorTagTest.java index 4498124bb2..fc03dda0d8 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/SubsetIteratorTagTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/SubsetIteratorTagTest.java @@ -18,15 +18,14 @@ */ package org.apache.struts2.views.jsp; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - +import com.opensymphony.xwork2.Action; +import com.opensymphony.xwork2.ActionSupport; import org.apache.struts2.util.SubsetIteratorFilter.Decider; import org.apache.struts2.views.jsp.iterator.SubsetIteratorTag; -import com.opensymphony.xwork2.Action; -import com.opensymphony.xwork2.ActionSupport; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; /** @@ -641,11 +640,11 @@ public Action getAction() { return new ActionSupport() { public List getMyList() { List l = new ArrayList(); - l.add(new Integer(1)); - l.add(new Integer(2)); - l.add(new Integer(3)); - l.add(new Integer(4)); - l.add(new Integer(5)); + l.add(1); + l.add(2); + l.add(3); + l.add(4); + l.add(5); return l; } @@ -660,11 +659,9 @@ public Integer[] getMyArray() { } public Decider getMyDecider() { - return new Decider() { - public boolean decide(Object element) throws Exception { - int integer = ((Integer)element).intValue(); - return (((integer % 2) == 0)?true:false); - } + return element -> { + int integer = (Integer) element; + return integer % 2 == 0; }; } }; diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ui/DoubleValidationAction.java b/core/src/test/java/org/apache/struts2/views/jsp/ui/DoubleValidationAction.java index e62e3be5cc..aedc8596c4 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/ui/DoubleValidationAction.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/ui/DoubleValidationAction.java @@ -19,6 +19,7 @@ package org.apache.struts2.views.jsp.ui; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; /** * @@ -30,6 +31,7 @@ public double getLongint() { return longint; } + @StrutsParameter public void setLongint(double longint) { this.longint = longint; } diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ui/FieldErrorTagTest.java b/core/src/test/java/org/apache/struts2/views/jsp/ui/FieldErrorTagTest.java index f8e6113373..348f98fbe5 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/ui/FieldErrorTagTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/ui/FieldErrorTagTest.java @@ -18,19 +18,18 @@ */ package org.apache.struts2.views.jsp.ui; +import com.opensymphony.xwork2.Action; +import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.TestAction; +import org.apache.struts2.views.jsp.AbstractUITagTest; +import org.apache.struts2.views.jsp.ParamTag; + import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import org.apache.struts2.views.jsp.AbstractUITagTest; -import org.apache.struts2.views.jsp.ParamTag; -import org.apache.struts2.TestAction; - -import com.opensymphony.xwork2.Action; -import com.opensymphony.xwork2.ActionSupport; - /** * FieldError Tag Test Case. * diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ui/IntValidationAction.java b/core/src/test/java/org/apache/struts2/views/jsp/ui/IntValidationAction.java index 2be6ebdd12..f996c066d0 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/ui/IntValidationAction.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/ui/IntValidationAction.java @@ -19,6 +19,7 @@ package org.apache.struts2.views.jsp.ui; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; /** * @@ -30,6 +31,7 @@ public int getLongint() { return longint; } + @StrutsParameter public void setLongint(int longint) { this.longint = longint; } diff --git a/plugins/bean-validation/src/test/java/org/apache/struts/beanvalidation/actions/FieldAction.java b/plugins/bean-validation/src/test/java/org/apache/struts/beanvalidation/actions/FieldAction.java index e9af62d4ff..1c0470d82a 100644 --- a/plugins/bean-validation/src/test/java/org/apache/struts/beanvalidation/actions/FieldAction.java +++ b/plugins/bean-validation/src/test/java/org/apache/struts/beanvalidation/actions/FieldAction.java @@ -19,6 +19,7 @@ package org.apache.struts.beanvalidation.actions; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import org.hibernate.validator.constraints.NotBlank; public class FieldAction extends ActionSupport { @@ -30,6 +31,7 @@ public String getTest() { return test; } + @StrutsParameter public void setTest(String test) { this.test = test; } diff --git a/plugins/bean-validation/src/test/java/org/apache/struts/beanvalidation/actions/FieldMatchAction.java b/plugins/bean-validation/src/test/java/org/apache/struts/beanvalidation/actions/FieldMatchAction.java index 935ad5d178..688661f638 100644 --- a/plugins/bean-validation/src/test/java/org/apache/struts/beanvalidation/actions/FieldMatchAction.java +++ b/plugins/bean-validation/src/test/java/org/apache/struts/beanvalidation/actions/FieldMatchAction.java @@ -20,6 +20,7 @@ import com.opensymphony.xwork2.ActionSupport; import org.apache.struts.beanvalidation.constraints.FieldMatch; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import org.hibernate.validator.constraints.Email; import org.hibernate.validator.constraints.NotBlank; @@ -48,6 +49,7 @@ public String getPassword() { return password; } + @StrutsParameter public void setPassword(String password) { this.password = password; } @@ -56,6 +58,7 @@ public String getConfirmPassword() { return confirmPassword; } + @StrutsParameter public void setConfirmPassword(String confirmPassword) { this.confirmPassword = confirmPassword; } @@ -64,6 +67,7 @@ public String getEmail() { return email; } + @StrutsParameter public void setEmail(String email) { this.email = email; } @@ -72,6 +76,7 @@ public String getConfirmEmail() { return confirmEmail; } + @StrutsParameter public void setConfirmEmail(String confirmEmail) { this.confirmEmail = confirmEmail; } diff --git a/plugins/bean-validation/src/test/java/org/apache/struts/beanvalidation/actions/ModelDrivenAction.java b/plugins/bean-validation/src/test/java/org/apache/struts/beanvalidation/actions/ModelDrivenAction.java index d39e04847b..9b32fa24b5 100644 --- a/plugins/bean-validation/src/test/java/org/apache/struts/beanvalidation/actions/ModelDrivenAction.java +++ b/plugins/bean-validation/src/test/java/org/apache/struts/beanvalidation/actions/ModelDrivenAction.java @@ -21,14 +21,17 @@ import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ModelDriven; import org.apache.struts.beanvalidation.models.Person; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import javax.validation.Valid; public class ModelDrivenAction extends ActionSupport implements ModelDriven, ModelDrivenActionInterface { @Valid - private Person model = new Person(); + private final Person model = new Person(); + @StrutsParameter(depth = 2) + @Override public Person getModel() { return model; } diff --git a/plugins/bean-validation/src/test/java/org/apache/struts/beanvalidation/actions/ValidateGroupAction.java b/plugins/bean-validation/src/test/java/org/apache/struts/beanvalidation/actions/ValidateGroupAction.java index 6b17ab7363..7d3540551e 100644 --- a/plugins/bean-validation/src/test/java/org/apache/struts/beanvalidation/actions/ValidateGroupAction.java +++ b/plugins/bean-validation/src/test/java/org/apache/struts/beanvalidation/actions/ValidateGroupAction.java @@ -22,14 +22,17 @@ import com.opensymphony.xwork2.ModelDriven; import org.apache.struts.beanvalidation.constraints.ValidationGroup; import org.apache.struts.beanvalidation.models.Person; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import javax.validation.Valid; public class ValidateGroupAction extends ActionSupport implements ModelDriven { @Valid - private Person model = new Person(); + private final Person model = new Person(); + @StrutsParameter(depth = 2) + @Override public Person getModel() { return model; } @@ -67,4 +70,4 @@ public String actionMultiGroupsChecks() { public String actionLongNameChecks() { return SUCCESS; } -} \ No newline at end of file +} diff --git a/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ActionNamesAction.java b/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ActionNamesAction.java index 9b6efbdad2..0686f21925 100644 --- a/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ActionNamesAction.java +++ b/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ActionNamesAction.java @@ -23,6 +23,7 @@ import com.opensymphony.xwork2.inject.Inject; import org.apache.commons.text.StringEscapeUtils; import org.apache.struts2.StrutsConstants; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.util.Set; import java.util.TreeSet; @@ -54,6 +55,7 @@ public String getNamespace() { return StringEscapeUtils.escapeHtml4(namespace); } + @StrutsParameter public void setNamespace(String namespace) { this.namespace = namespace; } @@ -81,9 +83,10 @@ public String getExtension() { return extension; } + @Override public String execute() throws Exception { namespaces = configHelper.getNamespaces(); - if (namespaces.size() == 0) { + if (namespaces.isEmpty()) { addActionError("There are no namespaces in this configuration"); return ERROR; } diff --git a/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ListValidatorsAction.java b/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ListValidatorsAction.java index 9eade6bb63..5a3344cf11 100644 --- a/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ListValidatorsAction.java +++ b/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ListValidatorsAction.java @@ -26,6 +26,7 @@ import com.opensymphony.xwork2.validator.Validator; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.util.Collections; import java.util.List; @@ -43,16 +44,17 @@ public class ListValidatorsAction extends ActionSupport { List validators = Collections.emptyList(); private ActionValidatorManager actionValidatorManager; - + @Inject public void setActionValidatorManager(ActionValidatorManager mgr) { this.actionValidatorManager = mgr; } - + public String getClazz() { return clazz; } + @StrutsParameter public void setClazz(String clazz) { this.clazz = clazz; } @@ -69,6 +71,7 @@ public String getContext() { return context; } + @StrutsParameter public void setContext(String context) { this.context = context; } @@ -77,6 +80,7 @@ public List getValidators() { return validators; } + @Override public String execute() throws Exception { loadValidators(); return super.execute(); diff --git a/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowBeansAction.java b/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowBeansAction.java index 1e8dab8be0..6248b69647 100644 --- a/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowBeansAction.java +++ b/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowBeansAction.java @@ -46,6 +46,7 @@ public class ShowBeansAction extends ActionNamesAction { Map> bindings; @Inject + @Override public void setContainer(Container container) { super.setContainer(container); bindings = new TreeMap<>(); @@ -123,6 +124,7 @@ public boolean isDefault() { return isDefault; } + @Override public int compareTo(Binding b2) { int ret; if (isDefault) { diff --git a/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowConfigAction.java b/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowConfigAction.java index 51b0d50e5c..25547c3958 100644 --- a/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowConfigAction.java +++ b/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowConfigAction.java @@ -21,10 +21,11 @@ import com.opensymphony.xwork2.ObjectFactory; import com.opensymphony.xwork2.config.entities.ActionConfig; import com.opensymphony.xwork2.inject.Inject; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; import com.opensymphony.xwork2.util.reflection.ReflectionProvider; import org.apache.commons.text.StringEscapeUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.beans.PropertyDescriptor; import java.util.Set; @@ -43,8 +44,8 @@ public class ShowConfigAction extends ActionNamesAction { private Set actionNames; private String detailView = "results"; private PropertyDescriptor[] properties; - private static Logger LOG = LogManager.getLogger(ShowConfigAction.class); - + private static final Logger LOG = LogManager.getLogger(ShowConfigAction.class); + private ObjectFactory objectFactory; private ReflectionProvider reflectionProvider; @@ -52,23 +53,26 @@ public String getDetailView() { return detailView; } + @StrutsParameter public void setDetailView(String detailView) { this.detailView = detailView; } + @Override public Set getActionNames() { return actionNames; } + @Override public String getNamespace() { return StringEscapeUtils.escapeHtml4(namespace); } - + @Inject public void setObjectFactory(ObjectFactory fac) { this.objectFactory = fac; } - + @Inject public void setReflectionProvider(ReflectionProvider prov) { this.reflectionProvider = prov; @@ -78,6 +82,7 @@ public String stripPackage(Class clazz) { return clazz.getName().substring(clazz.getName().lastIndexOf('.') + 1); } + @StrutsParameter public void setNamespace(String namespace) { this.namespace = namespace; } @@ -86,6 +91,7 @@ public String getActionName() { return actionName; } + @StrutsParameter public void setActionName(String actionName) { this.actionName = actionName; } @@ -98,16 +104,17 @@ public PropertyDescriptor[] getProperties() { return properties; } + @Override public String execute() throws Exception { super.execute(); config = configHelper.getActionConfig(namespace, actionName); - actionNames = new TreeSet(configHelper.getActionNames(namespace)); + actionNames = new TreeSet<>(configHelper.getActionNames(namespace)); try { Object action = objectFactory.buildAction(actionName, namespace, config, null); properties = reflectionProvider.getPropertyDescriptors(action); } catch (Exception e) { - LOG.error("Unable to get properties for action " + actionName, e); - addActionError("Unable to retrieve action properties: " + e.toString()); + LOG.error("Unable to get properties for action {}", actionName, e); + addActionError("Unable to retrieve action properties: " + e); } if (hasErrors()) //super might have set some :) diff --git a/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowValidatorAction.java b/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowValidatorAction.java index c740e1473f..524cee0212 100644 --- a/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowValidatorAction.java +++ b/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowValidatorAction.java @@ -19,12 +19,13 @@ package org.apache.struts2.config_browser; import com.opensymphony.xwork2.inject.Inject; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; import com.opensymphony.xwork2.util.reflection.ReflectionContextFactory; import com.opensymphony.xwork2.util.reflection.ReflectionException; import com.opensymphony.xwork2.util.reflection.ReflectionProvider; import com.opensymphony.xwork2.validator.Validator; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.beans.BeanInfo; import java.beans.IntrospectionException; @@ -32,6 +33,7 @@ import java.beans.PropertyDescriptor; import java.util.Collections; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.TreeSet; @@ -42,11 +44,11 @@ public class ShowValidatorAction extends ListValidatorsAction { private static final long serialVersionUID = 4061534149317835177L; - private static Logger LOG = LogManager.getLogger(ShowValidatorAction.class); + private static final Logger LOG = LogManager.getLogger(ShowValidatorAction.class); private Set properties = Collections.emptySet(); private int selected = 0; - + ReflectionProvider reflectionProvider; ReflectionContextFactory reflectionContextFactory; @@ -54,16 +56,17 @@ public class ShowValidatorAction extends ListValidatorsAction { public void setReflectionProvider(ReflectionProvider prov) { this.reflectionProvider = prov; } - + @Inject public void setReflectionContextFactory(ReflectionContextFactory fac) { this.reflectionContextFactory = fac; } - + public int getSelected() { return selected; } + @StrutsParameter public void setSelected(int selected) { this.selected = selected; } @@ -76,10 +79,11 @@ public Validator getSelectedValidator() { return validators.get(selected); } + @Override public String execute() throws Exception { loadValidators(); Validator validator = getSelectedValidator(); - properties = new TreeSet(); + properties = new TreeSet<>(); try { Map context = reflectionContextFactory.createDefaultContext(validator); BeanInfo beanInfoFrom; @@ -162,6 +166,7 @@ public void setName(String name) { this.name = name; } + @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof PropertyInfo)) return false; @@ -170,11 +175,11 @@ public boolean equals(Object o) { if (!name.equals(propertyInfo.name)) return false; if (!type.equals(propertyInfo.type)) return false; - if (value != null ? !value.equals(propertyInfo.value) : propertyInfo.value != null) return false; - return true; + return Objects.equals(value, propertyInfo.value); } + @Override public int hashCode() { int result; result = name.hashCode(); @@ -183,6 +188,7 @@ public int hashCode() { return result; } + @Override public int compareTo(Object o) { PropertyInfo other = (PropertyInfo) o; return this.name.compareTo(other.name); diff --git a/plugins/convention/src/test/java/actions/MessageAction.java b/plugins/convention/src/test/java/actions/MessageAction.java index 2482fdbc8c..3c963d5ca0 100644 --- a/plugins/convention/src/test/java/actions/MessageAction.java +++ b/plugins/convention/src/test/java/actions/MessageAction.java @@ -31,7 +31,7 @@ public String getMessage() { return message; } - + @Override public String execute() { message = "Hello World"; return SUCCESS; diff --git a/plugins/json/src/test/java/org/apache/struts2/json/JSONValidationInterceptorTest.java b/plugins/json/src/test/java/org/apache/struts2/json/JSONValidationInterceptorTest.java index 8cf3dcef10..b53187e252 100644 --- a/plugins/json/src/test/java/org/apache/struts2/json/JSONValidationInterceptorTest.java +++ b/plugins/json/src/test/java/org/apache/struts2/json/JSONValidationInterceptorTest.java @@ -29,6 +29,7 @@ import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator; import com.opensymphony.xwork2.validator.annotations.StringLengthFieldValidator; import org.apache.struts2.StrutsStatics; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor; import org.apache.struts2.interceptor.validation.SkipValidation; import org.apache.struts2.junit.StrutsTestCase; @@ -214,6 +215,7 @@ public static class TestAction extends ActionSupport { private boolean executed = false; private String password; + @Override public String execute() { executed = true; return Action.SUCCESS; @@ -230,11 +232,13 @@ public String getText() { @StringLengthFieldValidator(minLength = "2", message = "Too short") @EmailValidator(message = "This is no email") + @StrutsParameter public void setText(String text) { this.text = text; } @RequiredStringValidator(message = "Password isn't correct") + @StrutsParameter public void setPassword(String password) { this.password = password; } @@ -248,6 +252,7 @@ public int getValue() { } @IntRangeFieldValidator(min = "-1", message = "Min value is -1") + @StrutsParameter public void setValue(int value) { this.value = value; } diff --git a/plugins/junit/src/test/java/org/apache/struts2/junit/JUnitTestAction.java b/plugins/junit/src/test/java/org/apache/struts2/junit/JUnitTestAction.java index f09c341448..1531c3670b 100644 --- a/plugins/junit/src/test/java/org/apache/struts2/junit/JUnitTestAction.java +++ b/plugins/junit/src/test/java/org/apache/struts2/junit/JUnitTestAction.java @@ -19,6 +19,7 @@ package org.apache.struts2.junit; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import org.springframework.beans.factory.annotation.Autowired; public class JUnitTestAction extends ActionSupport { @@ -33,6 +34,7 @@ public String getName() { return name; } + @StrutsParameter public void setName(String name) { this.name = name; } diff --git a/plugins/junit/src/test/java/org/apache/struts2/junit/session/SessionGetAction.java b/plugins/junit/src/test/java/org/apache/struts2/junit/session/SessionGetAction.java index 2149f7bd06..039cf9cd98 100644 --- a/plugins/junit/src/test/java/org/apache/struts2/junit/session/SessionGetAction.java +++ b/plugins/junit/src/test/java/org/apache/struts2/junit/session/SessionGetAction.java @@ -27,6 +27,7 @@ public class SessionGetAction extends ActionSupport { private static final long serialVersionUID = 8366502863472148631L; + @Override public String execute() { return ActionSupport.SUCCESS; } diff --git a/plugins/junit/src/test/java/org/apache/struts2/junit/session/SessionSetAction.java b/plugins/junit/src/test/java/org/apache/struts2/junit/session/SessionSetAction.java index 7d3a0dc973..f463951c05 100644 --- a/plugins/junit/src/test/java/org/apache/struts2/junit/session/SessionSetAction.java +++ b/plugins/junit/src/test/java/org/apache/struts2/junit/session/SessionSetAction.java @@ -30,6 +30,7 @@ public class SessionSetAction extends ActionSupport { public String SESSION_KEY = "sessionKey"; public String SESSION_VALUE = "sessionValue"; + @Override public String execute() { ActionContext.getContext().getSession().put(SESSION_KEY, SESSION_VALUE); return ActionSupport.SUCCESS; diff --git a/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/FieldsWithProfiles.java b/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/FieldsWithProfiles.java index 5c5c342cd2..09b06df18e 100644 --- a/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/FieldsWithProfiles.java +++ b/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/FieldsWithProfiles.java @@ -20,6 +20,7 @@ import com.opensymphony.xwork2.ActionSupport; import net.sf.oval.constraint.NotNull; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import org.apache.struts2.oval.annotation.Profiles; public class FieldsWithProfiles extends ActionSupport { @@ -46,6 +47,7 @@ public String getFirstName() { return firstName; } + @StrutsParameter public void setFirstName(String firstName) { this.firstName = firstName; } @@ -54,6 +56,7 @@ public String getLastName() { return lastName; } + @StrutsParameter public void setLastName(String lastName) { this.lastName = lastName; } @@ -62,6 +65,7 @@ public String getMiddleName() { return middleName; } + @StrutsParameter public void setMiddleName(String middleName) { this.middleName = middleName; } diff --git a/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/MemberObject.java b/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/MemberObject.java index 591b1b206d..3abe9dca17 100644 --- a/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/MemberObject.java +++ b/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/MemberObject.java @@ -18,17 +18,17 @@ */ package org.apache.struts2.oval.interceptor; +import com.opensymphony.xwork2.ActionSupport; import net.sf.oval.constraint.AssertValid; - +import org.apache.struts2.interceptor.parameter.StrutsParameter; import org.apache.struts2.oval.interceptor.domain.Person; -import com.opensymphony.xwork2.ActionSupport; - public class MemberObject extends ActionSupport { @AssertValid - private Person person = new Person(); + private final Person person = new Person(); + @StrutsParameter(depth = 2) public Person getPerson() { return person; } diff --git a/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/ModelDrivenAction.java b/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/ModelDrivenAction.java index c4b7a2ed21..21e4e88eec 100644 --- a/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/ModelDrivenAction.java +++ b/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/ModelDrivenAction.java @@ -18,18 +18,19 @@ */ package org.apache.struts2.oval.interceptor; -import net.sf.oval.constraint.AssertValid; - -import org.apache.struts2.oval.interceptor.domain.Person; - import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ModelDriven; +import net.sf.oval.constraint.AssertValid; +import org.apache.struts2.interceptor.parameter.StrutsParameter; +import org.apache.struts2.oval.interceptor.domain.Person; public class ModelDrivenAction extends ActionSupport implements ModelDriven { @AssertValid - private Person person = new Person(); + private final Person person = new Person(); + @StrutsParameter(depth = 2) + @Override public Person getModel() { return person; } diff --git a/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleField.java b/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleField.java index 045dc1f684..e8bfa618cd 100644 --- a/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleField.java +++ b/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleField.java @@ -18,10 +18,11 @@ */ package org.apache.struts2.oval.interceptor; +import com.opensymphony.xwork2.ActionSupport; import net.sf.oval.constraint.Length; import net.sf.oval.constraint.NotEmpty; import net.sf.oval.constraint.NotNull; -import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; public class SimpleField extends ActionSupport{ @NotNull() @@ -35,10 +36,12 @@ public String getName() { return name; } + @StrutsParameter public void setName(String name) { this.name = name; } + @Override public void validate() { this.validateCalled = true; } diff --git a/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldI18n.java b/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldI18n.java index cc986ff1ea..48a271d612 100644 --- a/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldI18n.java +++ b/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldI18n.java @@ -21,6 +21,7 @@ import com.opensymphony.xwork2.ActionSupport; import net.sf.oval.constraint.Length; import net.sf.oval.constraint.NotNull; +import org.apache.struts2.interceptor.parameter.StrutsParameter; public class SimpleFieldI18n extends ActionSupport { @NotNull(message = "notnull.field") @@ -31,6 +32,7 @@ public String getName() { return name; } + @StrutsParameter public void setName(String name) { this.name = name; } diff --git a/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldI18nDefaultKey.java b/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldI18nDefaultKey.java index d758ec4b6c..2d8d507d64 100644 --- a/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldI18nDefaultKey.java +++ b/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldI18nDefaultKey.java @@ -20,8 +20,7 @@ import com.opensymphony.xwork2.ActionSupport; import net.sf.oval.constraint.NotNull; -import net.sf.oval.constraint.NotEmpty; -import net.sf.oval.constraint.Length; +import org.apache.struts2.interceptor.parameter.StrutsParameter; public class SimpleFieldI18nDefaultKey extends ActionSupport { @NotNull(message = "notnull.field") @@ -31,6 +30,7 @@ public String getName() { return name; } + @StrutsParameter public void setName(String name) { this.name = name; } diff --git a/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldJPAAnnotations.java b/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldJPAAnnotations.java index 8df5c55f1c..949a16958e 100644 --- a/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldJPAAnnotations.java +++ b/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldJPAAnnotations.java @@ -19,6 +19,7 @@ package org.apache.struts2.oval.interceptor; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import javax.persistence.Basic; @@ -30,6 +31,7 @@ public String getFirstName() { return firstName; } + @StrutsParameter public void setFirstName(String firstName) { this.firstName = firstName; } diff --git a/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldOGNLExpression.java b/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldOGNLExpression.java index 858c497c42..e5697a4487 100644 --- a/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldOGNLExpression.java +++ b/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldOGNLExpression.java @@ -18,8 +18,9 @@ */ package org.apache.struts2.oval.interceptor; -import net.sf.oval.constraint.Assert; import com.opensymphony.xwork2.ActionSupport; +import net.sf.oval.constraint.Assert; +import org.apache.struts2.interceptor.parameter.StrutsParameter; public class SimpleFieldOGNLExpression extends ActionSupport { @@ -30,6 +31,7 @@ public String getName() { return name; } + @StrutsParameter public void setName(String name) { this.name = name; } diff --git a/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldsXML.java b/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldsXML.java index 09bf3fa00a..32659fab11 100644 --- a/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldsXML.java +++ b/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldsXML.java @@ -19,8 +19,8 @@ package org.apache.struts2.oval.interceptor; import com.opensymphony.xwork2.ActionSupport; -import net.sf.oval.constraint.NotEmpty; import net.sf.oval.constraint.NotNull; +import org.apache.struts2.interceptor.parameter.StrutsParameter; public class SimpleFieldsXML extends ActionSupport { private String firstName; @@ -32,6 +32,7 @@ public String getFirstName() { return firstName; } + @StrutsParameter public void setFirstName(String firstName) { this.firstName = firstName; } @@ -40,6 +41,7 @@ public String getLastName() { return lastName; } + @StrutsParameter public void setLastName(String lastName) { this.lastName = lastName; } diff --git a/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldsXMLChild.java b/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldsXMLChild.java index 971afb7fed..6a98082298 100644 --- a/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldsXMLChild.java +++ b/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldsXMLChild.java @@ -18,6 +18,8 @@ */ package org.apache.struts2.oval.interceptor; +import org.apache.struts2.interceptor.parameter.StrutsParameter; + public class SimpleFieldsXMLChild extends SimpleFieldsXML { private String middleName; @@ -25,6 +27,7 @@ public String getMiddleName() { return middleName; } + @StrutsParameter public void setMiddleName(String middleName) { this.middleName = middleName; } diff --git a/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleMethod.java b/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleMethod.java index a3dc92a4bf..e693973220 100644 --- a/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleMethod.java +++ b/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleMethod.java @@ -19,9 +19,10 @@ package org.apache.struts2.oval.interceptor; import com.opensymphony.xwork2.ActionSupport; +import net.sf.oval.configuration.annotation.IsInvariant; import net.sf.oval.constraint.Length; import net.sf.oval.constraint.NotNull; -import net.sf.oval.configuration.annotation.IsInvariant; +import org.apache.struts2.interceptor.parameter.StrutsParameter; public class SimpleMethod extends ActionSupport { private String name; @@ -33,6 +34,7 @@ public String getSomeName() { return name; } + @StrutsParameter public void setSomeName(String name) { this.name = name; } diff --git a/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java b/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java index 8e83dc155f..6f22a583e0 100644 --- a/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java +++ b/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java @@ -32,6 +32,7 @@ import com.opensymphony.xwork2.util.XWorkTestCaseHelper; import junit.framework.TestCase; import org.apache.struts2.ServletActionContext; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import org.apache.struts2.result.HttpHeaderResult; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; @@ -53,7 +54,7 @@ public class RestActionInvocationTest extends TestCase { @Override protected void setUp() throws Exception { super.setUp(); - + restActionInvocation = new RestActionInvocationTester(); request = new MockHttpServletRequest(); response = new MockHttpServletResponse(); @@ -61,7 +62,7 @@ protected void setUp() throws Exception { ServletActionContext.setResponse(response); } - + /** * Test the correct action results: null, String, HttpHeaders, Result * @throws Exception @@ -71,12 +72,12 @@ public void testSaveResult() throws Exception { Object methodResult = "index"; ActionConfig actionConfig = restActionInvocation.getProxy().getConfig(); assertEquals("index", restActionInvocation.saveResult(actionConfig, methodResult)); - + setUp(); methodResult = new DefaultHttpHeaders("show"); assertEquals("show", restActionInvocation.saveResult(actionConfig, methodResult)); assertEquals(methodResult, restActionInvocation.httpHeaders); - + setUp(); methodResult = new HttpHeaderResult(HttpServletResponse.SC_ACCEPTED); assertEquals(null, restActionInvocation.saveResult(actionConfig, methodResult)); @@ -89,18 +90,18 @@ public void testSaveResult() throws Exception { // ko assertFalse(true); - + } catch (ConfigurationException c) { // ok, object not allowed } } - + /** * Test the target selection: exception, error messages, model and null * @throws Exception */ public void testSelectTarget() throws Exception { - + // Exception Exception e = new Exception(); restActionInvocation.getStack().set("exception", e); @@ -118,7 +119,7 @@ public void testSelectTarget() throws Exception { errors.put("actionErrors", list); restActionInvocation.selectTarget(); assertEquals(errors, restActionInvocation.target); - + // Model with get and no content in post, put, delete setUp(); RestAction restAction = (RestAction)restActionInvocation.getAction(); @@ -168,18 +169,18 @@ public int hashCode() { }; model.add("Item"); restAction.model = model; - + restActionInvocation.processResult(); assertEquals(SC_NOT_MODIFIED, response.getStatus()); - + } - + /** * Test the default error result. * @throws Exception */ public void testDefaultErrorResult() throws Exception { - + // Exception Exception e = new Exception(); restActionInvocation.getStack().set("exception", e); @@ -189,24 +190,24 @@ public void testDefaultErrorResult() throws Exception { List model = new ArrayList(); model.add("Item"); restAction.model = model; - + restActionInvocation.setDefaultErrorResultName("default-error"); - ResultConfig resultConfig = new ResultConfig.Builder("default-error", + ResultConfig resultConfig = new ResultConfig.Builder("default-error", "org.apache.struts2.result.HttpHeaderResult") .addParam("status", "123").build(); - ActionConfig actionConfig = new ActionConfig.Builder("org.apache.rest", + ActionConfig actionConfig = new ActionConfig.Builder("org.apache.rest", "RestAction", "org.apache.rest.RestAction") .addResultConfig(resultConfig) .build(); ((MockActionProxy)restActionInvocation.getProxy()).setConfig(actionConfig); - + restActionInvocation.processResult(); assertEquals(123, response.getStatus()); - + } - + public void testNoResult() throws Exception { - + RestAction restAction = (RestAction)restActionInvocation.getAction(); List model = new ArrayList(); model.add("Item"); @@ -219,34 +220,34 @@ public void testNoResult() throws Exception { // ko assertFalse(true); - + } catch (ConfigurationException c) { // ok, no result } } - + /** * Test the global execution * @throws Exception */ public void testInvoke() throws Exception { - + // Default index method return 'success' ((MockActionProxy)restActionInvocation.getProxy()).setMethod("index"); // Define result 'success' - ResultConfig resultConfig = new ResultConfig.Builder("success", + ResultConfig resultConfig = new ResultConfig.Builder("success", "org.apache.struts2.result.HttpHeaderResult") .addParam("status", "123").build(); - ActionConfig actionConfig = new ActionConfig.Builder("org.apache.rest", + ActionConfig actionConfig = new ActionConfig.Builder("org.apache.rest", "RestAction", "org.apache.rest.RestAction") .addResultConfig(resultConfig) .build(); ((MockActionProxy)restActionInvocation.getProxy()).setConfig(actionConfig); request.setMethod("GET"); - + restActionInvocation.setOgnlUtil(new OgnlUtil()); restActionInvocation.invoke(); @@ -264,7 +265,7 @@ class RestActionInvocationTester extends RestActionInvocation { interceptorMappings.add(new InterceptorMapping("interceptor", mockInterceptor)); interceptors = interceptorMappings.iterator(); MockActionProxy actionProxy = new MockActionProxy(); - ActionConfig actionConfig = new ActionConfig.Builder("org.apache.rest", + ActionConfig actionConfig = new ActionConfig.Builder("org.apache.rest", "RestAction", "org.apache.rest.RestAction").build(); actionProxy.setConfig(actionConfig); proxy = actionProxy; @@ -280,18 +281,20 @@ class RestActionInvocationTester extends RestActionInvocation { container = ActionContext.getContext().getContainer(); stack = ActionContext.getContext().getValueStack(); objectFactory = container.getInstance(ObjectFactory.class); - + } - + } - class RestAction extends RestActionSupport implements ModelDriven> { + static class RestAction extends RestActionSupport implements ModelDriven> { List model; - + + @StrutsParameter(depth = 1) + @Override public List getModel() { return model; } - + } } diff --git a/plugins/spring/src/test/java/com/opensymphony/xwork2/ModelDrivenAction.java b/plugins/spring/src/test/java/com/opensymphony/xwork2/ModelDrivenAction.java index fabc3ed95b..6ffcad2ff2 100644 --- a/plugins/spring/src/test/java/com/opensymphony/xwork2/ModelDrivenAction.java +++ b/plugins/spring/src/test/java/com/opensymphony/xwork2/ModelDrivenAction.java @@ -19,6 +19,8 @@ package com.opensymphony.xwork2; +import org.apache.struts2.interceptor.parameter.StrutsParameter; + /** * ModelDrivenAction * @@ -28,9 +30,9 @@ public class ModelDrivenAction extends ActionSupport implements ModelDriven { private String foo; - private TestBean model = new TestBean(); - + private final TestBean model = new TestBean(); + @StrutsParameter public void setFoo(String foo) { this.foo = foo; } @@ -42,6 +44,8 @@ public String getFoo() { /** * @return the model to be pushed onto the ValueStack after the Action itself */ + @StrutsParameter(depth = 2) + @Override public Object getModel() { return model; } From 8b4c188d0f29eead85ba4199543128420aaf77a5 Mon Sep 17 00:00:00 2001 From: Kusal Kithul-Godage Date: Sat, 13 Jul 2024 21:56:21 +1000 Subject: [PATCH 4/6] WW-5440 Fix Showcase App allowlist configuration --- .../struts2/showcase/modelDriven/ModelDrivenAction.java | 1 + .../showcase/modelDriven/{ => model}/Gangster.java | 2 +- apps/showcase/src/main/resources/struts.xml | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) rename apps/showcase/src/main/java/org/apache/struts2/showcase/modelDriven/{ => model}/Gangster.java (96%) diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/modelDriven/ModelDrivenAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/modelDriven/ModelDrivenAction.java index a491ba7ca6..60692b0e69 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/modelDriven/ModelDrivenAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/modelDriven/ModelDrivenAction.java @@ -22,6 +22,7 @@ import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ModelDriven; +import org.apache.struts2.showcase.modelDriven.model.Gangster; /** * Action to demonstrate simple model-driven feature of the framework. diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/modelDriven/Gangster.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/modelDriven/model/Gangster.java similarity index 96% rename from apps/showcase/src/main/java/org/apache/struts2/showcase/modelDriven/Gangster.java rename to apps/showcase/src/main/java/org/apache/struts2/showcase/modelDriven/model/Gangster.java index be2a571bb5..6d0b263662 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/modelDriven/Gangster.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/modelDriven/model/Gangster.java @@ -18,7 +18,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.struts2.showcase.modelDriven; +package org.apache.struts2.showcase.modelDriven.model; import java.io.Serializable; diff --git a/apps/showcase/src/main/resources/struts.xml b/apps/showcase/src/main/resources/struts.xml index 33095326c2..d0f57325d8 100644 --- a/apps/showcase/src/main/resources/struts.xml +++ b/apps/showcase/src/main/resources/struts.xml @@ -36,6 +36,15 @@ + + From cb62cb4e9aa34de3b53bb05182abe870b4253cb9 Mon Sep 17 00:00:00 2001 From: Kusal Kithul-Godage Date: Sat, 13 Jul 2024 23:08:46 +1000 Subject: [PATCH 5/6] WW-5440 Fix OGNL allowlist compat with Convention plugin --- apps/showcase/pom.xml | 6 ++ .../struts2/showcase/ConventionTest.java | 88 +++++++++++++++++++ .../xwork2/config/ConfigurationUtil.java | 13 ++- .../XmlDocConfigurationProvider.java | 5 +- .../struts2/ognl/ProviderAllowlist.java | 35 ++++++-- .../struts2/ognl/ProviderAllowlistTest.java | 27 +++--- .../ClasspathConfigurationProvider.java | 11 ++- .../convention/ClasspathPackageProvider.java | 11 ++- .../PackageBasedActionConfigBuilder.java | 61 ++++++++----- .../PackageBasedActionConfigBuilderTest.java | 52 +++++++++-- 10 files changed, 248 insertions(+), 61 deletions(-) create mode 100644 apps/showcase/src/test/java/it/org/apache/struts2/showcase/ConventionTest.java diff --git a/apps/showcase/pom.xml b/apps/showcase/pom.xml index 3ea6e3dc80..5b5f0e590c 100644 --- a/apps/showcase/pom.xml +++ b/apps/showcase/pom.xml @@ -137,6 +137,12 @@ test + + org.assertj + assertj-core + test + + net.sourceforge.htmlunit htmlunit diff --git a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ConventionTest.java b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ConventionTest.java new file mode 100644 index 0000000000..76fd0e840a --- /dev/null +++ b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ConventionTest.java @@ -0,0 +1,88 @@ +/* + * 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 it.org.apache.struts2.showcase; + +import com.gargoylesoftware.htmlunit.WebClient; +import com.gargoylesoftware.htmlunit.html.HtmlForm; +import com.gargoylesoftware.htmlunit.html.HtmlPage; +import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ConventionTest { + + private WebClient webClient; + + @Before + public void setUp() throws Exception { + webClient = new WebClient(); + } + + @After + public void tearDown() throws Exception { + webClient.close(); + } + + @Test + public void listPeople() throws Exception { + HtmlPage page = webClient.getPage(ParameterUtils.getBaseUrl() + "/person/list-people.action"); + + assertThat(page.asNormalizedText()).contains( + "3\tAlexandru\tPapesco\n" + + "4\tJay\tBoss\n" + + "5\tRainer\tHermanos\n" + ); + } + + @Test + public void editPeople() throws Exception { + HtmlPage page = webClient.getPage(ParameterUtils.getBaseUrl() + "/person/edit-person.action"); + HtmlForm form = page.getForms().get(0); + + form.getInputByName("persons(1).name").setValue("Lukasz"); + form.getInputByName("persons(1).lastName").setValue("Lenart"); + form.getInputByName("persons(2).name").setValue("Kusal"); + form.getInputByName("persons(2).lastName").setValue("Kithul-Godage"); + + HtmlSubmitInput button = form.getInputByValue("Save all persons"); + page = button.click(); + + assertThat(page.asNormalizedText()).contains( + "1\tLukasz\tLenart\n" + + "2\tKusal\tKithul-Godage\n" + ); + } + + @Test + public void createPerson() throws Exception { + HtmlPage page = webClient.getPage(ParameterUtils.getBaseUrl() + "/person/new-person!input.action"); + HtmlForm form = page.getForms().get(0); + + form.getInputByName("person.name").type("Lukasz"); + form.getInputByName("person.lastName").type("Lenart"); + + HtmlSubmitInput button = form.getInputByValue("Create person"); + page = button.click(); + + assertThat(page.asNormalizedText()).contains("6\tLukasz\tLenart\n"); + } +} diff --git a/core/src/main/java/com/opensymphony/xwork2/config/ConfigurationUtil.java b/core/src/main/java/com/opensymphony/xwork2/config/ConfigurationUtil.java index b85042688d..06381c5b01 100644 --- a/core/src/main/java/com/opensymphony/xwork2/config/ConfigurationUtil.java +++ b/core/src/main/java/com/opensymphony/xwork2/config/ConfigurationUtil.java @@ -19,18 +19,21 @@ package com.opensymphony.xwork2.config; import com.opensymphony.xwork2.config.entities.PackageConfig; +import org.apache.commons.lang3.ClassUtils; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.StringTokenizer; /** * ConfigurationUtil - * + * * @author Jason Carreira Created May 23, 2003 11:22:49 PM */ public class ConfigurationUtil { @@ -83,4 +86,12 @@ public static List buildParentListFromString(String parent) { return parents; } + + public static Set> getAllClassTypes(Class clazz) { + HashSet> classes = new HashSet<>(); + classes.add(clazz); + classes.addAll(ClassUtils.getAllSuperclasses(clazz)); + classes.addAll(ClassUtils.getAllInterfaces(clazz)); + return classes; + } } diff --git a/core/src/main/java/com/opensymphony/xwork2/config/providers/XmlDocConfigurationProvider.java b/core/src/main/java/com/opensymphony/xwork2/config/providers/XmlDocConfigurationProvider.java index 6de2024609..d874f850f9 100644 --- a/core/src/main/java/com/opensymphony/xwork2/config/providers/XmlDocConfigurationProvider.java +++ b/core/src/main/java/com/opensymphony/xwork2/config/providers/XmlDocConfigurationProvider.java @@ -45,7 +45,6 @@ import com.opensymphony.xwork2.util.location.Location; import com.opensymphony.xwork2.util.location.LocationUtils; import org.apache.commons.lang3.BooleanUtils; -import org.apache.commons.lang3.ClassUtils; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -149,9 +148,7 @@ public void destroy() { protected Class allowAndLoadClass(String className) throws ClassNotFoundException { Class clazz = loadClass(className); - allowlistClasses.add(clazz); - allowlistClasses.addAll(ClassUtils.getAllSuperclasses(clazz)); - allowlistClasses.addAll(ClassUtils.getAllInterfaces(clazz)); + allowlistClasses.addAll(ConfigurationUtil.getAllClassTypes(clazz)); return clazz; } diff --git a/core/src/main/java/org/apache/struts2/ognl/ProviderAllowlist.java b/core/src/main/java/org/apache/struts2/ognl/ProviderAllowlist.java index d103728853..93f7506b7a 100644 --- a/core/src/main/java/org/apache/struts2/ognl/ProviderAllowlist.java +++ b/core/src/main/java/org/apache/struts2/ognl/ProviderAllowlist.java @@ -28,13 +28,14 @@ import static java.util.Collections.unmodifiableSet; /** - * Allows {@link ConfigurationProvider}s to register classes that should be allowed to be used in OGNL expressions. + * Allows registration of classes that should be allowed to be used in OGNL expressions, using a key to identify the + * source of the allowlist. * * @since 6.4.0 */ public class ProviderAllowlist { - private final Map>> allowlistMap; + private final Map>> allowlistMap; private Set> allowlistClasses; public ProviderAllowlist() { @@ -42,24 +43,40 @@ public ProviderAllowlist() { reconstructAllowlist(); } - public synchronized void registerAllowlist(ConfigurationProvider configurationProvider, Set> allowlist) { - Set> existingAllowlist = allowlistMap.get(configurationProvider); + public synchronized void registerAllowlist(Object key, Set> allowlist) { + Set> existingAllowlist = allowlistMap.get(key); if (existingAllowlist != null) { - clearAllowlist(configurationProvider); + clearAllowlist(key); } - this.allowlistMap.put(configurationProvider, new HashSet<>(allowlist)); + this.allowlistMap.put(key, new HashSet<>(allowlist)); this.allowlistClasses.addAll(allowlist); } - public synchronized void clearAllowlist(ConfigurationProvider configurationProvider) { - Set> allowlist = allowlistMap.get(configurationProvider); + /** + * @deprecated since 6.6.0, use {@link #registerAllowlist(Object, Set)} + */ + @Deprecated + public synchronized void registerAllowlist(ConfigurationProvider configurationProvider, Set> allowlist) { + registerAllowlist((Object) configurationProvider, allowlist); + } + + public synchronized void clearAllowlist(Object key) { + Set> allowlist = allowlistMap.get(key); if (allowlist == null) { return; } - this.allowlistMap.remove(configurationProvider); + this.allowlistMap.remove(key); reconstructAllowlist(); } + /** + * @deprecated since 6.6.0, use {@link #clearAllowlist(Object)} + */ + @Deprecated + public synchronized void clearAllowlist(ConfigurationProvider configurationProvider) { + clearAllowlist((Object) configurationProvider); + } + public Set> getProviderAllowlist() { return unmodifiableSet(allowlistClasses); } diff --git a/core/src/test/java/org/apache/struts2/ognl/ProviderAllowlistTest.java b/core/src/test/java/org/apache/struts2/ognl/ProviderAllowlistTest.java index baf91b9b52..2584d16f40 100644 --- a/core/src/test/java/org/apache/struts2/ognl/ProviderAllowlistTest.java +++ b/core/src/test/java/org/apache/struts2/ognl/ProviderAllowlistTest.java @@ -18,7 +18,6 @@ */ package org.apache.struts2.ognl; -import com.opensymphony.xwork2.config.ConfigurationProvider; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -39,10 +38,10 @@ public class ProviderAllowlistTest { private ProviderAllowlist providerAllowlist; @Mock - private ConfigurationProvider provider1; + private Object key1; @Mock - private ConfigurationProvider provider2; + private Object key2; @Before public void setUp() throws Exception { @@ -51,37 +50,37 @@ public void setUp() throws Exception { @Test public void registerAllowlist() { - providerAllowlist.registerAllowlist(provider1, new HashSet<>(asList(String.class, Integer.class))); - providerAllowlist.registerAllowlist(provider2, new HashSet<>(asList(Double.class, Integer.class))); + providerAllowlist.registerAllowlist(key1, new HashSet<>(asList(String.class, Integer.class))); + providerAllowlist.registerAllowlist(key2, new HashSet<>(asList(Double.class, Integer.class))); assertThat(providerAllowlist.getProviderAllowlist()).containsExactlyInAnyOrder(String.class, Integer.class, Double.class); } @Test public void registerAllowlist_twice() { - providerAllowlist.registerAllowlist(provider1, new HashSet<>(asList(String.class, Integer.class))); - providerAllowlist.registerAllowlist(provider1, new HashSet<>(asList(Double.class, Integer.class))); + providerAllowlist.registerAllowlist(key1, new HashSet<>(asList(String.class, Integer.class))); + providerAllowlist.registerAllowlist(key1, new HashSet<>(asList(Double.class, Integer.class))); assertThat(providerAllowlist.getProviderAllowlist()).containsExactlyInAnyOrder(Integer.class, Double.class); } @Test public void clearAllowlist() { - providerAllowlist.registerAllowlist(provider1, new HashSet<>(asList(String.class, Integer.class))); - providerAllowlist.registerAllowlist(provider2, new HashSet<>(asList(Double.class, Integer.class))); + providerAllowlist.registerAllowlist(key1, new HashSet<>(asList(String.class, Integer.class))); + providerAllowlist.registerAllowlist(key2, new HashSet<>(asList(Double.class, Integer.class))); - providerAllowlist.clearAllowlist(provider1); + providerAllowlist.clearAllowlist(key1); assertThat(providerAllowlist.getProviderAllowlist()).containsExactlyInAnyOrder(Integer.class, Double.class); } @Test public void clearAllowlist_both() { - providerAllowlist.registerAllowlist(provider1, new HashSet<>(asList(String.class, Integer.class))); - providerAllowlist.registerAllowlist(provider2, new HashSet<>(asList(Double.class, Integer.class))); + providerAllowlist.registerAllowlist(key1, new HashSet<>(asList(String.class, Integer.class))); + providerAllowlist.registerAllowlist(key2, new HashSet<>(asList(Double.class, Integer.class))); - providerAllowlist.clearAllowlist(provider1); - providerAllowlist.clearAllowlist(provider2); + providerAllowlist.clearAllowlist(key1); + providerAllowlist.clearAllowlist(key2); assertThat(providerAllowlist.getProviderAllowlist()).isEmpty(); } diff --git a/plugins/convention/src/main/java/org/apache/struts2/convention/ClasspathConfigurationProvider.java b/plugins/convention/src/main/java/org/apache/struts2/convention/ClasspathConfigurationProvider.java index f3d8733221..71ac094cfb 100644 --- a/plugins/convention/src/main/java/org/apache/struts2/convention/ClasspathConfigurationProvider.java +++ b/plugins/convention/src/main/java/org/apache/struts2/convention/ClasspathConfigurationProvider.java @@ -36,7 +36,7 @@ *

*/ public class ClasspathConfigurationProvider implements ConfigurationProvider, DispatcherListener { - private ActionConfigBuilder actionConfigBuilder; + private final ActionConfigBuilder actionConfigBuilder; private boolean devMode; private boolean reload; private boolean listeningToDispatcher; @@ -59,6 +59,7 @@ public void setReload(String reload) { /** * Not used. */ + @Override public void destroy() { if (this.listeningToDispatcher) { Dispatcher.removeDispatcherListener(this); @@ -71,6 +72,7 @@ public void destroy() { * * @param configuration configuration */ + @Override public void init(Configuration configuration) { if (devMode && reload && !listeningToDispatcher) { //this is the only way I found to be able to get added to to ConfigurationProvider list @@ -88,6 +90,7 @@ public void init(Configuration configuration) { * * @throws ConfigurationException in case of configuration errors */ + @Override public void register(ContainerBuilder containerBuilder, LocatableProperties locatableProperties) throws ConfigurationException { } @@ -97,20 +100,24 @@ public void register(ContainerBuilder containerBuilder, LocatableProperties loca * * @throws ConfigurationException in case of configuration errors */ + @Override public void loadPackages() throws ConfigurationException { } /** * @return true if devMode, reload and actionConfigBuilder.needsReload() */ + @Override public boolean needsReload() { return devMode && reload && actionConfigBuilder.needsReload(); } + @Override public void dispatcherInitialized(Dispatcher du) { du.getConfigurationManager().addContainerProvider(this); } + @Override public void dispatcherDestroyed(Dispatcher du) { } -} \ No newline at end of file +} diff --git a/plugins/convention/src/main/java/org/apache/struts2/convention/ClasspathPackageProvider.java b/plugins/convention/src/main/java/org/apache/struts2/convention/ClasspathPackageProvider.java index 7b314c05b8..3ffec8488c 100644 --- a/plugins/convention/src/main/java/org/apache/struts2/convention/ClasspathPackageProvider.java +++ b/plugins/convention/src/main/java/org/apache/struts2/convention/ClasspathPackageProvider.java @@ -18,11 +18,11 @@ */ package org.apache.struts2.convention; -import com.opensymphony.xwork2.config.PackageProvider; import com.opensymphony.xwork2.config.Configuration; import com.opensymphony.xwork2.config.ConfigurationException; -import com.opensymphony.xwork2.inject.Inject; +import com.opensymphony.xwork2.config.PackageProvider; import com.opensymphony.xwork2.inject.Container; +import com.opensymphony.xwork2.inject.Inject; /** *

@@ -34,20 +34,23 @@ *

*/ public class ClasspathPackageProvider implements PackageProvider { - private ActionConfigBuilder actionConfigBuilder; + private final ActionConfigBuilder actionConfigBuilder; @Inject public ClasspathPackageProvider(Container container) { this.actionConfigBuilder = container.getInstance(ActionConfigBuilder.class, container.getInstance(String.class, ConventionConstants.CONVENTION_ACTION_CONFIG_BUILDER)); } + @Override public void init(Configuration configuration) throws ConfigurationException { } + @Override public boolean needsReload() { - return actionConfigBuilder.needsReload(); + return actionConfigBuilder.needsReload(); } + @Override public void loadPackages() throws ConfigurationException { actionConfigBuilder.buildActionConfigs(); } diff --git a/plugins/convention/src/main/java/org/apache/struts2/convention/PackageBasedActionConfigBuilder.java b/plugins/convention/src/main/java/org/apache/struts2/convention/PackageBasedActionConfigBuilder.java index 460cab49e0..71331d4efc 100644 --- a/plugins/convention/src/main/java/org/apache/struts2/convention/PackageBasedActionConfigBuilder.java +++ b/plugins/convention/src/main/java/org/apache/struts2/convention/PackageBasedActionConfigBuilder.java @@ -24,6 +24,7 @@ import com.opensymphony.xwork2.ObjectFactory; import com.opensymphony.xwork2.config.Configuration; import com.opensymphony.xwork2.config.ConfigurationException; +import com.opensymphony.xwork2.config.ConfigurationUtil; import com.opensymphony.xwork2.config.entities.ActionConfig; import com.opensymphony.xwork2.config.entities.ExceptionMappingConfig; import com.opensymphony.xwork2.config.entities.InterceptorMapping; @@ -57,6 +58,7 @@ import org.apache.struts2.convention.annotation.Namespace; import org.apache.struts2.convention.annotation.Namespaces; import org.apache.struts2.convention.annotation.ParentPackage; +import org.apache.struts2.ognl.ProviderAllowlist; import java.io.IOException; import java.lang.reflect.Method; @@ -125,6 +127,9 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder { private FileManager fileManager; private ClassFinderFactory classFinderFactory; + private final Set> allowlistClasses = new HashSet<>(); + private ProviderAllowlist providerAllowlist; + /** * Constructs actions based on a list of packages. * @@ -167,6 +172,11 @@ public void setDevMode(String mode) { this.devMode = BooleanUtils.toBoolean(mode); } + @Inject + public void setProviderAllowlist(ProviderAllowlist providerAllowlist) { + this.providerAllowlist = providerAllowlist; + } + /** * @param reload Reload configuration when classes change. Defaults to "false" and should not be used * in production. @@ -345,33 +355,38 @@ protected ClassLoader getClassLoader() { * annotation which is used to control the parent package for a specific action. Lastly, the * {@link ResultMapBuilder} is used to create ResultConfig instances of the action. */ + @Override public void buildActionConfigs() { + allowlistClasses.clear(); + //setup reload class loader based on dev settings initReloadClassLoader(); - if (!disableActionScanning) { - if (actionPackages == null && packageLocators == null) { - throw new ConfigurationException("At least a list of action packages or action package locators " + - "must be given using one of the properties [struts.convention.action.packages] or " + - "[struts.convention.package.locators]"); - } + if (disableActionScanning) { + return; + } - if (LOG.isTraceEnabled()) { - LOG.trace("Loading action configurations"); - if (actionPackages != null) { - LOG.trace("Actions being loaded from action packages: {}", (Object[]) actionPackages); - } - if (packageLocators != null) { - LOG.trace("Actions being loaded using package locator's: {}", (Object[]) packageLocators); - } - if (excludePackages != null) { - LOG.trace("Excluding actions from packages: {}", (Object[]) excludePackages); - } - } + if (actionPackages == null && packageLocators == null) { + throw new ConfigurationException("At least a list of action packages or action package locators " + + "must be given using one of the properties [struts.convention.action.packages] or " + + "[struts.convention.package.locators]"); + } - Set> classes = findActions(); - buildConfiguration(classes); + if (LOG.isTraceEnabled()) { + LOG.trace("Loading action configurations"); + if (actionPackages != null) { + LOG.trace("Actions being loaded from action packages: {}", (Object[]) actionPackages); + } + if (packageLocators != null) { + LOG.trace("Actions being loaded using package locator's: {}", (Object[]) packageLocators); + } + if (excludePackages != null) { + LOG.trace("Excluding actions from packages: {}", (Object[]) excludePackages); + } } + + Set> classes = findActions(); + buildConfiguration(classes); } protected ClassLoaderInterface getClassLoaderInterface() { @@ -765,7 +780,10 @@ protected void buildConfiguration(Set> classes) { } else if (actionAnnotation != null) createActionConfig(defaultPackageConfig, actionClass, defaultActionName, methodName, actionAnnotation, allowedMethods); } + + allowlistClasses.addAll(ConfigurationUtil.getAllClassTypes(actionClass)); } + providerAllowlist.registerAllowlist(this, allowlistClasses); buildIndexActions(packageConfigs); @@ -1153,10 +1171,13 @@ protected void buildIndexActions(Map packageConfi } } + @Override public void destroy() { loadedFileUrls.clear(); + providerAllowlist.clearAllowlist(this); } + @Override public boolean needsReload() { if (devMode && reload) { for (String url : loadedFileUrls) { diff --git a/plugins/convention/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java b/plugins/convention/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java index c44ca335a7..1643ce7ae5 100644 --- a/plugins/convention/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java +++ b/plugins/convention/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java @@ -18,9 +18,21 @@ */ package org.apache.struts2.convention; -import com.opensymphony.xwork2.*; +import com.opensymphony.xwork2.ActionChainResult; +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.FileManager; +import com.opensymphony.xwork2.FileManagerFactory; +import com.opensymphony.xwork2.ObjectFactory; +import com.opensymphony.xwork2.Result; import com.opensymphony.xwork2.config.Configuration; -import com.opensymphony.xwork2.config.entities.*; +import com.opensymphony.xwork2.config.entities.ActionConfig; +import com.opensymphony.xwork2.config.entities.ExceptionMappingConfig; +import com.opensymphony.xwork2.config.entities.InterceptorConfig; +import com.opensymphony.xwork2.config.entities.InterceptorMapping; +import com.opensymphony.xwork2.config.entities.InterceptorStackConfig; +import com.opensymphony.xwork2.config.entities.PackageConfig; +import com.opensymphony.xwork2.config.entities.ResultConfig; +import com.opensymphony.xwork2.config.entities.ResultTypeConfig; import com.opensymphony.xwork2.config.impl.DefaultConfiguration; import com.opensymphony.xwork2.factory.DefaultInterceptorFactory; import com.opensymphony.xwork2.factory.DefaultResultFactory; @@ -32,12 +44,20 @@ import com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory; import com.opensymphony.xwork2.util.reflection.ReflectionException; import junit.framework.TestCase; - import org.apache.commons.lang3.StringUtils; import org.apache.struts2.convention.actions.DefaultResultPathAction; import org.apache.struts2.convention.actions.NoAnnotationAction; import org.apache.struts2.convention.actions.Skip; -import org.apache.struts2.convention.actions.action.*; +import org.apache.struts2.convention.actions.action.ActionNameAction; +import org.apache.struts2.convention.actions.action.ActionNamesAction; +import org.apache.struts2.convention.actions.action.ClassLevelAnnotationAction; +import org.apache.struts2.convention.actions.action.ClassLevelAnnotationDefaultMethodAction; +import org.apache.struts2.convention.actions.action.ClassLevelAnnotationsAction; +import org.apache.struts2.convention.actions.action.ClassLevelAnnotationsDefaultMethodAction; +import org.apache.struts2.convention.actions.action.ClassNameAction; +import org.apache.struts2.convention.actions.action.SingleActionNameAction; +import org.apache.struts2.convention.actions.action.TestAction; +import org.apache.struts2.convention.actions.action.TestExtends; import org.apache.struts2.convention.actions.allowedmethods.ClassLevelAllowedMethodsAction; import org.apache.struts2.convention.actions.allowedmethods.PackageLevelAllowedMethodsAction; import org.apache.struts2.convention.actions.allowedmethods.sub.PackageLevelAllowedMethodsChildAction; @@ -61,7 +81,15 @@ import org.apache.struts2.convention.actions.parentpackage.PackageLevelParentPackageAction; import org.apache.struts2.convention.actions.parentpackage.sub.ClassLevelParentPackageChildAction; import org.apache.struts2.convention.actions.parentpackage.sub.PackageLevelParentPackageChildAction; -import org.apache.struts2.convention.actions.result.*; +import org.apache.struts2.convention.actions.result.ActionLevelResultAction; +import org.apache.struts2.convention.actions.result.ActionLevelResultsAction; +import org.apache.struts2.convention.actions.result.ActionLevelResultsNamesAction; +import org.apache.struts2.convention.actions.result.ClassLevelResultAction; +import org.apache.struts2.convention.actions.result.ClassLevelResultsAction; +import org.apache.struts2.convention.actions.result.GlobalResultAction; +import org.apache.struts2.convention.actions.result.GlobalResultOverrideAction; +import org.apache.struts2.convention.actions.result.InheritedResultExtends; +import org.apache.struts2.convention.actions.result.OverrideResultAction; import org.apache.struts2.convention.actions.resultpath.ClassLevelResultPathAction; import org.apache.struts2.convention.actions.resultpath.PackageLevelResultPathAction; import org.apache.struts2.convention.actions.skip.Index; @@ -69,15 +97,24 @@ import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Actions; import org.apache.struts2.convention.dontfind.DontFindMeAction; +import org.apache.struts2.ognl.ProviderAllowlist; import org.apache.struts2.result.ServletDispatcherResult; import org.easymock.EasyMock; import javax.servlet.ServletContext; import java.net.MalformedURLException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; import static org.apache.struts2.convention.ReflectionTools.getAnnotation; -import static org.easymock.EasyMock.*; +import static org.easymock.EasyMock.checkOrder; +import static org.easymock.EasyMock.createStrictMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.verify; /** *

@@ -388,6 +425,7 @@ public Container getContainer() { fileManagerFactory.setFileManager(new DefaultFileManager()); builder.setFileManagerFactory(fileManagerFactory); builder.setPackageLocatorsBase("org.apache.struts2.convention.actions"); + builder.setProviderAllowlist(new ProviderAllowlist()); builder.buildActionConfigs(); verify(resultMapBuilder); From 27e4d0d47aded060f12fd2121273d6a4eb69c206 Mon Sep 17 00:00:00 2001 From: Kusal Kithul-Godage Date: Sat, 13 Jul 2024 23:25:31 +1000 Subject: [PATCH 6/6] WW-5440 Fix inconsistent indenting --- .../showcase/action/AbstractCRUDAction.java | 92 +++++++++---------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/action/AbstractCRUDAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/action/AbstractCRUDAction.java index 2880f36581..e5204a1fad 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/action/AbstractCRUDAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/action/AbstractCRUDAction.java @@ -34,62 +34,62 @@ public abstract class AbstractCRUDAction extends ActionSupport { - private static final Logger log = LogManager.getLogger(AbstractCRUDAction.class); + private static final Logger log = LogManager.getLogger(AbstractCRUDAction.class); - private Collection availableItems; - private String[] toDelete; + private Collection availableItems; + private String[] toDelete; - protected abstract Dao getDao(); + protected abstract Dao getDao(); - public Collection getAvailableItems() { - return availableItems; - } + public Collection getAvailableItems() { + return availableItems; + } - public String[] getToDelete() { - return toDelete; - } + public String[] getToDelete() { + return toDelete; + } - @StrutsParameter - public void setToDelete(String[] toDelete) { - this.toDelete = toDelete; - } + @StrutsParameter + public void setToDelete(String[] toDelete) { + this.toDelete = toDelete; + } - public String list() throws Exception { - this.availableItems = getDao().findAll(); - if (log.isDebugEnabled()) { - log.debug("AbstractCRUDAction - [list]: " + (availableItems != null ? "" + availableItems.size() : "no") + " items found"); - } - return execute(); - } + public String list() throws Exception { + this.availableItems = getDao().findAll(); + if (log.isDebugEnabled()) { + log.debug("AbstractCRUDAction - [list]: " + (availableItems != null ? "" + availableItems.size() : "no") + " items found"); + } + return execute(); + } - public String delete() throws Exception { - if (toDelete != null) { - int count = 0; + public String delete() throws Exception { + if (toDelete != null) { + int count = 0; for (String s : toDelete) { count = count + getDao().delete(s); } - if (log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug("AbstractCRUDAction - [delete]: {} items deleted.", count); - } - } - return SUCCESS; - } + } + } + return SUCCESS; + } - /** - * Utility method for fetching already persistent object from storage for usage in params-prepare-params cycle. - * - * @param tryId The id to try to get persistent object for - * @param tryObject The object, induced by first params invocation, possibly containing id to try to get persistent - * object for - * @return The persistent object, if found. null otherwise. - */ - protected IdEntity fetch(Serializable tryId, IdEntity tryObject) { - IdEntity result = null; - if (tryId != null) { - result = getDao().get(tryId); - } else if (tryObject != null) { - result = getDao().get(tryObject.getId()); - } - return result; - } + /** + * Utility method for fetching already persistent object from storage for usage in params-prepare-params cycle. + * + * @param tryId The id to try to get persistent object for + * @param tryObject The object, induced by first params invocation, possibly containing id to try to get persistent + * object for + * @return The persistent object, if found. null otherwise. + */ + protected IdEntity fetch(Serializable tryId, IdEntity tryObject) { + IdEntity result = null; + if (tryId != null) { + result = getDao().get(tryId); + } else if (tryObject != null) { + result = getDao().get(tryObject.getId()); + } + return result; + } }