wso2 property to endpoint's address - wso2

What i am trying to do is get the value of property and put it in my endpoint's uri
my property
<property value="1" name="id" scope="default" type="STRING"/>
my endpoint's address
<address format="rest" uri="http://localhost:port/service?id={id}"/>

You can achieve this using a http endpoint,
<property name="uri.var.id" value="1" type="STRING"/>
<send>
<endpoint>
<http uri-template="http://localhost:port/service?id={uri.var.id}"/>
</endpoint>
</send>

There might be different solutions but one trick is to set the 'To' header with the value of the uri and then just call the send mediator. Like so:
<header name="To" expression="fn:concat('http://localhost:port/service?id=', get-property('id'))"/>
<send/>

Related

Unable to get the response from the API

Scenario
I'm sending a request payload to the API that further calls the SMS service provider in the in-sequence flow, I need to share back the response from the SMS service provider as it is. The API works fine and I do receive SMS on phone but I'm unable to share back the response from the service provider in the out sequence flow.
The response body from my SMS service provider is actually text as shown:
The Response header of SMS Service Provider looks like this:
API
<?xml version="1.0" encoding="UTF-8"?>
<api context="/mobilink" name="MobilinkSmsApi" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST" uri-template="/send">
<inSequence>
<property action="remove" name="TRANSPORT_HEADERS" scope="axis2"/>
<property description="username" expression="json-eval($.username)" name="uri.var.username" scope="default" type="STRING"/>
<property description="password" expression="json-eval($.password)" name="uri.var.password" scope="default" type="STRING"/>
<property description="to" expression="json-eval($.to)" name="uri.var.to" scope="default" type="STRING"/>
<property description="from" expression="json-eval($.from)" name="uri.var.from" scope="default" type="STRING"/>
<property description="message" expression="json-eval($.message)" name="uri.var.message" scope="default" type="STRING"/>
<log level="full"/>
<call>
<endpoint>
<http method="post" statistics="enable" trace="enable" uri-template="https://coXXXXX.XXXX.com/sendsms_url.html?Username={uri.var.username}&Password={uri.var.password}&From={uri.var.from}&To={uri.var.to}&Message={uri.var.message}">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>-1</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
</inSequence>
<outSequence>
<log category="TRACE" level="full"/>
<property description="Content-Type" name="Content-Type" scope="default" type="STRING" value="text/html"/>
<property name="messageType" scope="axis2" type="STRING" value="text/html"/>
<respond/>
</outSequence>
<faultSequence>
<log category="ERROR" level="full"/>
</faultSequence>
</resource>
</api>
Question
My Question is how to share back the response from the service provider in the out sequence? I tried to use property with value text/html and even used content-type as text/html but It didn't worked.
There are two ways to achieve this. either one of below mentioned way you can follow
place <respond/> after <call> mediator
Use <Send> mediator instead of <call>, so that flow will come from insequence to outsequence where you already placed <respond/> to send back message to client
The issue got resolved when I placed the mediator in the inSequence flow.
previously I was placing the mediator in the outSequence

Property mediator is disappearing in WSO2 EI 6.6

I'm trying to send the token before the endpoint but it's disappearing when it's deployed in the server and I even try to the pass the token within the endpoint properties but it's not accepting and thrown error like Invalid token, please help me to sort this out.
<log level="custom">
<property name="uri.var.apiurl ::::::::::::::::::: " expression="$ctx:uri.var.apiurl"/>
<property name="Authorization ::::::::::::::::::: " expression="$trp:Authorization"/>
</log>
<call description="VB iAppraisal Endpoint">
<property name="Authorization" scope="transport" value="Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjllMDA1MGQ4ZDFlNmZlMTYzMjllMGViYTY1MmE4NDBhMTZhMDUzZjQ3MWU0OTA4MmE0Y2ZkOGI2NTZhYjU3N2NkMmEwNTUxNjhkYzVhMjRiIn0.eyJhdWQiOiI3MjUiLCJqdGkiOiI5ZTAwNTBkOGQxZTZmZTE2MzI5ZTBlYmE2NTJhODQwYTE2YTA1M2Y0NzFlNDkwODJhNGNmZDhiNjU2YWI1NzdjZDJhMDU1MTY4ZGM1YTI0YiIsImlhdCI6MTY1MDk2ODgzMiwibmJmIjoxNjUwOTY4ODMyLCJleHAiOjE2ODI1MDQ4MzIsInN1YiI6IjU3NCIsInNjb3BlcyI6W119.BUyx65owuErEmx57_N-FC4kT_QvPQ01pvof_308hjWHPbfrajajs2oGJx0hTuztQUT5xTKqMEV9pFHfdUKM93VWTBBCMFrbP9Qg03dq1Se9fbXGJ5EkmRiAy9qJ2WCiMs2sj6sN3H7_aWxn0D6u9kbfymzRUdw3pP9KT0L0hl03RRAliW0JpVv6qJgog2bvCJni_BsM5kt84dXFohbEtRqas40bYCd-VHqy-pxlVbq6-y27OF5XC-qcWRxT78iXG2P9joULCZKTHINUPigpT2h8-QA8nPakmDflEgLScG1yAKlcgDY1aVLEZYOblkMryoITQ1bfGck_jdq_hiCu5qtz1JEhTyYXpv3RxJ_8Bnp4Do_PKfMUbqxNaDbZr75sr83HTWlcsBcPYIVG3xXRAXcB4rRKB25NitdGBkg4zqcc9SiVqBgxT2FNWEjugs-tanNjcNODX_sradOQ-7RLlcTy7NRLqa3lUyNSBpow__X5DjJpGRQoym-9j3PRQGQGOQgNImuplYQ066n4W-TzradcaxLm0oCaSqlfZ9Ozn-9as5NHMdUlNYHpOb1aAi5Qxg0JtVvdSKAYiWpwmEzBAkTm3PWMRwQpXHMqGNgkpibwI3QcqY5IrPB1ZZ0xnZ-_bOHbpFLxgAMGGBRkIBVIqPmxCxqZz06TsQWGAF9cZ12c "/>
<endpoint key="iAppraisal"/>
</call>
Don't wrap <property name="" ... /> inside <call > mediator. It should be before call endpoint like below:
<property name="Authorization" scope="transport" value="Bearer eyJ0eXAiOiJK /.../ Z12c"/>
<call description="VB iAppraisal Endpoint">
<endpoint key="iAppraisal"/>
</call>
Or optionally you can put that inside Endpoint definition.

Add query params dynamically at endpoint API WSO2 ESB

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}&registrosPorPagina={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.

Can we Set a Send mediator with Xpath expression

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..

WSO2 ESB If Then Else, authenticate or Error

This may be a basic question, I am just getting used to the WSO2 lingo. I have two services that I can deploy independently with WSDLs and pass the proper SOAP request, and return information accordingly. Now I want to combine them into an 'If then, else' statement sort of deal. This would be set up in a sequence of some sort I believe, just not sure how with the filters.
Send in request with authentication request and info request
Do authentication request – continue if passes, 401 on failure
Do info request – get info
Return the info
If you have a sample I could follow or point me to one of the hundreds WSO2 has, I just haven't been able to pull much from them. XML source example for the config could work also. Thanks for the help, and for my ignorance of WSO2 lingo, and workflow.
You can have a look at filter mediator to filter messages based on conditions Entitlement Mediator. You can find samples here as a reference which will be helpful for your use case.
So I ended up with something very similar to this. If someone down the road comes across this and looking for the wso2 configurations.
<proxy name="name"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<property xmlns:ns1="ns1"
xmlns:ns="ns"
name="userID"
expression="//ns:AuthenticateRequest/ns:Credentials/ns1:userID"
scope="default"
type="STRING"/>
<property xmlns:ns1="ns1"
xmlns:ns="ns1"
name="password"
expression="//ns:AuthenticateRequest/ns:Credentials/ns1:password"
scope="default"
type="STRING"/>
<log>
<property name="userID" expression="get-property('userID')"/>
<property name="password" expression="get-property('password')"/>
</log>
<header name="Action"
value="http://services.com:port/AuthenticateSecureCredential"/>
<send receive="AuthRecvSequence">
<endpoint>
<address uri="http://server.com:port/DefaultAuthenticationService"/>
</endpoint>
</send>
</inSequence>
</target>
</proxy>
<sequence name="AuthRecvSequence">
<filter xmlns:ns="ns"
source="//ns:AuthenticateSecureCredentialResponse/ns:isAuthenticated"
regex="false">
<then>
<makefault version="soap11">
<code xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/"
value="soap11Env:VersionMismatch"/>
<reason value="Not Authenticated"/>
<role/>
</makefault>
<header name="To" action="remove"/>
<property name="RESPONSE" value="true" scope="default" type="STRING"/>
<send/>
<drop/>
</then>
<else>
<payloadFactory>
<format>
<ns:INFO xmlns:ns="ns"
xmlns:ns1="ns1">
<ns:secureCredentials>
<ns1:userID>$1</ns1:userID>
<ns1:password>$2</ns1:password>
</ns:secureCredentials>
</ns:INFORequest>
</format>
<args>
<arg expression="get-property('userID')"/>
<arg expression="get-property('password')"/>
</args>
</payloadFactory>
<header name="Action"
value="http://services.com/GetINFO"/>
<send receive="INFOrRecvSeq">
<endpoint>
<address uri="http://server:port/INFOService"/>
</endpoint>
</send>
</else>
</filter>
</sequence>
<sequence name="INFORecvSeq">
<send/>
</sequence>
<sequence name="main">
<description>The main sequence for the message mediation</description>
</sequence>