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 2016/06/12 13:41:38 UTC
[1/2] struts git commit: Inlines constants and drops class
Repository: struts
Updated Branches:
refs/heads/master e60119436 -> 1afb48aa7
Inlines constants and drops class
Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/ca256a74
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/ca256a74
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/ca256a74
Branch: refs/heads/master
Commit: ca256a74e98861a70c446b309dbe8ca1669dbba6
Parents: e601194
Author: Lukasz Lenart <lu...@apache.org>
Authored: Sun Jun 12 15:22:45 2016 +0200
Committer: Lukasz Lenart <lu...@apache.org>
Committed: Sun Jun 12 15:22:45 2016 +0200
----------------------------------------------------------------------
.../com/opensymphony/xwork2/XWorkMessages.java | 31 --------------------
.../xwork2/conversion/impl/XWorkConverter.java | 2 +-
.../xwork2/util/LocalizedTextUtilTest.java | 13 ++++----
3 files changed, 6 insertions(+), 40 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts/blob/ca256a74/core/src/main/java/com/opensymphony/xwork2/XWorkMessages.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/XWorkMessages.java b/core/src/main/java/com/opensymphony/xwork2/XWorkMessages.java
deleted file mode 100644
index d187acc..0000000
--- a/core/src/main/java/com/opensymphony/xwork2/XWorkMessages.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2002-2006,2009 The Apache Software Foundation.
- *
- * Licensed 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 com.opensymphony.xwork2;
-
-
-/**
- * Contains constants for some default XWork messages.
- *
- * @author Jason Carreira
- */
-public interface XWorkMessages {
-
- public static final String ACTION_EXECUTION_ERROR = "xwork.error.action.execution";
- public static final String MISSING_ACTION_EXCEPTION = "xwork.exception.missing-action";
- public static final String MISSING_PACKAGE_ACTION_EXCEPTION = "xwork.exception.missing-package-action";
- public static final String DEFAULT_INVALID_FIELDVALUE = "xwork.default.invalid.fieldvalue";
-
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/ca256a74/core/src/main/java/com/opensymphony/xwork2/conversion/impl/XWorkConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/conversion/impl/XWorkConverter.java b/core/src/main/java/com/opensymphony/xwork2/conversion/impl/XWorkConverter.java
index c946d70..9dfcd4d 100644
--- a/core/src/main/java/com/opensymphony/xwork2/conversion/impl/XWorkConverter.java
+++ b/core/src/main/java/com/opensymphony/xwork2/conversion/impl/XWorkConverter.java
@@ -194,7 +194,7 @@ public class XWorkConverter extends DefaultTypeConverter {
}
public static String getConversionErrorMessage(String propertyName, ValueStack stack) {
- String defaultMessage = LocalizedTextUtil.findDefaultText(XWorkMessages.DEFAULT_INVALID_FIELDVALUE,
+ String defaultMessage = LocalizedTextUtil.findDefaultText("xwork.default.invalid.fieldvalue",
ActionContext.getContext().getLocale(),
new Object[]{
propertyName
http://git-wip-us.apache.org/repos/asf/struts/blob/ca256a74/core/src/test/java/com/opensymphony/xwork2/util/LocalizedTextUtilTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/util/LocalizedTextUtilTest.java b/core/src/test/java/com/opensymphony/xwork2/util/LocalizedTextUtilTest.java
index 1205852..f09bc9b 100644
--- a/core/src/test/java/com/opensymphony/xwork2/util/LocalizedTextUtilTest.java
+++ b/core/src/test/java/com/opensymphony/xwork2/util/LocalizedTextUtilTest.java
@@ -20,10 +20,7 @@ import com.opensymphony.xwork2.*;
import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
import com.opensymphony.xwork2.test.ModelDrivenAction2;
import com.opensymphony.xwork2.test.TestBean2;
-import org.apache.struts2.util.DateFormatter;
-import org.springframework.format.annotation.DateTimeFormat;
-import javax.swing.text.Style;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
@@ -134,17 +131,17 @@ public class LocalizedTextUtilTest extends XWorkTestCase {
}
public void testDefaultMessage() throws Exception {
- String message = LocalizedTextUtil.findDefaultText(XWorkMessages.ACTION_EXECUTION_ERROR, Locale.getDefault());
+ String message = LocalizedTextUtil.findDefaultText("xwork.error.action.execution", Locale.getDefault());
assertEquals("Error during Action invocation", message);
}
public void testDefaultMessageOverride() throws Exception {
- String message = LocalizedTextUtil.findDefaultText(XWorkMessages.ACTION_EXECUTION_ERROR, Locale.getDefault());
+ String message = LocalizedTextUtil.findDefaultText("xwork.error.action.execution", Locale.getDefault());
assertEquals("Error during Action invocation", message);
LocalizedTextUtil.addDefaultResourceBundle("com/opensymphony/xwork2/test");
- message = LocalizedTextUtil.findDefaultText(XWorkMessages.ACTION_EXECUTION_ERROR, Locale.getDefault());
+ message = LocalizedTextUtil.findDefaultText("xwork.error.action.execution", Locale.getDefault());
assertEquals("Testing resource bundle override", message);
}
@@ -187,12 +184,12 @@ public class LocalizedTextUtilTest extends XWorkTestCase {
}
public void testParameterizedDefaultMessage() throws Exception {
- String message = LocalizedTextUtil.findDefaultText(XWorkMessages.MISSING_ACTION_EXCEPTION, Locale.getDefault(), new String[]{"AddUser"});
+ String message = LocalizedTextUtil.findDefaultText("xwork.exception.missing-action", Locale.getDefault(), new String[]{"AddUser"});
assertEquals("There is no Action mapped for action name AddUser.", message);
}
public void testParameterizedDefaultMessageWithPackage() throws Exception {
- String message = LocalizedTextUtil.findDefaultText(XWorkMessages.MISSING_PACKAGE_ACTION_EXCEPTION, Locale.getDefault(), new String[]{"blah", "AddUser"});
+ String message = LocalizedTextUtil.findDefaultText("xwork.exception.missing-package-action", Locale.getDefault(), new String[]{"blah", "AddUser"});
assertEquals("There is no Action mapped for namespace blah and action name AddUser.", message);
}
[2/2] struts git commit: WW-4640 Adds more informative message when
method is not allowed
Posted by lu...@apache.org.
WW-4640 Adds more informative message when method is not allowed
Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/1afb48aa
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/1afb48aa
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/1afb48aa
Branch: refs/heads/master
Commit: 1afb48aa765a96a9d183bb4ac249bfcc8f7daf3a
Parents: ca256a7
Author: Lukasz Lenart <lu...@apache.org>
Authored: Sun Jun 12 15:41:28 2016 +0200
Committer: Lukasz Lenart <lu...@apache.org>
Committed: Sun Jun 12 15:41:28 2016 +0200
----------------------------------------------------------------------
.../opensymphony/xwork2/DefaultActionProxy.java | 14 +++++++++---
.../xwork2/xwork-messages.properties | 2 +-
.../xwork2/DefaultActionProxyTest.java | 24 ++++++++++++++++++++
3 files changed, 36 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts/blob/1afb48aa/core/src/main/java/com/opensymphony/xwork2/DefaultActionProxy.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/DefaultActionProxy.java b/core/src/main/java/com/opensymphony/xwork2/DefaultActionProxy.java
index 72c6e9e..2d8bc38 100644
--- a/core/src/main/java/com/opensymphony/xwork2/DefaultActionProxy.java
+++ b/core/src/main/java/com/opensymphony/xwork2/DefaultActionProxy.java
@@ -197,22 +197,30 @@ public class DefaultActionProxy implements ActionProxy, Serializable {
if (config.isAllowedMethod(method)) {
invocation.init(this);
} else {
- throw new ConfigurationException("This method: " + method + " for action " + actionName + " is not allowed!");
+ throw new ConfigurationException(prepareNotAllowedErrorMessage());
}
} finally {
UtilTimerStack.pop(profileKey);
}
}
+ protected String prepareNotAllowedErrorMessage() {
+ return LocalizedTextUtil.findDefaultText(
+ "struts.exception.method-not-allowed",
+ Locale.getDefault(),
+ new String[]{method, actionName}
+ );
+ }
+
protected String getErrorMessage() {
if ((namespace != null) && (namespace.trim().length() > 0)) {
return LocalizedTextUtil.findDefaultText(
- XWorkMessages.MISSING_PACKAGE_ACTION_EXCEPTION,
+ "xwork.exception.missing-package-action",
Locale.getDefault(),
new String[]{namespace, actionName});
} else {
return LocalizedTextUtil.findDefaultText(
- XWorkMessages.MISSING_ACTION_EXCEPTION,
+ "xwork.exception.missing-action",
Locale.getDefault(),
new String[]{actionName});
}
http://git-wip-us.apache.org/repos/asf/struts/blob/1afb48aa/core/src/main/resources/com/opensymphony/xwork2/xwork-messages.properties
----------------------------------------------------------------------
diff --git a/core/src/main/resources/com/opensymphony/xwork2/xwork-messages.properties b/core/src/main/resources/com/opensymphony/xwork2/xwork-messages.properties
index 6068879..94781f5 100644
--- a/core/src/main/resources/com/opensymphony/xwork2/xwork-messages.properties
+++ b/core/src/main/resources/com/opensymphony/xwork2/xwork-messages.properties
@@ -7,4 +7,4 @@ xwork.error.action.execution=Error during Action invocation
xwork.exception.missing-action=There is no Action mapped for action name {0}.
xwork.exception.missing-package-action=There is no Action mapped for namespace {0} and action name {1}.
xwork.default.invalid.fieldvalue=Invalid field value for field "{0}".
-
+struts.exception.method-not-allowed=Method {0} for action {1} is not allowed!
http://git-wip-us.apache.org/repos/asf/struts/blob/1afb48aa/core/src/test/java/com/opensymphony/xwork2/DefaultActionProxyTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/DefaultActionProxyTest.java b/core/src/test/java/com/opensymphony/xwork2/DefaultActionProxyTest.java
new file mode 100644
index 0000000..17d7c68
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/DefaultActionProxyTest.java
@@ -0,0 +1,24 @@
+package com.opensymphony.xwork2;
+
+import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
+import com.opensymphony.xwork2.mock.MockActionInvocation;
+import org.apache.struts2.StrutsInternalTestCase;
+import org.junit.Test;
+
+public class DefaultActionProxyTest extends StrutsInternalTestCase {
+
+ @Test
+ public void testThorwExceptionOnNotAllowedMethod() throws Exception {
+ final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-allowed-methods.xml";
+ loadConfigurationProviders(new XmlConfigurationProvider(filename));
+ DefaultActionProxy dap = new DefaultActionProxy(new MockActionInvocation(), "strict", "Default", "notAllowed", true, true);
+ container.inject(dap);
+
+ try {
+ dap.prepare();
+ fail("Must throw exception!");
+ } catch (Exception e) {
+ assertEquals(e.getMessage(), "Method notAllowed for action Default is not allowed!");
+ }
+ }
+}
\ No newline at end of file