Skip to content

Commit 11c1eff

Browse files
committed
Properties load IO fix
1 parent 27cf1f4 commit 11c1eff

File tree

5 files changed

+66
-36
lines changed

5 files changed

+66
-36
lines changed

QueueIT.Security/src/queueit/security/CookieValidateResultRepository.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,17 @@ public class CookieValidateResultRepository extends ValidateResultRepositoryBase
2222
}
2323

2424
private static void loadConfiguration()
25-
{
25+
{
2626
try {
2727
// Load the properties
28-
Properties props = new Properties();
29-
ClassLoader classLoader = CookieValidateResultRepository.class.getClassLoader();
30-
InputStream configFile = classLoader.getResourceAsStream("queueit.properties");
31-
if (configFile != null) {
32-
props.load(configFile);
33-
defaultCookieDomain = props.getProperty("cookieDomain", null);
34-
defaultCookieExpiration = Integer.parseInt(props.getProperty("cookieExpiration", "1200"));
35-
}
28+
Properties props = QueueitProperties.getProperties("queueit.properties");
29+
defaultCookieDomain = props.getProperty("cookieDomain", null);
30+
defaultCookieExpiration = Integer.parseInt(props.getProperty("cookieExpiration", "1200"));
3631
} catch (Exception e) {
3732
// no need to handle exception
38-
}
33+
}
3934
}
35+
4036
@Override
4137
public IValidateResult getValidationResult(IQueue queue) {
4238

QueueIT.Security/src/queueit/security/KnownUserFactory.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,12 @@ private static void loadConfiguration()
3232
{
3333
try {
3434
// Load the properties
35-
Properties props = new Properties();
36-
ClassLoader classLoader = KnownUserFactory.class.getClassLoader();
37-
InputStream configFile = classLoader.getResourceAsStream("queueit.properties");
38-
if (configFile != null) {
39-
props.load(configFile);
40-
defaultSecretKey = props.getProperty("secretKey", null);
41-
defaultQuerystringPrefix = props.getProperty("queryStringPrefix", null);
42-
}
35+
Properties props = QueueitProperties.getProperties("queueit.properties");
36+
defaultSecretKey = props.getProperty("secretKey", null);
37+
defaultQuerystringPrefix = props.getProperty("queryStringPrefix", null);
4338
} catch (Exception e) {
44-
String x = e.getMessage();
45-
// Handle exception as needed
46-
}
39+
// Ignore
40+
}
4741
}
4842

4943
public static void configure(String sharedEventKey) {

QueueIT.Security/src/queueit/security/QueueFactory.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,7 @@ public static IQueue createQueue(String queueName)
3232
String fileName = "queueit-" + queueName + ".properties";
3333
try {
3434
// Load the properties
35-
Properties props = new Properties();
36-
ClassLoader classLoader = KnownUserFactory.class.getClassLoader();
37-
InputStream configFile = classLoader.getResourceAsStream(fileName);
38-
if (configFile == null) {
39-
throw new IllegalArgumentException("Properties file '" + fileName + "' not found in classpath");
40-
}
41-
props.load(configFile);
35+
Properties props = QueueitProperties.getProperties(fileName);
4236

4337
String landingPage = props.getProperty("landingPage", null);
4438
String language = props.getProperty("language", null);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* To change this template, choose Tools | Templates
3+
* and open the template in the editor.
4+
*/
5+
package queueit.security;
6+
7+
import java.util.HashMap;
8+
import java.util.Map;
9+
import java.util.Properties;
10+
import java.io.IOException;
11+
import java.io.InputStream;
12+
13+
/**
14+
*
15+
* @author mala_000
16+
*/
17+
public class QueueitProperties {
18+
19+
private static Map<String, Properties> properties = new HashMap<String, Properties>();
20+
21+
public static Properties getProperties(String id) throws IOException {
22+
if (!properties.containsKey(id)) {
23+
24+
InputStream configFile = null;
25+
26+
try {
27+
// Load the properties
28+
Properties props = new Properties();
29+
ClassLoader classLoader = QueueitProperties.class.getClassLoader();
30+
configFile = classLoader.getResourceAsStream(id);
31+
if (configFile == null) {
32+
throw new IOException("Config file '" + id + "' was not loaded");
33+
}
34+
35+
props.load(configFile);
36+
properties.put(id, props);
37+
}
38+
finally {
39+
if (configFile != null) {
40+
try {
41+
configFile.close();
42+
} catch(Exception ex) {
43+
//ignore
44+
}
45+
}
46+
}
47+
}
48+
49+
return properties.get(id);
50+
}
51+
}

QueueIT.Security/src/queueit/security/SessionValidationController.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,16 +370,11 @@ private static IValidateResult validateRequest(
370370
}
371371
}
372372

373-
private static void loadConfiguration() {
373+
private static void loadConfiguration() {
374374
try {
375375
// Load the properties
376-
Properties props = new Properties();
377-
ClassLoader classLoader = KnownUserFactory.class.getClassLoader();
378-
InputStream configFile = classLoader.getResourceAsStream("queueit.properties");
379-
if (configFile != null) {
380-
props.load(configFile);
381-
defaultTicketExpiration = Integer.parseInt(props.getProperty("ticketExpiration", "180"));
382-
}
376+
Properties props = QueueitProperties.getProperties("queueit.properties");
377+
defaultTicketExpiration = Integer.parseInt(props.getProperty("ticketExpiration", "180"));
383378
} catch (Exception e) {
384379
// ignore
385380
}

0 commit comments

Comments
 (0)