Compare commits

..

14 Commits

Author SHA1 Message Date
Lukasz Lenart 17e14ef42b [maven-release-plugin] prepare release STRUTS_2_5_2 2016-07-07 10:48:45 +02:00
Lukasz Lenart d75a890482 WW-4655 Cleans up code and uses more user friendly logic to process parameters 2016-07-03 10:55:14 +02:00
Lukasz Lenart d06689120d Uses the latest OGNL version 2016-06-29 20:41:57 +02:00
Lukasz Lenart fb92c67d13 Cleans up test 2016-06-29 20:34:03 +02:00
victorsosa 6e07a63797 WW-4650 Json deserialization does not work in 2.5.1
logic need to be changed as accept can be a list; the check need to be
done in the list itself.

Accept:application/json, text/plain, */*
2016-06-24 09:06:52 -04:00
victorsosa b462286589 Merge branch 'apache-master' 2016-06-24 08:26:27 -04:00
victorsosa 4f07433626 Merge branch 'master' of https://github.com/apache/struts into apache-master 2016-06-24 08:25:42 -04:00
Lukasz Lenart cd13846e19 Fixes test and conflicts 2016-06-22 11:10:26 +02:00
Lukasz Lenart f096dd611e Adds test to guard pre-evaulation of name attribute 2016-06-22 11:10:04 +02:00
Lukasz Lenart cfcefcf589 Drops commented out test 2016-06-22 11:04:07 +02:00
Lukasz Lenart 8dfe178585 Uses LocaleProvider and default TextProvider instead of evaluating expression 2016-06-22 11:03:41 +02:00
Lukasz Lenart d5e0fe9207 WW-4648 Upgrades commons-fileupload to the latest version 2016-06-22 10:57:14 +02:00
Lukasz Lenart a2de255697 [maven-release-plugin] prepare for next development iteration 2016-06-14 08:07:45 +02:00
victor sosa 7985fd191a Merge pull request #17 from apache/master
update pull
2016-05-26 19:23:37 -04:00
55 changed files with 207 additions and 259 deletions
+3
View File
@@ -11,6 +11,9 @@
.metadata/
Servers/
#VSCode
.vscode
# OSX
.DS_Store
+1 -1
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-parent</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-apps</artifactId>
<packaging>pom</packaging>
+1 -1
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-apps</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-portlet</artifactId>
+2 -2
View File
@@ -26,12 +26,12 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-apps</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-rest-showcase</artifactId>
<packaging>war</packaging>
<version>2.5.1</version>
<version>2.5.2</version>
<name>Struts 2 Rest Showcase Webapp</name>
<description>Struts 2 Rest Showcase Example</description>
+1 -1
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-apps</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-showcase</artifactId>
+1 -1
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-parent</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-archetypes</artifactId>
@@ -2,7 +2,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-archetypes</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
+1 -1
View File
@@ -3,7 +3,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-archetypes</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -2,7 +2,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-archetypes</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -2,7 +2,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-archetypes</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
+1 -1
View File
@@ -2,7 +2,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-archetypes</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
+1 -1
View File
@@ -2,7 +2,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-archetypes</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
+1 -1
View File
@@ -4,7 +4,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-archetypes</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
+1 -1
View File
@@ -3,7 +3,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-parent</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-assembly</artifactId>
+3 -3
View File
@@ -10,7 +10,7 @@
</parent>
<artifactId>struts2-bom</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
<packaging>pom</packaging>
<name>Struts 2 Bill of Materials</name>
@@ -25,7 +25,7 @@
</licenses>
<properties>
<struts-version.version>2.5.1</struts-version.version>
<struts-version.version>2.5.2</struts-version.version>
</properties>
<build>
@@ -172,6 +172,6 @@
</dependencyManagement>
<scm>
<tag>STRUTS_2_5_1</tag>
<tag>STRUTS_2_5_2</tag>
</scm>
</project>
+1 -1
View File
@@ -4,7 +4,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-osgi-bundles</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-osgi-admin-bundle</artifactId>
+1 -1
View File
@@ -4,7 +4,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-osgi-bundles</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-osgi-demo-bundle</artifactId>
+1 -1
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-parent</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-osgi-bundles</artifactId>
+1 -1
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-parent</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-core</artifactId>
<packaging>jar</packaging>
@@ -21,7 +21,13 @@
package org.apache.struts2.components;
import com.opensymphony.xwork2.ActionContext;
import java.io.Writer;
import java.util.ResourceBundle;
import org.apache.struts2.views.annotations.StrutsTag;
import org.apache.struts2.views.annotations.StrutsTagAttribute;
import org.apache.struts2.StrutsException;
import com.opensymphony.xwork2.LocaleProvider;
import com.opensymphony.xwork2.TextProvider;
import com.opensymphony.xwork2.TextProviderFactory;
@@ -31,13 +37,6 @@ import com.opensymphony.xwork2.util.LocalizedTextUtil;
import com.opensymphony.xwork2.util.ValueStack;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.StrutsException;
import org.apache.struts2.views.annotations.StrutsTag;
import org.apache.struts2.views.annotations.StrutsTagAttribute;
import java.io.Writer;
import java.util.Locale;
import java.util.ResourceBundle;
/**
* <!-- START SNIPPET: javadoc -->
@@ -92,6 +91,8 @@ public class I18n extends Component {
protected String name;
protected Container container;
private TextProvider textProvider;
private TextProvider defaultTextProvider;
private LocaleProvider localeProvider;
public I18n(ValueStack stack) {
super(stack);
@@ -102,26 +103,31 @@ public class I18n extends Component {
this.container = container;
}
@Inject
public void setTextProvider(TextProvider textProvider) {
this.defaultTextProvider = textProvider;
}
@Inject
public void setLocaleProvider(LocaleProvider localeProvider) {
this.localeProvider = localeProvider;
}
public boolean start(Writer writer) {
boolean result = super.start(writer);
try {
String name = this.findString(this.name, "name", "Resource bundle name is required. Example: foo or foo_en");
ResourceBundle bundle = (ResourceBundle) findValue("getTexts('" + name + "')");
ResourceBundle bundle = defaultTextProvider.getTexts(name);
if (bundle == null) {
bundle = LocalizedTextUtil.findResourceBundle(name, (Locale) getStack().getContext().get(ActionContext.LOCALE));
bundle = LocalizedTextUtil.findResourceBundle(name, localeProvider.getLocale());
}
if (bundle != null) {
final Locale locale = (Locale) getStack().getContext().get(ActionContext.LOCALE);
TextProviderFactory tpf = new TextProviderFactory();
container.inject(tpf);
textProvider = tpf.createInstance(bundle, new LocaleProvider() {
public Locale getLocale() {
return locale;
}
});
textProvider = tpf.createInstance(bundle, localeProvider);
getStack().push(textProvider);
pushed = true;
}
@@ -22,7 +22,6 @@
package org.apache.struts2.result;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.util.ValueStack;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -218,15 +217,12 @@ public class StreamResult extends StrutsResultSupport {
* @see StrutsResultSupport#doExecute(java.lang.String, com.opensymphony.xwork2.ActionInvocation)
*/
protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
LOG.debug("Find the Response in context");
// Override any parameters using values on the stack
resolveParamsFromStack(invocation.getStack(), invocation);
// Find the Response in context
HttpServletResponse oResponse = (HttpServletResponse) invocation.getInvocationContext().get(HTTP_RESPONSE);
try (OutputStream oOutput = oResponse.getOutputStream()) {
if (inputStream == null) {
// Find the inputstream from the invocation variable stack
LOG.debug("Find the inputstream from the invocation variable stack");
inputStream = (InputStream) invocation.getStack().findValue(conditionalParse(inputName, invocation));
}
@@ -237,18 +233,17 @@ public class StreamResult extends StrutsResultSupport {
throw new IllegalArgumentException(msg);
}
// Set the content type
LOG.debug("Set the content type: {};charset{}", contentType, contentCharSet);
if (contentCharSet != null && ! contentCharSet.equals("")) {
oResponse.setContentType(conditionalParse(contentType, invocation)+";charset="+contentCharSet);
}
else {
oResponse.setContentType(conditionalParse(contentType, invocation)+";charset="+conditionalParse(contentCharSet, invocation));
} else {
oResponse.setContentType(conditionalParse(contentType, invocation));
}
// Set the content length
LOG.debug("Set the content length: {}", contentLength);
if (contentLength != null) {
String _contentLength = conditionalParse(contentLength, invocation);
int _contentLengthAsInt = -1;
int _contentLengthAsInt;
try {
_contentLengthAsInt = Integer.parseInt(_contentLength);
if (_contentLengthAsInt >= 0) {
@@ -260,12 +255,12 @@ public class StreamResult extends StrutsResultSupport {
}
}
// Set the content-disposition
LOG.debug("Set the content-disposition: {}", contentDisposition);
if (contentDisposition != null) {
oResponse.addHeader("Content-Disposition", conditionalParse(contentDisposition, invocation));
}
// Set the cache control headers if neccessary
LOG.debug("Set the cache control headers if necessary: {}", allowCaching);
if (!allowCaching) {
oResponse.addHeader("Pragma", "no-cache");
oResponse.addHeader("Cache-Control", "no-cache");
@@ -274,7 +269,6 @@ public class StreamResult extends StrutsResultSupport {
LOG.debug("Streaming result [{}] type=[{}] length=[{}] content-disposition=[{}] charset=[{}]",
inputName, contentType, contentLength, contentDisposition, contentCharSet);
// Copy input to output
LOG.debug("Streaming to output buffer +++ START +++");
byte[] oBuff = new byte[bufferSize];
int iSize;
@@ -289,44 +283,4 @@ public class StreamResult extends StrutsResultSupport {
}
}
/**
* Tries to lookup the parameters on the stack. Will override any existing parameters
*
* @param stack The current value stack
* @param invocation the action invocation
*/
protected void resolveParamsFromStack(ValueStack stack, ActionInvocation invocation) {
String disposition = stack.findString("contentDisposition");
if (disposition != null) {
setContentDisposition(disposition);
}
String contentType = stack.findString("contentType");
if (contentType != null) {
setContentType(contentType);
}
String inputName = stack.findString("inputName");
if (inputName != null) {
setInputName(inputName);
}
String contentLength = stack.findString("contentLength");
if (contentLength != null) {
setContentLength(contentLength);
}
Integer bufferSize = (Integer) stack.findValue("bufferSize", Integer.class);
if (bufferSize != null) {
setBufferSize(bufferSize);
}
if (contentCharSet != null ) {
contentCharSet = conditionalParse(contentCharSet, invocation);
}
else {
contentCharSet = stack.findString("contentCharSet");
}
}
}
@@ -119,24 +119,6 @@ public class SecurityMemberAccessTest extends TestCase {
assertTrue("fooLogic() from FooInterface isn't accessible!!!", accessible);
}
public void testMiddleOfInheritanceExclusion2() throws Exception {
// given
SecurityMemberAccess sma = new SecurityMemberAccess(false);
String propertyName = "barLogic";
Member member = BarInterface.class.getMethod(propertyName);
Set<Class<?>> excluded = new HashSet<Class<?>>();
excluded.add(BarInterface.class);
sma.setExcludedClasses(excluded);
// when
boolean accessible = sma.isAccessible(context, target, member, propertyName);
// then
assertFalse("barLogic() from BarInterface is accessible!!!", accessible);
}
public void testMiddleOfInheritanceExclusion3() throws Exception {
// given
SecurityMemberAccess sma = new SecurityMemberAccess(false);
@@ -144,12 +126,6 @@ public class SecurityMemberAccessTest extends TestCase {
String propertyName = "barLogic";
Member member = BarInterface.class.getMethod(propertyName);
/*
Set<Class<?>> excluded = new HashSet<Class<?>>();
excluded.add(BarInterface.class);
sma.setExcludedClasses(excluded);
*/
// when
boolean accessible = sma.isAccessible(context, target, member, propertyName);
@@ -256,7 +232,7 @@ public class SecurityMemberAccessTest extends TestCase {
public void testAccessStatic() throws Exception {
// given
SecurityMemberAccess sma = new SecurityMemberAccess(true);
sma.setExcludedClasses(new HashSet<Class<?>>(Arrays.<Class<?>>asList(Class.class)));
sma.setExcludedClasses(new HashSet<Class<?>>(Collections.singletonList(Class.class)));
// when
Member method = StaticTester.class.getMethod("sayHello");
@@ -269,7 +245,7 @@ public class SecurityMemberAccessTest extends TestCase {
public void testBlockStaticAccess() throws Exception {
// given
SecurityMemberAccess sma = new SecurityMemberAccess(false);
sma.setExcludedClasses(new HashSet<Class<?>>(Arrays.<Class<?>>asList(Class.class)));
sma.setExcludedClasses(new HashSet<Class<?>>(Collections.singletonList(Class.class)));
// when
Member method = StaticTester.class.getMethod("sayHello");
@@ -282,7 +258,7 @@ public class SecurityMemberAccessTest extends TestCase {
public void testBlockStaticAccessIfClassIsExcluded() throws Exception {
// given
SecurityMemberAccess sma = new SecurityMemberAccess(false);
sma.setExcludedClasses(new HashSet<Class<?>>(Arrays.<Class<?>>asList(Class.class)));
sma.setExcludedClasses(new HashSet<Class<?>>(Collections.singletonList(Class.class)));
// when
Member method = Class.class.getMethod("getClassLoader");
@@ -295,7 +271,7 @@ public class SecurityMemberAccessTest extends TestCase {
public void testAllowStaticAccessIfClassIsNotExcluded() throws Exception {
// given
SecurityMemberAccess sma = new SecurityMemberAccess(true);
sma.setExcludedClasses(new HashSet<Class<?>>(Arrays.<Class<?>>asList(ClassLoader.class)));
sma.setExcludedClasses(new HashSet<Class<?>>(Collections.singletonList(ClassLoader.class)));
// when
Member method = Class.class.getMethod("getClassLoader");
@@ -164,21 +164,4 @@ public class UIBeanTest extends StrutsInternalTestCase {
assertEquals("12", txtFld.getTheme());
}
// I couldn't figure out how to make this test work. Bailing for now.
// public void testEscapeLabel() throws Exception {
// ValueStack stack = ActionContext.getContext().getValueStack();
// MockHttpServletRequest req = new MockHttpServletRequest();
// MockHttpServletResponse res = new MockHttpServletResponse();
// stack.push(this);
//
// TextField txtFld = new TextField(stack, req, res);
// txtFld.setKey("test['foo']");
// txtFld.evaluateParams();
// assertEquals("test_label", txtFld.getParameters().get("label"));
// }
//
// public String getText(String key) {
// assertEquals("test[\\'foo\\']", key);
// return "test_label";
// }
}
@@ -78,8 +78,8 @@ public class StreamResultTest extends StrutsInternalTestCase {
result.doExecute("helloworld", mai);
assertEquals(String.valueOf(contentLength), result.getContentLength());
assertEquals("text/plain", result.getContentType());
assertEquals(contentLength, response.getContentLength());
assertEquals("text/plain", response.getContentType());
assertEquals("streamForImage", result.getInputName());
assertEquals(1024, result.getBufferSize()); // 1024 is default
assertEquals("inline", result.getContentDisposition());
@@ -94,7 +94,7 @@ public class StreamResultTest extends StrutsInternalTestCase {
result.setContentCharSet("ISO-8859-1");
result.doExecute("helloworld", mai);
assertEquals(String.valueOf(contentLength), result.getContentLength());
assertEquals(contentLength, response.getContentLength());
assertEquals("text/plain", result.getContentType());
assertEquals("streamForImage", result.getInputName());
assertEquals(1024, result.getBufferSize()); // 1024 is default
@@ -111,8 +111,9 @@ public class StreamResultTest extends StrutsInternalTestCase {
result.doExecute("helloworld", mai);
assertEquals(String.valueOf(contentLength), result.getContentLength());
assertEquals(contentLength, response.getContentLength());
assertEquals("text/plain", result.getContentType());
assertEquals("text/plain;charset=UTF-8", response.getContentType());
assertEquals("streamForImage", result.getInputName());
assertEquals(1024, result.getBufferSize()); // 1024 is default
assertEquals("inline", result.getContentDisposition());
@@ -220,6 +221,7 @@ public class StreamResultTest extends StrutsInternalTestCase {
response = new MockHttpServletResponse();
result = new StreamResult();
result.setContentLength("${contentLength}");
stack = ActionContext.getContext().getValueStack();
MyImageAction action = new MyImageAction();
@@ -337,4 +337,20 @@ public class TextfieldTest extends AbstractUITagTest {
verify(TextFieldTag.class.getResource("Textfield-11.txt"));
}
public void testNameEvaluation() throws Exception {
TestAction testAction = (TestAction) action;
testAction.setArray(new String[]{"test", "bar"});
testAction.setFooInt(1);
TextFieldTag tag = new TextFieldTag();
tag.setPageContext(pageContext);
tag.setName("array[%{fooInt}]");
tag.doStartTag();
tag.doEndTag();
verify(TextFieldTag.class.getResource("Textfield-14.txt"));
}
}
@@ -0,0 +1,4 @@
<tr>
<td class="tdLabel"></td>
<td class="tdInput"><input type="text" name="array[1]" value="bar" id="array_1_"/></td>
</tr>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
+1 -1
View File
@@ -25,7 +25,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-cdi-plugin</artifactId>
+1 -1
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-config-browser-plugin</artifactId>
+1 -1
View File
@@ -3,7 +3,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-convention-plugin</artifactId>
+1 -1
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-dwr-plugin</artifactId>
+1 -1
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-embeddedjsp-plugin</artifactId>
+1 -1
View File
@@ -3,7 +3,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-gxp-plugin</artifactId>
+1 -1
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-jasperreports-plugin</artifactId>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-java8-support-plugin</artifactId>
+1 -1
View File
@@ -25,7 +25,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-javatemplates-plugin</artifactId>
+1 -1
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-jfreechart-plugin</artifactId>
+1 -1
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-json-plugin</artifactId>
@@ -82,6 +82,8 @@ public class JSONInterceptor extends AbstractInterceptor {
accept = request.getHeader("accept");
}
String[] accepts = accept.split(",");
Object rootObject = null;
final ValueStack stack = invocation.getStack();
if (this.root != null) {
@@ -92,96 +94,98 @@ public class JSONInterceptor extends AbstractInterceptor {
}
}
if ((accept != null) && accept.equalsIgnoreCase("application/json")) {
// load JSON object
Object obj = JSONUtil.deserialize(request.getReader());
// JSON array (this.root cannot be null in this case)
if(obj instanceof List && this.root != null) {
String mapKey = this.root;
rootObject = null;
if(this.root.indexOf('.') != -1) {
mapKey = this.root.substring(this.root.lastIndexOf('.') + 1);
rootObject = stack.findValue(this.root.substring(0, this.root.lastIndexOf('.')));
if (rootObject == null) {
throw new RuntimeException("JSON array: Invalid root expression: '" + this.root + "'.");
}
}
// create a map with a list inside
Map m = new HashMap();
m.put(mapKey, new ArrayList((List) obj));
obj = m;
}
if (obj instanceof Map) {
Map json = (Map) obj;
// clean up the values
if (dataCleaner != null)
dataCleaner.clean("", json);
if (rootObject == null) // model overrides action
rootObject = invocation.getStack().peek();
// populate fields
populator.populateObject(rootObject, json);
} else {
LOG.error("Unable to deserialize JSON object from request");
throw new JSONException("Unable to deserialize JSON object from request");
}
} else if ((accept != null) && accept.equalsIgnoreCase("application/json-rpc")) {
Object result;
if (this.enableSMD) {
for (String accept : accepts) {
if ((accept != null) && accept.equalsIgnoreCase("application/json")) {
// load JSON object
Object obj = JSONUtil.deserialize(request.getReader());
if (obj instanceof Map) {
Map smd = (Map) obj;
// JSON array (this.root cannot be null in this case)
if(obj instanceof List && this.root != null) {
String mapKey = this.root;
rootObject = null;
if (rootObject == null) { // model makes no sense when using RPC
rootObject = invocation.getAction();
if(this.root.indexOf('.') != -1) {
mapKey = this.root.substring(this.root.lastIndexOf('.') + 1);
rootObject = stack.findValue(this.root.substring(0, this.root.lastIndexOf('.')));
if (rootObject == null) {
throw new RuntimeException("JSON array: Invalid root expression: '" + this.root + "'.");
}
}
// invoke method
try {
result = this.invoke(rootObject, smd);
} catch (Exception e) {
RPCResponse rpcResponse = new RPCResponse();
rpcResponse.setId(smd.get("id").toString());
rpcResponse.setError(new RPCError(e, RPCErrorCode.EXCEPTION, getDebug()));
// create a map with a list inside
Map m = new HashMap();
m.put(mapKey, new ArrayList((List) obj));
obj = m;
}
if (obj instanceof Map) {
Map json = (Map) obj;
// clean up the values
if (dataCleaner != null)
dataCleaner.clean("", json);
if (rootObject == null) // model overrides action
rootObject = invocation.getStack().peek();
// populate fields
populator.populateObject(rootObject, json);
} else {
LOG.error("Unable to deserialize JSON object from request");
throw new JSONException("Unable to deserialize JSON object from request");
}
} else if ((accept != null) && accept.equalsIgnoreCase("application/json-rpc")) {
Object result;
if (this.enableSMD) {
// load JSON object
Object obj = JSONUtil.deserialize(request.getReader());
if (obj instanceof Map) {
Map smd = (Map) obj;
if (rootObject == null) { // model makes no sense when using RPC
rootObject = invocation.getAction();
}
// invoke method
try {
result = this.invoke(rootObject, smd);
} catch (Exception e) {
RPCResponse rpcResponse = new RPCResponse();
rpcResponse.setId(smd.get("id").toString());
rpcResponse.setError(new RPCError(e, RPCErrorCode.EXCEPTION, getDebug()));
result = rpcResponse;
}
} else {
String message = "SMD request was not in the right format. See http://json-rpc.org";
RPCResponse rpcResponse = new RPCResponse();
rpcResponse.setError(new RPCError(message, RPCErrorCode.INVALID_PROCEDURE_CALL));
result = rpcResponse;
}
} else {
String message = "SMD request was not in the right format. See http://json-rpc.org";
String message = "Request with content type of 'application/json-rpc' was received but SMD is "
+ "not enabled for this interceptor. Set 'enableSMD' to true to enable it";
RPCResponse rpcResponse = new RPCResponse();
rpcResponse.setError(new RPCError(message, RPCErrorCode.INVALID_PROCEDURE_CALL));
rpcResponse.setError(new RPCError(message, RPCErrorCode.SMD_DISABLED));
result = rpcResponse;
}
} else {
String message = "Request with content type of 'application/json-rpc' was received but SMD is "
+ "not enabled for this interceptor. Set 'enableSMD' to true to enable it";
RPCResponse rpcResponse = new RPCResponse();
rpcResponse.setError(new RPCError(message, RPCErrorCode.SMD_DISABLED));
result = rpcResponse;
String json = JSONUtil.serialize(result, excludeProperties, getIncludeProperties(),
ignoreHierarchy, excludeNullProperties);
json = addCallbackIfApplicable(request, json);
boolean writeGzip = enableGZIP && JSONUtil.isGzipInRequest(request);
JSONUtil.writeJSONToResponse(new SerializationParams(response, this.defaultEncoding,
this.wrapWithComments, json, true, writeGzip, noCache, -1, -1, prefix, "application/json"));
return Action.NONE;
} else {
LOG.debug("Accept header parameter must be 'application/json' or 'application/json-rpc'. Ignoring request with accept ", accept);
break;
}
String json = JSONUtil.serialize(result, excludeProperties, getIncludeProperties(),
ignoreHierarchy, excludeNullProperties);
json = addCallbackIfApplicable(request, json);
boolean writeGzip = enableGZIP && JSONUtil.isGzipInRequest(request);
JSONUtil.writeJSONToResponse(new SerializationParams(response, this.defaultEncoding,
this.wrapWithComments, json, true, writeGzip, noCache, -1, -1, prefix, "application/json"));
return Action.NONE;
} else {
LOG.debug("Accept header parameter must be 'application/json' or 'application/json-rpc'. Ignoring request with accept ", accept);
}
return invocation.invoke();
@@ -71,7 +71,7 @@ public class JSONInterceptorTest extends StrutsTestCase {
private void tryBadJSON(String fileName) throws Exception {
// request
setRequestContent(fileName);
this.request.addHeader("accept", "application/json-rpc");
this.request.addHeader("accept", "application/json-rpc, text/plain, */*");
JSONInterceptor interceptor = new JSONInterceptor();
interceptor.setEnableSMD(true);
@@ -92,7 +92,7 @@ public class JSONInterceptorTest extends StrutsTestCase {
public void testSMDDisabledSMD() throws Exception {
// request
setRequestContent("smd-3.txt");
this.request.addHeader("accept", "application/json-rpc");
this.request.addHeader("accept", "application/json-rpc, text/plain, */*");
JSONInterceptor interceptor = new JSONInterceptor();
SMDActionTest1 action = new SMDActionTest1();
@@ -111,7 +111,7 @@ public class JSONInterceptorTest extends StrutsTestCase {
public void testSMDAliasedMethodCall1() throws Exception {
// request
setRequestContent("smd-14.txt");
this.request.addHeader("accept", "application/json-rpc");
this.request.addHeader("accept", "application/json-rpc, text/plain, */*");
JSONInterceptor interceptor = new JSONInterceptor();
interceptor.setEnableSMD(true);
@@ -129,7 +129,7 @@ public class JSONInterceptorTest extends StrutsTestCase {
public void testSMDAliasedMethodCall2() throws Exception {
// request
setRequestContent("smd-15.txt");
this.request.addHeader("accept", "application/json-rpc");
this.request.addHeader("accept", "application/json-rpc, text/plain, */*");
JSONInterceptor interceptor = new JSONInterceptor();
interceptor.setEnableSMD(true);
@@ -147,7 +147,7 @@ public class JSONInterceptorTest extends StrutsTestCase {
public void testSMDNoMethod() throws Exception {
// request
setRequestContent("smd-4.txt");
this.request.addHeader("accept", "application/json-rpc");
this.request.addHeader("accept", "application/json-rpc, text/plain, */*");
JSONInterceptor interceptor = new JSONInterceptor();
interceptor.setEnableSMD(true);
@@ -171,7 +171,7 @@ public class JSONInterceptorTest extends StrutsTestCase {
public void testSMDMethodWithoutAnnotations() throws Exception {
// request
setRequestContent("smd-9.txt");
this.request.addHeader("accept", "application/json-rpc");
this.request.addHeader("accept", "application/json-rpc, text/plain, */*");
JSONInterceptor interceptor = new JSONInterceptor();
interceptor.setEnableSMD(true);
@@ -192,7 +192,7 @@ public class JSONInterceptorTest extends StrutsTestCase {
public void testSMDPrimitivesNoResult() throws Exception {
// request
setRequestContent("smd-6.txt");
this.request.addHeader("accept", "application/json-rpc");
this.request.addHeader("accept", "application/json-rpc, text/plain, */*");
JSONInterceptor interceptor = new JSONInterceptor();
interceptor.setEnableSMD(true);
@@ -227,7 +227,7 @@ public class JSONInterceptorTest extends StrutsTestCase {
public void testSMDReturnObject() throws Exception {
// request
setRequestContent("smd-10.txt");
this.request.addHeader("accept", "application/json-rpc");
this.request.addHeader("accept", "application/json-rpc, text/plain, */*");
JSONInterceptor interceptor = new JSONInterceptor();
interceptor.setEnableSMD(true);
@@ -252,7 +252,7 @@ public class JSONInterceptorTest extends StrutsTestCase {
public void testSMDObjectsNoResult() throws Exception {
// request
setRequestContent("smd-7.txt");
this.request.addHeader("accept", "application/json-rpc");
this.request.addHeader("accept", "application/json-rpc, text/plain, */*");
JSONInterceptor interceptor = new JSONInterceptor();
interceptor.setEnableSMD(true);
@@ -300,7 +300,7 @@ public class JSONInterceptorTest extends StrutsTestCase {
public void testReadEmpty() throws Exception {
// request
setRequestContent("json-6.txt");
this.request.addHeader("accept", "application/json");
this.request.addHeader("accept", "application/json, text/plain, */*");
// interceptor
JSONInterceptor interceptor = new JSONInterceptor();
@@ -315,7 +315,7 @@ public class JSONInterceptorTest extends StrutsTestCase {
public void test() throws Exception {
// request
setRequestContent("json-1.txt");
this.request.addHeader("accept", "application/json");
this.request.addHeader("accept", "application/json, text/plain, */*");
// interceptor
JSONInterceptor interceptor = new JSONInterceptor();
@@ -437,7 +437,7 @@ public class JSONInterceptorTest extends StrutsTestCase {
public void testRoot() throws Exception {
setRequestContent("json-5.txt");
this.request.addHeader("accept", "application/json");
this.request.addHeader("accept", "application/json, text/plain, */*");
// interceptor
JSONInterceptor interceptor = new JSONInterceptor();
@@ -462,7 +462,7 @@ public class JSONInterceptorTest extends StrutsTestCase {
public void testJSONArray() throws Exception {
setRequestContent("json-12.txt");
this.request.addHeader("accept", "application/json");
this.request.addHeader("accept", "application/json, text/plain, */*");
// interceptor
JSONInterceptor interceptor = new JSONInterceptor();
@@ -488,7 +488,7 @@ public class JSONInterceptorTest extends StrutsTestCase {
public void testJSONArray2() throws Exception {
setRequestContent("json-12.txt");
this.request.addHeader("accept", "application/json");
this.request.addHeader("accept", "application/json, text/plain, */*");
// interceptor
JSONInterceptor interceptor = new JSONInterceptor();
+1 -1
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-junit-plugin</artifactId>
+1 -1
View File
@@ -4,7 +4,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-osgi-plugin</artifactId>
+1 -1
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-oval-plugin</artifactId>
+1 -1
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-pell-multipart-plugin</artifactId>
+1 -1
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-plexus-plugin</artifactId>
+1 -1
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-parent</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-plugins</artifactId>
+1 -1
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-portlet-tiles-plugin</artifactId>
+1 -1
View File
@@ -3,7 +3,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-portlet-plugin</artifactId>
+1 -1
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-rest-plugin</artifactId>
+1 -1
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-sitegraph-plugin</artifactId>
+1 -1
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-sitemesh-plugin</artifactId>
+1 -1
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-spring-plugin</artifactId>
+1 -1
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-testng-plugin</artifactId>
+1 -1
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>
<artifactId>struts2-tiles-plugin</artifactId>
+4 -4
View File
@@ -9,7 +9,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>struts2-parent</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
<packaging>pom</packaging>
<name>Struts 2</name>
<url>http://struts.apache.org/</url>
@@ -31,7 +31,7 @@
<connection>scm:git:git://git.apache.org/struts.git</connection>
<developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/struts.git</developerConnection>
<url>http://git.apache.org/struts.git</url>
<tag>STRUTS_2_5_1</tag>
<tag>STRUTS_2_5_2</tag>
</scm>
<issueManagement>
@@ -85,7 +85,7 @@
<properties>
<currentVersion>${project.version}</currentVersion>
<struts2.springPlatformVersion>4.1.6.RELEASE</struts2.springPlatformVersion>
<ognl.version>3.1.8</ognl.version>
<ognl.version>3.1.10</ognl.version>
<asm.version>3.3</asm.version>
<asm5.version>5.0.2</asm5.version>
<tiles.version>3.0.5</tiles.version>
@@ -711,7 +711,7 @@
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>