I am new to the WSO2 esb. I want to create a api in which i want to add a dynamic parameter from api Url to endpoint url.
My end point url is like http://example.com/api/sync/{session_id}.json
I tried to create api like
<api name="rest" context="/sync">
<resource methods="GET" uri-template="/{id}">
<inSequence>
<log level="full">
<property xmlns:ns="http://org.apache.synapse/xsd"
name="uri.var.session"
expression="get-property('uri.var.id')"
scope="axis2"/>
</log>
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
<send>
<endpoint name="Mecars">
<http trace="enable"
method="get"
uri-template="http://example.com/sync/{+uri.var.session}.json"/>
</endpoint>
</send>
</inSequence>
</resource>
</api>
In log i get the value of uri.var.session But on the endpoint Uri-template it is not appending.
Please guid me how append the {id} value in the api uri-template to end point uri-template?
Check this sample
I recommend you to do string concatenation at property mediator adn use that directly at uri-template, rather adding "variable +.json" at uri-template.
That is;
<property xmlns:ns="http://org.apache.synapse/xsd"
name="uri.var.session"
expression="get-property('uri.var.id')"
scope="axis2"/>
In the above for expression do string concatenation to construct full variable with ".json" ending.
Please remove the '+' symbol from your http end point.Its working fine to me
sample API
<api xmlns="http://ws.apache.org/ns/synapse" name="Elastic Search Using NPI" context="/api/npi/professional/npi.json">
<resource methods="OPTIONS GET" uri-template="/{npi}">
<inSequence>
<log level="full">
<property name="uri.var.npi" expression="get-property('uri.var.npi')"></property>
</log>
<send>
<endpoint>
<http method="get" uri-template="example.com/{uri.var.npi}"></http>
</endpoint>
</send>
</inSequence>
</resource>
</api>
Change the http endpoint uri template like follows.
<http trace="enable" method="get" uri-template="http://example.com/sync/{uri.var.id}.json"></http>
Following is the modified api configuration.
<api xmlns="http://ws.apache.org/ns/synapse" name="rest" context="/sync">
<resource methods="GET" uri-template="/{id}">
<inSequence>
<log level="full">
<property xmlns:ns="http://org.apache.synapse/xsd" name="uri.var.session" expression="get-property('uri.var.id')"></property>
</log>
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"></property>
<send>
<endpoint name="Mecars">
<http trace="enable" method="get" uri-template="http://example.com/sync/{uri.var.id}.json"></http>
</endpoint>
</send>
</inSequence>
</resource>
</api>
You can do the string concatenation at the property mediator as follows.
<property xmlns:ns="http://org.apache.synapse/xsd"
name="uri.var.session"
expression="fn:concat(get-property('uri.var.id'),'.json')"
scope="axis2"/>
Related
I have published a websocket api as given in the Documentation, So I wanted to call that websocket API through wso2 ESB. So, how to pass the Auth header as I'm getting the following error on the console.
[2018-10-02 18:24:36,503] ERROR - InboundWebsocketSourceHandler Endpoint not found for port : 9099 tenant domain : null
Below is the ESB to call websocket API:
<api context="/test" name="test" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<log level="full">
<property name="message" value="********************************************input**********************"/>
</log>
<property name="Authorization" scope="transport" type="STRING" value="Bearer cf920eb2-960c-383c-b556-78e9258fd8d3"/>
<send>
<endpoint>
<http method="post" uri-template="ws://localhost:9099/echowebsocket/1.0"/>
</endpoint>
</send>
</inSequence>
<outSequence>
</outSequence>
<faultSequence/>
</resource>
</api>
outflow sequence:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="outflowDispatchSeq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log level="full">
<property name="message" value="************************************************"/>
</log>
</sequence>
I'm trying to edit an api resource in WSO2 ESB to put query params dinamically in the end of endpoint URL.
At this moment, the resource is like this:
<resource methods="GET" uri-template="/searchEngine/sortAndFilterBeneficiaries*">
<inSequence>
<log level="custom">
<property name="Access token value" expression="$trp:Authorization"/>
</log>
<oauthService remoteServiceUrl="https://server:port/services/" username="admin#wso2.com" password="admin"/>
<header name="Authorization" scope="transport" action="remove"/>
<send>
<endpoint>
<http method="get"
uri-template="http://server:port/project-web-services/services/project-rs/searchEngine/sortAndFilterBeneficiaries?criterioOrdenacion={query.param.criterioOrdenacion}®istrosPorPagina={query.param.registrosPorPagina}&numPagina={query.param.numPagina}&userId={query.param.userId}&serviciosSeleccionados={query.param.serviciosSeleccionados}&fechaRequerida={query.param.fechaRequerida}&limiteInfDias={query.param.limiteInfDias}&limiteSupDias={query.param.limiteSupDias}&ubicacion={query.param.ubicacion}&limiteDistancia={query.param.limiteDistancia}&valoraciones={query.param.valoraciones}&competencias={query.param.competencias}"/>
</endpoint>
</send>
</inSequence>
But, I'm doing this:
<resource methods="GET" url-mapping="/searchEngine/sortAndFilterBeneficiaries*">
<inSequence>
<filter source="$ctx:query.param.criterioOrdenacion" regex="PRODUCTION">
<then>
<property name="REST_URL_POSTFIX" expression="fn:concat(get-property('axis2','REST_URL_POSTFIX'), '&criterioOrdenacion={query.param.type}')" scope="axis2" type="STRING"/>
</then>
</filter>
<log level="custom">
<property name="Access token value" expression="$trp:Authorization"/>
</log>
<oauthService remoteServiceUrl="https://server:port/services/" username="admin#wso2.com" password="admin"/>
<header name="Authorization" scope="transport" action="remove"/>
<send>
<endpoint>
<http method="get"
uri-template="http://server:port/project-web-services/services/project-rs"/>
</endpoint>
</send>
</inSequence>
Is this correct?
This is correct. When you want to change base path only one endpoint will be affected, but in first case you must update all dynamic endpoint.
I need to append query params to endpoint URI according to query params in request.
I have an resource API in ESB published like this:
<resource methods="GET" url-mapping="/searchEngine/sortAndFilterVolunteers*">
<inSequence>
<send>
<endpoint>
<address
uri="http://localhost:8080/project-web-services/services/project-rs"></address>
</endpoint>
</send>
</inSequence>
I have to append query params dinamically.
How could I do that?
Following sample API definition may help you.
<api xmlns="http://ws.apache.org/ns/synapse" name="sample" context="/api/sample">
<resource methods="OPTIONS GET" uri-template="/{val1}/groups/{val2}.json?q1={v1}&q2={v2}">
<inSequence>
<property name="uri.var.q1" expression="$url:q1"></property>
<property name="uri.var.q2" expression="$url:q2"></property>
<property name="uri.var.val1" expression="get-property('uri.var.val1')"></property>
<property name="uri.var.val2" expression="get-property('uri.var.val2')"></property>
<send>
<endpoint>
<http method="GET" uri-template=""></http>
</endpoint>
</send>
</inSequence>
<outSequence>
<send></send>
</outSequence>
</resource>
</api>
Add the query parameter to uri-template in resource as below :
<resource methods="GET" uri-template="/getStudents/{id}">
When sending to the endpoint,
<send>
<endpoint>
<http method="get" uri-template="http://studentsapi/student/{uri.var.id}"/>
</endpoint>
</send>
Add the query parameter to url-mapping in resource as below : url-mapping="/*"
*
you can send a request may be server:port/service?q1={q1} and other request may be server:port/service?q2={q2}&q3={q3}.
i am trying to send a message to my email for that i am using send mediator as well i setup required configurations in AXIS2 file
is it work for below proxy
if not what is the way to give xpath to send mediator
<proxy xmlns="http://ws.apache.org/ns/synapse" name="mailCheck" transports="http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="Subject" value="Alert Message From WSO2 ESB - Service Down !!!" scope="transport" type="STRING"/>
<property name="messageType" value="text/html" scope="axis2" type="STRING"/>
<property name="ContentType" value="text/html" scope="axis2" type="STRING"/>
<property name="Mail" value="mailto:faisal.shaik#youtility.in" scope="default" type="STRING"/>
<log level="full">
<property name="Mail" value="mailto:faisal.shaik#youtility.in"/>
</log>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<send>
<endpoint key-expression="get-property('Mail')"/>
</send>
</inSequence>
<outSequence/>
</target>
<description></description>
</proxy>
if need any changes pls let me know
if you want to get the email address from a property value then use the header mediator to set value of "To" to "mailto:faisal.shaik#youtility.in".
You can do that adding the following before the send mediator
<header name="To" expression="fn:concat('mailto:', get-property('Mail'))"/>
You can use this:
<property name="To" expression="get-property('uri.var.to')" scope="transport"/>
<send>
<endpoint>
<address uri="mailto:"/>
</endpoint>
</send>
<send>
<address uri="mailto:xxx#yyy"/>
</send>
key-expression also can be used..
I have created a proxy service who transform a message using a xslt mediator and then transformed to JSON,
I want now to post the JSON message in a rest web service how i can do that directely in my proxy service?
This is my proxy service :
<proxy xmlns="http://ws.apache.org/ns/synapse" name="CategoryProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="Authorization" expression="fn:concat('Basic ', base64Encode('admin:admin'))" scope="transport" type="STRING"/>
<send>
<endpoint>
<address uri="http://localhost:8068/database/library.author/301"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<xslt key="conf:/ressources/catXsl.xsl"/>
<property name="messageType" value="application/json" scope="axis2" type="STRING"/>
<send/>
</outSequence>
<faultSequence/>
</target>
<description></description>
</proxy>
I want the message sent by this proxy to be post in a rest web ressource, How I can do it in my proxy?
Looks like you are looking for service chaining and you can do that in two ways:
1) Using a receiving sequence
<inSequence>
<property name="Authorization" expression="fn:concat('Basic ', base64Encode('admin:admin'))" scope="transport" type="STRING"/>
<send receive="receivingSeqForChaining">
<endpoint>
<address uri="http://localhost:8068/database/library.author/301"/>
</endpoint>
</send>
</inSequence>
You can define whatever sequence of operations you want in that receiving sequence. Output from this will be handed out to receiving sequence. If you don't want to do any specific action in outSequence for this case you can just add a to that.
2) Using outSequence to trigger other service call
You can also make that http call directly from outSequence something like this:
<outSequence>
<send>
<endpoint>
<http method="get"
uri-template="https://www.abc.com/resource/foo"/>
</endpoint>
</send>
</outSequence>
Hope this helps.