Permalink
Browse files

Uses default error key if specified key doesn't exist

  • Loading branch information...
lukaszlenart committed Mar 6, 2017
1 parent 54dff36 commit 352306493971e7d5a756d61780d57a76eb1f519a
@@ -120,7 +120,11 @@ protected String buildErrorMessage(Throwable e, Object[] args) {
if (LOG.isDebugEnabled()) {
LOG.debug("Preparing error message for key: [#0]", errorKey);
}
- return LocalizedTextUtil.findText(this.getClass(), errorKey, defaultLocale, e.getMessage(), args);
+ if (LocalizedTextUtil.findText(this.getClass(), errorKey, defaultLocale, null, new Object[0]) == null) {
+ return LocalizedTextUtil.findText(this.getClass(), "struts.messages.error.uploading", defaultLocale, null, new Object[] { e.getMessage() });
+ } else {
+ return LocalizedTextUtil.findText(this.getClass(), errorKey, defaultLocale, null, args);
+ }
}
protected void processUpload(HttpServletRequest request, String saveDir) throws FileUploadException, UnsupportedEncodingException {
@@ -539,7 +539,11 @@ private String buildErrorMessage(Throwable e, Object[] args) {
String errorKey = "struts.message.upload.error." + e.getClass().getSimpleName();
if (LOG.isDebugEnabled())
LOG.debug("Preparing error message for key: [#0]", errorKey);
- return LocalizedTextUtil.findText(this.getClass(), errorKey, defaultLocale, e.getMessage(), args);
+ if (LocalizedTextUtil.findText(this.getClass(), errorKey, defaultLocale, null, new Object[0]) == null) {
+ return LocalizedTextUtil.findText(this.getClass(), "struts.messages.error.uploading", defaultLocale, null, new Object[] { e.getMessage() });
+ } else {
+ return LocalizedTextUtil.findText(this.getClass(), errorKey, defaultLocale, null, args);
+ }
}
/**
@@ -108,7 +108,11 @@ protected String buildErrorMessage(Throwable e, Object[] args) {
if (LOG.isDebugEnabled()) {
LOG.debug("Preparing error message for key: [#0]", errorKey);
}
- return LocalizedTextUtil.findText(this.getClass(), errorKey, defaultLocale, e.getMessage(), args);
+ if (LocalizedTextUtil.findText(this.getClass(), errorKey, getLocale(), null, new Object[0]) == null) {
+ return LocalizedTextUtil.findText(this.getClass(), "struts.messages.error.uploading", defaultLocale, null, new Object[] { e.getMessage() });
+ } else {
+ return LocalizedTextUtil.findText(this.getClass(), errorKey, defaultLocale, null, args);
+ }
}
/**

1 comment on commit 3523064

@robertyumao

This comment has been minimized.

Show comment
Hide comment
@robertyumao

robertyumao Mar 8, 2017

hello:
You can also add a filter before StrutsPrepareAndExecuteFilter in web.xml, Just make a simple judgment in the filter, if there are illegal characters exists on Content-Type, Don't call StrutsPrepareAndExecuteFilter.

hello:
You can also add a filter before StrutsPrepareAndExecuteFilter in web.xml, Just make a simple judgment in the filter, if there are illegal characters exists on Content-Type, Don't call StrutsPrepareAndExecuteFilter.

Please sign in to comment.