KernelConfigServlet.java
4.58 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.servlet.ServletException
* org.apache.commons.collections.Predicate
* org.apache.commons.collections.iterators.FilterIterator
* org.apache.commons.lang3.StringUtils
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.sling.SlingServlet
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.SlingHttpServletResponse
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceUtil
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.api.servlets.SlingSafeMethodsServlet
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.granite.contexthub.impl;
import com.adobe.granite.contexthub.api.ContextHub;
import com.adobe.granite.contexthub.api.Store;
import com.adobe.granite.contexthub.impl.StoreConfigFilter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import javax.servlet.ServletException;
import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.iterators.FilterIterator;
import org.apache.commons.lang3.StringUtils;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SlingServlet(resourceTypes={"/libs/granite/contexthub/cloudsettings/components/baseconfiguration"}, selectors={"config_kernel"}, extensions={"json"}, methods={"GET"})
public class KernelConfigServlet
extends SlingSafeMethodsServlet {
private static final long serialVersionUID = 6670736259060128610L;
private static final Logger log = LoggerFactory.getLogger(KernelConfigServlet.class);
@Reference
private ContextHub contextHub;
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
ValueMap vm = ResourceUtil.getValueMap((Resource)request.getResource());
try {
Boolean isDebug = (Boolean)vm.get("debug", (Object)false);
if (this.contextHub.isSilentMode()) {
isDebug = false;
}
JSONObject config = new JSONObject();
config.put("debug", (Object)isDebug);
config.put("initializationTimeout", vm.get("initializationTimeout", (Object)2000));
JSONObject stores = new JSONObject();
config.put("stores", (Object)stores);
Iterator childrenIt = request.getResource().listChildren();
FilterIterator configIt = new FilterIterator(childrenIt, (Predicate)new StoreConfigFilter());
while (configIt.hasNext()) {
Resource storeConfigRes = (Resource)configIt.next();
Store store = new Store(storeConfigRes);
if (!store.isEnabled()) continue;
ValueMap storeConfigVm = ResourceUtil.getValueMap((Resource)storeConfigRes);
JSONObject storeConfigItem = new JSONObject();
stores.put(storeConfigRes.getName(), (Object)storeConfigItem);
storeConfigItem.put("type", storeConfigVm.get("storeType", String.class));
storeConfigItem.put("required", storeConfigVm.get("required", (Object)false));
String configJson = (String)storeConfigVm.get("configjson", String.class);
if (!StringUtils.isNotEmpty((CharSequence)configJson)) continue;
JSONObject storeJSONConfig = new JSONObject(configJson);
storeConfigItem.put("config", (Object)storeJSONConfig);
}
response.getWriter().append(config.toString(4));
}
catch (JSONException ex) {
log.warn("Could not create valid JSON config for ContextHub: ", (Throwable)ex);
response.getWriter().append("{ \"error\": true }");
}
}
protected void bindContextHub(ContextHub contextHub) {
this.contextHub = contextHub;
}
protected void unbindContextHub(ContextHub contextHub) {
if (this.contextHub == contextHub) {
this.contextHub = null;
}
}
}