forked from actframework/actframework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppConfig.java
More file actions
3099 lines (2704 loc) · 97.1 KB
/
AppConfig.java
File metadata and controls
3099 lines (2704 loc) · 97.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package act.conf;
/*-
* #%L
* ACT Framework
* %%
* Copyright (C) 2014 - 2017 ActFramework
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import static act.conf.AppConfigKey.*;
import static org.osgl.http.H.Header.Names.X_XSRF_TOKEN;
import act.Act;
import act.Constants;
import act.app.*;
import act.app.conf.AppConfigurator;
import act.app.event.SysEventId;
import act.app.util.NamedPort;
import act.cli.CliOverHttpAuthority;
import act.crypto.HMAC;
import act.crypto.RotateSecretHMAC;
import act.data.DateTimeStyle;
import act.data.DateTimeType;
import act.db.util.SequenceNumberGenerator;
import act.db.util._SequenceNumberGenerator;
import act.handler.UnknownHttpMethodProcessor;
import act.handler.event.ResultEvent;
import act.i18n.I18n;
import act.internal.util.StrBufRetentionLimitCalculator;
import act.security.CSRFProtector;
import act.session.*;
import act.util.*;
import act.validation.Password;
import act.validation.PasswordSpec;
import act.view.TemplatePathResolver;
import act.view.View;
import act.ws.DefaultSecureTicketCodec;
import act.ws.SecureTicketCodec;
import act.ws.UsernameSecureTicketCodec;
import org.osgl.$;
import org.osgl.OsglConfig;
import org.osgl.cache.CacheService;
import org.osgl.cache.CacheServiceProvider;
import org.osgl.exception.ConfigurationException;
import org.osgl.exception.NotAppliedException;
import org.osgl.http.H;
import org.osgl.mvc.MvcConfig;
import org.osgl.util.*;
import org.osgl.web.util.UserAgent;
import org.rythmengine.utils.Time;
import java.io.File;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import javax.inject.Provider;
public class AppConfig<T extends AppConfig> extends Config<AppConfigKey> implements AppHolder<AppConfig<T>> {
public static final String CONF_FILE_NAME = "app.conf";
public static final String CSRF_TOKEN_NAME = "__csrf__";
public static final String PORT_CLI_OVER_HTTP = "__admin__";
private App app;
static {
MvcConfig.registerAlarmListener(MvcConfig.ALARM_BIG_CONTENT_ENCOUNTERED, new $.Func0() {
@Override
public Object apply() throws NotAppliedException, $.Break {
ActionContext ctx = ActionContext.current();
if (null != ctx) {
ctx.setLargeResponseHint();
}
return null;
}
});
MvcConfig.errorPageRenderer(new ActErrorPageRender());
MvcConfig.beforeCommitResultHandler(ResultEvent.BEFORE_COMMIT_HANDLER);
MvcConfig.afterCommitResultHandler(ResultEvent.AFTER_COMMIT_HANDLER);
MvcConfig.messageTranslater(new $.Transformer<String, String>() {
@Override
public String transform(String message) {
if (Act.appConfig().i18nEnabled()) {
String translated = I18n.i18n(message);
if (message == translated) {
translated = I18n.i18n(MvcConfig.class, message);
message = translated;
}
return message;
}
return message;
}
});
}
private RouterRegexMacroLookup routerRegexMacroLookup;
/**
* Construct a <code>AppConfig</code> with a map. The map is copied to
* the original map of the configuration instance
*
* @param configuration
*/
public AppConfig(Map<String, ?> configuration) {
super(configuration);
routerRegexMacroLookup = new RouterRegexMacroLookup(this);
}
public AppConfig() {
this((Map) System.getProperties());
}
public AppConfig<T> app(App app) {
E.NPE(app);
this.app = app;
AppConfigKey.onApp(app);
return this;
}
public void preloadConfigurations() {
// ensure JWT get evaluated first to set
// default value for dependency settings
jwtEnabled();
for (Method method : AppConfig.class.getDeclaredMethods()) {
boolean isPublic = Modifier.isPublic(method.getModifiers());
if (isPublic && 0 == method.getParameterTypes().length && !"preloadConfigurations".equals(method.getName())) {
$.invokeVirtual(this, method);
}
}
MvcConfig.renderJsonOutputCharset(renderJsonOutputCharset());
$.Func0<H.Format> jsonContentProvider = jsonContentTypeProvider();
if (null != jsonContentTypeProvider) {
MvcConfig.jsonMediaTypeProvider(jsonContentProvider);
}
OsglConfig.internalCache().clear();
OsglConfig.setThreadLocalBufferLimit(threadLocalBufRetentionLimit());
OsglConfig.registerGlobalInstanceFactory(new $.Function<Class, Object>() {
final App app = Act.app();
@Override
public Object apply(Class aClass) throws NotAppliedException, $.Break {
return app.getInstance(aClass);
}
});
}
public App app() {
return app;
}
public RouterRegexMacroLookup routerRegexMacroLookup() {
return routerRegexMacroLookup;
}
@Override
protected ConfigKey keyOf(String s) {
return AppConfigKey.valueOfIgnoreCase(s);
}
private Boolean apiDoc;
protected T enableApiDoc(boolean b) {
this.apiDoc = b;
return me();
}
public boolean apiDocEnabled() {
if (null == apiDoc) {
this.apiDoc = get(API_DOC_EABLED, Act.isDev());
}
return this.apiDoc;
}
private void _mergeApiDocEnabled(AppConfig conf) {
if (!hasConfiguration(API_DOC_EABLED)) {
this.apiDoc = conf.apiDoc;
}
}
private Boolean apiDocBuiltInHide;
protected T hideBuiltInEndpointsInApiDoc(boolean b) {
this.apiDocBuiltInHide = b;
return me();
}
public boolean isHideBuiltInEndpointsInApiDoc() {
if (null == apiDocBuiltInHide) {
apiDocBuiltInHide = get(API_DOC_HIDE_BUILT_IN_ENDPOINTS, false);
}
return apiDocBuiltInHide;
}
private void _mergeHideBuiltInEndpointsInApiDoc(AppConfig conf) {
if (!hasConfiguration(API_DOC_HIDE_BUILT_IN_ENDPOINTS)) {
this.apiDocBuiltInHide = conf.apiDocBuiltInHide;
}
}
private Boolean basicAuth;
protected T enableBasicAuthentication(boolean b) {
this.basicAuth = b;
return me();
}
public boolean basicAuthenticationEnabled() {
if (null == basicAuth) {
this.basicAuth = get(BASIC_AUTHENTICATION, Act.isDev());
}
return this.basicAuth;
}
private void _mergeBasicAuthentication(AppConfig conf) {
if (!hasConfiguration(BASIC_AUTHENTICATION)) {
this.basicAuth = conf.basicAuth;
}
}
private Boolean builtInReqHandlerEnabled;
protected T disableBuiltInReqHandler() {
builtInReqHandlerEnabled = false;
return me();
}
public boolean builtInReqHandlerEnabled() {
if (null == builtInReqHandlerEnabled) {
builtInReqHandlerEnabled = get(BUILT_IN_REQ_HANDLER_ENABLED, true);
}
return builtInReqHandlerEnabled;
}
private void _mergeBuiltInReqHandler(AppConfig conf) {
if (!hasConfiguration(BUILT_IN_REQ_HANDLER_ENABLED)) {
this.builtInReqHandlerEnabled = conf.builtInReqHandlerEnabled;
}
}
private Boolean cacheForOnDev;
protected T enableCacheForOnDevMode() {
cacheForOnDev = false;
return me();
}
public boolean cacheForOnDevMode() {
if (null == cacheForOnDev) {
cacheForOnDev = get(CACHE_FOR_ON_DEV, false);
}
return cacheForOnDev;
}
private void _mergeCacheForOnDev(AppConfig config){
if (!hasConfiguration(CACHE_FOR_ON_DEV)) {
cacheForOnDev = config.cacheForOnDev;
}
}
private Boolean cors;
protected T enableCors(boolean b) {
this.cors = b;
return me();
}
public boolean corsEnabled() {
if (null == cors) {
this.cors = get(CORS, false);
}
return this.cors;
}
private void _mergeCors(AppConfig conf) {
if (!hasConfiguration(CORS)) {
this.cors = conf.cors;
}
}
private String corsOrigin;
protected T corsAllowOrigin(String s) {
this.corsOrigin = s;
return me();
}
public String corsAllowOrigin() {
if (null == corsOrigin) {
corsOrigin = get(CORS_ORIGIN, "*");
}
return corsOrigin;
}
private void _mergeCorsOrigin(AppConfig conf) {
if (!hasConfiguration(CORS_ORIGIN)) {
corsOrigin = conf.corsOrigin;
}
}
private String corsHeaders;
protected T corsHeaders(String s) {
this.corsHeaders = s;
return me();
}
private String corsHeaders() {
if (null == corsHeaders) {
corsHeaders = get(CORS_HEADERS, "Content-Type, X-HTTP-Method-Override, X-Requested-With");
}
return corsHeaders;
}
private void _mergeCorsHeaders(AppConfig conf) {
if (!hasConfiguration(CORS_HEADERS)) {
corsHeaders = conf.corsHeaders;
}
}
private String corsHeadersExpose;
protected T corsHeadersExpose(String s) {
this.corsHeadersExpose = s;
return me();
}
public String corsExposeHeaders() {
if (null == corsHeadersExpose) {
corsHeadersExpose = get(CORS_HEADERS_EXPOSE, corsHeaders());
}
return corsHeadersExpose;
}
private void _mergeCorsHeadersExpose(AppConfig conf) {
if (!hasConfiguration(CORS_HEADERS_EXPOSE)) {
corsHeadersExpose = conf.corsHeadersExpose;
}
}
private Boolean corsOptionCheck;
protected T corsOptionCheck(Boolean b) {
this.corsOptionCheck = b;
return me();
}
public Boolean corsOptionCheck() {
if (null == corsOptionCheck) {
corsOptionCheck = get(CORS_CHECK_OPTION_METHOD, true);
}
return corsOptionCheck;
}
private void _mergeCorsOptionCheck(AppConfig conf) {
if (!hasConfiguration(CORS_CHECK_OPTION_METHOD)) {
corsOptionCheck = conf.corsOptionCheck;
}
}
private String corsHeadersAllowed;
protected T corsAllowHeaders(String s) {
this.corsHeadersExpose = s;
return me();
}
public String corsAllowHeaders() {
if (null == corsHeadersAllowed) {
corsHeadersAllowed = get(CORS_HEADERS_ALLOWED, corsHeaders());
}
return corsHeadersAllowed;
}
private void _mergeCorsHeadersAllowed(AppConfig conf) {
if (!hasConfiguration(CORS_HEADERS_EXPOSE)) {
corsHeadersAllowed = conf.corsHeadersAllowed;
}
}
private Integer corsMaxAge;
protected T corsMaxAge(int corsMaxAge) {
this.corsMaxAge = corsMaxAge;
return me();
}
public int corsMaxAge() {
if (null == corsMaxAge) {
corsMaxAge = getInteger(CORS_MAX_AGE, 30 * 60);
}
return corsMaxAge;
}
private void _mergeCorsMaxAge(AppConfig conf) {
if (!hasConfiguration(CORS_MAX_AGE)) {
corsMaxAge = conf.corsMaxAge;
}
}
private Boolean corsAllowCredentials;
protected T corsAllowCredentials(boolean b) {
this.corsAllowCredentials = b;
return me();
}
public boolean corsAllowCredentials() {
if (null == corsAllowCredentials) {
corsAllowCredentials = get(CORS_ALLOW_CREDENTIALS, false);
}
return corsAllowCredentials;
}
private void _mergeCorsAllowCredential(AppConfig conf) {
if (!hasConfiguration(CORS_ALLOW_CREDENTIALS)) {
corsAllowCredentials = conf.corsAllowCredentials;
}
}
private String contentSecurityPolicy;
private boolean cspSet;
protected T contentSecurityPolicy(String policy) {
this.contentSecurityPolicy = policy;
cspSet = null != policy;
return me();
}
public String contentSecurityPolicy() {
if (!cspSet) {
contentSecurityPolicy = get(CONTENT_SECURITY_POLICY, null);
cspSet = true;
}
return contentSecurityPolicy;
}
private void _mergeCsp(AppConfig conf) {
if (!hasConfiguration(CONTENT_SECURITY_POLICY)) {
contentSecurityPolicy = conf.contentSecurityPolicy;
cspSet = null != contentSecurityPolicy;
}
}
private Boolean csrf;
protected T enableCsrf(boolean b) {
this.csrf = b;
return me();
}
public boolean csrfEnabled() {
if (null == csrf) {
this.csrf = get(CSRF, false);
}
return this.csrf;
}
private void _mergeCsrf(AppConfig conf) {
if (!hasConfiguration(CSRF)) {
this.csrf = conf.csrf;
}
}
private String csrfParamName;
protected T csrfParamName(String s) {
this.csrfParamName = s;
return me();
}
public String csrfParamName() {
if (null == csrfParamName) {
csrfParamName = get(CSRF_PARAM_NAME, CSRF_TOKEN_NAME);
}
return csrfParamName;
}
private void _mergeCsrfParamName(AppConfig conf) {
if (!hasConfiguration(CSRF_PARAM_NAME)) {
csrfParamName = conf.csrfParamName;
}
}
private CSRFProtector csrfProtector;
protected T csrfProtector(CSRFProtector protector) {
this.csrfProtector = $.requireNotNull(protector);
return me();
}
public CSRFProtector csrfProtector() {
if (null == csrfProtector) {
try {
csrfProtector = get(CSRF_PROTECTOR, CSRFProtector.Predefined.HMAC);
} catch (ConfigurationException e) {
Object obj = helper.getValFromAliases(raw, CSRF_PROTECTOR.key(), "impl", null);
if (null != obj) {
this.csrfProtector = CSRFProtector.Predefined.valueOfIgnoreCase(obj.toString());
if (null != csrfProtector) {
set(CSRF_PROTECTOR, csrfProtector);
return this.csrfProtector;
}
}
throw e;
}
}
return csrfProtector;
}
private void _mergeCsrfProtector(AppConfig config) {
if (!hasConfiguration(CSRF_PROTECTOR)) {
csrfProtector = config.csrfProtector;
}
}
private String csrfCookieName;
protected T csrfCookieName(String s) {
this.csrfCookieName = s;
return me();
}
public String csrfCookieName() {
if (null == csrfCookieName) {
csrfCookieName = get(CSRF_COOKIE_NAME, cookieName("xsrf-token"));
}
return csrfCookieName;
}
private void _mergeCsrfCookieName(AppConfig conf) {
if (!hasConfiguration(CSRF_COOKIE_NAME)) {
csrfCookieName = conf.csrfCookieName;
}
}
private String csrfHeaderName;
protected T csrfHeaderName(String s) {
this.csrfHeaderName = s;
return me();
}
public String csrfHeaderName() {
if (null == csrfHeaderName) {
csrfHeaderName = get(CSRF_HEADER_NAME, X_XSRF_TOKEN);
}
return csrfHeaderName;
}
private void _mergeCsrfHeaderName(AppConfig conf) {
if (!hasConfiguration(CSRF_HEADER_NAME)) {
csrfHeaderName = conf.csrfHeaderName;
}
}
private Boolean cliEnabled;
protected T cliEnable(boolean enable) {
cliEnabled = enable;
return me();
}
public boolean cliEnabled() {
if (null == cliEnabled) {
cliEnabled = get(CLI_ENABLED, true);
}
return cliEnabled;
}
private void _mergeCliEnabled(AppConfig conf) {
if (!hasConfiguration(CLI_ENABLED)) {
cliEnabled = conf.cliEnabled;
}
}
private int cliTablePageSz = -1;
protected T cliTablePageSz(int sz) {
E.illegalArgumentIf(sz < 1, "CLI table page size not valid: %s", sz);
this.cliTablePageSz = sz;
return me();
}
public int cliTablePageSize() {
if (-1 == cliTablePageSz) {
cliTablePageSz = getInteger(CLI_PAGE_SIZE_TABLE, 22);
}
return cliTablePageSz;
}
private void _mergeCliTablePageSz(AppConfig conf) {
if (!hasConfiguration(CLI_PAGE_SIZE_TABLE)) {
cliTablePageSz = conf.cliTablePageSz;
}
}
private int cliJSONPageSz = -1;
protected T cliJSONPageSz(int sz) {
E.illegalArgumentIf(sz < 1, "CLI JSON page size not valid: %s", sz);
this.cliJSONPageSz = sz;
return me();
}
public int cliJSONPageSize() {
if (-1 == cliJSONPageSz) {
cliJSONPageSz = getInteger(CLI_PAGE_SIZE_TABLE, 22);
}
return cliJSONPageSz;
}
private void _mergeCliJSONPageSz(AppConfig conf) {
if (!hasConfiguration(CLI_PAGE_SIZE_TABLE)) {
cliJSONPageSz = conf.cliJSONPageSz;
}
}
private Boolean cliOverHttp;
protected T cliOverHttp(boolean enabled) {
this.cliOverHttp = enabled;
return me();
}
public boolean cliOverHttp() {
if (null == cliOverHttp) {
cliOverHttp = get(CLI_OVER_HTTP, false);
}
return cliOverHttp;
}
private void _mergeCliOverHttp(AppConfig config) {
if (!hasConfiguration(CLI_OVER_HTTP)) {
cliOverHttp = config.cliOverHttp;
}
}
private CliOverHttpAuthority cliOverHttpAuthority;
protected T cliOverHttpAuthority(CliOverHttpAuthority authority) {
this.cliOverHttpAuthority = authority;
return me();
}
public CliOverHttpAuthority cliOverHttpAuthority() {
if (null == cliOverHttpAuthority) {
cliOverHttpAuthority = get(CLI_OVER_HTTP_AUTHORITY, new CliOverHttpAuthority.AllowAll());
}
return cliOverHttpAuthority;
}
private void _mergeCliOverHttpAuthority(AppConfig config) {
if (!hasConfiguration(CLI_OVER_HTTP_AUTHORITY)) {
cliOverHttpAuthority = config.cliOverHttpAuthority;
}
}
Integer cliOverHttpPort;
protected T cliOverHttpPort(int port) {
this.cliOverHttpPort = port;
return me();
}
public int cliOverHttpPort() {
if (null == cliOverHttpPort) {
cliOverHttpPort = get(CLI_OVER_HTTP_PORT, 5462);
}
return cliOverHttpPort;
}
private void _mergeCliOverHttpPort(AppConfig config) {
if (!hasConfiguration(CLI_OVER_HTTP_PORT)) {
cliOverHttpPort = config.cliOverHttpPort;
}
}
String cliOverHttpTitle;
protected T cliOverHttpTitle(String title) {
this.cliOverHttpTitle = title;
return me();
}
public String cliOverHttpTitle() {
if (null == cliOverHttpTitle) {
cliOverHttpTitle = get(CLI_OVER_HTTP_TITLE, "Cli Over Http");
}
return cliOverHttpTitle;
}
private void _mergeCliOverHttpTitle(AppConfig config) {
if (!hasConfiguration(CLI_OVER_HTTP_TITLE)) {
cliOverHttpTitle = config.cliOverHttpTitle;
}
}
Boolean cliOverHttpSysCmd;
protected T cliOverHttpSysCmd(boolean enabled) {
this.cliOverHttpSysCmd = enabled;
return me();
}
public boolean cliOverHttpSysCmdEnabled() {
if (null == cliOverHttpSysCmd) {
cliOverHttpSysCmd = get(CLI_OVER_HTTP_SYS_CMD, true);
}
return cliOverHttpSysCmd;
}
private void _mergeCliOverHttpSysCmd(AppConfig config) {
if (!hasConfiguration(CLI_OVER_HTTP_SYS_CMD)) {
cliOverHttpSysCmd = config.cliOverHttpSysCmd;
}
}
private Integer cliPort;
protected T cliPort(int port) {
E.illegalArgumentIf(port < 1, "port value not valid: %s", port);
this.cliPort = port;
return me();
}
public int cliPort() {
if (null == cliPort) {
cliPort = get(CLI_PORT, 5461);
}
return cliPort;
}
private void _mergeCliPort(AppConfig conf) {
if (!hasConfiguration(CLI_PORT)) {
cliPort = conf.cliPort;
}
}
private int cliSessionExpiration = -1;
protected T cliSessionExpiration(int expire) {
E.illegalArgumentIf(expire < 1, "cli session expire not valid: %s", expire);
this.cliSessionExpiration = expire;
return me();
}
public int cliSessionExpiration() {
if (-1 == cliSessionExpiration) {
cliSessionExpiration = get(CLI_SESSION_TTL, 300);
}
return cliSessionExpiration;
}
private void _mergeCliSessionExpiration(AppConfig conf) {
if (!hasConfiguration(CLI_SESSION_TTL)) {
cliSessionExpiration = conf.cliSessionExpiration;
}
}
private String dspToken;
protected T dspToken(final String tokenName) {
this.dspToken = tokenName;
return me();
}
public String dspToken() {
if (null == dspToken) {
dspToken = get(DOUBLE_SUBMISSION_PROTECT_TOKEN, "act_dsp_token");
}
return dspToken;
}
private void _mergeDspToken(AppConfig conf) {
if (!hasConfiguration(DOUBLE_SUBMISSION_PROTECT_TOKEN)) {
dspToken = conf.dspToken;
}
}
private Provider<String> cookieDomainProvider;
protected T cookieDomain(final String domain) {
this.cookieDomainProvider = new Provider<String>() {
@Override
public String get() {
return domain;
}
};
return me();
}
protected T cookieDomainProvider(Provider<String> provider) {
this.cookieDomainProvider = $.requireNotNull(provider);
return me();
}
public String cookieDomain() {
String domain = cookieDomainProvider().get();
return "localhost".equals(domain) ? null : domain;
}
private Provider<String> cookieDomainProvider() {
if (null == cookieDomainProvider) {
try {
cookieDomainProvider = get(COOKIE_DOMAIN_PROVIDER, new Provider<String>() {
@Override
public String get() {
return host();
}
});
} catch (ConfigurationException e) {
Object obj = helper.getValFromAliases(raw, COOKIE_DOMAIN_PROVIDER.key(), "impl", null);
String s = obj.toString();
if ("dynamic".equalsIgnoreCase(s) || "flexible".equalsIgnoreCase(s) || "contextual".equalsIgnoreCase(s)) {
cookieDomainProvider = new Provider<String>() {
@Override
public String get() {
H.Request req = ActionContext.current().req();
return req.domain();
}
};
return cookieDomainProvider;
}
throw e;
}
}
return cookieDomainProvider;
}
private void _mergeCookieDomain(AppConfig config) {
if (!hasConfiguration(COOKIE_DOMAIN_PROVIDER)) {
cookieDomainProvider = config.cookieDomainProvider;
}
}
private int maxCliSession = -1;
protected T maxCliSession(int size) {
E.illegalArgumentIf(size < 1, "max cli session number cannot be zero or negative number: %s", size);
this.maxCliSession = size;
return me();
}
public int maxCliSession() {
if (-1 == maxCliSession) {
maxCliSession = get(CLI_SESSION_MAX, 3);
}
return maxCliSession;
}
private void _mergeMaxCliSession(AppConfig conf) {
if (!hasConfiguration(CLI_SESSION_MAX)) {
maxCliSession = conf.maxCliSession;
}
}
private Boolean enumResolvingCaseSensitive;
protected T enumResolvingCaseSensitive(boolean b) {
enumResolvingCaseSensitive = b;
return me();
}
@Deprecated
public boolean enumResolvingCaseSensitive() {
synchronized (ENUM_RESOLVING_CASE_SENSITIVE) {
if (null == enumResolvingCaseSensitive) {
enumResolvingCaseSensitive = get(ENUM_RESOLVING_CASE_SENSITIVE, false);
}
return enumResolvingCaseSensitive;
}
}
private void _mergeEnumResolvingCaseSensitive(AppConfig conf) {
if (!hasConfiguration(ENUM_RESOLVING_CASE_SENSITIVE)) {
enumResolvingCaseSensitive = conf.enumResolvingCaseSensitive;
}
}
private Boolean enumResolvingExactMatch;
protected T enumResolvingExactMatch(boolean b) {
enumResolvingExactMatch = b;
return me();
}
public boolean enumResolvingExactMatch() {
synchronized (ENUM_RESOLVING_EXACT_MATCH) {
if (null == enumResolvingExactMatch) {
enumResolvingExactMatch = get(ENUM_RESOLVING_EXACT_MATCH, enumResolvingCaseSensitive());
}
return enumResolvingExactMatch;
}
}
private void _mergeEnumResolvingExactMatch(AppConfig config) {
if (!hasConfiguration(ENUM_RESOLVING_EXACT_MATCH)) {
enumResolvingExactMatch = config.enumResolvingExactMatch;
}
}
private String defViewName = null;
private View defView = null;
protected T defaultView(View view) {
E.NPE(view);
defView = view;
return me();
}
public View defaultView() {
if (null == defViewName) {
defViewName = get(AppConfigKey.VIEW_DEFAULT, "rythm");
defView = Act.viewManager().view(defViewName);
}
return defView;
}
private void _mergeDefaultView(AppConfig conf) {
if (!hasConfiguration(AppConfigKey.VIEW_DEFAULT)) {
defViewName = conf.defViewName;
defView = conf.defView;
}
}
private String xForwardedProtocol = null;
protected T forceHttps() {
xForwardedProtocol = "https";
return me();
}
public String xForwardedProtocol() {
if (null == xForwardedProtocol) {
xForwardedProtocol = get(X_FORWARD_PROTOCOL, "http");
}
return xForwardedProtocol;
}
private void _mergeXForwardedProtocol(AppConfig conf) {
if (!hasConfiguration(X_FORWARD_PROTOCOL)) {
xForwardedProtocol = conf.xForwardedProtocol;
}
}
private Boolean contentSuffixAware = null;
protected T contentSuffixAware(boolean b) {
contentSuffixAware = b;
return me();
}
public Boolean contentSuffixAware() {
if (null == contentSuffixAware) {
contentSuffixAware = get(CONTENT_SUFFIX_AWARE, false);
}
return contentSuffixAware;
}
private void _mergeContentSuffixAware(AppConfig conf) {
if (!hasConfiguration(CONTENT_SUFFIX_AWARE)) {
contentSuffixAware = conf.contentSuffixAware;
}
}
private _SequenceNumberGenerator seqGen = null;
protected T sequenceNumberGenerator(_SequenceNumberGenerator seqGen) {
this.seqGen = seqGen;
return me();
}
public _SequenceNumberGenerator sequenceNumberGenerator() {
if (null == seqGen) {
javax.inject.Provider<_SequenceNumberGenerator> provider = app().getInstance(SequenceNumberGenerator.Provider.class);
seqGen = get(DB_SEQ_GENERATOR, provider.get());
}
return seqGen;
}
private void _mergeSequenceNumberGenerator(AppConfig conf) {
if (!hasConfiguration(DB_SEQ_GENERATOR)) {
seqGen = conf.seqGen;
}
}
private ErrorTemplatePathResolver errorTemplatePathResolver = null;
protected T errorTemplatePathResolver(ErrorTemplatePathResolver resolver) {
errorTemplatePathResolver = resolver;
return me();
}
public ErrorTemplatePathResolver errorTemplatePathResolver() {
if (null == errorTemplatePathResolver) {
errorTemplatePathResolver = get(RESOLVER_ERROR_TEMPLATE_PATH, new ErrorTemplatePathResolver.DefaultErrorTemplatePathResolver());
}