diff options
author | Weston M. Price <wprice@apache.org> | 2012-05-13 10:27:23 +0000 |
---|---|---|
committer | Weston M. Price <wprice@apache.org> | 2012-05-13 10:27:23 +0000 |
commit | 850bd17e9cfc9196478bddf9668238db8432811f (patch) | |
tree | 4186e1b9164277e29069de49bacb9ff44645911e | |
parent | 30c12a0d7fb3855ff7d4b2fb8c5245f8b63a0ab8 (diff) | |
download | qpid-python-850bd17e9cfc9196478bddf9668238db8432811f.tar.gz |
QPID-3994: add support for optionally retrieving FindBugs using Ivy
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1337829 13f79535-47bb-0310-9956-ffa450edef68
2 files changed, 51 insertions, 35 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 9b202a13ee..935b4e7d9d 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 @@ -69,46 +69,24 @@ public class PropertiesFileInitialContextFactory implements InitialContextFactor public Context getInitialContext(Hashtable environment) throws NamingException { Map data = new ConcurrentHashMap(); - + File file = null; + BufferedInputStream inputStream = null; try { - String file = null; - - if (environment.containsKey(Context.PROVIDER_URL)) - { - file = (String) environment.get(Context.PROVIDER_URL); - } - else - { - file = System.getProperty(Context.PROVIDER_URL); - } + String fileName = (environment.containsKey(Context.PROVIDER_URL)) + ? (String)environment.get(Context.PROVIDER_URL) : System.getProperty(Context.PROVIDER_URL); - // Load the properties specified - if (file != null) + _logger.info("Attempting to load " + fileName); + + + if (fileName != null) { - _logger.info("Loading Properties from:" + file); - BufferedInputStream inputStream = null; - if(file.contains("file:")) - { - inputStream = new BufferedInputStream(new FileInputStream(new File(new URI(file)))); - } - else - { - inputStream = new BufferedInputStream(new FileInputStream(file)); - } - + inputStream = new BufferedInputStream(new FileInputStream((fileName.contains("file:")) + ? new File(new URI(fileName)) : new File(fileName))); Properties p = new Properties(); - - try - { - p.load(inputStream); - } - finally - { - inputStream.close(); - } + p.load(inputStream); Strings.Resolver resolver = new Strings.ChainedResolver (Strings.SYSTEM_RESOLVER, new Strings.PropertiesResolver(p)); @@ -134,12 +112,23 @@ public class PropertiesFileInitialContextFactory implements InitialContextFactor catch (IOException ioe) { _logger.warn("Unable to load property file specified in Provider_URL:" + environment.get(Context.PROVIDER_URL) +"\n" + - "Due to:"+ioe.getMessage()); + "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()); + "Due to:" + uoe.getMessage()); + } + finally + { + try + { + if(inputStream != null) + { + inputStream.close(); + } + } + catch(Exception ignore){} } createConnectionFactories(data, environment); diff --git a/qpid/java/client/src/test/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactoryTest.java b/qpid/java/client/src/test/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactoryTest.java index 2989970dcd..5f0fa9550f 100644 --- a/qpid/java/client/src/test/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactoryTest.java +++ b/qpid/java/client/src/test/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactoryTest.java @@ -21,6 +21,10 @@ package org.apache.qpid.jndi; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileWriter; import java.util.Properties; import javax.jms.Destination; @@ -51,7 +55,30 @@ public class PropertiesFileInitialContextFactoryTest extends TestCase ctx = new InitialContext(properties); } + public void testContextFromProviderURL() throws Exception + { + Properties properties = new Properties(); + properties.load(this.getClass().getResourceAsStream("hello.properties")); + File f = new File(System.getProperty("java.io.tmpdir") + FILE_NAME); + FileOutputStream fos = new FileOutputStream(f); + properties.store(fos, null); + + System.setProperty("java.naming.factory.initial", "org.apache.qpid.jndi.PropertiesFileInitialContextFactory"); + System.setProperty("java.naming.provider.url", "file://" + f.getCanonicalPath()); + + InitialContext context = new InitialContext(); + assertNotNull("Lookup from URI based context should not be null", context.lookup("topicExchange")); + context.close(); + + System.setProperty("java.naming.provider.url", f.getCanonicalPath()); + context = new InitialContext(); + assertNotNull("Lookup from fileName should not be null", context.lookup("qpidConnectionfactory")); + + context.close(); + f.delete(); + + } public void testQueueNamesWithTrailingSpaces() throws Exception { Queue queue = (Queue)ctx.lookup("QueueNameWithSpace"); |