Project

General

Profile

Download (2.09 KB) Statistics
| Branch: | Tag: | Revision:
1 1beda15e Andreas Kohlbecker
<%@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="java.util.Set"
5
%><%@page import="java.net.URL"
6
%><%@page import="org.codehaus.jackson.map.ObjectMapper"
7
%><%@page import="org.codehaus.jackson.JsonNode"
8
%><%@page import="org.codehaus.jackson.node.ObjectNode"
9 43d63f00 Andreas Kohlbecker
%><%@page import="eu.etaxonomy.cdm.server.CdmInstanceProperties"
10
%><%
11
//////////////////////////////////////////////////////////////////////////////////
12
//
13 1beda15e Andreas Kohlbecker
// 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 43d63f00 Andreas Kohlbecker
// For security the password field will be hidden!
17
//
18
//////////////////////////////////////////////////////////////////////////////////
19
20 1beda15e Andreas Kohlbecker
    ObjectMapper jsonMapper = new ObjectMapper();
21
22 43d63f00 Andreas Kohlbecker
    response.setHeader("Content-Type", "application/json;charset=UTF-8");
23 1beda15e Andreas Kohlbecker
24
  // the servelt context must use the class loader of the Bootloader class otherwise
25
  // getting the status will not work in mulithreading environments !!!
26
  Bootloader bootloader = Bootloader.getBootloader();
27
  java.util.List<CdmInstanceProperties> configAndStatus = bootloader.getConfigAndStatus();
28
  if(configAndStatus != null){
29
   int i = 0;
30
31
   ArrayNode arrayNode = jsonMapper.createArrayNode();
32
33
   for(CdmInstanceProperties props : configAndStatus){
34
    i++;
35
    String basePath = request.getContextPath() + "/" + props.getDataSourceName();
36
      URL fullURL = new URL(request.getScheme(),
37
                  request.getServerName(),
38
                  request.getServerPort(),
39
                  basePath);
40
41
      JsonNode jsonNode = jsonMapper.valueToTree(props);
42
      if(jsonNode instanceof ObjectNode){
43
           ((ObjectNode)jsonNode).put("basePath", basePath);
44
           ((ObjectNode)jsonNode).put("fullUrl", fullURL.toString());
45
           ((ObjectNode)jsonNode).remove("password");
46
      }
47
      arrayNode.add(jsonNode);
48
   }
49
   out.append(arrayNode.toString());
50
  }
51 43d63f00 Andreas Kohlbecker
%>