Web Service Executor Sample
This sample explains how the Web Service Executor can be used in lifecycle configurations to invoke a Web Service in a synchronous manner.
Prerequisites
- Download Apache Axis2 and SoapUI.
Steps To Get This Sample To Work
- Start the Apache Axis2 server and add the AdderService.aar file which can be downloaded here, into
AXIS2_HOME/repository/services
. - Go to
http://localhost:8080/axis2/services/
and get AdderService from this. You can copy the WSDL location which should look like the following:http://localhost:8080/axis2/services/AdderService?wsdl.
- Start SoapUI and create a new project and give the WSDL path that was obtained in step 2.
- Send an request to the Web Service using the SoapUI. Add some random values to args0 and args1.
The response can be seen through SoapUI after successful service invocation.
- Start WSO2 Governance Registry and go to Extensions > Configure > Lifecycles and click on Add New Lifecycle.
Add the following segment under the datamodel tag in Development state and save the Lifecycle.
<data name="transitionExecution"> <execution forEvent="Promote" class="org.wso2.carbon.governance.registry.extensions.executors.WSExecutor"> <parameter name="async" value="false"/> <parameter name="save.type" value="property"/> <parameter name="save.name" value="response"/> <parameter name="response.xpath" value="//ns:return"/> <parameter name="response.namespace" value="http://ws.apache.org/axis2"/> <parameter name="response.namespace.prefix" value="ns"/> <parameter name="epr" value="http://localhost:8080/axis2/services/AdderService.AdderServiceHttpSoap11Endpoint/"/> <parameter name="payload"> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:axis="http://ws.apache.org/axis2"> <soapenv:Header/> <soapenv:Body> <axis:add> <axis:args0>5</axis:args0> <axis:args1>6</axis:args1> </axis:add> </soapenv:Body> </soapenv:Envelope> </parameter> </execution> </data>
async - This is set to false since this is meant to be a synchronous call.
save.type - This is given as a property to save the response in a property.
save.name - This is given as response. You can change this to any value you prefer.
response.xpath - XPath to evaluate the response. This example only takes the return segment into consideration.
response.namespace - This can be found in the response in SoapUI.
response.namespace.prefix - This can be found in the response in SoapUI
epr - The endpoint of the service this can be found from soapUI. For this example it is:http://localhost:8080/axis2/services/AdderService.AdderServiceHttpSoap11Endpoint/
.
payload - The payload can be directly copied from the request in soapUI.<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:axis="http://ws.apache.org/axis2"> <soapenv:Header/> <soapenv:Body> <axis:add> <axis:args0>5</axis:args0> <axis:args1>6</axis:args1> </axis:add> </soapenv:Body> </soapenv:Envelope>
Create a new API and add the “SampleLifeCycle” as the lifecycle.
Alternatively, it is possible to specify the lifecycle in the default lifecycle tag of the artifact configuration:
<lifecycle>SampleLifeCycle</lifecycle>.
- Do an Promote operation. The response value is saved in the property when the promote operation is successful.