Calling WSO2 Admin Services

Naduni Pamudika
Sep 7, 2018 · 4 min read

In this blog post let’s see how to call a WSO2 Admin Service. WSO2 Admin Services are SOAP services. So you need to use one of the SOAP Clients (Like SoapUI) to call the WSO2 Admin Services. You can also call the Admin Services via CURL as well.

I am going to show how to call TenantMgtAdminService in WSO2 Identity and Access Management (IAM) product in both the above mentioned ways.


Calling TenantMgtAdminService via SoapUI

https://smartbear.com/blog/test-and-monitor/the-rest-is-coming-to-soapui/

First you need to allow access to the Admin Services. In order to allow access to the Admin Services, you need to set the following property to false in the carbon.xml in <SERVER_HOME>/repository/conf folder, so that you could be able to access the available list of Admin Services.

<HideAdminServiceWSDLs>false</HideAdminServiceWSDLs>

Then start the Server from the OSGI Console by navigating to the <SERVER_HOME>/bin directory and typing the below command (in Linux). If you are using Windows OS, follow the commands accordingly as guided in the WSO2 Documentation.

sh wso2server.sh -DosgiConsole

After the server started, you will be getting the OSGI Console and type the following command to list down the Admin Services.

>osgi listAdminServices

It will list the Admin Services as below, and search for the Admin Service you need.

List of WSO2 Admin Services

Here I am using the TenantMgtAdminService. If you want to see the service, you can view it via the below link in your browser.

https://localhost:8243/services/TenantMgtAdminService?wsdl

Now you have the Admin Service with you, let’s call it via the SoapUI.

Download and open the SoapUI and create a new SOAP Project by giving TenantMgtAdminService ad the Project Name and https://localhost:8243/services/TenantMgtAdminService?wsdl as the Initial WSDL as below.

Adding a new SOAP Project

Let’s see how to call addTenant method in the TenantMgtAdminService.

AddTenant View

Set the Authorization to Basic and add admin and admin as the username and password by clicking Auth tab in the bottom and adding new Authorization type as Basic.

Add Authorization View
Basic Auth

Set the parameters in the request as below.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.mgt.tenant.carbon.wso2.org" xmlns:xsd="http://beans.common.stratos.carbon.wso2.org/xsd">
<soapenv:Header/>
<soapenv:Body>
<ser:addTenant>
<!--Optional:-->
<ser:tenantInfoBean>
<!--Optional:-->
<xsd:active>true</xsd:active>
<!--Optional:-->
<xsd:admin>wso2user</xsd:admin>
<!--Optional:-->
<xsd:adminPassword>wso2123</xsd:adminPassword>
<!--Optional:-->
<xsd:email>wso2user@wso2.com</xsd:email>
<!--Optional:-->
<xsd:firstname>wso2</xsd:firstname>
<!--Optional:-->
<xsd:lastname>user</xsd:lastname>
<!--Optional:-->
<xsd:successKey>true</xsd:successKey>
<!--Optional:-->
<xsd:tenantDomain>wso2.com</xsd:tenantDomain>
<!--Optional:-->
<xsd:tenantId>3</xsd:tenantId>
<!--Optional:-->
<xsd:usagePlan>demo</xsd:usagePlan>
</ser:tenantInfoBean>
</ser:addTenant>
</soapenv:Body>
</soapenv:Envelope>

Change the endpoint by updating the port as https://localhost:9443/services/TenantMgtAdminService.TenantMgtAdminServiceHttpsSoap11Endpoint

Click send button. Then you will get a response and you have successfully created a tenant via the Admin Service!!!

Request and Response of addTenant method call

Calling TenantMgtAdminService via CURL

Create a request.xml file by adding the content as below.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.mgt.tenant.carbon.wso2.org" xmlns:xsd="http://beans.common.stratos.carbon.wso2.org/xsd">
<soapenv:Header/>
<soapenv:Body>
<ser:addTenant>
<!--Optional:-->
<ser:tenantInfoBean>
<!--Optional:-->
<xsd:active>true</xsd:active>
<!--Optional:-->
<xsd:admin>wso2user</xsd:admin>
<!--Optional:-->
<xsd:adminPassword>wso2123</xsd:adminPassword>
<!--Optional:-->
<xsd:email>wso2user@wso2.com</xsd:email>
<!--Optional:-->
<xsd:firstname>wso2</xsd:firstname>
<!--Optional:-->
<xsd:lastname>user</xsd:lastname>
<!--Optional:-->
<xsd:successKey>true</xsd:successKey>
<!--Optional:-->
<xsd:tenantDomain>wso2.com</xsd:tenantDomain>
<!--Optional:-->
<xsd:tenantId>3</xsd:tenantId>
<!--Optional:-->
<xsd:usagePlan>demo</xsd:usagePlan>
</ser:tenantInfoBean>
</ser:addTenant>
</soapenv:Body>
</soapenv:Envelope>

Now call the TenantMgtAdminService’s addTenant method via CURL as below.

curl -k -H "Content-Type: application/soap+xml;charset=UTF-8;"  -H "SOAPAction:urn:addTenant" --basic -u "admin:admin" --data @request.xml https://localhost:9443/services/TenantMgtAdminService.TenantMgtAdminServiceHttpsSoap11Endpoint

Like wise you can call any method in any WSO2 Admin Service via either SoapUI or CURL.

Happy Coding :)

Naduni Pamudika

Written by

Senior Software Engineer @ WSO2 | Graduate from the Department of Computer Science & Engineering, University of Moratuwa

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade