-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathSystemRuntime.java
59 lines (51 loc) · 1.91 KB
/
SystemRuntime.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*******************************************************************************
* Copyright (c) 2022 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - Initial implementation
*******************************************************************************/
package io.openliberty.sample.system;
import java.lang.management.ManagementFactory;
import jakarta.enterprise.context.RequestScoped;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import javax.management.ObjectName;
import javax.management.MBeanInfo;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanServer;
@RequestScoped
@Path("/runtime")
public class SystemRuntime {
@GET
@Produces(MediaType.TEXT_PLAIN)
public Response getRuntime() {
String libertyVersion = getServerVersion();
System.out.println("FW: SystemRuntime 20240503-A");
return Response.ok(libertyVersion).build();
}
String getServerVersion() {
String version = null;
try {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName objName = new ObjectName("WebSphere:feature=kernel,name=ServerInfo");
MBeanInfo beanInfo = mbs.getMBeanInfo(objName);
for (MBeanAttributeInfo attr : beanInfo.getAttributes()) {
if (attr.getName().equals("LibertyVersion")) {
version = String.valueOf(mbs.getAttribute(objName, attr.getName()));
break;
}
}
} catch (Exception ex) {
System.out.println("Unable to retrieve server version.");
System.out.println("FW");
}
return version;
}
}