Author: norman.richards(a)jboss.com
Date: 2008-10-13 18:46:22 -0400 (Mon, 13 Oct 2008)
New Revision: 9286
Modified:
trunk/src/main/org/jboss/seam/bpm/Jbpm.java
trunk/src/main/org/jboss/seam/bpm/PageflowDeploymentHandler.java
trunk/src/main/org/jboss/seam/exception/Exceptions.java
trunk/src/main/org/jboss/seam/init/Initialization.java
trunk/src/main/org/jboss/seam/navigation/Pages.java
trunk/src/main/org/jboss/seam/util/Resources.java
trunk/src/pdf/org/jboss/seam/pdf/ui/UISignature.java
Log:
JBSEAM-3500
Modified: trunk/src/main/org/jboss/seam/bpm/Jbpm.java
===================================================================
--- trunk/src/main/org/jboss/seam/bpm/Jbpm.java 2008-10-13 21:54:29 UTC (rev 9285)
+++ trunk/src/main/org/jboss/seam/bpm/Jbpm.java 2008-10-13 22:46:22 UTC (rev 9286)
@@ -35,6 +35,7 @@
import org.jboss.seam.log.LogProvider;
import org.jboss.seam.log.Logging;
import org.jboss.seam.util.Naming;
+import org.jboss.seam.util.Resources;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.graph.def.ProcessDefinition;
@@ -165,6 +166,8 @@
catch (JpdlException e)
{
throw new JpdlException("Unable to parse process definition " +
resourceName, e);
+ } finally {
+ Resources.closeStream(resource);
}
}
@@ -175,7 +178,12 @@
{
throw new IllegalArgumentException("process definition resource not found:
" + resourceName);
}
- return ProcessDefinition.parseXmlInputStream(resource);
+
+ try {
+ return ProcessDefinition.parseXmlInputStream(resource);
+ } finally {
+ Resources.closeStream(resource);
+ }
}
public String[] getPageflowDefinitions()
@@ -216,7 +224,13 @@
*/
public ProcessDefinition getPageflowDefinitionFromXml(String pageflowDefinition)
{
- return Jbpm.parseInputSource( new InputSource( new ReaderInputStream( new
StringReader(pageflowDefinition) ) ) );
+ InputStream stream = null;
+ try {
+ stream = new ReaderInputStream(new StringReader(pageflowDefinition));
+ return Jbpm.parseInputSource(new InputSource(stream));
+ } finally {
+ Resources.closeStream(stream);
+ }
}
/**
@@ -226,7 +240,13 @@
*/
public ProcessDefinition getProcessDefinitionFromXml(String processDefinition)
{
- return ProcessDefinition.parseXmlInputStream( new ReaderInputStream( new
StringReader(processDefinition) ) );
+ InputStream stream = null;
+ try {
+ stream = new ReaderInputStream(new StringReader(processDefinition));
+ return ProcessDefinition.parseXmlInputStream(stream);
+ } finally {
+ Resources.closeStream(stream);
+ }
}
/**
Modified: trunk/src/main/org/jboss/seam/bpm/PageflowDeploymentHandler.java
===================================================================
--- trunk/src/main/org/jboss/seam/bpm/PageflowDeploymentHandler.java 2008-10-13 21:54:29
UTC (rev 9285)
+++ trunk/src/main/org/jboss/seam/bpm/PageflowDeploymentHandler.java 2008-10-13 22:46:22
UTC (rev 9286)
@@ -35,21 +35,20 @@
public void handle(String name, ClassLoader classLoader)
{
- if (name.endsWith(".jpdl.xml"))
- {
+ if (name.endsWith(".jpdl.xml")) {
InputStream inputStream = Resources.getResourceAsStream(name, null);
- try
- {
+ try {
Element root = XML.getRootElementSafely(inputStream);
if ("pageflow-definition".equals(root.getName()))
{
pageflowDefinitions.add(name);
}
- }
- catch (DocumentException e)
- {
+ } catch (DocumentException e) {
log.debug("Unable to parse " + name, e);
+ } finally {
+ Resources.closeStream(inputStream);
}
+
}
}
Modified: trunk/src/main/org/jboss/seam/exception/Exceptions.java
===================================================================
--- trunk/src/main/org/jboss/seam/exception/Exceptions.java 2008-10-13 21:54:29 UTC (rev
9285)
+++ trunk/src/main/org/jboss/seam/exception/Exceptions.java 2008-10-13 22:46:22 UTC (rev
9286)
@@ -28,6 +28,7 @@
import org.jboss.seam.log.Logging;
import org.jboss.seam.navigation.Pages;
import org.jboss.seam.util.Reflections;
+import org.jboss.seam.util.Resources;
import org.jboss.seam.util.Strings;
import org.jboss.seam.util.XML;
@@ -147,8 +148,15 @@
InputStream stream = ResourceLoader.instance().getResourceAsStream(fileName);
if (stream!=null)
{
- log.debug("reading exception mappings from " + fileName);
- List<Element> elements =
XML.getRootElement(stream).elements("exception");
+ log.debug("reading exception mappings from " + fileName);
+
+ List<Element> elements = null;
+ try {
+ elements = XML.getRootElement(stream).elements("exception");
+ } finally {
+ Resources.closeStream(stream);
+ }
+
for (final Element exception: elements)
{
String className = exception.attributeValue("class");
Modified: trunk/src/main/org/jboss/seam/init/Initialization.java
===================================================================
--- trunk/src/main/org/jboss/seam/init/Initialization.java 2008-10-13 21:54:29 UTC (rev
9285)
+++ trunk/src/main/org/jboss/seam/init/Initialization.java 2008-10-13 22:46:22 UTC (rev
9286)
@@ -186,20 +186,20 @@
seenDocuments.addAll(documentNames);
}
- if (!skip)
- {
- try
- {
+ if (!skip) {
+ try{
+ InputStream stream = url.openStream();
+
log.debug("reading " + url);
- installComponentsFromXmlElements( XML.getRootElement( url.openStream() ),
replacements );
- }
- catch (Exception e)
- {
+ try {
+ installComponentsFromXmlElements(XML.getRootElement(stream),
replacements);
+ } finally {
+ Resources.closeStream(stream);
+ }
+ } catch (Exception e) {
throw new RuntimeException("error while reading " + url, e);
}
- }
- else
- {
+ } else {
log.trace("skipping read of duplicate components.xml " + url);
}
}
@@ -219,22 +219,26 @@
catch (Exception e)
{
throw new RuntimeException("error while reading
/WEB-INF/components.xml", e);
+ } finally {
+ Resources.closeStream(stream);
}
}
}
private Properties getReplacements()
{
- try
- {
+ InputStream replaceStream = null;
+ try {
Properties replacements = new Properties();
- InputStream replaceStream =
Resources.getResourceAsStream("/components.properties", servletContext);
- if (replaceStream != null) replacements.load(replaceStream);
+ replaceStream =
Resources.getResourceAsStream("/components.properties", servletContext);
+ if (replaceStream != null) {
+ replacements.load(replaceStream);
+ }
return replacements;
- }
- catch (IOException ioe)
- {
+ } catch (IOException ioe) {
throw new RuntimeException("error reading components.properties",
ioe);
+ } finally {
+ Resources.closeStream(replaceStream);
}
}
@@ -908,10 +912,10 @@
classFilenameFromDescriptor(fileName),
replacements);
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
throw new RuntimeException("error while reading " + fileName, e);
+ } finally {
+ Resources.closeStream(stream);
}
}
}
@@ -1021,13 +1025,9 @@
log.error("could not read " + resource, ioe);
}
}
- finally
+ finally
{
- try
- {
- stream.close();
- }
- catch (IOException ex) { } // swallow
+ Resources.closeStream(stream);
}
}
else
Modified: trunk/src/main/org/jboss/seam/navigation/Pages.java
===================================================================
--- trunk/src/main/org/jboss/seam/navigation/Pages.java 2008-10-13 21:54:29 UTC (rev
9285)
+++ trunk/src/main/org/jboss/seam/navigation/Pages.java 2008-10-13 22:46:22 UTC (rev
9286)
@@ -57,6 +57,7 @@
import org.jboss.seam.pageflow.Pageflow;
import org.jboss.seam.security.Identity;
import org.jboss.seam.security.NotLoggedInException;
+import org.jboss.seam.util.Resources;
import org.jboss.seam.util.Strings;
import org.jboss.seam.util.XML;
import org.jboss.seam.web.Parameters;
@@ -120,7 +121,11 @@
log.info("no pages.xml file found: " + resource);
} else {
log.debug("reading pages.xml file: " + resource);
- parse(stream);
+ try {
+ parse(stream);
+ } finally {
+ Resources.closeStream(stream);
+ }
}
}
@@ -153,7 +158,11 @@
else
{
log.debug("reading pages.xml file: " + fileName);
- parse(stream,viewId);
+ try {
+ parse(stream,viewId);
+ } finally {
+ Resources.closeStream(stream);
+ }
}
}
}
Modified: trunk/src/main/org/jboss/seam/util/Resources.java
===================================================================
--- trunk/src/main/org/jboss/seam/util/Resources.java 2008-10-13 21:54:29 UTC (rev 9285)
+++ trunk/src/main/org/jboss/seam/util/Resources.java 2008-10-13 22:46:22 UTC (rev 9286)
@@ -1,14 +1,18 @@
package org.jboss.seam.util;
+import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import javax.servlet.ServletContext;
import org.jboss.seam.Seam;
+import org.jboss.seam.log.LogProvider;
+import org.jboss.seam.log.Logging;
public class Resources
{
+ private static final LogProvider log = Logging.getLogProvider(Resources.class);
public static InputStream getResourceAsStream(String resource, ServletContext
servletContext)
{
@@ -17,17 +21,18 @@
InputStream stream = null;
- if (servletContext!=null)
- {
- try
- {
+ if (servletContext!=null) {
+ try {
stream = servletContext.getResourceAsStream(resource);
+ if (stream!=null) {
+ log.debug("Loaded resource from servlet context: " +
resource);
+ }
+ } catch (Exception e) {
+ //
}
- catch (Exception e) {}
}
- if (stream==null)
- {
+ if (stream==null) {
stream = getResourceAsStream(resource, stripped);
}
@@ -43,11 +48,12 @@
if (servletContext!=null)
{
- try
- {
+ try {
url = servletContext.getResource(resource);
+ log.debug("Loaded resource from servlet context: " + url);
+ } catch (Exception e) {
+ //
}
- catch (Exception e) {}
}
if (url==null)
@@ -62,38 +68,68 @@
{
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream stream = null;
- if (classLoader!=null)
- {
+ if (classLoader!=null) {
stream = classLoader.getResourceAsStream(stripped);
+ if (stream !=null) {
+ log.debug("Loaded resource from context classloader: " +
stripped);
+ }
}
- if ( stream == null )
- {
+
+ if (stream == null) {
stream = Seam.class.getResourceAsStream(resource);
+ if (stream !=null) {
+ log.debug("Loaded resource from Seam classloader: " + resource);
+ }
}
- if ( stream == null )
- {
+
+ if (stream == null) {
stream = Seam.class.getClassLoader().getResourceAsStream(stripped);
+ if (stream!=null) {
+ log.debug("Loaded resource from Seam classloader: " + stripped);
+ }
}
+
return stream;
}
static URL getResource(String resource, String stripped)
{
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- URL url = null;
- if (classLoader!=null)
- {
- url = classLoader.getResource(stripped);
- }
- if ( url == null )
- {
- url = Seam.class.getResource(resource);
- }
- if ( url == null )
- {
- url = Seam.class.getClassLoader().getResource(stripped);
- }
- return url;
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ URL url = null;
+ if (classLoader!=null) {
+ url = classLoader.getResource(stripped);
+ if (url!=null) {
+ log.debug("Loaded resource from context classloader: " + url);
+ }
+ }
+
+ if (url == null) {
+ url = Seam.class.getResource(resource);
+ if (url!=null) {
+ log.debug("Loaded resource from Seam classloader: " + url);
+ }
+ }
+
+ if (url == null) {
+ url = Seam.class.getClassLoader().getResource(stripped);
+ if (url!=null) {
+ log.debug("Loaded resource from Seam classloader: " + url);
+ }
+ }
+
+ return url;
}
+ public static void closeStream(InputStream inputStream) {
+ if (inputStream == null) {
+ return;
+ }
+
+ try {
+ inputStream.close();
+ } catch (IOException e) {
+ //
+ }
+ }
+
}
Modified: trunk/src/pdf/org/jboss/seam/pdf/ui/UISignature.java
===================================================================
--- trunk/src/pdf/org/jboss/seam/pdf/ui/UISignature.java 2008-10-13 21:54:29 UTC (rev
9285)
+++ trunk/src/pdf/org/jboss/seam/pdf/ui/UISignature.java 2008-10-13 22:46:22 UTC (rev
9286)
@@ -12,6 +12,7 @@
import org.jboss.seam.pdf.ITextUtils;
import org.jboss.seam.pdf.KeyStoreConfig;
import org.jboss.seam.util.FacesResources;
+import org.jboss.seam.util.Resources;
import com.lowagie.text.DocWriter;
import com.lowagie.text.pdf.PdfAcroForm;
@@ -123,11 +124,10 @@
public byte[] sign(byte[] originalBytes)
{
KeyStoreConfig store = KeyStoreConfig.instance();
+ InputStream is = null;
+ try {
+ is = FacesResources.getResourceAsStream(store.getKeyStore(),
getFacesContext().getExternalContext());
- try
- {
- InputStream is = FacesResources.getResourceAsStream(store.getKeyStore(),
getFacesContext().getExternalContext());
-
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(is, store.getKeyStorePassword().toCharArray());
@@ -148,10 +148,10 @@
stamper.close();
return os.toByteArray();
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
throw new RuntimeException(e);
+ } finally {
+ Resources.closeStream(is);
}
}