Tuesday, May 8, 2018

WSO2 Admin Services.

WSO2 products are internally manage by using SOAP Web services known as Admin Services. WSO2 products come with a management console UI, which communicates with these admin services to facilitate administration capabilities through the UI.
A service in WSO2 products is defined by the following components:
  • Service component: provides the actual service
  • UI component: provides the Web user interface to the service
  • Service stub: provides the interface to invoke the service generated from the service WSDL
There can be instances where you want to call back-end Web services directly. For example, in test automation, to minimize the overhead of having to change automation scripts whenever a UI change happens, developers prefer to call the underlying services in scripts. 

Discovering WSO2 Admin Services:


By default, the WSDLs of admin services are hidden from consumers. So we are going to discover them using OSGI console. Please follow below steps: 

1. Set the <HideAdminServiceWSDLs> element to false in <PRODUCT_HOME>/repository/conf/carbon.xml file.

2. Go to <PRODUCT_HOME>/bin/  folder and start the WSO2 product as follows,

  • In Linux environment:  sh wso2server.sh -DosgiConsole
  • In Windows environment:  wso2server.bat -DosgiConsole
3. When the server is started, hit the enter/return key several times to get the OSGI shell in the console.
4. In the OSGI shell, type: listAdminServices
5. The list of admin services of your product are listed as follows:


6. To see the WSDL of any admin service, select the admin service's URL and paste it in your browser with ?wsdl at the end. For example:
https://SL-PRABODP:8243/services/InboundAdmin?wsdl
Note : Replace SL-PRABODP with your local IP or localhost.
Then you can see it as below

And also you can create a soap project in SoapUI as well
Then you can see as below in soapUI
Then you can check all available functionalities using this soapUI

Invoking WSO2 admin service

WSO2 Admin services are secured using common types of security protocols. ex:
  • HTTP basic auth
  • WS-Security username token
  • session based authentication

For example,  UserAdmin service is secured with HTTP basic auth. to invoke a service, follow these steps:
  1. Authenticate yourself and get the session cookie.
  2. Generate client stubs to access the back-end web services.

How to generate client stubs:

There are several methods / tools to generate client stubs:
  • Using Axis2 client API - I will explain in this blog.
  • Using SoapUI (4.5.1 or later)
  • Using wsdl2java

Generate Client stubs using Axis2 client API

First you need to create AdminService.wsdl file for which admin service you need to create stubs. For an example here i'm going to create for stubs for InboundAdmin service.
wsdl file for InboundAdmin service: 

To create a client using ADB execute the following steps:

1. Download and unpack the Apache Axis2 Standard Distribution.
2. Create the client stub with the following command:
%AXIS2_HOME%\bin\wsdl2java -uri InboundAdmin.xml -p wso2.adminservices.stubs -d adb -s
Assuming that you have InboundAdmin.xml file on your current directory.
wso2.adminservices.stubs - you can change this as your package name.

3. Create the client (for example Client.java), a java application that uses the generated stub, and save it in wso2/adminservices/inboundadmin directory.
4. Build the client by typing: ant jar.client
5. Assuming you have a corresponding service, run the client by adding the generated InboundAdmin-test-client.jar file located in build/lib to the classpath and type: java wso2.adminservices.inboundadmin.Client

Sample reference for Client.java