Project

General

Profile

« Previous | Next » 

Revision 1beda15e

Added by Andreas Kohlbecker over 11 years ago

replacing page refresh by ajax status update

View differences:

src/main/webapp/manage/BootloaderService.jsp
1

  
2
<%@page import="org.codehaus.jackson.node.ArrayNode"%><%@ page contentType="text/html;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" 
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 9
%><%@page import="eu.etaxonomy.cdm.server.CdmInstanceProperties"
10 10
%><%
11 11
//////////////////////////////////////////////////////////////////////////////////
12 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. 
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 16
// For security the password field will be hidden!
17 17
//
18 18
//////////////////////////////////////////////////////////////////////////////////
19 19

  
20
    ObjectMapper jsonMapper = new ObjectMapper(); 
21
    
20
    ObjectMapper jsonMapper = new ObjectMapper();
21

  
22 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.Set<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 = "/" + 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).remove("password");
45
	    }
46
	    arrayNode.add(jsonNode);
47
	 }
48
	 out.append(arrayNode.toString());
49
	}
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
  }
50 51

  
51 52
%>

Also available in: Unified diff