diff --git a/.asf.yaml b/.asf.yaml index 673c6e25c..87706aa57 100644 --- a/.asf.yaml +++ b/.asf.yaml @@ -13,7 +13,13 @@ notifications: github: del_branch_on_merge: true protected_branches: - master: { } + master: + # contexts are the names of checks that must pass. + contexts: + - build + required_pull_request_reviews: + require_code_owner_reviews: true + required_approving_review_count: 1 autolink_jira: - WW dependabot_alerts: true diff --git a/README.md b/README.md index ca6366563..cdabef1fc 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ The Apache Struts web framework ------------------------------- -[![Jenkins Build](https://builds.apache.org/buildStatus/icon?job=Struts%2FStruts+Core%2Fmaster)](https://ci-builds.apache.org/job/Struts/job/Struts%20Core/job/master/) +[![Build Status](https://ci-builds.apache.org/buildStatus/icon?job=Struts%2FStruts+Core%2Fmaster)](https://ci-builds.apache.org/job/Struts/job/Struts%20Core/job/master/) [![Java Build](https://github.com/apache/struts/actions/workflows/maven.yml/badge.svg)](https://github.com/apache/struts/actions/workflows/maven.yml) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.struts/struts2-core/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.apache.struts/struts2-core/) [![Javadocs](https://javadoc.io/badge/org.apache.struts/struts2-core.svg)](https://javadoc.io/doc/org.apache.struts/struts2-core) diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/fileupload/FileUploadAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/fileupload/FileUploadAction.java index a1381c08c..279c1e928 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/fileupload/FileUploadAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/fileupload/FileUploadAction.java @@ -25,7 +25,6 @@ import org.apache.struts2.action.UploadedFilesAware; import org.apache.struts2.dispatcher.multipart.UploadedFile; import org.apache.struts2.interceptor.parameter.StrutsParameter; -import java.io.File; import java.util.List; /** @@ -34,7 +33,7 @@ import java.util.List; public class FileUploadAction extends ActionSupport implements UploadedFilesAware { private String contentType; - private UploadedFile uploadedFile; + private UploadedFile uploadedFile; private String fileName; private String caption; private String originalName; @@ -81,7 +80,7 @@ public class FileUploadAction extends ActionSupport implements UploadedFilesAwar } @Override - public void withUploadedFiles(List> uploadedFiles) { + public void withUploadedFiles(List uploadedFiles) { this.uploadedFile = uploadedFiles.get(0); this.fileName = uploadedFile.getName(); this.contentType = uploadedFile.getContentType(); 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 dcf671e5e..59ea954e2 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 @@ -22,61 +22,51 @@ package org.apache.struts2.showcase.fileupload; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.action.UploadedFilesAware; +import org.apache.struts2.dispatcher.multipart.UploadedFile; -import java.io.File; +import java.util.List; /** * Showcase action - mutiple file upload using array. - * - * @version $Date$ $Id$ */ -public class MultipleFileUploadUsingArrayAction extends ActionSupport { +public class MultipleFileUploadUsingArrayAction extends ActionSupport implements UploadedFilesAware { - private File[] uploads = new File[0]; - private String[] uploadFileNames = new String[0]; - private String[] uploadContentTypes = new String[0]; + private List uploadedFiles; + public String upload() throws Exception { + System.out.println("\n\n upload2"); + System.out.println("files:"); + for (UploadedFile u : uploadedFiles) { + System.out.println("*** " + u + "\t" + u.length()); + } + System.out.println("filenames:"); + for (String n : getUploadFileNames()) { + System.out.println("*** " + n); + } + System.out.println("content types:"); + for (String c : getUploadContentTypes()) { + System.out.println("*** " + c); + } + System.out.println("\n\n"); + return SUCCESS; + } - public String upload() throws Exception { - System.out.println("\n\n upload2"); - System.out.println("files:"); - for (File u : uploads) { - System.out.println("*** " + u + "\t" + u.length()); - } - System.out.println("filenames:"); - for (String n : uploadFileNames) { - System.out.println("*** " + n); - } - System.out.println("content types:"); - for (String c : uploadContentTypes) { - System.out.println("*** " + c); - } - System.out.println("\n\n"); - return SUCCESS; - } + @Override + public void withUploadedFiles(List uploadedFiles) { + this.uploadedFiles = uploadedFiles; + } - public File[] getUpload() { - return this.uploads; - } + private String[] getUploadFileNames() { + return this.uploadedFiles.stream() + .map(UploadedFile::getOriginalName) + .toArray(String[]::new); + } - public void setUpload(File[] upload) { - this.uploads = upload; - } + private String[] getUploadContentTypes() { + return this.uploadedFiles.stream() + .map(UploadedFile::getContentType) + .toArray(String[]::new); + } - public String[] getUploadFileName() { - return this.uploadFileNames; - } - - public void setUploadFileName(String[] uploadFileName) { - this.uploadFileNames = uploadFileName; - } - - public String[] getUploadContentType() { - return this.uploadContentTypes; - } - - public void setUploadContentType(String[] uploadContentType) { - this.uploadContentTypes = uploadContentType; - } } -// END SNIPPET: entire-file \ No newline at end of file diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/fileupload/MultipleFileUploadUsingListAction.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/fileupload/MultipleFileUploadUsingListAction.java index 7b4325e98..e60b0df3e 100644 --- a/apps/showcase/src/main/java/org/apache/struts2/showcase/fileupload/MultipleFileUploadUsingListAction.java +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/fileupload/MultipleFileUploadUsingListAction.java @@ -22,64 +22,56 @@ package org.apache.struts2.showcase.fileupload; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.action.UploadedFilesAware; +import org.apache.struts2.dispatcher.multipart.UploadedFile; -import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; /** * Showcase action - multiple file upload using List - * - * @version $Date$ $Id$ */ -public class MultipleFileUploadUsingListAction extends ActionSupport { +public class MultipleFileUploadUsingListAction extends ActionSupport implements UploadedFilesAware { - private List uploads = new ArrayList<>(); - private List uploadFileNames = new ArrayList<>(); - private List uploadContentTypes = new ArrayList<>(); + private List uploads = new ArrayList<>(); + public List getUpload() { + return this.uploads; + } - public List getUpload() { - return this.uploads; - } + @Override + public void withUploadedFiles(List uploads) { + this.uploads = uploads; + } - public void setUpload(List uploads) { - this.uploads = uploads; - } + private List getUploadFileNames() { + return this.uploads.stream() + .map(UploadedFile::getOriginalName) + .collect(Collectors.toList()); + } - public List getUploadFileName() { - return this.uploadFileNames; - } + private List getUploadContentTypes() { + return this.uploads.stream() + .map(UploadedFile::getContentType) + .collect(Collectors.toList()); + } - public void setUploadFileName(List uploadFileNames) { - this.uploadFileNames = uploadFileNames; - } - - public List getUploadContentType() { - return this.uploadContentTypes; - } - - public void setUploadContentType(List contentTypes) { - this.uploadContentTypes = contentTypes; - } - - public String upload() throws Exception { - - System.out.println("\n\n upload1"); - System.out.println("files:"); - for (File u : uploads) { - System.out.println("*** " + u + "\t" + u.length()); - } - System.out.println("filenames:"); - for (String n : uploadFileNames) { - System.out.println("*** " + n); - } - System.out.println("content types:"); - for (String c : uploadContentTypes) { - System.out.println("*** " + c); - } - System.out.println("\n\n"); - return SUCCESS; - } -} -// END SNIPPET: entire-file \ No newline at end of file + public String upload() throws Exception { + System.out.println("\n\n upload1"); + System.out.println("files:"); + for (UploadedFile u : uploads) { + System.out.println("*** " + u + "\t" + u.length()); + } + System.out.println("filenames:"); + for (String n : getUploadFileNames()) { + System.out.println("*** " + n); + } + System.out.println("content types:"); + for (String c : getUploadContentTypes()) { + System.out.println("*** " + c); + } + System.out.println("\n\n"); + return SUCCESS; + } +} \ No newline at end of file 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 bae553789..cad52fb79 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 @@ -142,7 +142,9 @@ public abstract class XmlDocConfigurationProvider implements ConfigurationProvid @Override public void destroy() { - providerAllowlist.clearAllowlist(this); + if (providerAllowlist != null) { + providerAllowlist.clearAllowlist(this); + } } protected Class allowAndLoadClass(String className) throws ClassNotFoundException { diff --git a/core/src/main/java/org/apache/struts2/action/UploadedFilesAware.java b/core/src/main/java/org/apache/struts2/action/UploadedFilesAware.java index 2946af23a..92ec9c98b 100644 --- a/core/src/main/java/org/apache/struts2/action/UploadedFilesAware.java +++ b/core/src/main/java/org/apache/struts2/action/UploadedFilesAware.java @@ -20,7 +20,6 @@ package org.apache.struts2.action; import org.apache.struts2.dispatcher.multipart.UploadedFile; -import java.io.File; import java.util.List; /** @@ -36,6 +35,6 @@ public interface UploadedFilesAware { * * @param uploadedFiles a list of {@link UploadedFile}, cannot be null. It can be empty. */ - void withUploadedFiles(List> uploadedFiles); + void withUploadedFiles(List uploadedFiles); } diff --git a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java index 4b335afe6..70bbf70dd 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java @@ -987,10 +987,12 @@ public class Dispatcher { public HttpServletRequest wrapRequest(HttpServletRequest request) throws IOException { // don't wrap more than once if (request instanceof StrutsRequestWrapper) { + LOG.debug("Request already wrapped with: {}", StrutsRequestWrapper.class.getSimpleName()); return request; } if (isMultipartSupportEnabled(request) && isMultipartRequest(request)) { + LOG.debug("Wrapping multipart request with: {}", MultiPartRequestWrapper.class.getSimpleName()); request = new MultiPartRequestWrapper( getMultiPartRequest(), request, @@ -999,6 +1001,7 @@ public class Dispatcher { disableRequestAttributeValueStackLookup ); } else { + LOG.debug("Wrapping request using: {}", StrutsRequestWrapper.class.getSimpleName()); request = new StrutsRequestWrapper(request, disableRequestAttributeValueStackLookup); } @@ -1013,6 +1016,7 @@ public class Dispatcher { * @since 2.5.11 */ protected boolean isMultipartSupportEnabled(HttpServletRequest request) { + LOG.debug("Support for multipart request is enabled: {}", multipartSupportEnabled); return multipartSupportEnabled; } @@ -1027,9 +1031,12 @@ public class Dispatcher { String httpMethod = request.getMethod(); String contentType = request.getContentType(); - return REQUEST_POST_METHOD.equalsIgnoreCase(httpMethod) && - contentType != null && - multipartValidationPattern.matcher(contentType.toLowerCase(Locale.ENGLISH)).matches(); + boolean isPostRequest = REQUEST_POST_METHOD.equalsIgnoreCase(httpMethod); + boolean isProperContentType = contentType != null && multipartValidationPattern.matcher(contentType.toLowerCase(Locale.ENGLISH)).matches(); + + LOG.debug("Validating if this is a proper Multipart request. Request is POST: {} and ContentType matches pattern ({}): {}", + isPostRequest, multipartValidationPattern, isProperContentType); + return isPostRequest && isProperContentType; } /** diff --git a/core/src/main/java/org/apache/struts2/dispatcher/multipart/AbstractMultiPartRequest.java b/core/src/main/java/org/apache/struts2/dispatcher/multipart/AbstractMultiPartRequest.java index 1c9148047..630d2ca43 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/multipart/AbstractMultiPartRequest.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/multipart/AbstractMultiPartRequest.java @@ -46,7 +46,7 @@ import java.util.Map; * Abstract class with some helper methods, it should be used * when starting development of another implementation of {@link MultiPartRequest} */ -public abstract class AbstractMultiPartRequest implements MultiPartRequest { +public abstract class AbstractMultiPartRequest implements MultiPartRequest { protected static final String STRUTS_MESSAGES_UPLOAD_ERROR_PARAMETER_TOO_LONG_KEY = "struts.messages.upload.error.parameter.too.long"; @@ -100,7 +100,7 @@ public abstract class AbstractMultiPartRequest implements MultiPartRequest { /** * Map between file fields and file data. */ - protected Map>> uploadedFiles = new HashMap<>(); + protected Map> uploadedFiles = new HashMap<>(); /** * Map between non-file fields and values. @@ -326,8 +326,7 @@ public abstract class AbstractMultiPartRequest implements MultiPartRequest { /* (non-Javadoc) * @see org.apache.struts2.dispatcher.multipart.MultiPartRequest#getFile(java.lang.String) */ - @SuppressWarnings("unchecked") - public UploadedFile[] getFile(String fieldName) { + public UploadedFile[] getFile(String fieldName) { return uploadedFiles.getOrDefault(fieldName, Collections.emptyList()) .toArray(UploadedFile[]::new); } @@ -383,8 +382,8 @@ public abstract class AbstractMultiPartRequest implements MultiPartRequest { public void cleanUp() { try { LOG.debug("Performing File Upload temporary storage cleanup."); - for (List> uploadedFileList : uploadedFiles.values()) { - for (UploadedFile uploadedFile : uploadedFileList) { + for (List uploadedFileList : uploadedFiles.values()) { + for (UploadedFile uploadedFile : uploadedFileList) { if (uploadedFile.isFile()) { LOG.debug("Deleting file: {}", uploadedFile.getName()); if (!uploadedFile.delete()) { diff --git a/core/src/main/java/org/apache/struts2/dispatcher/multipart/JakartaMultiPartRequest.java b/core/src/main/java/org/apache/struts2/dispatcher/multipart/JakartaMultiPartRequest.java index c71a1ee25..b3227cb64 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/multipart/JakartaMultiPartRequest.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/multipart/JakartaMultiPartRequest.java @@ -26,7 +26,6 @@ import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.io.File; import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Path; @@ -36,7 +35,7 @@ import java.util.List; /** * Multipart form data request adapter for Jakarta Commons FileUpload package. */ -public class JakartaMultiPartRequest extends AbstractMultiPartRequest { +public class JakartaMultiPartRequest extends AbstractMultiPartRequest { private static final Logger LOG = LogManager.getLogger(JakartaMultiPartRequest.class); @@ -104,7 +103,7 @@ public class JakartaMultiPartRequest extends AbstractMultiPartRequest { return; } - List> values; + List values; if (uploadedFiles.get(item.getFieldName()) != null) { values = uploadedFiles.get(item.getFieldName()); } else { @@ -114,7 +113,7 @@ public class JakartaMultiPartRequest extends AbstractMultiPartRequest { if (item.isInMemory()) { LOG.warn("Storing uploaded files just in memory isn't supported currently, skipping file: {}!", item.getName()); } else { - UploadedFile uploadedFile = StrutsUploadedFile.Builder + UploadedFile uploadedFile = StrutsUploadedFile.Builder .create(item.getPath().toFile()) .withOriginalName(item.getName()) .withContentType(item.getContentType()) diff --git a/core/src/main/java/org/apache/struts2/dispatcher/multipart/JakartaStreamMultiPartRequest.java b/core/src/main/java/org/apache/struts2/dispatcher/multipart/JakartaStreamMultiPartRequest.java index c6457c605..df7b07e22 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/multipart/JakartaStreamMultiPartRequest.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/multipart/JakartaStreamMultiPartRequest.java @@ -50,7 +50,7 @@ import java.util.UUID; * * @since 2.3.18 */ -public class JakartaStreamMultiPartRequest extends AbstractMultiPartRequest { +public class JakartaStreamMultiPartRequest extends AbstractMultiPartRequest { private static final Logger LOG = LogManager.getLogger(JakartaStreamMultiPartRequest.class); @@ -247,7 +247,7 @@ public class JakartaStreamMultiPartRequest extends AbstractMultiPartRequest uploadedFile = StrutsUploadedFile.Builder + UploadedFile uploadedFile = StrutsUploadedFile.Builder .create(file) .withOriginalName(fileName) .withContentType(fileItemInput.getContentType()) @@ -256,7 +256,7 @@ public class JakartaStreamMultiPartRequest extends AbstractMultiPartRequest> infos = new ArrayList<>(); + List infos = new ArrayList<>(); infos.add(uploadedFile); uploadedFiles.put(fieldName, infos); } diff --git a/core/src/main/java/org/apache/struts2/dispatcher/multipart/MultiPartRequest.java b/core/src/main/java/org/apache/struts2/dispatcher/multipart/MultiPartRequest.java index d366bd5e3..72392cd6f 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/multipart/MultiPartRequest.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/multipart/MultiPartRequest.java @@ -58,7 +58,7 @@ public interface MultiPartRequest { * @param fieldName input field name * @return a UploadedFile[] object for files associated with the specified input field name */ - UploadedFile[] getFile(String fieldName); + UploadedFile[] getFile(String fieldName); /** * Returns a String[] of file names for files associated with the specified input field name diff --git a/core/src/main/java/org/apache/struts2/dispatcher/multipart/MultiPartRequestWrapper.java b/core/src/main/java/org/apache/struts2/dispatcher/multipart/MultiPartRequestWrapper.java index 7ddadb8c5..532a5e45a 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/multipart/MultiPartRequestWrapper.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/multipart/MultiPartRequestWrapper.java @@ -26,7 +26,6 @@ import org.apache.struts2.dispatcher.StrutsRequestWrapper; import jakarta.servlet.http.HttpServletRequest; -import java.io.File; import java.io.IOException; import java.util.*; @@ -139,7 +138,7 @@ public class MultiPartRequestWrapper extends StrutsRequestWrapper { * @param fieldName input field name * @return a File[] object for files associated with the specified input field name */ - public UploadedFile[] getFiles(String fieldName) { + public UploadedFile[] getFiles(String fieldName) { if (multi == null) { return null; } diff --git a/core/src/main/java/org/apache/struts2/dispatcher/multipart/StrutsUploadedFile.java b/core/src/main/java/org/apache/struts2/dispatcher/multipart/StrutsUploadedFile.java index 2359b222c..07e936ef0 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/multipart/StrutsUploadedFile.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/multipart/StrutsUploadedFile.java @@ -20,7 +20,7 @@ package org.apache.struts2.dispatcher.multipart; import java.io.File; -public class StrutsUploadedFile implements UploadedFile { +public class StrutsUploadedFile implements UploadedFile { private final File file; private final String contentType; @@ -116,7 +116,7 @@ public class StrutsUploadedFile implements UploadedFile { return this; } - public UploadedFile build() { + public UploadedFile build() { return new StrutsUploadedFile(this.file, this.contentType, this.originalName); } } diff --git a/core/src/main/java/org/apache/struts2/dispatcher/multipart/UploadedFile.java b/core/src/main/java/org/apache/struts2/dispatcher/multipart/UploadedFile.java index c48054765..ddebac122 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/multipart/UploadedFile.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/multipart/UploadedFile.java @@ -23,7 +23,7 @@ import java.io.Serializable; /** * Virtual representation of an uploaded file used by {@link MultiPartRequest} */ -public interface UploadedFile extends Serializable { +public interface UploadedFile extends Serializable { /** * @return size of the content of file/stream/array @@ -58,7 +58,7 @@ public interface UploadedFile extends Serializable { /** * @return content of the upload file */ - T getContent(); + Object getContent(); /** * @return content type of the uploaded file diff --git a/core/src/main/java/org/apache/struts2/interceptor/AbstractFileUploadInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/AbstractFileUploadInterceptor.java index 264f6b9c1..1113f4491 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/AbstractFileUploadInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/AbstractFileUploadInterceptor.java @@ -34,7 +34,6 @@ import org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper; import org.apache.struts2.dispatcher.multipart.UploadedFile; import org.apache.struts2.util.ContentTypeMatcher; -import java.io.File; import java.text.NumberFormat; import java.util.Arrays; import java.util.Collection; @@ -109,7 +108,7 @@ public abstract class AbstractFileUploadInterceptor extends AbstractInterceptor * @param inputName - inputName of the file. * @return true if the proposed file is acceptable by contentType and size. */ - protected boolean acceptFile(Object action, UploadedFile file, String originalFilename, String contentType, String inputName) { + protected boolean acceptFile(Object action, UploadedFile file, String originalFilename, String contentType, String inputName) { Set errorMessages = new HashSet<>(); ValidationAware validation = null; diff --git a/core/src/main/java/org/apache/struts2/interceptor/ActionFileUploadInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/ActionFileUploadInterceptor.java index 72fe043da..3cd0529ae 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/ActionFileUploadInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/ActionFileUploadInterceptor.java @@ -28,7 +28,6 @@ import org.apache.struts2.action.UploadedFilesAware; import org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper; import org.apache.struts2.dispatcher.multipart.UploadedFile; -import java.io.File; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; @@ -154,19 +153,19 @@ public class ActionFileUploadInterceptor extends AbstractFileUploadInterceptor { // bind allowed Files Enumeration fileParameterNames = multiWrapper.getFileParameterNames(); - List> acceptedFiles = new ArrayList<>(); + List acceptedFiles = new ArrayList<>(); while (fileParameterNames != null && fileParameterNames.hasMoreElements()) { // get the value of this input tag String inputName = fileParameterNames.nextElement(); - UploadedFile[] uploadedFiles = multiWrapper.getFiles(inputName); + UploadedFile[] uploadedFiles = multiWrapper.getFiles(inputName); if (uploadedFiles == null || uploadedFiles.length == 0) { if (LOG.isWarnEnabled()) { LOG.warn(getTextMessage(action, STRUTS_MESSAGES_INVALID_FILE_KEY, new String[]{inputName})); } } else { - for (UploadedFile uploadedFile : uploadedFiles) { + for (UploadedFile uploadedFile : uploadedFiles) { if (acceptFile(action, uploadedFile, uploadedFile.getOriginalName(), uploadedFile.getContentType(), inputName)) { acceptedFiles.add(uploadedFile); } diff --git a/core/src/main/java/org/apache/struts2/interceptor/ApplicationAware.java b/core/src/main/java/org/apache/struts2/interceptor/ApplicationAware.java new file mode 100644 index 000000000..166f484c9 --- /dev/null +++ b/core/src/main/java/org/apache/struts2/interceptor/ApplicationAware.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.interceptor; + +import java.util.Map; + +@Deprecated +public interface ApplicationAware extends org.apache.struts2.action.ApplicationAware { + + void setApplication(Map application); + + @Override + default void withApplication(Map application) { + setApplication(application); + } +} diff --git a/core/src/main/java/org/apache/struts2/interceptor/HttpParametersAware.java b/core/src/main/java/org/apache/struts2/interceptor/HttpParametersAware.java new file mode 100644 index 000000000..1c4b758f7 --- /dev/null +++ b/core/src/main/java/org/apache/struts2/interceptor/HttpParametersAware.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.interceptor; + +import org.apache.struts2.dispatcher.HttpParameters; + +@Deprecated +public interface HttpParametersAware extends org.apache.struts2.action.ParametersAware { + + void setParameters(HttpParameters parameters); + + @Override + default void withParameters(HttpParameters parameters) { + setParameters(parameters); + } +} diff --git a/core/src/main/java/org/apache/struts2/interceptor/ParameterAware.java b/core/src/main/java/org/apache/struts2/interceptor/ParameterAware.java new file mode 100644 index 000000000..561542376 --- /dev/null +++ b/core/src/main/java/org/apache/struts2/interceptor/ParameterAware.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.interceptor; + +import org.apache.struts2.dispatcher.HttpParameters; + +import java.util.Map; + +import static java.util.stream.Collectors.toMap; + +@Deprecated +public interface ParameterAware extends org.apache.struts2.action.ParametersAware { + + void setParameters(Map map); + + @Override + default void withParameters(HttpParameters parameters) { + setParameters(parameters.entrySet().stream().collect(toMap(Map.Entry::getKey, e -> e.getValue().getMultipleValues()))); + } +} diff --git a/core/src/main/java/org/apache/struts2/interceptor/PrincipalAware.java b/core/src/main/java/org/apache/struts2/interceptor/PrincipalAware.java new file mode 100644 index 000000000..dfe4203ff --- /dev/null +++ b/core/src/main/java/org/apache/struts2/interceptor/PrincipalAware.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.interceptor; + +@Deprecated +public interface PrincipalAware extends org.apache.struts2.action.PrincipalAware { + + void setPrincipalProxy(PrincipalProxy principalProxy); + + @Override + default void withPrincipalProxy(PrincipalProxy principalProxy) { + setPrincipalProxy(principalProxy); + } +} diff --git a/core/src/main/java/org/apache/struts2/interceptor/RequestAware.java b/core/src/main/java/org/apache/struts2/interceptor/RequestAware.java new file mode 100644 index 000000000..5e24e8dfb --- /dev/null +++ b/core/src/main/java/org/apache/struts2/interceptor/RequestAware.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.interceptor; + +import org.apache.struts2.dispatcher.RequestMap; + +import jakarta.servlet.http.HttpServletRequest; +import java.util.Map; + +@Deprecated +public interface RequestAware extends ServletRequestAware { + + @Override + default void setServletRequest(HttpServletRequest httpServletRequest) { + // default no-op + } + + @Override + default void withServletRequest(HttpServletRequest request) { + ServletRequestAware.super.withServletRequest(request); + setRequest(new RequestMap(request)); + } + + void setRequest(Map request); +} diff --git a/core/src/main/java/org/apache/struts2/interceptor/ServletRequestAware.java b/core/src/main/java/org/apache/struts2/interceptor/ServletRequestAware.java new file mode 100644 index 000000000..8f059d479 --- /dev/null +++ b/core/src/main/java/org/apache/struts2/interceptor/ServletRequestAware.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.interceptor; + +import jakarta.servlet.http.HttpServletRequest; + +@Deprecated +public interface ServletRequestAware extends org.apache.struts2.action.ServletRequestAware { + + void setServletRequest(HttpServletRequest httpServletRequest); + + @Override + default void withServletRequest(HttpServletRequest request) { + setServletRequest(request); + } +} diff --git a/core/src/main/java/org/apache/struts2/interceptor/ServletResponseAware.java b/core/src/main/java/org/apache/struts2/interceptor/ServletResponseAware.java new file mode 100644 index 000000000..de054878a --- /dev/null +++ b/core/src/main/java/org/apache/struts2/interceptor/ServletResponseAware.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.interceptor; + +import jakarta.servlet.http.HttpServletResponse; + +@Deprecated +public interface ServletResponseAware extends org.apache.struts2.action.ServletResponseAware { + + void setServletResponse(HttpServletResponse httpServletResponse); + + @Override + default void withServletResponse(HttpServletResponse response) { + setServletResponse(response); + } +} diff --git a/core/src/main/java/org/apache/struts2/interceptor/SessionAware.java b/core/src/main/java/org/apache/struts2/interceptor/SessionAware.java new file mode 100644 index 000000000..828284d53 --- /dev/null +++ b/core/src/main/java/org/apache/struts2/interceptor/SessionAware.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.interceptor; + +import java.util.Map; + +@Deprecated +public interface SessionAware extends org.apache.struts2.action.SessionAware { + + void setSession(Map session); + + @Override + default void withSession(Map session) { + setSession(session); + } +} diff --git a/core/src/main/java/org/apache/struts2/util/ServletContextAware.java b/core/src/main/java/org/apache/struts2/util/ServletContextAware.java new file mode 100644 index 000000000..593736643 --- /dev/null +++ b/core/src/main/java/org/apache/struts2/util/ServletContextAware.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.util; + +import jakarta.servlet.ServletContext; + +@Deprecated +public interface ServletContextAware extends org.apache.struts2.action.ServletContextAware { + + void setServletContext(ServletContext context); + + @Override + default void withServletContext(ServletContext context) { + setServletContext(context); + } +} diff --git a/core/src/test/java/org/apache/struts2/dispatcher/multipart/AbstractMultiPartRequestTest.java b/core/src/test/java/org/apache/struts2/dispatcher/multipart/AbstractMultiPartRequestTest.java index eaf7049ae..fb30bb289 100644 --- a/core/src/test/java/org/apache/struts2/dispatcher/multipart/AbstractMultiPartRequestTest.java +++ b/core/src/test/java/org/apache/struts2/dispatcher/multipart/AbstractMultiPartRequestTest.java @@ -46,9 +46,9 @@ abstract class AbstractMultiPartRequestTest { protected final String boundary = "_boundary_"; protected final String endline = "\r\n"; - protected AbstractMultiPartRequest multiPart; + protected AbstractMultiPartRequest multiPart; - abstract protected AbstractMultiPartRequest createMultipartRequest(); + abstract protected AbstractMultiPartRequest createMultipartRequest(); @BeforeClass public static void beforeClass() throws IOException { @@ -268,8 +268,8 @@ abstract class AbstractMultiPartRequestTest { .isEqualTo("5,6,7,8"); }); - List> uploadedFiles = new ArrayList<>(); - for (Map.Entry>> entry : multiPart.uploadedFiles.entrySet()) { + List uploadedFiles = new ArrayList<>(); + for (Map.Entry> entry : multiPart.uploadedFiles.entrySet()) { uploadedFiles.addAll(entry.getValue()); } diff --git a/core/src/test/java/org/apache/struts2/dispatcher/multipart/JakartaMultiPartRequestTest.java b/core/src/test/java/org/apache/struts2/dispatcher/multipart/JakartaMultiPartRequestTest.java index e24dc133d..c5fe42b1c 100644 --- a/core/src/test/java/org/apache/struts2/dispatcher/multipart/JakartaMultiPartRequestTest.java +++ b/core/src/test/java/org/apache/struts2/dispatcher/multipart/JakartaMultiPartRequestTest.java @@ -18,12 +18,10 @@ */ package org.apache.struts2.dispatcher.multipart; -import java.io.File; - public class JakartaMultiPartRequestTest extends AbstractMultiPartRequestTest { @Override - protected AbstractMultiPartRequest createMultipartRequest() { + protected AbstractMultiPartRequest createMultipartRequest() { return new JakartaMultiPartRequest(); } diff --git a/core/src/test/java/org/apache/struts2/interceptor/ActionFileUploadInterceptorTest.java b/core/src/test/java/org/apache/struts2/interceptor/ActionFileUploadInterceptorTest.java index 0c383e024..5b63c7147 100644 --- a/core/src/test/java/org/apache/struts2/interceptor/ActionFileUploadInterceptorTest.java +++ b/core/src/test/java/org/apache/struts2/interceptor/ActionFileUploadInterceptorTest.java @@ -51,7 +51,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class ActionFileUploadInterceptorTest extends StrutsInternalTestCase { - private static final UploadedFile EMPTY_FILE = new UploadedFile<>() { + private static final UploadedFile EMPTY_FILE = new UploadedFile() { @Override public Long length() { return 0L; @@ -210,7 +210,7 @@ public class ActionFileUploadInterceptorTest extends StrutsInternalTestCase { URL url = ClassLoaderUtil.getResource("log4j2.xml", ActionFileUploadInterceptorTest.class); File file = new File(new URI(url.toString())); assertTrue("log4j2.xml should be in src/test folder", file.exists()); - UploadedFile uploadedFile = StrutsUploadedFile.Builder.create(file).withContentType("text/html").withOriginalName("filename").build(); + UploadedFile uploadedFile = StrutsUploadedFile.Builder.create(file).withContentType("text/html").withOriginalName("filename").build(); boolean notOk = interceptor.acceptFile(validation, uploadedFile, "filename", "text/html", "inputName"); assertFalse(notOk); @@ -310,7 +310,7 @@ public class ActionFileUploadInterceptorTest extends StrutsInternalTestCase { assertFalse(action.hasErrors()); - List> files = action.getUploadFiles(); + List files = action.getUploadFiles(); assertNotNull(files); assertEquals(1, files.size()); @@ -345,7 +345,7 @@ public class ActionFileUploadInterceptorTest extends StrutsInternalTestCase { interceptor.setAllowedTypes("text/html"); interceptor.intercept(mai); - List> files = action.getUploadFiles(); + List files = action.getUploadFiles(); assertNotNull(files); assertEquals("files accepted ", 2, files.size()); @@ -563,14 +563,14 @@ public class ActionFileUploadInterceptorTest extends StrutsInternalTestCase { } public static class MyFileUploadAction extends ActionSupport implements UploadedFilesAware { - private List> uploadedFiles; + private List uploadedFiles; @Override - public void withUploadedFiles(List> uploadedFiles) { + public void withUploadedFiles(List uploadedFiles) { this.uploadedFiles = uploadedFiles; } - public List> getUploadFiles() { + public List getUploadFiles() { return this.uploadedFiles; } } 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 57f4650cc..8dbd173e5 100644 --- a/core/src/test/java/org/apache/struts2/interceptor/FileUploadInterceptorTest.java +++ b/core/src/test/java/org/apache/struts2/interceptor/FileUploadInterceptorTest.java @@ -53,7 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class FileUploadInterceptorTest extends StrutsInternalTestCase { - private static final UploadedFile EMPTY_FILE = new UploadedFile<>() { + private static final UploadedFile EMPTY_FILE = new UploadedFile() { @Override public Long length() { return 0L; @@ -204,7 +204,7 @@ public class FileUploadInterceptorTest extends StrutsInternalTestCase { URL url = ClassLoaderUtil.getResource("log4j2.xml", FileUploadInterceptorTest.class); File file = new File(new URI(url.toString())); assertTrue("log4j2.xml should be in src/test folder", file.exists()); - UploadedFile uploadedFile = StrutsUploadedFile.Builder.create(file) + UploadedFile uploadedFile = StrutsUploadedFile.Builder.create(file) .withContentType("text/html") .withOriginalName("filename") .build(); @@ -307,7 +307,7 @@ public class FileUploadInterceptorTest extends StrutsInternalTestCase { HttpParameters parameters = mai.getInvocationContext().getParameters(); assertEquals(3, parameters.keySet().size()); - UploadedFile[] files = (UploadedFile[]) parameters.get("file").getObject(); + UploadedFile[] files = (UploadedFile[]) parameters.get("file").getObject(); String[] fileContentTypes = parameters.get("fileContentType").getMultipleValues(); String[] fileRealFilenames = parameters.get("fileFileName").getMultipleValues(); @@ -363,7 +363,7 @@ public class FileUploadInterceptorTest extends StrutsInternalTestCase { HttpParameters parameters = mai.getInvocationContext().getParameters(); assertEquals(3, parameters.keySet().size()); - UploadedFile[] files = (UploadedFile[]) parameters.get("file").getObject(); + UploadedFile[] files = (UploadedFile[]) parameters.get("file").getObject(); String[] fileContentTypes = parameters.get("fileContentType").getMultipleValues(); String[] fileRealFilenames = parameters.get("fileFileName").getMultipleValues(); @@ -642,14 +642,14 @@ public class FileUploadInterceptorTest extends StrutsInternalTestCase { } public static class MyFileUploadAction extends ActionSupport implements UploadedFilesAware { - private List> uploadedFiles; + private List uploadedFiles; @Override - public void withUploadedFiles(List> uploadedFiles) { + public void withUploadedFiles(List uploadedFiles) { this.uploadedFiles = uploadedFiles; } - public List> getUploadFiles() { + public List getUploadFiles() { return this.uploadedFiles; } } diff --git a/plugins/jasperreports/pom.xml b/plugins/jasperreports/pom.xml index c18fc9946..be177c89d 100644 --- a/plugins/jasperreports/pom.xml +++ b/plugins/jasperreports/pom.xml @@ -35,7 +35,7 @@ net.sf.jasperreports jasperreports - 6.20.6 + 6.21.0 provided diff --git a/plugins/portlet/src/main/java/org/apache/struts2/portlet/interceptor/PortletContextAware.java b/plugins/portlet/src/main/java/org/apache/struts2/portlet/interceptor/PortletContextAware.java new file mode 100644 index 000000000..67e360a39 --- /dev/null +++ b/plugins/portlet/src/main/java/org/apache/struts2/portlet/interceptor/PortletContextAware.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.portlet.interceptor; + +import javax.portlet.PortletContext; + +@Deprecated +public interface PortletContextAware extends org.apache.struts2.portlet.action.PortletContextAware { + + void setPortletContext(PortletContext portletContext); + + @Override + default void withPortletContext(PortletContext context) { + setPortletContext(context); + } +} diff --git a/plugins/portlet/src/main/java/org/apache/struts2/portlet/interceptor/PortletPreferencesAware.java b/plugins/portlet/src/main/java/org/apache/struts2/portlet/interceptor/PortletPreferencesAware.java new file mode 100644 index 000000000..fae552c91 --- /dev/null +++ b/plugins/portlet/src/main/java/org/apache/struts2/portlet/interceptor/PortletPreferencesAware.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.portlet.interceptor; + +import javax.portlet.PortletPreferences; + +@Deprecated +public interface PortletPreferencesAware extends org.apache.struts2.portlet.action.PortletPreferencesAware { + + void setPortletPreferences(PortletPreferences prefs); + + @Override + default void withPortletPreferences(PortletPreferences prefs) { + setPortletPreferences(prefs); + } +} diff --git a/plugins/portlet/src/main/java/org/apache/struts2/portlet/interceptor/PortletRequestAware.java b/plugins/portlet/src/main/java/org/apache/struts2/portlet/interceptor/PortletRequestAware.java new file mode 100644 index 000000000..5565ecf70 --- /dev/null +++ b/plugins/portlet/src/main/java/org/apache/struts2/portlet/interceptor/PortletRequestAware.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.portlet.interceptor; + +import javax.portlet.PortletRequest; + +@Deprecated +public interface PortletRequestAware extends org.apache.struts2.portlet.action.PortletRequestAware { + + void setPortletRequest(PortletRequest request); + + @Override + default void withPortletRequest(PortletRequest request) { + setPortletRequest(request); + } +} diff --git a/plugins/portlet/src/main/java/org/apache/struts2/portlet/interceptor/PortletResponseAware.java b/plugins/portlet/src/main/java/org/apache/struts2/portlet/interceptor/PortletResponseAware.java new file mode 100644 index 000000000..8f9641936 --- /dev/null +++ b/plugins/portlet/src/main/java/org/apache/struts2/portlet/interceptor/PortletResponseAware.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.portlet.interceptor; + +import javax.portlet.PortletResponse; + +@Deprecated +public interface PortletResponseAware extends org.apache.struts2.portlet.action.PortletResponseAware { + + void setPortletResponse(PortletResponse response); + + @Override + default void withPortletResponse(PortletResponse response) { + setPortletResponse(response); + } +} diff --git a/plugins/tiles/pom.xml b/plugins/tiles/pom.xml index 44e6a7793..92c3edceb 100644 --- a/plugins/tiles/pom.xml +++ b/plugins/tiles/pom.xml @@ -35,9 +35,6 @@ build-autotags - - true - diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java index 8ef7cc561..def7aab96 100644 --- a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java +++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java @@ -25,11 +25,6 @@ import ognl.PropertyAccessor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.tiles.api.TilesContainer; -import org.apache.tiles.request.ApplicationContext; -import org.apache.tiles.request.ApplicationResource; -import org.apache.tiles.request.Request; -import org.apache.tiles.request.render.BasicRendererFactory; -import org.apache.tiles.request.render.ChainedDelegateRenderer; import org.apache.tiles.core.definition.DefinitionsFactory; import org.apache.tiles.core.definition.pattern.DefinitionPatternMatcherFactory; import org.apache.tiles.core.definition.pattern.PatternDefinitionResolver; @@ -57,6 +52,11 @@ import org.apache.tiles.ognl.PropertyAccessorDelegateFactory; import org.apache.tiles.ognl.ScopePropertyAccessor; import org.apache.tiles.ognl.TilesApplicationContextNestedObjectExtractor; import org.apache.tiles.ognl.TilesContextPropertyAccessorDelegateFactory; +import org.apache.tiles.request.ApplicationContext; +import org.apache.tiles.request.ApplicationResource; +import org.apache.tiles.request.Request; +import org.apache.tiles.request.render.BasicRendererFactory; +import org.apache.tiles.request.render.ChainedDelegateRenderer; import org.apache.tiles.request.render.Renderer; import jakarta.el.ArrayELResolver; @@ -68,7 +68,10 @@ import jakarta.el.MapELResolver; import jakarta.el.ResourceBundleELResolver; import jakarta.servlet.jsp.JspFactory; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; @@ -102,8 +105,19 @@ public class StrutsTilesContainerFactory extends BasicTilesContainerFactory { /** * Default pattern to be used to collect Tiles definitions if user didn't configure any + * + * @deprecated since Struts 6.4.0, use {@link #TILES_DEFAULT_PATTERNS} instead */ - public static final String TILES_DEFAULT_PATTERN = "tiles*.xml"; + @Deprecated + public static final String TILES_DEFAULT_PATTERN = "/WEB-INF/**/tiles*.xml,classpath*:META-INF/**/tiles*.xml"; + + /** + * Default pattern to be used to collect Tiles definitions if user didn't configure any + */ + public static final Set TILES_DEFAULT_PATTERNS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList( + "/WEB-INF/**/tiles*.xml", + "classpath*:META-INF/**/tiles*.xml" + ))); /** * Supported expression languages @@ -213,7 +227,7 @@ public class StrutsTilesContainerFactory extends BasicTilesContainerFactory { if (params.containsKey(DefinitionsFactory.DEFINITIONS_CONFIG)) { return TextParseUtil.commaDelimitedStringToSet(params.get(DefinitionsFactory.DEFINITIONS_CONFIG)); } - return TextParseUtil.commaDelimitedStringToSet(TILES_DEFAULT_PATTERN); + return TILES_DEFAULT_PATTERNS; } protected ELAttributeEvaluator createELEvaluator(ApplicationContext applicationContext) { diff --git a/plugins/tiles/src/test/java/org/apache/struts2/tiles/StrutsTilesContainerFactoryTest.java b/plugins/tiles/src/test/java/org/apache/struts2/tiles/StrutsTilesContainerFactoryTest.java new file mode 100644 index 000000000..dbadffa7a --- /dev/null +++ b/plugins/tiles/src/test/java/org/apache/struts2/tiles/StrutsTilesContainerFactoryTest.java @@ -0,0 +1,128 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.tiles; + +import org.apache.tiles.api.TilesContainer; +import org.apache.tiles.core.evaluator.AttributeEvaluatorFactory; +import org.apache.tiles.core.evaluator.impl.DirectAttributeEvaluator; +import org.apache.tiles.core.locale.LocaleResolver; +import org.apache.tiles.core.prepare.factory.BasicPreparerFactory; +import org.apache.tiles.core.prepare.factory.PreparerFactory; +import org.apache.tiles.ognl.OGNLAttributeEvaluator; +import org.apache.tiles.request.ApplicationContext; +import org.apache.tiles.request.ApplicationResource; +import org.apache.tiles.request.locale.URLApplicationResource; +import org.apache.tiles.request.render.BasicRendererFactory; +import org.apache.tiles.request.render.ChainedDelegateRenderer; +import org.apache.tiles.request.render.Renderer; +import org.junit.Before; +import org.junit.Test; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.jsp.JspFactory; +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class StrutsTilesContainerFactoryTest { + + private StrutsTilesContainerFactory factory; + private ApplicationContext applicationContext; + + @Before + public void setUp() throws Exception { + applicationContext = mock(ApplicationContext.class); + factory = new StrutsTilesContainerFactory(); + } + + @Test + public void getSources() { + ApplicationResource pathResource = new URLApplicationResource( + "/org/apache/tiles/core/config/tiles-defs.xml", + Objects.requireNonNull(getClass().getResource("/org/apache/tiles/core/config/tiles-defs.xml")) + ); + ApplicationResource classpathResource = new URLApplicationResource( + "/org/apache/tiles/core/config/defs1.xml", + Objects.requireNonNull(getClass().getResource("/org/apache/tiles/core/config/defs1.xml")) + ); + when(applicationContext.getInitParams()).thenReturn(Collections.emptyMap()); + when(applicationContext.getResources("/WEB-INF/**/tiles*.xml")).thenReturn(Collections.singleton(pathResource)); + when(applicationContext.getResources("classpath*:META-INF/**/tiles*.xml")).thenReturn(Collections.singleton(classpathResource)); + + List resources = factory.getSources(applicationContext); + assertEquals("The urls list is not two-sized", 2, resources.size()); + assertEquals("The URL is not correct", pathResource, resources.get(0)); + assertEquals("The URL is not correct", classpathResource, resources.get(1)); + } + + @Test + public void createAttributeEvaluatorFactory() { + LocaleResolver resolver = factory.createLocaleResolver(applicationContext); + // explicitly disables support for EL + JspFactory.setDefaultFactory(null); + + AttributeEvaluatorFactory attributeEvaluatorFactory = factory.createAttributeEvaluatorFactory(applicationContext, resolver); + assertTrue("The class of the evaluator is not correct", + attributeEvaluatorFactory.getAttributeEvaluator((String) null) instanceof DirectAttributeEvaluator); + assertTrue("The class of the evaluator is not correct", + attributeEvaluatorFactory.getAttributeEvaluator("S2") instanceof StrutsAttributeEvaluator); + assertTrue("The class of the evaluator is not correct", + attributeEvaluatorFactory.getAttributeEvaluator("OGNL") instanceof OGNLAttributeEvaluator); + assertTrue("The class of the evaluator is not correct", + attributeEvaluatorFactory.getAttributeEvaluator("I18N") instanceof I18NAttributeEvaluator); + assertTrue("The class of the evaluator is not correct", + attributeEvaluatorFactory.getAttributeEvaluator("EL") instanceof DirectAttributeEvaluator); + } + + @Test + public void createPreparerFactory() { + PreparerFactory preparerFactory = factory.createPreparerFactory(applicationContext); + assertTrue("The class of the preparer factory is not correct", preparerFactory instanceof BasicPreparerFactory); + } + + @Test + public void createDefaultAttributeRenderer() { + TilesContainer container = mock(TilesContainer.class); + AttributeEvaluatorFactory attributeEvaluatorFactory = mock(AttributeEvaluatorFactory.class); + BasicRendererFactory rendererFactory = mock(BasicRendererFactory.class); + Renderer stringRenderer = mock(Renderer.class); + Renderer templateRenderer = mock(Renderer.class); + Renderer definitionRenderer = mock(Renderer.class); + + when(rendererFactory.getRenderer("string")).thenReturn(stringRenderer); + when(rendererFactory.getRenderer("template")).thenReturn(templateRenderer); + when(rendererFactory.getRenderer("definition")).thenReturn(definitionRenderer); + when(rendererFactory.getRenderer("freemarker")).thenReturn(definitionRenderer); + + Renderer renderer = factory.createDefaultAttributeRenderer(rendererFactory, applicationContext, container, attributeEvaluatorFactory); + + assertTrue("The default renderer class is not correct", renderer instanceof ChainedDelegateRenderer); + verify(rendererFactory).getRenderer("string"); + verify(rendererFactory).getRenderer("template"); + verify(rendererFactory).getRenderer("definition"); + verify(rendererFactory).getRenderer("freemarker"); + } + +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 4de073e0d..963b80b1a 100644 --- a/pom.xml +++ b/pom.xml @@ -82,7 +82,7 @@ bom - jakarta + core plugins apps @@ -115,12 +115,12 @@ 2.3.32 8.0.1.Final 2.16.0 - 2.22.1 + 2.23.1 3.2.5 5.8.0 3.3.4 2.5.0 - 2.0.11 + 2.0.12 6.0.13 3.0.8 1.0.7 @@ -287,14 +287,7 @@ org.apache.maven.plugins maven-source-plugin - - - attach-sources - - jar - - - + 3.3.0 org.apache.rat @@ -349,6 +342,17 @@ true + + org.apache.maven.plugins + maven-assembly-plugin + 3.6.0 + + true + true + assembly/out + assembly/work + + org.apache.maven.plugins maven-enforcer-plugin @@ -372,14 +376,6 @@ maven-wrapper-plugin 3.2.0 - - org.apache.maven.plugins - maven-assembly-plugin - 3.6.0 - - true - - @@ -387,7 +383,6 @@ org.apache.maven.plugins maven-release-plugin - 3.0.1 @@ -411,10 +406,6 @@ - - org.apache.maven.plugins - maven-source-plugin - org.apache.maven.plugins maven-site-plugin @@ -426,12 +417,12 @@ org.apache.maven.doxia doxia-core - 1.9.1 + 1.12.0 org.apache.maven.doxia doxia-module-markdown - 1.9.1 + 1.12.0 @@ -860,7 +851,7 @@ commons-validator commons-validator - 1.6 + 1.8.0 @@ -991,7 +982,7 @@ org.apache.commons commons-compress - 1.25.0 + 1.26.0