Compare commits

..

24 Commits

Author SHA1 Message Date
Lukasz Lenart 1fec084542 [maven-release-plugin] prepare release STRUTS_2_5_16 2018-03-02 12:59:53 +01:00
Yasser Zamani 26babb6fdf Merge pull request #210 from lukaszlenart/jackson-xml
WW-4922: Jackson XML
2018-03-02 13:17:38 +03:30
Lukasz Lenart 6e691ffdbf Merge pull request #212 from zepernick/master
WW-4923 Null check to avoid NPE when not passing a JDBC connection
2018-02-28 10:16:06 +01:00
Yasser Zamani 4b540f1ab4 fix location with full path of resource 2018-02-28 11:24:31 +03:30
Lukasz Lenart a292920462 Merge pull request #211 from yasserzamani/struts_user_mbox_201802
WW-4920 fix java.net.JarURLConnection#parseSpecs
2018-02-28 08:12:43 +01:00
Paul Zepernick 10ba97f08f Merge pull request #1 from yasserzamani/WW-4923
WW-4923 add test if connection close after result
2018-02-27 11:00:39 -05:00
Lukasz Lenart 54fa3f7b04 Merge pull request #214 from yasserzamani/WW-4921
WW-4921 initialize session like WW-3442
2018-02-27 12:04:12 +01:00
Yasser Zamani a448b8a91b make newly added methods protected to allow users to override them
See also WW-4921, WW-3442
2018-02-27 14:18:46 +03:30
Lukasz Lenart 6c5b79c204 Adds explanation how to use the commented configuration 2018-02-27 11:13:39 +01:00
Yasser Zamani b806c11ea5 initialize session
See also WW-4921
2018-02-27 13:20:33 +03:30
Yasser Zamani a64b8b27fb add test if connection close after result
See also WW-4923
2018-02-27 08:45:27 +03:30
Lukasz Lenart b4ca6ceec9 Fixes suppression file 2018-02-26 09:27:26 +01:00
Lukasz Lenart 7619ed3076 Cleans up suppression file and uses full path 2018-02-23 17:15:03 +01:00
Paul Zepernick 8bf6605e6b WW-4923 Null check to avoid NPE when not passing a JDBC connection to the jasper report 2018-02-22 10:13:14 -05:00
Yasser Zamani 8d91536b17 fix javadoc to being consistent with WW-3915 changes
See also WW-3915
2018-02-20 17:32:45 +03:30
Lukasz Lenart 02c347afd4 Upgrades OWASP Dependency Check plugin to the latest version
and reduces CVSS to 7 to detect other important vulnerable libraries
2018-02-20 07:07:28 +01:00
Lukasz Lenart ce1ac9d381 Adds example how to use the handler 2018-02-20 06:50:06 +01:00
Lukasz Lenart 9260720568 Adds test to cover basic functionality 2018-02-20 06:49:50 +01:00
Lukasz Lenart 67ecf3a216 Defines a new handler using Jackson XML 2018-02-20 06:49:25 +01:00
Lukasz Lenart 4260bee634 Adds Jackson XML binding dependency 2018-02-20 06:48:48 +01:00
Yasser Zamani f929673a91 replace sun.net.www.ParseUtil#decode
See also WW-4920
2018-02-17 11:22:24 +03:30
Yasser Zamani 4718dccd1c comment jira issue id and fix a few typos
See also WW-4920
2018-02-16 14:14:21 +03:30
Yasser Zamani 155dff745e fix java.net.JarURLConnection#parseSpecs
See also WW-4920
2018-02-16 14:01:38 +03:30
Lukasz Lenart def4adacd6 [maven-release-plugin] prepare for next development iteration 2018-02-09 09:36:39 +01:00
49 changed files with 577 additions and 82 deletions
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-parent</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-apps</artifactId>
<packaging>pom</packaging>
+7 -2
View File
@@ -24,12 +24,12 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-apps</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-rest-showcase</artifactId>
<packaging>war</packaging>
<version>2.5.15</version>
<version>2.5.16</version>
<name>Struts 2 Rest Showcase Webapp</name>
<description>Struts 2 Rest Showcase Example</description>
@@ -47,6 +47,11 @@
<artifactId>struts2-config-browser-plugin</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
@@ -32,6 +32,12 @@
<constant name="struts.convention.package.locators" value="example"/>
<!-- Uncomment the lines below to use Jackson XML bindings instead of the XStream library to handle XML serialisations -->
<!--
<bean name="jacksonXml" type="org.apache.struts2.rest.handler.ContentTypeHandler" class="org.apache.struts2.rest.handler.JacksonXmlHandler" />
<constant name="struts.rest.handlerOverride.xml" value="jacksonXml"/>
-->
<package name="rest-showcase" extends="rest-default">
<global-allowed-methods>index,show,create,update,destroy,deleteConfirm,edit,editNew</global-allowed-methods>
</package>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-apps</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-showcase</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-parent</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-assembly</artifactId>
+3 -3
View File
@@ -30,7 +30,7 @@
</parent>
<artifactId>struts2-bom</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
<packaging>pom</packaging>
<name>Struts 2 Bill of Materials</name>
@@ -45,7 +45,7 @@
</licenses>
<properties>
<struts-version.version>2.5.15</struts-version.version>
<struts-version.version>2.5.16</struts-version.version>
<maven.site.skip>true</maven.site.skip>
<maven.site.deploy.skip>true</maven.site.deploy.skip>
</properties>
@@ -181,6 +181,6 @@
</dependencyManagement>
<scm>
<tag>STRUTS_2_5_15</tag>
<tag>STRUTS_2_5_16</tag>
</scm>
</project>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-osgi-bundles</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-osgi-admin-bundle</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-osgi-bundles</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-osgi-demo-bundle</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-parent</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-osgi-bundles</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-parent</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-core</artifactId>
<packaging>jar</packaging>
@@ -36,7 +36,7 @@ public interface FileManager {
void setReloadingConfigs(boolean reloadingConfigs);
/**
* Checks if given file changed and must be reloaded if {@link #setReloadingConfigs(boolean)} is true
* Checks if given file changed and must be reloaded
*
* @param fileName to check
* @return true if file changed
@@ -44,7 +44,7 @@ public interface FileManager {
boolean fileNeedsReloading(String fileName);
/**
* Checks if file represented by provided URL should be reloaded
* Checks if file represented by provided URL changed and must be reloaded
*
* @param fileUrl url to a file
* @return true if file exists and should be reloaded, if url is null return false
@@ -61,7 +61,7 @@ public interface FileManager {
InputStream loadFile(URL fileUrl);
/**
* Adds file to list of monitored files if {@link #setReloadingConfigs(boolean)} is true
* Adds file to list of monitored files
*
* @param fileUrl {@link URL} to file to be monitored
*/
@@ -37,7 +37,7 @@ public class JarEntryRevision extends Revision {
private long lastModified;
public static Revision build(URL fileUrl, FileManager fileManager) {
JarURLConnection conn = null;
StrutsJarURLConnection conn = null;
try {
conn = StrutsJarURLConnection.openConnection(fileUrl);
conn.setUseCaches(false);
@@ -70,7 +70,7 @@ public class JarEntryRevision extends Revision {
}
public boolean needsReloading() {
JarURLConnection conn = null;
StrutsJarURLConnection conn = null;
long lastLastModified = lastModified;
try {
conn = StrutsJarURLConnection.openConnection(jarFileURL);
@@ -20,34 +20,89 @@ package com.opensymphony.xwork2.util.fs;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.JarURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLDecoder;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
/**
* WW-4901 Decouples from underlying implementation of {@link URL#openConnection()}
* WW-4901 If was needed, decouples from underlying implementation of {@link URL#openConnection()}
* e.g. from IBM WebSphere com.ibm.ws.classloader.Handler$ClassLoaderURLConnection
* WW-4920 Also decouples from and fixes {@link JarURLConnection#parseSpecs(URL)} if was needed
* e.g. from Oracle WebLogic which may report jar urls like "zip:C:/web-app-lib-path/some-jar.jar"
* but {@link JarURLConnection#parseSpecs(URL)} breaks on such urls
* While {@link JarURLConnection#parseSpecs(URL)} is private, then we had to extend {@link URLConnection} instead
* @since 2.5.15
*/
class StrutsJarURLConnection extends JarURLConnection {
private JarFile jarFile;
class StrutsJarURLConnection extends URLConnection {
private static final String FILE_URL_PREFIX = "file:";
private StrutsJarURLConnection(URL url) throws MalformedURLException {
private JarURLConnection jarURLConnection;
private JarFile jarFile;
private String entryName;
private URL jarFileURL;
private StrutsJarURLConnection(URL url) throws IOException {
super(url);
URLConnection conn = this.url.openConnection();
if (conn instanceof JarURLConnection) {//decoupling is not needed?
jarURLConnection = (JarURLConnection) conn;
} else {
try {
conn.getInputStream().close();
} catch (IOException ignored) {
}
parseSpecs(url);
}
}
@Override
public JarFile getJarFile() throws IOException {
connect();
return jarFile;
/**
* A fixed copy of {@link JarURLConnection#parseSpecs(URL)}
*/
private void parseSpecs(URL url) throws MalformedURLException, UnsupportedEncodingException {
String spec = url.getFile();
int separator = spec.indexOf("!/");
/*
* REMIND: we don't handle nested JAR URLs
*/
if (separator == -1) {
throw new MalformedURLException("no !/ found in url spec:" + spec);
}
// start of fixing JarURLConnection#parseSpecs(URL) via handling MalformedURLException
String jarFileSpec = spec.substring(0, separator++);
try {
jarFileURL = new URL(jarFileSpec);
} catch (MalformedURLException e) {
// Probably no protocol in original jar URL, like "jar:C:/mypath/myjar.jar".
// This usually indicates that the jar file resides in the file system.
if (!jarFileSpec.startsWith("/")) {
jarFileSpec = "/" + jarFileSpec;
}
jarFileURL = new URL(FILE_URL_PREFIX + jarFileSpec);
}
// end of fix
entryName = null;
/* if ! is the last letter of the innerURL, entryName is null */
if (++separator != spec.length()) {
entryName = spec.substring(separator, spec.length());
entryName = URLDecoder.decode (entryName, "UTF-8");
}
}
@Override
@@ -56,7 +111,12 @@ class StrutsJarURLConnection extends JarURLConnection {
return;
}
try (final InputStream in = getJarFileURL().openConnection().getInputStream()) {
if (jarURLConnection != null) {
connected = true;
return;
}
try (final InputStream in = jarFileURL.openConnection().getInputStream()) {
jarFile = AccessController.doPrivileged(
new PrivilegedExceptionAction<JarFile>() {
public JarFile run() throws IOException {
@@ -84,19 +144,34 @@ class StrutsJarURLConnection extends JarURLConnection {
}
}
static JarURLConnection openConnection(URL url) throws IOException {
URLConnection conn = url.openConnection();
if (conn instanceof JarURLConnection) {
return (JarURLConnection) conn;
JarEntry getJarEntry() throws IOException {
if (jarURLConnection != null) {
return jarURLConnection.getJarEntry();
} else {
try {
conn.getInputStream().close();
} catch (IOException ignored) {
}
connect();
return jarFile.getJarEntry(entryName);
}
}
StrutsJarURLConnection result = new StrutsJarURLConnection(url);
return result;
@Override
public void setUseCaches(boolean usecaches) {
super.setUseCaches(usecaches);
if (jarURLConnection != null) {
jarURLConnection.setUseCaches(usecaches);
}
}
@Override
public InputStream getInputStream() throws IOException {
if (jarURLConnection != null) {
return jarURLConnection.getInputStream();
} else {
return jarFile.getInputStream(jarFile.getJarEntry(entryName));
}
}
static StrutsJarURLConnection openConnection(URL url) throws IOException {
return new StrutsJarURLConnection(url);
}
}
@@ -23,6 +23,7 @@ import com.opensymphony.xwork2.FileManagerFactory;
import com.opensymphony.xwork2.XWorkTestCase;
import org.apache.commons.io.IOUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -67,6 +68,7 @@ public class JarEntryRevisionTest extends XWorkTestCase {
createJarFile(now);
URL url = new URL("jar:file:target/JarEntryRevisionTest_testNeedsReloading.jar!/com/opensymphony/xwork2/util/fs/JarEntryRevisionTest.class");
Revision entry = JarEntryRevision.build(url, fileManager);
assert entry != null;
assertFalse(entry.needsReloading());
createJarFile(now + 60000);
@@ -81,6 +83,30 @@ public class JarEntryRevisionTest extends XWorkTestCase {
"jar:file:target/JarEntryRevisionTest_testNeedsReloading.jar!/com/opensymphony/xwork2/util/fs/JarEntryRevisionTest.class",
new ContainerProvidedURLStreamHandler());
Revision entry = JarEntryRevision.build(url, fileManager);
assert entry != null;
assertFalse(entry.needsReloading());
createJarFile(now + 60000);
assertTrue(entry.needsReloading());
}
public void testNeedsReloadingWithContainerProvidedURLConnectionEmptyProtocol() throws Exception {
long now = System.currentTimeMillis();
createJarFile(now);
File targetDir = new File("target");
String targetUrlStr = targetDir.toURI().toURL().toString();
if (targetUrlStr.startsWith("file:")) {
targetUrlStr = targetUrlStr.substring(5);//emptying protocol; we expect framework will fix it
}
if (targetUrlStr.startsWith("/")) {
targetUrlStr = targetUrlStr.substring(1);//we expect framework will fix it also
}
URL url = new URL(null,
"zip:" + targetUrlStr + "JarEntryRevisionTest_testNeedsReloading.jar!/com/opensymphony/xwork2/util/fs/JarEntryRevisionTest.class",
new ContainerProvidedURLStreamHandler());
Revision entry = JarEntryRevision.build(url, fileManager);
assert entry != null;
assertFalse(entry.needsReloading());
createJarFile(now + 60000);
@@ -107,7 +133,7 @@ public class JarEntryRevisionTest extends XWorkTestCase {
*/
private class ContainerProvidedURLConnection extends URLConnection {
protected ContainerProvidedURLConnection(URL url) {
ContainerProvidedURLConnection(URL url) {
super(url);
}
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.15</version>
<version>2.5.16</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.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-cdi-plugin</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-config-browser-plugin</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-convention-plugin</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-dwr-plugin</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-embeddedjsp-plugin</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-gxp-plugin</artifactId>
+27 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-jasperreports-plugin</artifactId>
@@ -49,6 +49,32 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-junit-plugin</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -384,7 +384,10 @@ public class JasperReportsResult extends StrutsResultSupport implements JasperRe
throw new ServletException(e.getMessage(), e);
} finally {
try {
conn.close();
if (conn != null) {
// avoid NPE if connection was not used for the report
conn.close();
}
} catch (Exception e) {
LOG.warn("Could not close db connection properly", e);
}
@@ -0,0 +1,89 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.struts2.views.jasperreports;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.mock.MockActionInvocation;
import com.opensymphony.xwork2.util.ClassLoaderUtil;
import com.opensymphony.xwork2.util.ValueStack;
import net.sf.jasperreports.engine.JasperCompileManager;
import org.apache.struts2.StrutsStatics;
import org.apache.struts2.StrutsTestCase;
import org.easymock.IAnswer;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockServletContext;
import java.net.URL;
import java.sql.Connection;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
public class JasperReportsResultTest extends StrutsTestCase {
private MockActionInvocation invocation;
private ValueStack stack;
public void testConnClose() throws Exception {
JasperReportsResult result = new JasperReportsResult();
URL url = ClassLoaderUtil.getResource("org/apache/struts2/views/jasperreports/empty.jrxml", this.getClass());
JasperCompileManager.compileReportToFile(url.getFile(), url.getFile() + ".jasper");
result.setLocation("org/apache/struts2/views/jasperreports/empty.jrxml.jasper");
result.setFormat(JasperReportConstants.FORMAT_XML);
Connection connection = createMock(Connection.class);
final Boolean[] closed = {false};
connection.close();
expectLastCall().andAnswer(new IAnswer() {
@Override
public Object answer() throws Throwable {
closed[0] = true;
return null;
}
});
replay(connection);
stack.push(connection);
result.setConnection("top");
assertFalse(closed[0]);
result.execute(this.invocation);
verify(connection);
assertTrue(closed[0]);
}
@Override
protected void setUp() throws Exception {
super.setUp();
MockHttpServletResponse response = new MockHttpServletResponse();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI("http://sumeruri");
ActionContext context = ActionContext.getContext();
context.put(StrutsStatics.HTTP_RESPONSE, response);
context.put(StrutsStatics.HTTP_REQUEST, request);
this.stack = context.getValueStack();
MockServletContext servletContext = new MockServletContext();
context.put(StrutsStatics.SERVLET_CONTEXT, servletContext);
this.invocation = new MockActionInvocation();
this.invocation.setInvocationContext(context);
this.invocation.setStack(this.stack);
}
}
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
-->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="test" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="e65f69ca-7c62-4b4b-abc6-2e1a8710f23e">
</jasperReport>
+1 -1
View File
@@ -25,7 +25,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-javatemplates-plugin</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-jfreechart-plugin</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-json-plugin</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-junit-plugin</artifactId>
@@ -37,6 +37,7 @@ import org.apache.struts2.util.StrutsTestCaseHelper;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.mock.web.MockPageContext;
import org.springframework.mock.web.MockServletContext;
@@ -155,10 +156,7 @@ public abstract class StrutsJUnit4TestCase<T> extends XWorkJUnit4TestCase {
ActionProxy proxy = config.getContainer().getInstance(ActionProxyFactory.class).createActionProxy(
namespace, name, method, new HashMap<String, Object>(), true, false);
ActionContext invocationContext = proxy.getInvocation().getInvocationContext();
invocationContext.setParameters(HttpParameters.create(request.getParameterMap()).build());
// set the action context to the one used by the proxy
ActionContext.setContext(invocationContext);
initActionContext(proxy.getInvocation().getInvocationContext());
// this is normally done in onSetUp(), but we are using Struts internal
// objects (proxy and action invocation)
@@ -170,6 +168,20 @@ public abstract class StrutsJUnit4TestCase<T> extends XWorkJUnit4TestCase {
return proxy;
}
protected void initActionContext(ActionContext actionContext) {
actionContext.setParameters(HttpParameters.create(request.getParameterMap()).build());
initSession(actionContext);
// set the action context to the one used by the proxy
ActionContext.setContext(actionContext);
}
protected void initSession(ActionContext actionContext) {
if (actionContext.getSession() == null) {
actionContext.setSession(new HashMap<String, Object>());
request.setSession(new MockHttpSession(servletContext));
}
}
/**
* Finds an ActionMapping for a given request
*/
@@ -18,6 +18,7 @@
*/
package org.apache.struts2;
import com.opensymphony.xwork2.ActionProxy;
import org.junit.Assert;
import org.junit.Test;
@@ -33,6 +34,13 @@ public class StrutsJUnit4TestCaseTest extends StrutsJUnit4TestCase<JUnitTestActi
Assert.assertEquals("Test-2", output);
}
@Test
public void testSessionInitialized() throws Exception {
ActionProxy proxy = getActionProxy("/test/testAction-2.action");
Assert.assertNotNull("invocation session should being initialized",
proxy.getInvocation().getInvocationContext().getSession());
}
@Override
protected String getConfigPath() {
return "struts-test.xml";
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-osgi-plugin</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-oval-plugin</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-pell-multipart-plugin</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-plexus-plugin</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-parent</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-plugins</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-portlet-tiles-plugin</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-portlet-plugin</artifactId>
+12 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-rest-plugin</artifactId>
@@ -55,6 +55,11 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mockobjects</groupId>
@@ -80,6 +85,12 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert</artifactId>
<scope>test</scope>
</dependency>
<!-- The Servlet API mocks in Spring Framework 4.x only supports Servlet 3.0 and higher.
This is only necessary in tests-->
<dependency>
@@ -0,0 +1,61 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.struts2.rest.handler;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.opensymphony.xwork2.ActionInvocation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
/**
* Handles XML content using Jackson
*/
public class JacksonXmlHandler extends AbstractContentTypeHandler {
private static final Logger LOG = LogManager.getLogger(JacksonXmlHandler.class);
private static final String DEFAULT_CONTENT_TYPE = "application/xml";
private XmlMapper mapper = new XmlMapper();
public void toObject(ActionInvocation invocation, Reader in, Object target) throws IOException {
LOG.debug("Converting input into an object of: {}", target.getClass().getName());
ObjectReader or = mapper.readerForUpdating(target);
or.readValue(in);
}
public String fromObject(ActionInvocation invocation, Object obj, String resultCode, Writer stream) throws IOException {
LOG.debug("Converting an object of {} into string", obj.getClass().getName());
mapper.writeValue(stream, obj);
return null;
}
public String getContentType() {
return DEFAULT_CONTENT_TYPE;
}
public String getExtension() {
return "xml";
}
}
@@ -0,0 +1,87 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.struts2.rest.handler;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.XWorkTestCase;
import com.opensymphony.xwork2.mock.MockActionInvocation;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Arrays;
import static org.fest.assertions.Assertions.assertThat;
public class JacksonXmlHandlerTest extends XWorkTestCase {
private String xml;
private JacksonXmlHandler handler;
private ActionInvocation ai;
public void setUp() throws Exception {
super.setUp();
xml = "<SimpleBean>" +
"<name>Jan</name>" +
"<age>12</age>" +
"<parents>" +
"<parents>Adam</parents>" +
"<parents>Ewa</parents>" +
"</parents>" +
"</SimpleBean>";
handler = new JacksonXmlHandler();
ai = new MockActionInvocation();
}
public void testObjectToXml() throws Exception {
// given
SimpleBean obj = new SimpleBean();
obj.setName("Jan");
obj.setAge(12L);
obj.setParents(Arrays.asList("Adam", "Ewa"));
// when
Writer stream = new StringWriter();
handler.fromObject(ai, obj, null, stream);
// then
stream.flush();
assertEquals(xml, stream.toString());
}
public void testXmlToObject() throws Exception {
// given
SimpleBean obj = new SimpleBean();
// when
Reader in = new StringReader(xml);
handler.toObject(ai, in, obj);
// then
assertNotNull(obj);
assertEquals(obj.getName(), "Jan");
assertEquals(obj.getAge().longValue(), 12L);
assertNotNull(obj.getParents());
assertThat(obj.getParents())
.hasSize(2)
.containsExactly("Adam", "Ewa");
}
}
@@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.struts2.rest.handler;
import java.util.List;
public class SimpleBean {
private String name;
private Long age;
private List<String> parents;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Long getAge() {
return age;
}
public void setAge(Long age) {
this.age = age;
}
public List<String> getParents() {
return parents;
}
public void setParents(List<String> parents) {
this.parents = parents;
}
}
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-sitegraph-plugin</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-sitemesh-plugin</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-spring-plugin</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-testng-plugin</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
</parent>
<artifactId>struts2-tiles-plugin</artifactId>
+11 -6
View File
@@ -29,7 +29,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>struts2-parent</artifactId>
<version>2.5.15</version>
<version>2.5.16</version>
<packaging>pom</packaging>
<name>Struts 2</name>
<url>http://struts.apache.org/</url>
@@ -51,7 +51,7 @@
<connection>scm:git:https://gitbox.apache.org/repos/asf/struts.git</connection>
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/struts.git</developerConnection>
<url>https://github.com/apache/struts/</url>
<tag>STRUTS_2_5_15</tag>
<tag>STRUTS_2_5_16</tag>
</scm>
<issueManagement>
@@ -103,7 +103,7 @@
<tiles.version>3.0.7</tiles.version>
<tiles-request.version>1.0.6</tiles-request.version>
<log4j2.version>2.10.0</log4j2.version>
<jackson.version>2.9.2</jackson.version>
<jackson.version>2.9.4</jackson.version>
<!-- Site generation -->
<fluido-skin.version>1.6</fluido-skin.version>
@@ -311,12 +311,12 @@
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>3.0.2</version>
<version>3.1.1</version>
<configuration>
<suppressionFiles>
<suppressionFile>src/etc/project-suppression.xml</suppressionFile>
</suppressionFiles>
<failBuildOnCVSS>8</failBuildOnCVSS>
<failBuildOnCVSS>7</failBuildOnCVSS>
<skipProvidedScope>true</skipProvidedScope>
<skipRuntimeScope>true</skipRuntimeScope>
</configuration>
@@ -1064,7 +1064,12 @@
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>${jackson.version}</version>
</dependency>
<!-- CDI & Weld -->
<dependency>
<groupId>javax.enterprise</groupId>
+14 -8
View File
@@ -22,16 +22,22 @@
<notes><![CDATA[
This suppresses false positives identified on Struts Annotations.
]]></notes>
<gav regex="true">org\.apache\.struts:struts\-annotations\:1\.0\.6</gav>
<gav regex="true">org\.apache\.struts:struts\-annotations\:1\.0\.6.*$</gav>
<cpe>cpe:/a:apache:struts:1.0.6</cpe>
</suppress>
<suppress>
<notes><![CDATA[
This suppresses false positives identified on Struts 1.
]]></notes>
<gav regex="true">org\.apache\.struts\:struts\-*:1\.3\.8</gav>
<cpe>cpe:/a:apache:struts:1.3.8</cpe>
<cpe>cpe:/a:apache:tiles:1.3.8</cpe>
<cpe>cpe:/a:apache:struts:1.3.8</cpe>
<notes><![CDATA[file name: struts-core-1.3.8.jar]]></notes>
<gav regex="true">^org\.apache\.struts:struts\-core\:1\.3\.8.*$</gav>
<cpe>cpe:/a:apache:struts</cpe>
</suppress>
<suppress>
<notes><![CDATA[file name: struts-tiles-1.3.8.jar]]></notes>
<gav regex="true">^org\.apache\.struts:struts\-tiles\:1\.3\.8.*$</gav>
<cpe>cpe:/a:apache:struts</cpe>
</suppress>
<suppress>
<notes><![CDATA[file name: struts-taglib-1.3.8.jar]]></notes>
<gav regex="true">^org\.apache\.struts:struts\-taglib\:1\.3\.8.*$</gav>
<cpe>cpe:/a:apache:struts</cpe>
</suppress>
</suppressions>