WSO2 – How to call admin services

Posted: October 3, 2013 in java, linux, ubuntu, wso2
Tags: ,
  • This post will describe basic steps in calling an admin service using an axis2 client. Note that if you want to invoke admin services using SOAP UI, please fallow the post by Charitha on Invoking WSO2 Carbon admin services with soapUI
    Let’s say we want to call the admin service name “ProvisioningAdminService” which will give us the set of installed features of the carbon server.

A call to an admin service should be authenticated first. So we call the AuthenticationAdmin admin service first to get a authentication session cookie. We add this session cookie to the subsequent requests so they will be authenticated.

private static String SEVER_URL = "";
private static String USER_NAME = "admin";private static String PASSWORD = "admin";
String AUTHENTICATION_ADMIN_SERVICE_URL = "AuthenticationAdmin";

//Create an instance of a Authentication stub
AuthenticationAdminStub authenticationStub = new AuthenticationAdminStub(SEVER_URL +  AUTHENTICATION_ADMIN_SERVICE_URL);

// log in with the username=admin and password=admin.
// They are the default username, passowrd of carbon super admin user.
boolean loginStatus = authenticationStub.login(USER_NAME, PASSWORD,(new URL(SEVER_URL)).getHost());
System.out.println("login " + loginStatus);

ServiceContext serviceContext = authenticationStub._getServiceClient()

//Let's get the session cookie string of the last call to authentication admin service. Subsequent requests will be authenticated only if the request contains this session cookie header.
String sessionCookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING);

// Let's try to call ProvisioningAdminService admin service.
serviceEndPoint = SEVER_URL + "ProvisioningAdminService";
ProvisioningAdminServiceStub provisioningAdminService = new ProvisioningAdminServiceStub(serviceEndPoint);

ServiceClient client2 = provisioningAdminService._getServiceClient();
Options option2 = client2.getOptions();

// set the session cookie of the previous call to AuthenticationAdmin service
option2.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, sessionCookie);

//print the installed services
ProvisioningAdminServiceStub.Feature [] features;
features = provisioningAdminService.getAllInstalledFeatures();
for (ProvisioningAdminServiceStub.Feature f : features) {


If you didn’t set the sessionManage to true for the request to the ProvisioningAdminService you will get the following error since your request does not carries the authentication session cookie.

org.apache.axis2.AxisFault: Transport error: 401 Error: Unauthorized
at org.apache.axis2.transport.http.HTTPSender.handleResponse(
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(
at org.apache.axis2.transport.http.HTTPSender.send(
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(
at org.apache.axis2.engine.AxisEngine.send(
at org.apache.axis2.description.OutInAxisOperationClient.send(
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(
at org.apache.axis2.client.OperationClient.execute(
at org.wso2.carbon.user.mgt.sample.SampleUserRoleMgtClient.main(

Following are recommended for a comprehensive knowledge on WSO2 authentication.
Authentication and Authorization Choices in WSO2 Platform 
Securing Web Service Integration


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s