Call/Send mediator inside ForEach mediator - wso2

According to the documentation
ForEach does not allow using Call , Send and Callout mediators in the sequence.
But it is possible to use a Call/Send/Callout mediator inside a ForEach mediator if you place it inside a sequence, and invoke this sequence inside of it, like in this example:
<!-- myProxy.xml -->
<for-each expression="//foo" >
<sequence>
<sequence key="myCallSequence"/>
</sequence>
</for-each>
<!-- myCallSequence.xml -->
<call>
<endpoint>
<address format="soap11" uri="http://my.uri.com"/>
</endpoint>
</call>
Which I observed could result in some very unexpected results, especially regarding the aggregated payload after the for each being mixed with the return of a callout.
I stumbled accross this while dealing with a situation where I had to split my original message and validate some data from the splitted parts with an external service, but still needed to do more processing with the original message if the validations where successfull.
Is this kind of configuration considered a bad practice? And if so, why?

ForEach mediator should only be used if you need to transform a payload in an iterative manner (for example, an array). ForEach mediator is not implemented to support calling back-ends. If you need to achieve this use case, use the Iterate mediator which allows you to call back-end. Please refer https://docs.wso2.com/display/EI611/Iterate+Mediator for more information.

Related

Veins: How to verify if rerouting is using user set algorithm

I'm using veins 4.6 and trying to evaluate the change in emissions due to different routing protocols. By exploring SUMO site I have managed to set base for the experiment. For now I'm using veins demo application with minor configurations changes. Here is content of my erlangen.sumo.cfg file:
<?xml version="1.0" encoding="iso-8859-1"?>
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.sf.net/xsd/sumoConfiguration.xsd">
<input>
<net-file value="erlangen.net.xml"/>
<route-files value="erlangen.rou.xml"/>
<additional-files value="erlangen.poly.xml"/>
</input>
<time>
<begin value="0"/>
<end value="400"/>
<step-length value="1"/>
</time>
<routing>
<routing-algorithm value="CHWrapper"/>
<device.rerouting.probability value="1"/>
</routing>
<emissions>
<device.emissions.probability value="1"/>
</emissions>
<report>
<no-step-log value="true"/>
</report>
<gui_only>
<start value="true"/>
</gui_only>
<output>
<fcd-output value="erlangen.fcd.xml"/>
<emission-output value="erlangen.emission.xml"/>
<tripinfo-output value="erlangen.trip_info.xml"/>
<vehroute-output value="erlangen.route_followed.xml"/>
<summary value="erlangen.summary.xml" />
</output>
</configuration>
Routes file (erlangen.rou.xml) content is as follows:
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/routes_file.xsd">
<vType id="passenger" vClass="passenger" accel="2.6" decel="4.5" sigma="0.5" length="2.5" minGap="2.5"
maxSpeed="120" guiShape="passenger/sedan" color="1,0,0" emissionClass="HBEFA3/LDV_G_EU4">
<param key="has.emission.device" value="true"/>
<param key="has.rerouting.device" value="true"/>
<param key="device.fcd.probability" value="1"/>
</vType>
<flow id="flow0" type="passenger" from="3013106#1" to="29900564#1" begin="0" period="3" number="30" />
erlangen.net.xml is unchanged and in omnetpp.ini I have changed *.connectionManager.maxInterfDist from 2600m to 100m only.
Using these configurations I have ran the simulation using A* and CHWrapper algorithm but output of both is ditto copy. In below image it is visible that node 25 - 29 followed a different path after rerouting, but these are same in both cases.
Tripinfo results are given below, as discussed here "tripinfo_rerouteNo" clearly shows that nodes have been rerouted.
Now following is revolving in my mind:
Are routing algorithms applied successfully (set in erlangen.sumo.cfg) or in both cases default Dijkstra was used?
Routing algorithms applied successfully but results are same because network was not congested enough / don't have enough alternate paths to follow. So I should have change network, with multiple accident count etc.
I'm not getting how rerouting is working here.
I'm stuck here, any directions will be highly appreciated.
It is not easy to say from the outside which routing algorithm has been applied, but I would assume 2. is the correct solution. The different algorithms are basically different in the way they can handle dynamic changes to the edge weight vs. the calculation speed but in most cases they should give the same result. You might wish to try the scale option to increase traffic easily or set device.rerouting.period to a value like 10 (seconds) to enable periodic rerouting of the vehicles to see more effects. Also setting weights.random-factor to a large value can help.
One can verify using a sample network like following:
In my test case I set starting position of vehicles as left most edge bottom lane and destination was upper lane of same edge. No uTurn was implemented therefore vehicles had to pass through junction, and FCD for every algorithm was significantly different.

WSO2 add API context to headers

I have several APIs behind a WSO2 instance, each with it's own context ("/api-1/", "/api-2/", ...)
I'd like to add this context string dynamically to an Http header (without hardcoding it on a per-API basis).
So, for example:
<sequence name="WSO2AM--Ext--In">
<header name="X-Script-Name"
scope="transport" expression="get-property('', '')"/>
</sequence>
Is there an expression that I can use to achieve this? Or should I resort to creating a per-API mediator to include it?
Edit:
I have tried using the url regex, expecting it to treat {context} as part of the uri variables, but it doesn't seem to do it:
<header name="X-Script-Name" scope="transport" expression="uri.var.context"/>
Did you define "uri.var.context" before? It is not inbuilt variable to be used.
You can read the "To" header and apply the string manipulation using xpath, so you can get the context.
Edit;
You can read API metadata(context,version etc..) from jwt token.Get the jwt token from transport header and manipulate it.

how to use lookups in xslt mediator in wso2esb

In WSO2ESB, using the xslt mediator, I want to transform a webservice result. I do that using an xslt file. In this file, I want to do some lookups, to transform some values into something else.
In Oracle, you can use a dvm for that.
In plain xslt, it looks like the document('somefile.xml') function could do the trick, but WSO2ESB looks for the xml file on the filesystem, and the resources property on the xslt mediator does not translate document() contents into correct paths.
Then, I tried inputting the XML by reading it into a property in ESB, and then pass the property to the mediator. This also does not work, because the content of the XML is then
passed as one string value instead of a nodeset.
Am I doing something wrong - what is the correct way of doing this?
you can inject the content of your document 'somefile.xml' as a subtree inside the current message before invoking XSLT mediator :
Define a local entry named 'somefile' with the content of 'somefile.xml'
Use enrich mediator to inject it's content inside current message :
<enrich>
<source clone="true" xpath="get-property('somefile')"/>
<target type="body" action="child"/>
</enrich>
In your XSL transformation, use this content rather than refering to $somefile/xxx...
(and forget this content in the result)
By default, the XSLT mediator acts on the message body, so shouldn't be necessary to use the document function to load the XML seperately. For an example of the xslt mediator, see this link to the current wso2esb documentation.
If you want to replace a few values in your XML, you may want to try the enrich mediator. The enrich mediator can use Xpath expressions to select the source and target expressions for replacement.

Can we able to write the data into existing .csv file using wso2esb4.8.0

I am using wso2esb4.8.0.I wish to write the data into .CSV file using wso2esb4.8.0
if file is empty i am able to write means Append but my issue is already has file just i need to add one more data column to that
m csv file is
mdata
======
john,us,24,monnaco
ahemad,uk,54,bresbane
rajulak,srilanks,35,dar
above my csv file look like but i need to write(ADD) data in next column like this'
Desire .CSV file is
mdata
==========
john,us,24,monnaco,man
ahemad,uk,54,bresbane,man
rajulak,srilanks,35,dar,man
like this i wish to write the data into existing row only
how would i achive this
i tried this but its adding in next row
actually that one column may come from my client as json data
i wsih to add into that .CSV file
i have done like this but no use my config is
<inSequence>
<log level="full"/>type="STRING"/>
<property name="transport.vfs.ReplyFileName" expression="mdata.csv" scope="transport" type="STRING"/>
<send>
<endpoint>
<address uri="vfs:file:///Y6/Desktop/MyOutputDirectory?transport.vfs.Append=true"/>
</endpoint>
</send>
</inSequence>
how would i achive my desire file format is there any way into esb or not
You can achive this by writing your own class mediator to write to .csv file as your desired format. VFS does not support the requirement of writing custom files in different formats. You can write a simple java code to achieve this . Please refer [1] for more info how to write a custom mediatorfor WSO2 ESB.
[1]. http://wso2.com/library/2898/
Thank You,
Dharshana.

C++ XML-RPC Calling

I haven't seen any documentation for calling XML-RPC by inputing certain strings and get respone of some strings in c++ by connecting to an XML API. This is a documentation provided by the server. I can't figure out how to do this
A client can interact with a Pandorabot by POST'ing to:
http://www.pandorabots.com/pandora/talk-xml
The form variables the client needs to POST are:
botid - see H.1 above.
input - what you want said to the bot.
custid - an ID to track the conversation with a particular customer. This variable is optional. If you don't send a value Pandorabots will return a custid attribute value in the <result> element of the returned XML. Use this in subsequent POST's to continue a conversation.
This will give a text/xml response. For example:
<result status="0" botid="c49b63239e34d1d5" custid="d2228e2eee12d255">
<input>hello</input>
<that>Hi there!</that>
</result>
The <input> and <that> elements are named after the corresponding AIML elements for bot
input and last response.
If there is an error, status will be non-zero and there will be a human readable <message> element included describing the error.
For example:
<result status="1" custid="d2228e2eee12d255">
<input>hello</input>
<message>Missing botid</message>
</result>
The easiest way to communicate via HTTP in C++ is to use a library designed for that purpose. For example, libcurl provides all the facilities you would need to send and receive the kind of requests and responses you showed in the question.