Injecting Messages to a RESTful Endpoint¶
In order to use the Message Injector to inject messages to a RESTful endpoint, you can specify the injector with the required payload and inject the message to the sequence or proxy service as defined below. The sample below shows a RESTful message injection through a proxy service.
Synapse configurations¶
Following are the integration artifacts that we can used to implement this scenario. See the instructions on how to build and run this example.
<task class="org.apache.synapse.startup.tasks.MessageInjector" group="synapse.simple.quartz" name="SampleInjectToProxyTask" xmlns="http://ws.apache.org/ns/synapse">
<trigger count="2" interval="5"/>
<property name="injectTo" value="proxy" xmlns:task="http://www.wso2.org/products/wso2commons/tasks"/>
<property name="message" xmlns:task="http://www.wso2.org/products/wso2commons/tasks">
<request xmlns="">
<location>
<city>London</city>
<country>UK</country>
</location>
</request>
</property>
<property name="proxyName" value="SampleProxy" xmlns:task="http://www.wso2.org/products/wso2commons/tasks"/>
</task>
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="SampleProxy" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<property expression="//request/location/city" name="uri.var.city" scope="default" type="STRING"/>
<property expression="//request/location/country" name="uri.var.cc" scope="default" type="STRING"/>
<log>
<property expression="get-property('uri.var.city')" name="Which city?"/>
<property expression="get-property('uri.var.cc')" name="Which country?"/>
</log>
<send>
<endpoint name="EP">
<http method="get" uri-template="http://api.openweathermap.org/data/2.5/weather?q={uri.var.city},{uri.var.cc}&APPID=ae2a70399cf2c35940a6538f38fee3d3"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full"/>
</outSequence>
<faultSequence/>
</target>
</proxy>
Build and run¶
Create the artifacts:
- Set up ESB Integration Studio.
- Create an integration project with an ESB Configs module and an Composite Exporter.
- Create the proxy service and a scheduled task with the configurations given above.
- Deploy the artifacts in your Micro Integrator.
The XML message you injected (i.e., This is a scheduled task of the default implementation.) will be printed in the logs of the Micro Integrator twice, 5 seconds apart.
INFO {org.apache.synapse.mediators.builtin.LogMediator} - Which city? = London, Which country? = UK
Top