Project

General

Profile

Download (2.09 KB) Statistics
| Branch: | Tag: | Revision:
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="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
%><%@page import="eu.etaxonomy.cdm.server.CdmInstanceProperties"
10
%><%
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 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
%>
(1-1/3)