summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/network
diff options
context:
space:
mode:
authorBjörn Hagemeister2014-11-12 15:01:39 +0100
committerBjörn Hagemeister2014-11-12 15:01:39 +0100
commitbcc7a3761ce5801d747653f6f97b094c9ccdbb45 (patch)
tree384c9331c2f0c99ce76608ab628ab02fa8772e7d /src/main/java/org/openslx/network
parentParametrized Enumerator. (diff)
downloadmaster-sync-shared-bcc7a3761ce5801d747653f6f97b094c9ccdbb45.tar.gz
master-sync-shared-bcc7a3761ce5801d747653f6f97b094c9ccdbb45.tar.xz
master-sync-shared-bcc7a3761ce5801d747653f6f97b094c9ccdbb45.zip
Added class for reading proxy setting from proxy configuration file.
Added class utils for some necessary tools, used in ProxyConfiguration.
Diffstat (limited to 'src/main/java/org/openslx/network')
-rw-r--r--src/main/java/org/openslx/network/ProxyConfiguration.java73
1 files changed, 73 insertions, 0 deletions
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));
+ }
+}