Tuesday, May 8, 2018

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


No comments:

Post a Comment