WSO2 ESB using jms failover into recipient list - wso2

I'm trying to use recipientList to send to multiple JMS endpoints. I'm using ActiveMQ as message broker. My problem is: Whether I set the URL as a one single node of ActiveMQ it works perfectly when I set a failover endpoint comma separated I just get that it splits the comma inside the failover URL. Is there a way I can skip this split of commas character inside the failover?
This works:
jms:/myQueue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://myIP:61616&transport.jms.DestinationType=queue
But this doesn't work because it splits the comma.
jms:/myQueue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=failover:(tcp://myIP:61616,tcp://myIP2:61616)&transport.jms.DestinationType=queue
In my case I concatenate multiple uris like the ones above with ',' for making the recipientList work, but the comma inside the failover is making it fail.
Is there a work-around?
Thanks,
Antonio

You can try like below instead of comma
<send>
<endpoint key="jmsMBendpoint1"/>
</send>
<send>
<endpoint key="jmsMBendpoint2"/>
</send>
or you can use Recipienlist endpoint to send a single message to multiple endpoints. After defining recipient list store taht as localentry and provide that as endpoint key.
for more
WSO2 ESB send to multiple endpoints

I don't know what is the workaround with recipientlist but an other way to achieve your need is :
<property name="EIP_LIST" type="OM">
<list xmlns="">
<epr>jms:/myQueue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=failover:(tcp://myIP:61616,tcp://myIP2:61616)&transport.jms.DestinationType=queue</epr>
<epr>jms:/myQueue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=failover:(tcp://myIP3:61616,tcp://myIP4:61616)&transport.jms.DestinationType=queue</epr>
</list>
</property>
<iterate expression="$ctx:EIP_LIST//epr">
<target>
<sequence>
<header name="To" expression="$body/epr"/>
<send/>
</sequence>
</target>
</iterate>
You just have to dynamically compose the content of EIP_LIST

Related

how to convert json to path variable data in wso2 esb?

I have an Endpoint : http://localhost:8080/customer/get/1
and i want to send a json data to api in wso2esb and transform the value of id to path variable and send it to the Endpoint.
something like this:
{"id":"1"}
how can i do this?
please give me some advice.
You should build Uri-template path, with property named with prefix uri.var. For example named: uri.var.myId. and extract from JSON interesting value.
Next you can use that property in http endpoint in uri-template in brackets.
For your example, what you are looking for is something like this:
<property name="uri.var.myId" expression="json-eval($.id)" scope="default" type="STRING"/>
<call>
<endpoint>
<http uri-template="http://localhost:8080/customer/get/{uri.var.myId}"/>
</endpoint>
</call>
It is more precise described in wso2esb 4.9.0 documentation

how to pass query URL in wso2esb to endpoint

I'm having the following API configured in WSO2ESB:
<api xmlns="http://ws.apache.org/ns/synapse" name="service" context="/service">
<resource methods="POST">
<inSequence>
<call>
<endpoint>
<http method="POST" uri-template="https://webapps.localhost/service.php"/>
</endpoint>
</call>
<send/>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence>
<log level="full"/>
</faultSequence>
</resource>
</api>
The call works fine and POST content goes fine to the endpoint.
curl -X POST -d "a=1&b=2" localhost:8280/service
from the service.php file I can extract POST parameters fine.
Now if I want to have dynamic GET parameters passed as is to the endpoint, what would be the way to do it?
curl -X POST -d "a=1&b=2" localhost:8280/service?c=3&d=4
I know (at least what i understood) property mediator could be used but this is for known parameters in the query url (for example, $url:c) but I don't want to limit it, just pass the query url as is to the destination endpoint.
Any help would be appreciated.
You can access the resource path through REST_URL_POSTFIX
<property name="path" expression="$axis2:REST_URL_POSTFIX"/>
According to your request URL, $ctx:path should contain ?c=3&d=4
Just to update here, use Address EndPoint instead of HTTP EndPoint (which is based on URI-Template)
Usually what I do is defining two variables on the endpoint's URI template, and then use the property mediators to set them.
Something like
<http method="POST" uri-template="https://webapps.localhost/service?c={uri.var.c}&d={uri.var.d}"
Then use the property mediator to set the property uri.var.c and uri.var.d with the intended values.

Parse JSON Response Array using ForEach component in WSO2 ESB

I have a requirement to parse JSON response which contain array of products(P1,P2,P3,etc.). Each product contains multiple information like name, type, cost, etc.
I need to read each product one by one and append additional data got from the another service into an new JSON output. I am thinking of using ForEach component of WSO2 ESB to iterate each product one by one.
Problem is that ForEach component uses ForEachExpression which expects XML expression in the configuration.
Please suggest on the method to parse array of JSON response one by one in WSO2 ESB.
/Abhishek
Can use both Iterate or ForEach mediator for iterating the JSON array, since both are content aware mediators and support JSON.
Which one to use depends upon the specific usecase as Iterate provides the capability to use call / callout / send mediators in the sequence whereas ForEach doesn´t allow it.
For the below given sample JSON request, the following iteration works and the JSON array and objects can be referred like the same.
{
"products":[
{
"product":{
"id":"1234",
"size":"20",
"quantity":"1",
"price":"990",
"type":"Electronics",
"store":{
"id":"001"
}
}
}
]
}
<iterate expression="//products" id="PRD_ITR">
<target>
<sequence>
<sequence key="Product_Enrich_Sequence_s"/>
<!-- For example, Switching sequence based on the product type -->
<switch source="//products/product/type">
<case regex="Computer">
<sequence key="Computer_Product_Enrich_Sequence_s"/>
</case>
<case regex="Mobile">
<sequence key="Mobile_Product_Enrich_Sequence_s"/>
</case>
<case regex="Grocery">
<sequence key="GR_Product_Enrich_Sequence_s"/>
</case>
<default>
<!-- default stuff --!>
</default>
</switch>
</sequence>
</target>
</iterate>
FYR
https://docs.wso2.com/display/ESB490/Iterate+Mediator
https://docs.wso2.com/display/ESB490/ForEach+Mediator
Note: tested in WSO2 ESB 4.9.0

How to make a asynchronous call in WSO2 ESB 4.8.1

I have a proxy service which is exposed on http. After receiving the request the service validates it against its schema. Now if a validation fails, the service should send back client an error response and should also send that error message to a queue.
<validate [source="xpath"]>
<property name="validation-feature-id" value="true|false"/>*
<schema key="string"/>+
<on-fail>
mediator+
</on-fail>
</validate>
Problem:
I am making a custom message in "Validate" mediator "on-fail" sequence. I am sending back that message by using "Response" mediator. After sending back the response I want to send this same error message to a jms queue. But the problem is that after "Respond" mediator, no mediator works and if I put "Call" mediator" before the "Respond" mediator, only message is sent to queue, no response is sent back to client.
Things to achieve:
To summarize, I need to do following two things in a validate mediator fault sequence.
Send Back the Response to client.
Send the response to a queue.
how can I achieve that or is there any alternative approach to achieve this task?
When you say
I am making a custom message in "Validate" mediator "on-fail" sequence
I assume you are using payloadFactory. So , once you have built you're custom message , you can use the < clone > mediator to send the message to 2 destinations like so :
<clone>
<target>
<sequence>
<respond/>
</sequence>
</target>
<target>
<sequence>
<send>
<endpoint>
<address uri=""/> <!-- Specify the JMS connection URL here -->
</endpoint>
</send>
</sequence>
</target>
</clone>
Hope that works for you!

wso2: Looking for XSLT transformation working example

Can some one point me to a working example of xsl transformation using the proxy services xslt mediator option.
Basically, my requirement is, i will have a request where i will get some data which determines the routing and after that from other elements of requested data i have to re frame soap request to trigger another bpel service.
Please let me know the better approach to this.
You can very well use XSLT transformation in your sequence, using XSLT Mediator.
In your sequence file you can specify the XSLT file to tranform the request. Sample sequence code snippet:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="SampleInterceptorSequence">
<in>
<log level="full" category="DEBUG">
<property name="sequence" value="inSequence-Request Before XSLT" />
</log>
<xslt key="RequestTranformerXSLT" />
<log level="full" category="DEBUG">
<property name="sequence" value="inSequence-Request After XSLT" />
</log>
<send>
<endpoint key="MyActualServiceEPR" />
</send>
</in>
Your xslt would contain the style for the actual request to be formed for hitting the end point reference.
Further if you can check this nice article of web service chaining to get a real time idea of xslt mediation.
Web Service Chaining from WSO2 ESB Developers
Hope this helps.
Thanks.
Find the sample below..
http://wso2.org/project/esb/java/4.0.0/docs/samples/message_mediation_samples.html#Sample8