Author: jholmes
Date: Tue Aug 28 11:26:48 2007
New Revision: 570518
URL: http://svn.apache.org/viewvc?rev=570518&view=rev
Log:
WW-2142 input streams need to be explicitly closed
Modified:
struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/source/ViewSourceAction.java
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/template/BaseTemplateEngine.java
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StreamResult.java
struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerManager.java
Modified:
struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/source/ViewSourceAction.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/source/ViewSourceAction.java?rev=570518&r1=570517&r2=570518&view=diff
==============================================================================
---
struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/source/ViewSourceAction.java
(original)
+++
struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/source/ViewSourceAction.java
Tue Aug 28 11:26:48 2007
@@ -72,6 +72,10 @@
}
}
pageLines = read(in, -1);
+
+ if (in != null) {
+ in.close();
+ }
}
if (className != null && className.trim().length() > 0) {
@@ -81,6 +85,10 @@
in =
servletContext.getResourceAsStream("/WEB-INF/src"+className);
}
classLines = read(in, -1);
+
+ if (in != null) {
+ in.close();
+ }
}
String rootPath =
ServletActionContext.getServletContext().getRealPath("/");
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/template/BaseTemplateEngine.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/template/BaseTemplateEngine.java?rev=570518&r1=570517&r2=570518&view=diff
==============================================================================
---
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/template/BaseTemplateEngine.java
(original)
+++
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/template/BaseTemplateEngine.java
Tue Aug 28 11:26:48 2007
@@ -52,7 +52,7 @@
if (props == null) {
String propName = template.getDir() + "/" +
template.getTheme() + "/"+getThemePropertiesFileName();
-// WW-1292
+ // WW-1292
// let's try getting it from the filesystem
File propFile = new File(propName);
InputStream is = null;
@@ -77,6 +77,12 @@
props.load(is);
} catch (IOException e) {
LOG.error("Could not load " + propName, e);
+ } finally {
+ try {
+ is.close();
+ } catch(IOException io) {
+ LOG.warn("Unable to close input stream", io);
+ }
}
}
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StreamResult.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StreamResult.java?rev=570518&r1=570517&r2=570518&view=diff
==============================================================================
---
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StreamResult.java
(original)
+++
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StreamResult.java
Tue Aug 28 11:26:48 2007
@@ -33,7 +33,7 @@
/**
* <!-- START SNIPPET: description -->
*
- * A custom Result type for send raw data (via an InputStream) directly to the
+ * A custom Result type for sending raw data (via an InputStream) directly to
the
* HttpServletResponse. Very useful for allowing users to download content.
*
* <!-- END SNIPPET: description -->
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerManager.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerManager.java?rev=570518&r1=570517&r2=570518&view=diff
==============================================================================
---
struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerManager.java
(original)
+++
struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerManager.java
Tue Aug 28 11:26:48 2007
@@ -105,7 +105,7 @@
*/
public class FreemarkerManager {
- private static final Log log = LogFactory.getLog(FreemarkerManager.class);
+ private static final Log LOG = LogFactory.getLog(FreemarkerManager.class);
public static final String CONFIG_SERVLET_CONTEXT_KEY =
"freemarker.Configuration";
public static final String KEY_EXCEPTION = "exception";
@@ -270,7 +270,7 @@
try {
templatePathLoader = new FileTemplateLoader(new
File(templatePath));
} catch (IOException e) {
- log.error("Invalid template path specified: " +
e.getMessage(), e);
+ LOG.error("Invalid template path specified: " +
e.getMessage(), e);
}
}
@@ -325,8 +325,10 @@
* @see freemarker.template.Configuration#setSettings for the definition
of valid settings
*/
protected void loadSettings(ServletContext servletContext,
freemarker.template.Configuration configuration) {
+ InputStream in = null;
+
try {
- InputStream in = FileManager.loadFile("freemarker.properties",
FreemarkerManager.class);
+ in = FileManager.loadFile("freemarker.properties",
FreemarkerManager.class);
if (in != null) {
Properties p = new Properties();
@@ -334,9 +336,17 @@
configuration.setSettings(p);
}
} catch (IOException e) {
- log.error("Error while loading freemarker settings from
/freemarker.properties", e);
+ LOG.error("Error while loading freemarker settings from
/freemarker.properties", e);
} catch (TemplateException e) {
- log.error("Error while loading freemarker settings from
/freemarker.properties", e);
+ LOG.error("Error while loading freemarker settings from
/freemarker.properties", e);
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch(IOException io) {
+ LOG.warn("Unable to close input stream", io);
+ }
+ }
}
}