1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package io.wcm.caravan.io.http.impl;
21
22 import static io.wcm.caravan.io.http.impl.CaravanHttpServiceConfig.RIBBON_HOSTS_PROPERTY;
23 import static io.wcm.caravan.io.http.impl.CaravanHttpServiceConfig.RIBBON_PARAM_LISTOFSERVERS;
24
25 import java.util.Map;
26
27 import org.apache.commons.configuration.Configuration;
28 import org.apache.commons.lang3.StringUtils;
29 import org.apache.sling.commons.osgi.PropertiesUtil;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33
34
35
36 public final class CaravanHttpServiceConfigValidator {
37
38 private static final Logger log = LoggerFactory.getLogger(CaravanHttpServiceConfigValidator.class);
39
40 private CaravanHttpServiceConfigValidator() {
41
42 }
43
44
45
46
47
48
49
50
51 public static boolean hasValidConfiguration(String serviceId) {
52 Configuration archaiusConfig = ArchaiusConfig.getConfiguration();
53 return StringUtils.isNotEmpty(archaiusConfig.getString(serviceId + RIBBON_PARAM_LISTOFSERVERS));
54 }
55
56
57
58
59
60
61 public static boolean isValidServiceConfig(String serviceId, Map<String, Object> config) {
62 if (StringUtils.isBlank(serviceId)) {
63 log.warn("Invalid transport layer service configuration without service ID, ignoring.", serviceId);
64 return false;
65 }
66 String[] hosts = PropertiesUtil.toStringArray(config.get(RIBBON_HOSTS_PROPERTY));
67 if (hosts == null || hosts.length == 0) {
68 log.warn("Invalid transport layer service configuration for '{}' without hosts, ignoring.", serviceId);
69 return false;
70 }
71 return true;
72 }
73
74
75
76
77
78
79 public static boolean throwExceptionForStatus500(String serviceId) {
80 return ArchaiusConfig.getConfiguration().getBoolean(serviceId + CaravanHttpServiceConfig.THROW_EXCEPTION_FOR_STATUS_500,
81 CaravanHttpServiceConfig.THROW_EXCEPTION_FOR_STATUS_500_DEFAULT);
82 }
83
84 }