|
33 | 33 | import java.net.MalformedURLException; |
34 | 34 | import java.net.URL; |
35 | 35 | import java.nio.charset.StandardCharsets; |
| 36 | +import java.util.Optional; |
36 | 37 | import java.util.Properties; |
37 | 38 |
|
38 | 39 | public class IoTDBRestServiceDescriptor { |
@@ -80,45 +81,92 @@ private Properties loadProps(String configName) { |
80 | 81 | private void loadProps(Properties properties) { |
81 | 82 | conf.setEnableRestService( |
82 | 83 | Boolean.parseBoolean( |
83 | | - properties.getProperty( |
84 | | - "enable_rest_service", Boolean.toString(conf.isEnableRestService())))); |
| 84 | + Optional.ofNullable( |
| 85 | + properties.getProperty( |
| 86 | + "enable_rest_service", Boolean.toString(conf.isEnableRestService()))) |
| 87 | + .map(String::trim) |
| 88 | + .orElse(Boolean.toString(conf.isEnableRestService())))); |
85 | 89 | conf.setRestServicePort( |
86 | 90 | Integer.parseInt( |
87 | | - properties.getProperty( |
88 | | - "rest_service_port", Integer.toString(conf.getRestServicePort())))); |
| 91 | + Optional.ofNullable( |
| 92 | + properties.getProperty( |
| 93 | + "rest_service_port", Integer.toString(conf.getRestServicePort()))) |
| 94 | + .map(String::trim) |
| 95 | + .orElse(Integer.toString(conf.getRestServicePort())))); |
89 | 96 | conf.setRestQueryDefaultRowSizeLimit( |
90 | 97 | Integer.parseInt( |
91 | | - properties.getProperty( |
92 | | - "rest_query_default_row_size_limit", |
93 | | - Integer.toString(conf.getRestQueryDefaultRowSizeLimit())))); |
| 98 | + Optional.ofNullable( |
| 99 | + properties.getProperty( |
| 100 | + "rest_query_default_row_size_limit", |
| 101 | + Integer.toString(conf.getRestQueryDefaultRowSizeLimit()))) |
| 102 | + .map(String::trim) |
| 103 | + .orElse(Integer.toString(conf.getRestQueryDefaultRowSizeLimit())))); |
94 | 104 | conf.setEnableSwagger( |
95 | 105 | Boolean.parseBoolean( |
96 | | - properties.getProperty("enable_swagger", Boolean.toString(conf.isEnableSwagger())))); |
| 106 | + Optional.ofNullable( |
| 107 | + properties.getProperty( |
| 108 | + "enable_swagger", Boolean.toString(conf.isEnableSwagger()))) |
| 109 | + .map(String::trim) |
| 110 | + .orElse(Boolean.toString(conf.isEnableSwagger())))); |
97 | 111 |
|
98 | 112 | conf.setEnableHttps( |
99 | 113 | Boolean.parseBoolean( |
100 | | - properties.getProperty("enable_https", Boolean.toString(conf.isEnableHttps())))); |
| 114 | + Optional.ofNullable( |
| 115 | + properties.getProperty("enable_https", Boolean.toString(conf.isEnableHttps()))) |
| 116 | + .map(String::trim) |
| 117 | + .orElse(Boolean.toString(conf.isEnableHttps())))); |
101 | 118 | conf.setClientAuth( |
102 | 119 | Boolean.parseBoolean( |
103 | | - properties.getProperty("client_auth", Boolean.toString(conf.isClientAuth())))); |
104 | | - conf.setKeyStorePath(properties.getProperty("key_store_path", conf.getKeyStorePath())); |
105 | | - conf.setKeyStorePwd(properties.getProperty("key_store_pwd", conf.getKeyStorePwd())); |
106 | | - conf.setTrustStorePath(properties.getProperty("trust_store_path", conf.getTrustStorePath())); |
107 | | - conf.setTrustStorePwd(properties.getProperty("trust_store_pwd", conf.getTrustStorePwd())); |
| 120 | + Optional.ofNullable( |
| 121 | + properties.getProperty("client_auth", Boolean.toString(conf.isClientAuth()))) |
| 122 | + .map(String::trim) |
| 123 | + .orElse(Boolean.toString(conf.isClientAuth())))); |
| 124 | + conf.setKeyStorePath( |
| 125 | + Optional.ofNullable(properties.getProperty("key_store_path", conf.getKeyStorePath())) |
| 126 | + .map(String::trim) |
| 127 | + .orElse(conf.getKeyStorePath())); |
| 128 | + conf.setKeyStorePwd( |
| 129 | + Optional.ofNullable(properties.getProperty("key_store_pwd", conf.getKeyStorePwd())) |
| 130 | + .map(String::trim) |
| 131 | + .orElse(conf.getKeyStorePwd())); |
| 132 | + conf.setTrustStorePath( |
| 133 | + Optional.ofNullable(properties.getProperty("trust_store_path", conf.getTrustStorePath())) |
| 134 | + .map(String::trim) |
| 135 | + .orElse(conf.getTrustStorePath())); |
| 136 | + conf.setTrustStorePwd( |
| 137 | + Optional.ofNullable(properties.getProperty("trust_store_pwd", conf.getTrustStorePwd())) |
| 138 | + .map(String::trim) |
| 139 | + .orElse(conf.getTrustStorePwd())); |
108 | 140 | conf.setIdleTimeoutInSeconds( |
109 | 141 | Integer.parseInt( |
110 | | - properties.getProperty( |
111 | | - "idle_timeout_in_seconds", Integer.toString(conf.getIdleTimeoutInSeconds())))); |
| 142 | + Optional.ofNullable( |
| 143 | + properties.getProperty( |
| 144 | + "idle_timeout_in_seconds", |
| 145 | + Integer.toString(conf.getIdleTimeoutInSeconds()))) |
| 146 | + .map(String::trim) |
| 147 | + .orElse(Integer.toString(conf.getIdleTimeoutInSeconds())))); |
112 | 148 | conf.setCacheExpireInSeconds( |
113 | 149 | Integer.parseInt( |
114 | | - properties.getProperty( |
115 | | - "cache_expire_in_seconds", Integer.toString(conf.getCacheExpireInSeconds())))); |
| 150 | + Optional.ofNullable( |
| 151 | + properties.getProperty( |
| 152 | + "cache_expire_in_seconds", |
| 153 | + Integer.toString(conf.getCacheExpireInSeconds()))) |
| 154 | + .map(String::trim) |
| 155 | + .orElse(Integer.toString(conf.getCacheExpireInSeconds())))); |
116 | 156 | conf.setCacheInitNum( |
117 | 157 | Integer.parseInt( |
118 | | - properties.getProperty("cache_init_num", Integer.toString(conf.getCacheInitNum())))); |
| 158 | + Optional.ofNullable( |
| 159 | + properties.getProperty( |
| 160 | + "cache_init_num", Integer.toString(conf.getCacheInitNum()))) |
| 161 | + .map(String::trim) |
| 162 | + .orElse(Integer.toString(conf.getCacheInitNum())))); |
119 | 163 | conf.setCacheMaxNum( |
120 | 164 | Integer.parseInt( |
121 | | - properties.getProperty("cache_max_num", Integer.toString(conf.getCacheMaxNum())))); |
| 165 | + Optional.ofNullable( |
| 166 | + properties.getProperty( |
| 167 | + "cache_max_num", Integer.toString(conf.getCacheMaxNum()))) |
| 168 | + .map(String::trim) |
| 169 | + .orElse(Integer.toString(conf.getCacheMaxNum())))); |
122 | 170 | } |
123 | 171 |
|
124 | 172 | /** |
|
0 commit comments