diff options
| author | Weston M. Price <wprice@apache.org> | 2012-05-03 19:03:57 +0000 |
|---|---|---|
| committer | Weston M. Price <wprice@apache.org> | 2012-05-03 19:03:57 +0000 |
| commit | 7d01b7ea7529ccb52e4f965f3997d67f153a5b0e (patch) | |
| tree | 7a591efe6018c346003aeaab43ca1c564a072499 /qpid/java/client/src/main | |
| parent | 82695a85d7f1caa65b6ce805f2214abafd2f7f52 (diff) | |
| download | qpid-python-7d01b7ea7529ccb52e4f965f3997d67f153a5b0e.tar.gz | |
QPID-3971: PropertiesFileInitialContextFactory cannot open file URL
*Added capability to read java.naming.provider.url from file:// URI
*Added PropertiesFileInitialContextFactoryTest
*Moved functionaly from old JNDIPropertiesTest to new test class
*Minor cleanup. Added @SuppressWarnings annotation to
PropertiesFileInitialContext
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1333586 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/client/src/main')
| -rw-r--r-- | qpid/java/client/src/main/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactory.java | 62 |
1 files changed, 42 insertions, 20 deletions
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactory.java b/qpid/java/client/src/main/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactory.java index bc3f89849e..9b202a13ee 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactory.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactory.java @@ -20,8 +20,26 @@ */ package org.apache.qpid.jndi; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; +import java.util.concurrent.ConcurrentHashMap; + +import javax.jms.ConnectionFactory; +import javax.jms.Destination; +import javax.jms.Queue; +import javax.jms.Topic; +import javax.naming.ConfigurationException; +import javax.naming.Context; +import javax.naming.NamingException; +import javax.naming.spi.InitialContextFactory; import org.apache.qpid.client.AMQConnectionFactory; import org.apache.qpid.client.AMQDestination; @@ -33,23 +51,10 @@ import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.url.BindingURL; import org.apache.qpid.url.URLSyntaxException; import org.apache.qpid.util.Strings; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + -import javax.jms.ConnectionFactory; -import javax.jms.Destination; -import javax.jms.Queue; -import javax.jms.Topic; -import javax.naming.ConfigurationException; -import javax.naming.Context; -import javax.naming.NamingException; -import javax.naming.spi.InitialContextFactory; -import java.io.BufferedInputStream; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.Map; -import java.util.Properties; -import java.util.concurrent.ConcurrentHashMap; public class PropertiesFileInitialContextFactory implements InitialContextFactory { @@ -60,6 +65,7 @@ public class PropertiesFileInitialContextFactory implements InitialContextFactor private String QUEUE_PREFIX = "queue."; private String TOPIC_PREFIX = "topic."; + @SuppressWarnings({ "rawtypes", "unchecked" }) public Context getInitialContext(Hashtable environment) throws NamingException { Map data = new ConcurrentHashMap(); @@ -68,6 +74,7 @@ public class PropertiesFileInitialContextFactory implements InitialContextFactor { String file = null; + if (environment.containsKey(Context.PROVIDER_URL)) { file = (String) environment.get(Context.PROVIDER_URL); @@ -77,13 +84,23 @@ public class PropertiesFileInitialContextFactory implements InitialContextFactor file = System.getProperty(Context.PROVIDER_URL); } + // Load the properties specified if (file != null) { _logger.info("Loading Properties from:" + file); + BufferedInputStream inputStream = null; - // Load the properties specified - BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(file)); + if(file.contains("file:")) + { + inputStream = new BufferedInputStream(new FileInputStream(new File(new URI(file)))); + } + else + { + inputStream = new BufferedInputStream(new FileInputStream(file)); + } + Properties p = new Properties(); + try { p.load(inputStream); @@ -119,6 +136,11 @@ public class PropertiesFileInitialContextFactory implements InitialContextFactor _logger.warn("Unable to load property file specified in Provider_URL:" + environment.get(Context.PROVIDER_URL) +"\n" + "Due to:"+ioe.getMessage()); } + catch(URISyntaxException uoe) + { + _logger.warn("Unable to load property file specified in Provider_URL:" + environment.get(Context.PROVIDER_URL) +"\n" + + "Due to:"+uoe.getMessage()); + } createConnectionFactories(data, environment); |
