Calling WSO2 Enterprise Integrator SOAP Services using WSO2 Streaming Integrator.

Today we are going to see how we can call a SOAP service from WSO2 Streaming Integrator (WSO2 SI).

For our SOAP service, we will be using the Echo service which is exposed as a default service in the WSO2 Enterprise Integrator (WSO2 EI)vanilla distribution. The functionality of this Echo service is that the number sent will be echoed back to the user.

If you are familiar with WSO2 SI, then you already know that to deploy custom logic in the SI server we use Siddhi Language. So let’s see what we are gonna use and how we are gonna do it using Siddhi to satisfy our requirement.

We will be using the following elements. You can refer to the official siddhi documentation [1] to study more these elements

  • http-call sink :
  • http-call-response source :
  • log sink :
  • streams :

Let be briefly explain what each and every element does:

The http-call sink publishes messages to endpoints via HTTP or HTTPS protocols using methods such as POST, GET, PUT, and DELETE on formats text, XML or JSON and consume responses through its corresponding http-call-response source. It also supports calling endpoints protected with basic authentication or OAuth 2.0.

The http-call-response source receives the responses for the calls made by its corresponding http-call sink and maps them from formats such as text, XML and JSON.

We use the sink.id to correlate the http-call-response source with its corresponding http-call sink.

For both sink and source, we have an associated stream and these streams are used to hold events.

The final element is the sink log which is used as a logger. This will log the output events in the output stream.

Now let's see the elements in use for our use-case

Our complete http-call sink definition is as follow; using the POST method the value is published to the http://localhost:8280/services/echo service. And the@map annotation will convert the Siddhi event to an outgoing message format (XML in our case) and has the sink ID as A1.

@sink(type=’http-call’, sink.id=’A1', publisher.url=’http://localhost:8280/services/echo', method=’POST’,headers=”’Content-Type:text/xml’,’SOAPAction:urn:echoInt’”,
@map(type=’xml’, enclosing.element=”<soapenv:Envelope xmlns:echo=’http://echo.services.core.carbon.wso2.org' xmlns:soapenv=’http://schemas.xmlsoap.org/soap/envelope/'>",
@payload( “<soapenv:Header/><soapenv:Body><echo:echoInt><in>{{attr}}</in></echo:echoInt></soapenv:Body>”)))

Our http-call-response source definition is as follow which will capture the responses for sink ID A1 with status code 200. And the @map annotation converts the format of the incoming message (XML in our case) to Siddhi events.

@source(type='http-call-response',sink.id='A1',http.status.code='200', 
@map(type='xml', namespaces ="xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/',xmlns:ns='http://echo.services.core.carbon.wso2.org'",
@attributes(echoed_no = '//return')))
@sink(type='log')

Also, we have a stream named inputNumberStream to initiate the flow. We can simulate this stream by sending a number as attr.

define stream inputNumberStream(attr int);

And we have a query named query1, where we will send the number from the inputNumberStream to the inputStream and via that to the associated sink which will call the Echo soap service. (The echo service will echo back the character received)

@info(name='query1')from inputNumberStream
select *
insert into inputStream;

Once received, its response will be captured via outputStream associated with the http-call-response source as echoed_no and printed using a log sink.

@sink(type='log')
define stream outputStream (echoed_no string);

And full sample siddhi application can be found below.

@App:name("SiddhiAppSOAPTest")define stream inputNumberStream(attr int);@sink(type='http-call', sink.id='A1', publisher.url='http://localhost:8280/services/echo', method='POST',headers="'Content-Type:text/xml','SOAPAction:urn:echoInt'",
@map(type='xml', enclosing.element="<soapenv:Envelope xmlns:echo='http://echo.services.core.carbon.wso2.org' xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>",
@payload( "<soapenv:Header/><soapenv:Body><echo:echoInt><in>{{attr}}</in></echo:echoInt></soapenv:Body>")))
define stream inputStream (attr int);@source(type='http-call-response',sink.id='A1',http.status.code='200',
@map(type='xml', namespaces ="xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/',xmlns:ns='http://echo.services.core.carbon.wso2.org'",
@attributes(echoed_no = '//return')))
@sink(type='log')
define stream outputStream (echoed_no string);
@info(name='query1')from inputNumberStream
select *
insert into inputStream;

You can test this out by simulating a number (eg:34) to the inputNumberStream and observe a similar logline as below will be logged in your SI server carbon log using the log sink.

INFO {io.siddhi.core.stream.output.sink.LogSink} — SiddhiAppSOAPTest : outputStream : [Event{timestamp=1632067939566, data=[34], isExpired=false}]

This basic Siddhi application which is used to call a SOAP service can be further improved by customizing and creating complex logic as per your requirements.

Till we see each other in another blog stay safe.

Happy Coding :)

[1].https://siddhi.io/en/v5.0/docs/query-guide/

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Auto Deploy Angular website on S3 using GitLab CI

Andela Boot Camp Cohort XIV Day 2

Svitla Smart Talk: Adventures in TensorFlow.js. Event summary.

FlutterForce — #Week 136

Istumbler 103 4 — Find Local Wireless Networks

Find

The District Weekly — August 15th

Game Dev in Progress… Day 17

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Umesha Guruge

Umesha Guruge

More from Medium

BLM makes innovations in fire equipment with rollover protection systems

Travel between 360s with Navigation Hotspots

Pearl Harbor at 80: Hurshel E. Ward Jr.’s Typed Pearl Harbor Account