From bcc7a3761ce5801d747653f6f97b094c9ccdbb45 Mon Sep 17 00:00:00 2001 From: Björn Hagemeister Date: Wed, 12 Nov 2014 15:01:39 +0100 Subject: Added class for reading proxy setting from proxy configuration file. Added class utils for some necessary tools, used in ProxyConfiguration. --- .../org/openslx/network/ProxyConfiguration.java | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/main/java/org/openslx/network/ProxyConfiguration.java (limited to 'src/main/java/org/openslx/network') diff --git a/src/main/java/org/openslx/network/ProxyConfiguration.java b/src/main/java/org/openslx/network/ProxyConfiguration.java new file mode 100644 index 0000000..5a97b62 --- /dev/null +++ b/src/main/java/org/openslx/network/ProxyConfiguration.java @@ -0,0 +1,73 @@ +package org.openslx.network; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.Properties; + +import org.apache.log4j.Logger; +import org.openslx.util.Util; + +public class ProxyConfiguration +{ + private static Logger log = Logger.getLogger( ProxyConfiguration.class ); + private static final Properties properties = new Properties(); + + // Getting the proxy settings from config file stored in + // "/opt/openslx/proxy/conf". + public static String getProxyConf() + { + return properties.getProperty( "PROXY_CONF" ); + } + + public static String getProxyAddress() + { + return properties.getProperty( "PROXY_ADDR" ); + } + + public static String getProxyUsername() + { + return properties.getProperty( "PROXY_USERNAME" ); + } + + public static String getProxyPassword() + { + return properties.getProperty( "PROXY_PASSWORD" ); + } + + // Integers // + public static int getProxyPort() + { + return Util.tryToParseInt( properties.getProperty( "PROXY_PORT" ) ); + } + + /** + * Load properties + */ + static { + InputStreamReader stream = null; + try { + // Load all entries of the config file into properties + stream = new InputStreamReader( + new FileInputStream("/opt/openslx/proxy/config"), StandardCharsets.UTF_8); + properties.load(stream); + stream.close(); + } catch (IOException e) { + log.error("Could not load proxy properties from '/opt/openslx/proxy/conf'. Exiting."); + System.exit( 2 ); + } finally { + Util.streamClose( stream ); + } + } + + /** + * Check proxy settings for being not empty. + * @return + */ + public static boolean checkProxySettings() { + return ( + (getProxyAddress() != "") && + (getProxyPort() != 0)); + } +} -- cgit v1.2.3-55-g7522