Permalink
Browse files

Uses default error key if specified key doesn't exist

  • Loading branch information...
lukaszlenart committed Mar 6, 2017
1 parent f487d7e commit 6b8272ce47160036ed120a48345d9aa884477228
@@ -26,7 +26,6 @@
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.util.ContentTypeMatcher;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.text.NumberFormat;
import java.util.*;
@@ -258,11 +256,16 @@ public String intercept(ActionInvocation invocation) throws Exception {
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);
}
}
@@ -231,7 +231,7 @@ public void testInvalidContentTypeMultipartRequest() throws Exception {
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 void testNoContentMultipartRequest() throws Exception {
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 void testMultipartRequestLocalizedError() throws Exception {
"-----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 @@ protected void tearDown() throws Exception {
super.tearDown();
}
private class MyFileupAction extends ActionSupport {
public static class MyFileupAction extends ActionSupport {
private static final long serialVersionUID = 6255238895447968889L;

0 comments on commit 6b8272c

Please sign in to comment.