Dynamically constructing the endpoint in a WSO2ESB Callout Mediator - wso2

I am trying to use a Callout Mediator to call one of two endpoints (stored in the registry), based on a property of the message. The way I would like to do this would be essentially concatenating some properties to provide the path of an endpoint, or by using XPATH if that is not possible.
I know that, using a Send Mediator, XPATH is a possible option for choosing an endpoint, e.g.
<send xmlns:ns="http://ws.apache.org/ns/synapse">
<endpoint key-expression="//ns:abc"/>
</send>
However, this syntax doesn't seem to work using the Callout Mediator.
Unfortunately my current "solution" to this problem is to have a filter based on this property and n cases, where n is the number of different endpoints I am considering. However, I was hoping to not require a change to the sequence if I added a new endpoint- simply a difference in the message.

This doesn't seem possible in the current implementation of the Callout Mediator.
I ultimately decided to write my own mediator. It is essentially a copy of the CalloutMediator but adds the functionality of using xpath for endpoints.

Related

Handle Path Parameters from API call in WSO2 EI/ESB Integration Studio

I'm developing an API using WSO2 Integration Studio ESB Solution Project.
I'm calling this API from postman like "https://localhost:port/context/3542" where '3542' is the value of the path parameter being sent (let's say employeeId).
Further, I want to use this value (3542) in the http endpoint implemented in the same API to make a back-end call.
I'm not able to handle that path parameter. I tried using property mediator, didn't work.
Didn't find anything in the official documentation either.
Help appreciated. Thanks already.
You can use REST_URL_POSTFIX property in order to use the value in the implementation. An example code segment is given below.
<property expression="$axis2:REST_URL_POSTFIX" name="Path"/>

WSO2 ESB REST API Chaining issue

I am facing some issues when doing service chaining is WSO2 ESB. Below is the xml file.
Following is my use case. I need to call Service 1, get the response, do validation check on it and then call Service 2. Through the below code I am successfully able to call Service 1. For the service two request, I have hard coded the request in the payload. Issue is coming when setting the header parameters. The header properties are not getting set due to which call to Service 2 is not going. For testing purpose I have kept both the URLs same.
Please let me know the following:
1. How to set HTTP Header values.
2. Is there a way to persist the Initial input request and then use it in the second Service call.
Although your synapse configs are not there I'll answer your question.
You can do this two ways. One is by using the Header Mediator. You can reffer this Doc. Example code below,
<header name="Accept" value="image/jpeg" scope="transport"/>
The second approach is using the property mediator, You can set the Header value and set the scope to transport. So the Header property will be added.
What you simply need to do it assign the original request content to a Property, so you can use it later. There are many ways to do this, Following example is by using the enrich mediator
<enrich>
<source type="body" clone="true"/>
<target type="property" property="request"/>
</enrich>

WSO2 API Manager - Replace URLs in response body

I'm trying to setup a proxy for my RESTful API using WSO2 API Manager. My problem is that the responses from the backend API are left untouched so all the urls that connect to other endpoints still reference the backend server rather than the proxy. I need a way to replace those url values in the response body to point to the proxied api. I understand this can be accomplished via Mediation Extensions, using ESB Mediators.
I'm not familiar enough with them to pick the one better suited for the job. URLRewrite mediator looks pretty straightforward, but it doesn't seem to apply to the message body but the headers. Payload Factory seems to require a fixed structure for the message, which is not very convenient for me, since I need it to work on the different responses that my API provides (and I wouldn't want to maintain those structures in the mediator definition).
I've managed to solve it by setting the headers my application checks to build its urls:X-Forwarded-Host and X-Forwarded-Proto.
So I've created a Header Mediator that looks like:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="WSO2AM--Ext--In">
<header name="X-Forwarded-Host" expression="get-property('transport','Host')" scope="transport"/>
<header name="X-Forwarded-Proto" value="https" scope="transport"/>
</sequence>
And that did the trick.

How to call multiple web service using conditional route mediator and proxy service in wso2

Hi I am new to wso2 .
I want to call two different service (different URL) using a Proxy service based on some condition
I have two different service 1) One service to add and subtract two numbers 2) Another service to multiply and divide two numbers I want to create a proxy service to call this two service based on some condition,say if 1st number greater than second number,i need to call 1st service,otherwise i need to call second service
How to implement this using a proxy service
Can anyone help me how to use Conditional route mediator to implement this
Suggest me the best way to do this,Since i am new to WSO2,please help me in brief
Thanks in Advance
With WSO2 ESB, you can do this either via Filter Mediator or Conditional Router Mediator. There are many mediators and you can build your logic using desired mediators.
I would suggest you to go through documentation and samples.
There is one sample on Conditional Router Mediator, which will help you to understand on Conditional Router usage.
I think in your case, you should be able to use Filter mediator to compare your values via XPath operators.
For example, see the sample 156's filter mediator usage.
If you pass your values as URL parameters, you can get those URL parameters as properties.
Please note that these are just pointers for you to get started.
You can also try the WSO2 Developer Studio to create the ESB artifacts.
I hope this helps.

Adding user defined headers in wso2 esb custom proxy

I have created a custom proxy for a given address endpoint. The custom proxy exposes the methods which are there in the actual endpoint. However I wanted the custom proxy to expose some custom headers in the SOAP header to the end user. The end user would then pass the data in these custom headers and these values would be used in the mediation logic. How would I do this ?
Thanks.
To manipulate header values, you can add a Header mediator (Transform->Header) in the in/out sequences. Use a Property mediator(Core->Property) to set/remove property values in the message context. These can be retrieved by get-property(proerty-name) later.
You can use script mediators to carry out mediation on the message headers. You can extract message headers using the following code
<property name="authheader" expression="get-property('transport','Accept')"/>
In the wsdl, you can add soap:header elements, that are transmitted inside the Header element of the SOAP Envelope. I believe you have a custom wsdl, which is exposed via the proxy..So you can edit that..