You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2017/03/06 13:45:51 UTC
struts git commit: Uses default error key if specified key doesn't
exist
Repository: struts
Updated Branches:
refs/heads/master f487d7e7d -> 6b8272ce4
Uses default error key if specified key doesn't exist
Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/6b8272ce
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/6b8272ce
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/6b8272ce
Branch: refs/heads/master
Commit: 6b8272ce47160036ed120a48345d9aa884477228
Parents: f487d7e
Author: Lukasz Lenart <lu...@apache.org>
Authored: Mon Mar 6 11:17:38 2017 +0100
Committer: Lukasz Lenart <lu...@apache.org>
Committed: Mon Mar 6 14:45:26 2017 +0100
----------------------------------------------------------------------
.../struts2/interceptor/FileUploadInterceptor.java | 13 ++++++++-----
.../struts2/interceptor/FileUploadInterceptorTest.java | 8 ++++----
2 files changed, 12 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts/blob/6b8272ce/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java
index b9f5cb6..aa7fe01 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java
@@ -26,7 +26,6 @@ import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.interceptor.ValidationAware;
-import com.opensymphony.xwork2.util.LocalizedTextUtil;
import com.opensymphony.xwork2.util.TextParseUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -38,7 +37,6 @@ import org.apache.struts2.dispatcher.multipart.UploadedFile;
import org.apache.struts2.util.ContentTypeMatcher;
import javax.servlet.http.HttpServletRequest;
-import java.io.File;
import java.text.NumberFormat;
import java.util.*;
@@ -258,11 +256,16 @@ public class FileUploadInterceptor extends AbstractInterceptor {
MultiPartRequestWrapper multiWrapper = (MultiPartRequestWrapper) request;
- if (multiWrapper.hasErrors()) {
+ if (multiWrapper.hasErrors() && validation != null) {
+ TextProvider textProvider = getTextProvider(action);
for (LocalizedMessage error : multiWrapper.getErrors()) {
- if (validation != null) {
- validation.addActionError(LocalizedTextUtil.findText(error.getClazz(), error.getTextKey(), ActionContext.getContext().getLocale(), error.getDefaultMessage(), error.getArgs()));
+ String errorMessage;
+ if (textProvider.hasKey(error.getTextKey())) {
+ errorMessage = textProvider.getText(error.getTextKey(), Arrays.asList(error.getArgs()));
+ } else {
+ errorMessage = textProvider.getText("struts.messages.error.uploading", error.getDefaultMessage());
}
+ validation.addActionError(errorMessage);
}
}
http://git-wip-us.apache.org/repos/asf/struts/blob/6b8272ce/core/src/test/java/org/apache/struts2/interceptor/FileUploadInterceptorTest.java
----------------------------------------------------------------------
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 0224f68..8e68cef 100644
--- a/core/src/test/java/org/apache/struts2/interceptor/FileUploadInterceptorTest.java
+++ b/core/src/test/java/org/apache/struts2/interceptor/FileUploadInterceptorTest.java
@@ -231,7 +231,7 @@ public class FileUploadInterceptorTest extends StrutsInternalTestCase {
req.setContentType("text/xml"); // not a multipart contentype
req.addHeader("Content-type", "multipart/form-data");
- MyFileupAction action = new MyFileupAction();
+ MyFileupAction action = container.inject(MyFileupAction.class);
MockActionInvocation mai = new MockActionInvocation();
mai.setAction(action);
mai.setResultCode("success");
@@ -252,7 +252,7 @@ public class FileUploadInterceptorTest extends StrutsInternalTestCase {
req.addHeader("Content-type", "multipart/form-data");
req.setContent(null); // there is no content
- MyFileupAction action = new MyFileupAction();
+ MyFileupAction action = container.inject(MyFileupAction.class);
MockActionInvocation mai = new MockActionInvocation();
mai.setAction(action);
mai.setResultCode("success");
@@ -386,7 +386,7 @@ public class FileUploadInterceptorTest extends StrutsInternalTestCase {
"-----1234--\r\n");
req.setContent(content.getBytes("US-ASCII"));
- MyFileupAction action = new MyFileupAction();
+ MyFileupAction action = container.inject(MyFileupAction.class);
MockActionInvocation mai = new MockActionInvocation();
mai.setAction(action);
@@ -453,7 +453,7 @@ public class FileUploadInterceptorTest extends StrutsInternalTestCase {
super.tearDown();
}
- private class MyFileupAction extends ActionSupport {
+ public static class MyFileupAction extends ActionSupport {
private static final long serialVersionUID = 6255238895447968889L;