During the project I had to call certain admin services's methods of WSO2 G-Reg 5.0.0. using jaggery application. Following are the steps I went through to discover available admin services exposed to outside in Greg. Since this procedure would be the same for any of WSO2 servers ( e.g. WSO2 ESB, GReg, IS, CEP, BPS, ES, AS, BAM, etc.) I will try to make this post as general as possible.
To find out the available Admin services:
1. Open “wso2greg-5.0.0-SNAPSHOT/repository/conf/carbon.xml” file
For the general case it would be : <server_home>/repository/conf' directory
and then open carbon.xml
2. Setting HideAdminServises property to 'false', will allow us to view the admin service's wsdl.
(Not mandatory - If you are not willing to view the wsdl of the service in browser, you can left out this step)
<HideAdminServiceWSDLs>false</HideAdminServiceWSDLs>
3. Start the server with the OSGIConsole.
./wso2server.sh -DosgiConsole
4.Once the server is started we can view Adin servoces :
Press enter & type 'listAdminServices'
osgi > listAdminServices
Part of the list of admin services of GReg |
5. To check the wsdl of the admin service in the browser:
Add ?wsdl to the url at its end.
HTTP 403 error is thrown if we have not set the hideAdminServiceWSDLs to false.
wsdl of a sample admin service |
To use Soap UI to test the services:
Soap creates a Soap Envelope and call the given endpoint. Basically it does the job of a Soap client.
1. Download and install SoapUI at http://www.soapui.org/
I. Go to File > New SOAP Project.
II.Paste the wsdl url in the 'initial wsdl' box and click OK.
SoapUI 5.0.0- Add new SOAP Project |
2. Click on the Admin Service method from which you want to call from SoapUI and try sending a request.
We have to set Authentication and security related settings to access the admin service.
I. Click on 'Auth' below and click 'Add New Authorization'.
II. Select type Basic and set the username and password. ( Default username and password for every WSO2 Product would be 'admin').
III.Insert the values of the parameters and click the submit request button.
SoapUI 5.0.0 Successful request to an endpoint |
If everything went well, we will end up with successful response.
In the response envelope check the return tag to see if the response we are getting is correct.
To call an Admin Service using Jaggery WS-Request:
We don't have to find out available admin services and to use SoapUI to test services if Admin Service endpoint URL and the action that should be called. Basically we can call the same admin service method uisng Jaggery WSRequest.
Jaggery documentation can be found at http://jaggeryjs.org/documentation.jag?api=ws
Jaggery code to call the above Admin service.
<%
var rxt = "JSON RXT Config Should go here";
var log = new Log();
var ws = require('ws');
var addRxt = new ws.WSRequest();
var options = new Array();
options.useSOAP = 1.1;
options.action = "urn:addJSONRXTResource";
var payload = '<ser:addJSONRXTResource xmlns:ser="http://services.generic.governance.carbon.wso2.org"> <ser:jsonRxtConfig>'+rxt+'</ser:jsonRxtConfig> </ser:addJSONRXTResource>';
var result;
try {
addRxt.open(options, "https://localhost:9443/services/ManageGenericArtifactService", false, "admin", "admin");
addRxt.send(payload);
result = addRxt.responseE4X;
} catch (e) {
log.error(e.toString());
}
print(result);
%>
Action:Method to be called from the Admin Service
Payload:Actual request payload to be sent to the endpoint.
Specify the name servers correctly when sending the payload. WSRequest's open() will open the connection with the endpoint with necessary authentication and then sends the payload. Result will get the response Soap Message in which it will print in the page itself.
No comments:
Post a Comment