Author: richard.opalka(a)jboss.com
Date: 2009-04-09 08:41:31 -0400 (Thu, 09 Apr 2009)
New Revision: 9770
Modified:
common/trunk/src/main/java/org/jboss/ws/core/utils/JBossWSEntityResolver.java
Log:
[JBWS-2598] fix
Modified: common/trunk/src/main/java/org/jboss/ws/core/utils/JBossWSEntityResolver.java
===================================================================
---
common/trunk/src/main/java/org/jboss/ws/core/utils/JBossWSEntityResolver.java 2009-04-08
15:32:16 UTC (rev 9769)
+++
common/trunk/src/main/java/org/jboss/ws/core/utils/JBossWSEntityResolver.java 2009-04-09
12:41:31 UTC (rev 9770)
@@ -25,6 +25,8 @@
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.util.Enumeration;
import java.util.Properties;
@@ -37,7 +39,7 @@
* Dynamically register the JBossWS entities.
*
* @author Thomas.Diesler(a)jboss.org
- * @since 02-Aug-2006
+ * @author Richard.Opalka(a)jboss.org
*/
public class JBossWSEntityResolver extends JBossEntityResolver
{
@@ -52,40 +54,54 @@
public JBossWSEntityResolver(final String entitiesResource)
{
super();
- // get stream
- InputStream is =
this.getClass().getClassLoader().getResourceAsStream(entitiesResource);
- if (is == null)
- throw new IllegalArgumentException("Resource " + entitiesResource + "
not found");
-
- // load props
- Properties props = new Properties();
- try
- {
- props.load(is);
- }
- catch (IOException ioe)
- {
- log.error("Cannot read resource: " + entitiesResource, ioe);
- }
- finally
- {
- try { is.close(); } catch (IOException ioe) {} // ignore
- }
-
- if (props.size() == 0)
- throw new IllegalArgumentException("Resource " + entitiesResource + "
have no mappings defined");
-
+
+ // load entities
+ Properties props = loadEntitiesMappingFromClasspath(entitiesResource);
+ if (props.size() == 0)
+ throw new IllegalArgumentException("No entities mapping defined in resource
file: " + entitiesResource);
+
// register entities
String key = null, val = null;
for (Enumeration<Object> keys = props.keys(); keys.hasMoreElements();)
{
key = (String)keys.nextElement();
val = props.getProperty(key);
+
registerEntity(key, val);
}
}
+ private Properties loadEntitiesMappingFromClasspath(final String entitiesResource)
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<Properties>()
+ {
+ public Properties run()
+ {
+ InputStream is =
this.getClass().getClassLoader().getResourceAsStream(entitiesResource);
+ // get stream
+ if (is == null)
+ throw new IllegalArgumentException("Resource " +
entitiesResource + " not found");
+ // load props
+ Properties props = new Properties();
+ try
+ {
+ props.load(is);
+ }
+ catch (IOException ioe)
+ {
+ log.error("Cannot read resource: " + entitiesResource, ioe);
+ }
+ finally
+ {
+ try { is.close(); } catch (IOException ioe) {} // ignore
+ }
+
+ return props;
+ }
+ });
+ }
+
public InputSource resolveEntity(String publicId, String systemId) throws
SAXException, IOException
{
if(log.isDebugEnabled()) log.debug("resolveEntity: [pub=" + publicId +
",sysid=" + systemId + "]");
Show replies by date