info@yenlo.com
eng
Menu
WSO2 Tutorial 5 min

How to check if WSO2 is up and running?

Luis Bustamante
Luis Bustamante
Integration Consultant
Running WSO2

Regardless of what WSO2 product is being used, once it is in production, it is important to know the current server status and accordingly trigger the process of starting it, shutting it down or just leaving it running fine. Manually, it could be reviewed and assumed by just login into the carbon console, but when the process must run automatic this is not a good option anymore. In this blog I’ll tell you how you can check if WSO2 is up and running.

Internally, the WSO2 server is always set to one of the following statuses: STARTING, RUNNING, IN_MAINTENANCE, RESTARTING, or SHUTTING_DOWN. Assuming each status is self-explanatory, the rest of this blog will focus on how to obtain the current one from an installed WSO2 instance.

The main two methods to access the status of the WSO2 server are first, calling the SOAP APIs and second, using JMX-RMI to get it from the MBean.

Status Check via SOAP API

WSO2 includes a considerable list of admin services. The list is viewable when starting the server with the OSGI console enabled using ./wso2server.sh –DosgiConsole, and issuing the command osgi> listAdminServices in the console.

From this list, the service ServerAdmin provides the status information about the server. This information is also accessible via SOAP so when the carbon.xml <HideAdminServiceWSDLs> flag is set to false, the wsdl of the service can be retrieved from the URL
https://[WSO2-HOST]:9443/services/ServerAdmin?wsdl

The WSDL file defines a list of operations from which two of them can be used for checking the status. The operation names are “getServerStatus” and “isAlive” which are posted as SOAP requests to the server endpoint located in
https://[WSO2-HOST]:9443/services/ServerAdmin  

Next, are these operation requests and example answers from the server:

isAlive Operation

Using this operation doesn’t require parameters and it will return a binary true/false regarding the liveness of the WSO2 server. Useful for liveness probing.

isAlive request:

<soap:Envelope xmlns_soap="http://www.w3.org/2003/05/soap-envelope" xmlns_xsd="http://org.apache.axis2/xsd">
   <soap:Header/>
   <soap:Body>
      <xsd:isAlive/>
   </soap:Body>
</soap:Envelope>

isAlive response example:

<soapenv:Envelope xmlns_soapenv="http://www.w3.org/2003/05/soap-envelope">   <soapenv:Body> 
 

 
      <ns:isAliveResponse xmlns_ns="http://org.apache.axis2/xsd">
 <ns:return>true</ns:return>
 </ns:isAliveResponse>
 </soapenv:Body>
 </soapenv:Envelope>

getServerStatus Operation

This operation will return any of the internal WSO2 instance statuses mentioned previously. Useful mostly for triggering processes at certain point of the instance’s life. Again no request parameters are needed.

getServerStatus request:

<soap:Envelope xmlns_soap=”http://www.w3.org/2003/05/soap-envelope” xmlns_xsd=”http://org.apache.axis2/xsd”>
 

   <soap:Header/>
<soap:Body>
<xsd:getServerStatus/>
</soap:Body>
</soap:Envelope>

getServerStatus response example:

<soapenv:Envelope xmlns_soapenv="http://www.w3.org/2003/05/soap-envelope">   <soapenv:Body> 
 

 
      <ns:getServerStatusResponse xmlns_ns="http://org.apache.axis2/xsd">
 <ns:return>RUNNING</ns:return>
 </ns:getServerStatusResponse>
 </soapenv:Body>
 </soapenv:Envelope>

To use curl to send the request to the server save the request in a XML file getServerStatus.xml and type the command:

curl -k -H "Content-Type: application/soap+xml;charset=UTF-8;"  -H "SOAPAction:urn:getServerStatus " --basic -u "user:password" --data @getServerStatus.xml https://host:9443/services/ServerAdmin

Status Check via JMX-RMI

If checking the status via SOAP services is not coming into the question, another standard possibility is to the check the status directly from the MBean. In the running java process org.wso2.carbon.bootstrap.Bootstrap the MBean ServerAdmin is exposed. This MBean contains the attributes “Alive” and “ServerStatus” which provide the same information as its SOAP request equivalents. Manually, the attributes can be reviewed using the Java Monitoring Console which is easily opened using the command $jconsole, as shown in the following screenshots.

Alive attribute:

Here can be seen a “Alive = true” in the attribute value box:

Alive Attribute-WSO2.png

ServerStatus attribute:

Here can be seen a “ServerStatus = RUNNING” in the attribute value box:

Servers Status Attribute - WSO2.png

Now, when the server attributes are to be collected programmatically, a connection to the process MBean must be established via             JMX remote method invocation (RMI).

The following code snippet, shows how this connection could be built using Java:

import javax.management.JMX;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;   

… 

String JMX_SERVICE_URL = "service:jmx:rmi://[host]:11111/jndi/rmi://[host]:9999/jmxrmi"; 

//Provide credentials required by server for user authentication            HashMap   environment = new HashMap();
String[]  credentials = new String[] {"user", "password"};            environment.put (JMXConnector.CREDENTIALS, credentials); 

//Create an RMI connection Client and connect to RMI Server            JMXServiceURL url = new JMXServiceURL(JMX_SERVICE_URL);            JMXConnector jmxc = JMXConnectorFactory.connect(url, environment); 

//Get an MBeanServerConnection
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); 

//Construct the ObjectName for the Carbon MBean
ObjectName mBeanName = new ObjectName("org.wso2.carbon:type=ServerAdmin");            ServerAdminMBean mBeanProxy = JMX.newMBeanProxy(mbsc, mBeanName,ServerAdminMBean.class); 

System.out.println("Status: " + mBeanProxy.getServerStatus());
System.out.println("is alive: " + mBeanProxy.isAlive()); 

jmxc.close();

The complete code and a compiled version is available in GitHub on https://github.com/luisguillo/wso2-server-probe

Conclusion

The WSO2 carbon based applications provide different options to check if the application is running, like the SOAP service or the JMX MBean. Being a Java based web application, many more approaches could be used, however it may not be possible to obtain the current WSO2 server status as exposed previously in this blog.

Yenlo is the leading, global, multi-technology integration specialist in the field of API-management, Integration technology and Identity Management. Known for our strong focus on best-of-breed hybrid and cloud-based iPaaS technologies. Yenlo is the product leader and multi-award winner in WSO2, Boomi, MuleSoft and Microsoft Azure technologies and offers best-of-breed solutions from multiple leading integration vendors.

eng
Close