|
1 | 1 | package de.rwth.idsg.steve; |
2 | 2 |
|
3 | 3 | import de.rwth.idsg.steve.ocpp.ws.custom.WsSessionSelectStrategyEnum; |
| 4 | +import de.rwth.idsg.steve.utils.PropertiesFileLoader; |
| 5 | +import lombok.Builder; |
| 6 | +import lombok.Getter; |
4 | 7 |
|
5 | 8 | /** |
6 | 9 | * @author Sevket Goekay <goekay@dbis.rwth-aachen.de> |
7 | 10 | * @since 19.08.2014 |
8 | 11 | */ |
| 12 | +@Getter |
9 | 13 | public final class SteveConfiguration { |
10 | | - private SteveConfiguration() { } |
| 14 | + public static final SteveConfiguration CONFIG = new SteveConfiguration(); |
11 | 15 |
|
12 | 16 | // Root mapping for Spring |
13 | | - public static final String SPRING_MAPPING = "/"; |
| 17 | + private String springMapping = "/"; |
14 | 18 | // Web frontend |
15 | | - public static final String SPRING_MANAGER_MAPPING = "/manager/*"; |
| 19 | + private String springManagerMapping = "/manager/*"; |
16 | 20 | // Mapping for CXF SOAP services |
17 | | - public static final String CXF_MAPPING = "/services/*"; |
| 21 | + private String cxfMapping = "/services/*"; |
18 | 22 | // Just to be backwards compatible with previous versions of Steve, |
19 | 23 | // since there might be already configured chargepoints expecting the older path. |
20 | 24 | // Otherwise, might as well be "/". |
21 | | - public static final String CONTEXT_PATH = "/steve"; |
| 25 | + private String contextPath = "/steve"; |
22 | 26 | // Dummy service path |
23 | | - public static final String ROUTER_ENDPOINT_PATH = "/CentralSystemService"; |
| 27 | + private String routerEndpointPath = "/CentralSystemService"; |
24 | 28 |
|
25 | 29 | // ------------------------------------------------------------------------- |
26 | 30 | // main.properties |
27 | 31 | // ------------------------------------------------------------------------- |
28 | 32 |
|
29 | | - public static String STEVE_VERSION; |
30 | | - public static ApplicationProfile PROFILE; |
| 33 | + private String steveVersion; |
| 34 | + private ApplicationProfile profile; |
| 35 | + private Ocpp ocpp; |
| 36 | + private Auth auth; |
| 37 | + private DB db; |
| 38 | + private Jetty jetty; |
31 | 39 |
|
32 | | - /** |
33 | | - * Jetty configuration |
34 | | - */ |
35 | | - public static final class Jetty { |
36 | | - public static String SERVER_HOST; |
37 | | - public static boolean GZIP_ENABLED; |
| 40 | + private SteveConfiguration() { |
| 41 | + PropertiesFileLoader p = new PropertiesFileLoader("main.properties"); |
| 42 | + |
| 43 | + steveVersion = p.getString("steve.version"); |
| 44 | + profile = ApplicationProfile.fromName(p.getString("profile")); |
| 45 | + |
| 46 | + jetty = Jetty.builder() |
| 47 | + .serverHost(p.getString("server.host")) |
| 48 | + .gzipEnabled(p.getBoolean("server.gzip.enabled")) |
| 49 | + .httpEnabled(p.getBoolean("http.enabled")) |
| 50 | + .httpPort(p.getInt("http.port")) |
| 51 | + .httpsEnabled(p.getBoolean("https.enabled")) |
| 52 | + .httpsPort(p.getInt("https.port")) |
| 53 | + .keyStorePath(p.getString("keystore.path")) |
| 54 | + .keyStorePassword(p.getString("keystore.password")) |
| 55 | + .build(); |
| 56 | + |
| 57 | + db = DB.builder() |
| 58 | + .ip(p.getString("db.ip")) |
| 59 | + .port(p.getInt("db.port")) |
| 60 | + .schema(p.getString("db.schema")) |
| 61 | + .userName(p.getString("db.user")) |
| 62 | + .password(p.getString("db.password")) |
| 63 | + .sqlLogging(p.getBoolean("db.sql.logging")) |
| 64 | + .build(); |
| 65 | + |
| 66 | + auth = Auth.builder() |
| 67 | + .userName(p.getString("auth.user")) |
| 68 | + .password(p.getString("auth.password")) |
| 69 | + .build(); |
| 70 | + |
| 71 | + ocpp = Ocpp.builder() |
| 72 | + .wsSessionSelectStrategy( |
| 73 | + WsSessionSelectStrategyEnum.fromName(p.getString("ws.session.select.strategy"))) |
| 74 | + .build(); |
| 75 | + |
| 76 | + validate(); |
| 77 | + } |
| 78 | + |
| 79 | + private void validate() { |
| 80 | + if (!(jetty.httpEnabled || jetty.httpsEnabled)) { |
| 81 | + throw new IllegalArgumentException( |
| 82 | + "HTTP and HTTPS are both disabled. Well, how do you want to access the server, then?"); |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + // ------------------------------------------------------------------------- |
| 87 | + // Class declarations |
| 88 | + // ------------------------------------------------------------------------- |
| 89 | + |
| 90 | + // Jetty configuration |
| 91 | + @Builder @Getter |
| 92 | + public static class Jetty { |
| 93 | + private String serverHost; |
| 94 | + private boolean gzipEnabled; |
38 | 95 |
|
39 | 96 | // HTTP |
40 | | - public static boolean HTTP_ENABLED; |
41 | | - public static int HTTP_PORT; |
| 97 | + private boolean httpEnabled; |
| 98 | + private int httpPort; |
42 | 99 |
|
43 | 100 | // HTTPS |
44 | | - public static boolean HTTPS_ENABLED; |
45 | | - public static int HTTPS_PORT; |
46 | | - public static String KEY_STORE_PATH; |
47 | | - public static String KEY_STORE_PASSWORD; |
| 101 | + private boolean httpsEnabled; |
| 102 | + private int httpsPort; |
| 103 | + private String keyStorePath; |
| 104 | + private String keyStorePassword; |
48 | 105 | } |
49 | 106 |
|
50 | | - /** |
51 | | - * Database configuration |
52 | | - */ |
53 | | - public static final class DB { |
54 | | - public static String IP; |
55 | | - public static int PORT; |
56 | | - public static String SCHEMA; |
57 | | - public static String USERNAME; |
58 | | - public static String PASSWORD; |
59 | | - public static boolean SQL_LOGGING; |
| 107 | + // Database configuration |
| 108 | + @Builder @Getter |
| 109 | + public static class DB { |
| 110 | + private String ip; |
| 111 | + private int port; |
| 112 | + private String schema; |
| 113 | + private String userName; |
| 114 | + private String password; |
| 115 | + private boolean sqlLogging; |
60 | 116 | } |
61 | 117 |
|
62 | | - /** |
63 | | - * Credentials for Web interface access |
64 | | - */ |
65 | | - public static final class Auth { |
66 | | - public static String USERNAME; |
67 | | - public static String PASSWORD; |
| 118 | + // Credentials for Web interface access |
| 119 | + @Builder @Getter |
| 120 | + public static class Auth { |
| 121 | + private String userName; |
| 122 | + private String password; |
68 | 123 | } |
69 | 124 |
|
70 | | - /** |
71 | | - * OCPP-related configuration |
72 | | - */ |
73 | | - public static final class Ocpp { |
74 | | - public static WsSessionSelectStrategyEnum WS_SESSION_SELECT_STRATEGY; |
| 125 | + // OCPP-related configuration |
| 126 | + @Builder @Getter |
| 127 | + public static class Ocpp { |
| 128 | + private WsSessionSelectStrategyEnum wsSessionSelectStrategy; |
75 | 129 | } |
76 | 130 |
|
77 | 131 | } |
0 commit comments