Project

General

Profile

« Previous | Next » 

Revision b91fa795

Added by Cherian Mathew over 8 years ago

#5302 Add new jsp to provide general server info

View differences:

src/main/java/eu/etaxonomy/cdm/server/Bootloader.java
26 26
import java.io.File;
27 27
import java.io.FileNotFoundException;
28 28
import java.io.FileOutputStream;
29
import java.io.FilenameFilter;
29 30
import java.io.IOException;
30 31
import java.io.InputStream;
31 32
import java.io.InputStreamReader;
......
35 36
import java.util.ArrayList;
36 37
import java.util.List;
37 38
import java.util.Properties;
39
import java.util.jar.Attributes;
40
import java.util.jar.JarFile;
41
import java.util.jar.Manifest;
38 42
import java.util.regex.Pattern;
39 43

  
40 44
import org.apache.commons.cli.CommandLine;
......
135 139

  
136 140
    private boolean isRunningFromWarFile;
137 141

  
142
    private String cdmlibServicesVersion = "";
143
    private String cdmlibServicesLastModified = "";
144

  
138 145

  
139 146
    /* thread save singleton implementation */
140 147

  
......
241 248
            try {
242 249
                logger.info("Unpacking " + warFileName);
243 250
                warFile = unzip(warFile, warName);
251

  
252
                // get the 'Bundle-Version' and 'Bnd-LastModified' properties of the
253
                // manifest file in the cdmlib services jar
254
                if(warFile != null && warFile.isDirectory()) {
255
                    // generate the webapp lib dir path
256
                    String warLibDirAbsolutePath = warFile.getAbsolutePath() +
257
                            File.separator +
258
                            "WEB-INF" +
259
                            File.separator +
260
                            "lib";
261
                    File warLibDir = new File(warLibDirAbsolutePath);
262
                    if(warLibDir.exists()) {
263
                        // get the cdmlib-services jar
264
                        File [] files = warLibDir.listFiles(new FilenameFilter() {
265
                            @Override
266
                            public boolean accept(File dir, String name) {
267
                                return name.startsWith("cdmlib-services") && name.endsWith(".jar");
268
                            }
269
                        });
270
                        if(files != null && files.length > 0) {
271
                            // get the relevant info from the jar manifest
272
                            JarFile jarFile = new JarFile(files[0]);
273
                            Manifest manifest = jarFile.getManifest();
274
                            Attributes attributes = manifest.getMainAttributes();
275
                            // from the OSGI spec the LastModified value is " the number of milliseconds
276
                            // since midnight Jan. 1, 1970 UTC with the condition that a change must
277
                            // always result in a higher value than the previous last modified time
278
                            // of any bundle"
279
                            cdmlibServicesVersion = attributes.getValue("Bundle-Version");
280
                            logger.warn("cdmlib-services version : " + cdmlibServicesVersion);
281
                            cdmlibServicesLastModified = attributes.getValue("Bnd-LastModified");
282
                            logger.warn("cdmlib-services last modified timestamp : " + cdmlibServicesLastModified);
283

  
284
                            if(cdmlibServicesVersion == null || cdmlibServicesLastModified == null) {
285
                                throw new IllegalStateException("Invalid cdmlib-services manifest file");
286
                            }
287
                        } else {
288
                            throw new IllegalStateException("cdmlib-services jar not found ");
289
                        }
290
                    }
291
                }
244 292
            } catch (IOException e) {
245 293
                logger.error("extractWar() - Unziping of war file " + warFile + " failed. Will return the war file itself instead of the extracted folder.", e);
246 294
            }
......
250 298
    }
251 299

  
252 300

  
301
    public String getCdmlibServicesVersion() {
302
        return cdmlibServicesVersion;
303
    }
304

  
305
    public String getCdmlibServicesLastModified() {
306
        return cdmlibServicesLastModified;
307
    }
253 308
    /**
254 309
     * @param extractWar
255 310
     * @return
src/main/webapp/info.jsp
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
  
28
  ObjectNode infoNode = jsonMapper.createObjectNode();
29
  infoNode.put("cdmlibServicesVersion", bootloader.getCdmlibServicesVersion());
30
  infoNode.put("cdmlibServicesLastModified", bootloader.getCdmlibServicesLastModified());
31

  
32
  out.append(infoNode.toString());
33
  %>

Also available in: Unified diff