Scheduled tasks for REST request in WSO2 ESB - web-services

I'd like to schedule tasks in WSO2 ESB in order to use restful web services and obtain, from these web services, some responses every N seconds.
In the task configuration page in WSO2 ESB configuring SOAP services is simple, but what about REST services? For example, if I want to ask some information to this web service http://maps.googleapis.com/maps, how can i configure a working task?

From a task, you can inject messages to RESTful Endpoints through a sequence or a proxy service. Refer Injecting messages to RESTful Endpoints section of [1] for more details on how to do this.
[1] https://docs.wso2.com/display/ESB481/Adding+and+Scheduling+Tasks

First you need to define a sequence to call the REST endpoint and inject it with the scheduled task. Try the following example :
<sequence xmlns="http://ws.apache.org/ns/synapse" name="callAPI">
<call>
<endpoint>
<http method="GET" uri-template="http://testAPI/test"/>
</endpoint>
</call>
</sequence>
<task xmlns="http://ws.apache.org/ns/synapse"
name="testTask"
class="org.apache.synapse.startup.tasks.MessageInjector"
group="synapse.simple.quartz">
<trigger interval="5"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
name="sequenceName"
value="callAPI"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
name="injectTo"
value="sequence"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks" name="message">
<test xmlns=""/>
</property>
</task>

Related

WSO2 API Manager - load balancing with dynamic endpoints

I've got an API that uses dynamic endpoints. Now I want it to also do load balancing. I know how to do that using element, however when using dynamic endpoints in APIM you only manipulate the "To" header.
Below is the mediation sequence used to set the endpoint. Instead of addressing just a single endpoint in each case, I'd like to be able to loadbalance between 2 servers.
Any thoughts?
Thanks.
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="inSequence_clientEquipmentsAPI_1_2_STG" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<!-- check for healthcheck operation -->
<filter xpath="get-property('To')='/etc/equipments/client/1.0/healthCheck'">
<!-- if healthCheck, directs to healthCheck API (EI)-->
<then>
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
<header name="To" value="http://10.220.160.36:8290/healthCheck/clientEquipments"/>
</then>
<!-- else direct to regular clientEquipment API (EI)-->
<else>
<property name="newContext" expression="substring-after(get-property('To'),'/etc')"/>
<header name="To" expression="fn:concat('http://10.220.160.36:8290', $ctx:newContext)"/>
</else>
</filter>
</sequence>

How to engage a custom module in a Send Mediator?

I am trying to disable WS-Security for incoming Response of my secured Request. The request is secured by Policy in send mediator like this:
<send>
<endpoint>
<address format="soap11" uri="${endpoint}">
<enableSec policy="conf:policies/Policy.xml" />
</address>
</endpoint>
</send>
For disabling WS-Security on incoming messages I followed this article SOA Security - Disabling WS-Security for IN or OUT messages in Axis2. It uses a custom module to replace Policy file for the message validation.
For writing custom module and engaging it inside my services I followed Writing an Axis2 Module and Engaging Module from WSO2 documentation.
If i engage the module globally by adding nosecurity module to axis2.xml, it works for every incoming message like its supposed to.
<!-- ================================================= -->
<!-- Global Engaged Modules -->
<!-- ================================================= -->
<!-- Comment this out to disable Addressing -->
<module ref="addressing"/>
<module ref="nosecurity"/>
But I don't know how to engage the module only for the Send Mediator.
When using this proxy from Engaging Module, it only engages the module for incoming requests to this proxy and not to the request of my call to an endpoint with Send Mediator.
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="Pass"
transports="http,https"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<send>
<endpoint>
<address format="soap11" uri="${endpoint}">
<enableSec policy="conf:policies/Policy.xml" />
</address>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
<parameter name="engagedModules">nosecurity</parameter>
</proxy>
So my question is, how do i engage my custom Axis2 module only for the Send Mediator? Thank you for any input.
You can engage modules at service level too.
Please check To engage a module at service level at [1]
[1] https://docs.wso2.com/display/EI640/Working+with+Modules#WorkingwithModules-Engagingmodules

SOAP messages are not sent using wso2 ESB REST API

I'm trying to expose SOAP backend as REST API using wso2 ESB. I'm using payload factory to send the soap body message, but it doesn't work.
This is my API resource in wso2 esb code :
<?xml version="1.0" encoding="UTF-8"?>
<api context="/akademik" name="SampleAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" uri-template="/students?symbol={symbol}">
<inSequence>
<log level="custom">
<property expression="$url:symbol" name="symbol"/>
</log>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:sem="http://semogabisa.te.net/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<sem:sayHi>
<arg0>$1</arg0>
</sem:sayHi>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="$url:symbol"/>
</args>
</payloadFactory>
<header scope="default">
<m:complexHeader xmlns:m="http://org.synapse.example">
<m:property key="Content-Type" value="application/xml"/>
</m:complexHeader>
</header>
<send>
<endpoint>
<address format="soap11" uri="http://localhost:8084/HelloWorld"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
Soap messages are not sent to the backend web service, it says null.
I've test the backend service with SOAPUI with same soap envelope format and it's working
I think you make some mistake on the header mediator. "HelloWorld" back end service didn't need the SOAP header based on your SOAP UI request. so remove the header mediator.
Select Synapse if you want to manipulate SOAP headers. Select Transport if you want to manipulate HTTP headers.
And it's seems back end is SOAP11, SOAP11 type is "text/xml". Your may need set this property.
<property name="messageType" value="text/xml" scope="axis2"/>
When you send message out from ESB, you need set property "messageType", then ESB will formatter the message that match back end required.
You may probably need this property, if you found ESB append some context to your back end URI when send message to back end.
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
Good Tips:
Please open your "synapse.transport.http.wire" as DEBUG, this will output every message in and out from ESB. This log will including HTTP header and body. After you got the wire log, you can compare wire log with your SOAPUI request, then find out which part is wrong.
https://docs.wso2.com/display/ESB481/Setting+Up+Logging

WSO2 endpoint format

new to WSO2 but trying to do something that should be relatively straightforward even for the uninitiated, before I have a crack at some xslt mediation in a wso2 proxy.
All im trying to do as a first step is change the transport between the wso2 client (jms) and the endpoint (http). The client is sending a full soap envelope in the JMS payload.
I can see that my endpoint is being invoked from the server logs (however I can see requests are rejected).
Sure enough, I can see from the proxy logs that WSO2 is adding an additional SOAP envelope wrapper around the soap payload from the client.
My understanding is that this should be correctable by setting the format attribute of the endpoint to "leave as-is". This doesnt make a difference however. I suspect this is an easy endpoint or proxy configuration fix, rather than requiring some xsl mediation? Any guidnace gratefully received:
my code:
Endpoint:
<endpoint xmlns="http://ws.apache.org/ns/synapse">
<address uri="http://d26li228.au.alcatel-lucent.com:44006/ilws/InstantLinkSOA">
<suspendOnFailure>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
</address>
</endpoint>
Proxy:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="McProxy3"
transports="McJMS"
statistics="disable"
trace="enable"
startOnLoad="true">
<target>
<inSequence>
<log level="full"/>
<property name="OUT_ONLY" value="true"/>
<send>
<endpoint key="conf:/ilepr"/>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
<parameter name="transport.jms.Destination">McQueue</parameter>
<description/>
</proxy>
Set the content type of the message you are receiving from JMS : if there is already a SOAP Envelope, it's text/xml :
<parameter name="transport.jms.ContentType">
<rules xmlns="">
<jmsProperty>contentType</jmsProperty>
<default>text/xml</default>
</rules>
</parameter>
If the service you're calling through your endpoint wait soap11 or soap12, you can set this format in your endpoint definition (don't let "leave as-is")
You've defined OUT_ONLY to true inside your inSequence, before sending your message through your endpoint : the ESB won't instanciate any callback and will not receive any response (outSequence will never be executed)

WSO2 ESB JMS sample showing vfs transport configuration error

I am trying to implement ESB as a JMS Consumer sample, given at WSO2 ESB documentation.
http://docs.wso2.org/display/ESB470/ESB+as+a+JMS+Consumer
I have followed below steps:
configuring JMS listener and sender in
ESB_Home\repository\conf\axis2\axis2.xml
copied all the jar file as mentioned
created a message queue in ActiveMQ using its web console.
Below is my proxy service code:
<proxy xmlns="http://ws.apache.org/ns/synapse" name="JMStoHTTPStockQuote" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="OUT_ONLY" value="true"/>
</inSequence>
<outSequence>
<send/>
</outSequence>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
</endpoint>
</target>
<description></description>
</proxy>
But still my proxy service is showing as faulty service. with the message:-
Unable to configure the service JMStoHTTPStockQuote for the VFS transport: Service doesn't have configuration information for transport vfs. This service is being marked as faulty and will not be available over the VFS transport.
As you can see I am not using VFS transport for my service and I have uncommented the code for VFS in axis2.xml but still I am getting this faulty exception.
First of all your proxy configuration is not correct. If you want to listen to a JMS queue, you need to use the jms transport in your proxy service. In the link you have mentioned, the proxy service is given as below.
<proxy xmlns="http://ws.apache.org/ns/synapse" name="JMStoHTTPStockQuoteProxy" transports="jms">
<target>
<inSequence>
<property action="set" name="OUT_ONLY" value="true"/>
</inSequence>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
</endpoint>
<outSequence>
<send/>
</outSequence>
</target>
</proxy>
Here the transport is "jms". Please try with this config.