1616// under the License.
1717package com .cloud .utils .server ;
1818
19- import com .cloud .utils .PropertiesUtil ;
2019import com .cloud .utils .crypt .EncryptionSecretKeyChecker ;
2120import com .cloud .utils .StringUtils ;
2221import org .apache .commons .io .IOUtils ;
2322import org .apache .logging .log4j .Logger ;
2423import org .apache .logging .log4j .LogManager ;
2524
2625import java .io .File ;
27- import java .io .FileInputStream ;
2826import java .io .IOException ;
2927import java .io .InputStream ;
3028import java .util .Properties ;
3129
3230public class ServerProperties {
3331 protected Logger logger = LogManager .getLogger (getClass ());
3432
33+ public static final String HTTP_ENABLE = "http.enable" ;
34+ public static final String HTTP_PORT = "http.port" ;
3535 public static final String HTTPS_ENABLE = "https.enable" ;
36+ public static final String HTTPS_PORT = "https.port" ;
3637 public static final String KEYSTORE_FILE = "https.keystore" ;
3738 public static final String PASSWORD_ENCRYPTION_TYPE = "password.encryption.type" ;
3839
3940 private static Properties properties = new Properties ();
4041 private static boolean loaded = false ;
4142
43+ private static int httpPort = 8080 ;
44+
45+ private static boolean httpsEnable = false ;
46+ private static int httpsPort = 8443 ;
47+
4248 public synchronized static Properties getServerProperties (InputStream inputStream ) {
4349 if (!loaded ) {
4450 Properties serverProps = new Properties ();
@@ -57,31 +63,29 @@ public synchronized static Properties getServerProperties(InputStream inputStrea
5763 IOUtils .closeQuietly (inputStream );
5864 }
5965
66+ httpPort = Integer .parseInt (serverProps .getProperty (ServerProperties .HTTP_PORT , "8080" ));
67+
68+ boolean httpsEnabled = Boolean .parseBoolean (serverProps .getProperty (ServerProperties .HTTPS_ENABLE , "false" ));
69+ String keystoreFile = serverProps .getProperty (KEYSTORE_FILE );
70+ httpsEnable = httpsEnabled && StringUtils .isNotEmpty (keystoreFile ) && new File (keystoreFile ).exists ();
71+ httpsPort = Integer .parseInt (serverProps .getProperty (ServerProperties .HTTPS_PORT , "8443" ));
72+
6073 properties = serverProps ;
6174 loaded = true ;
6275 }
6376
6477 return properties ;
6578 }
6679
67- public static boolean isHttpsEnabled () {
68- final File confFile = PropertiesUtil .findConfigFile ("server.properties" );
69- if (confFile == null ) {
70- return false ;
71- }
80+ public static int getHttpPort () {
81+ return httpPort ;
82+ }
7283
73- try {
74- InputStream is = new FileInputStream (confFile );
75- final Properties properties = ServerProperties .getServerProperties (is );
76- if (properties == null ) {
77- return false ;
78- }
84+ public static boolean isHttpsEnabled () {
85+ return httpsEnable ;
86+ }
7987
80- boolean httpsEnable = Boolean .parseBoolean (properties .getProperty (HTTPS_ENABLE , "false" ));
81- String keystoreFile = properties .getProperty (KEYSTORE_FILE );
82- return httpsEnable && StringUtils .isNotEmpty (keystoreFile ) && new File (keystoreFile ).exists ();
83- } catch (final IOException e ) {
84- return false ;
85- }
88+ public static int getHttpsPort () {
89+ return httpsPort ;
8690 }
8791}
0 commit comments