1
|
<%@page import="org.codehaus.jackson.node.ArrayNode"
|
2
|
%><%@ page contentType="application/json;charset=UTF-8" language="java"
|
3
|
%><%@page import="eu.etaxonomy.cdm.server.Bootloader"
|
4
|
%><%@page import="eu.etaxonomy.cdm.server.instance.CdmInstance"
|
5
|
%><%@page import="java.util.Set"
|
6
|
%><%@page import="java.net.URL"
|
7
|
%><%@page import="org.codehaus.jackson.map.ObjectMapper"
|
8
|
%><%@page import="org.codehaus.jackson.JsonNode"
|
9
|
%><%@page import="org.codehaus.jackson.node.ObjectNode"
|
10
|
%><%@page import="eu.etaxonomy.cdm.server.instance.Configuration"
|
11
|
%><%//////////////////////////////////////////////////////////////////////////////////
|
12
|
//
|
13
|
// The BootloaderService service exposes the Bootloader.getConfigAndStatus()
|
14
|
// property as webservice. Before beeing serialized to JSON the ConfigAndStatus
|
15
|
// properties will be extended by the basePath of the cdm-remote instances.
|
16
|
// For security the password field will be hidden!
|
17
|
//
|
18
|
//////////////////////////////////////////////////////////////////////////////////
|
19
|
|
20
|
ObjectMapper jsonMapper = new ObjectMapper();
|
21
|
|
22
|
response.setHeader("Content-Type", "application/json;charset=UTF-8");
|
23
|
|
24
|
// the servelt context must use the class loader of the Bootloader class otherwise
|
25
|
// getting the status will not work in multihreading environments !!!
|
26
|
Bootloader bootloader = Bootloader.getBootloader();
|
27
|
java.util.List<CdmInstance> instances = bootloader.getCdmInstances();
|
28
|
if(instances != null){
|
29
|
int i = 0;
|
30
|
|
31
|
ArrayNode arrayNode = jsonMapper.createArrayNode();
|
32
|
|
33
|
for(CdmInstance instance: instances){
|
34
|
i++;
|
35
|
ObjectNode instanceNode = jsonMapper.createObjectNode();
|
36
|
instanceNode.put("status", instance.getStatus().name());
|
37
|
instanceNode.put("messages", jsonMapper.valueToTree(instance.getProblems()));
|
38
|
|
39
|
|
40
|
Configuration conf = instance.getConfiguration();
|
41
|
String basePath = request.getContextPath() + "/" + conf.getInstanceName();
|
42
|
URL fullURL = new URL(request.getScheme(),
|
43
|
request.getServerName(),
|
44
|
request.getServerPort(),
|
45
|
basePath);
|
46
|
|
47
|
JsonNode configNode = jsonMapper.valueToTree(conf);
|
48
|
if(configNode instanceof ObjectNode){
|
49
|
((ObjectNode)configNode).put("basePath", basePath);
|
50
|
((ObjectNode)configNode).put("fullUrl", fullURL.toString());
|
51
|
((ObjectNode)configNode).remove("password");
|
52
|
}
|
53
|
|
54
|
((ObjectNode)instanceNode).put("configuration", configNode);
|
55
|
arrayNode.add(instanceNode);
|
56
|
}
|
57
|
out.append(arrayNode.toString());
|
58
|
}%>
|