I'm new in WS02 but I'm having a trouble to get a url param and pass it.
Following the Sending a Simple Message example
my resource is
<resource methods="GET" uri-template="/wholesales/{dlrcode}">
<inSequence>
<log level="custom">
<property name="message" value="Whole sales request"/>
<property expression="/default/expression" name="p_dlrCode"/>
</log>
<send>
<endpoint key="WholeSales"/>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
and my END is
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="WholeSales" xmlns="http://ws.apache.org/ns/synapse">
<http method="get" uri-template="http://xxx/RDRSvc//vehicle/wholesaleD/{url.var.dlrcode}?format=json"/>
</endpoint>
but stil when I call api like
http://xxx.xx.xx.xx:8280/rdr/wholesales/42103
I see no dlrCode ???
TID[-1234] [ESB] [2017-03-07 11:08:29,464] INFO {org.apache.synapse.mediators.builtin.LogMediator} - message = "Whole sales request", p_dlrCode =
how can I put the 42103 in property p_dlrCode?
Try this:
Your resource:
<resource methods="GET" uri-template="/wholesales/{dlrcode}">
<inSequence>
<log level="custom">
<property name="message" value="Whole sales request"/>
<property expression="get-property('uri.var.dlrcode')" name="p_dlrCode"/>
</log>
<send>
<endpoint key="WholeSales"/>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
Your endpoint fixed:
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="WholeSales" xmlns="http://ws.apache.org/ns/synapse">
<http method="get" uri-template="http://xxx/RDRSvc//vehicle/wholesaleD/{uri.var.dlrcode}?format=json"/>
</endpoint>
Related
Hi i'm new in wso2 and I have 2 api's, I want to call the second one using the first, but the url that the callout mediator is using is diferente from the one I set up, resulting in error HTTPSender Unable to sendViaGet to url[http://192.168.20.1:8280/loginAPI/login/Nurse]
The code is below
Any help will be welcome
<api context="/Staff" name="StaffAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" url-mapping="/Nurse">
<inSequence>
<log level="full"/>
<callout description="" initAxis2ClientOptions="false" serviceURL="http://192.168.20.1:8280/loginAPI/login">
<source type="envelope"/>
<target key="response"/>
</callout>
<log level="custom">
<property expression="get-property('response')" name="response"/>
</log>
<send>
<endpoint key="NurseEP"/>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
<api context="/loginAPI" name="LoginAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" uri-template="/login">
<inSequence>
<payloadFactory media-type="json">
<format>{
"userName": "xxx",
"password": "xxx",
"rememberMe": true,
"fireBaseToken": "string"
}</format>
<args/>
</payloadFactory>
<cache collector="false" hashGenerator="org.wso2.carbon.mediator.cache.digest.DOMHASHGenerator" id="Token" maxMessageSize="2000" scope="per-host" timeout="5000">
<onCacheHit/>
<implementation maxSize="1000" type="memory"/>
</cache>
<send>
<endpoint key="LoginEP"/>
</send>
</inSequence>
<outSequence>
<cache collector="true" scope="per-host"/>
<send/>
</outSequence>
<faultSequence/>
</resource>
The http://192.168.20.1:8280/loginAPI/login endpoint when called on postman is valid
It seams that your serviceURL is suffixed by your api url-mapping, try to add that before callout (it has to be used in case of send mediator, not sure for callout but it looks like the same behavior) :
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
I have created a API in API manager. I can invoke it with
http://localhost:6547/generatereports/1.0/Reports/dcuid/vcid
I am passing two parameters with "dcuid and vcid" at a time but not passing.
reportsapi:
<?xml version="1.0" encoding="UTF-8"?>
<api context="generatereports/1.0/Reports" name="reportsdataapi" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" protocol="http" uri-template="/{dcuid}/{vcid}">
<inSequence>
<property description="http" name="HTTP_SC" scope="axis2" type="STRING" value="404"/>
<log level="full"/>
<send>
<endpoint key="reportsendpoint"/>
</send>
</inSequence>
<outSequence>
<switch source="get-property('axis2','HTTP_SC')">
<case regex="200">
<log description="200log" level="custom">
<property expression="$ctx:ERROR_CODE" name="200reserrorcode"/>
</log>
<send/>
</case>
<default>
<log description="reslog" level="custom">
<property expression="$ctx:ERROR_CODE" name="reserrorcode"/>
<property expression="$ctx:ERROR_MESSAGE" name="reserrormessage"/>
<property expression="get-property('axis2','HTTP_SC')" name="reshttpsc"/>
</log>
</default>
</switch>
<send/>
</outSequence>
<faultSequence>
<switch source="get-property('axis2','HTTP_SC')">
<case regex="200">
<log description="200log" level="custom">
<property expression="$ctx:ERROR_CODE" name="200reserrorcode"/>
</log>
</case>
<default>
<log description="reslog" level="custom">
<property expression="$ctx:ERROR_CODE" name="reserrorcode"/>
<property expression="$ctx:ERROR_MESSAGE" name="reserrormessage"/>
<property expression="get-property('axis2','HTTP_SC')" name="reshttpsc"/>
</log>
</default>
</switch>
<send/>
</faultSequence>
</resource>
</api>
wso2 configuration process with to send the response is other than 200 response code
reportsendpoint:
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="reporsendpoint" xmlns="http://ws.apache.org/ns/synapse">
<http method="get" uri-template="http://localhost:6547/generatereports/1.0/Reports/{uri.var.dcuid}/{uri.var.vcid}"/>
</endpoint>
I assume you want to send a mail if the status code is other than 200. Then you can use mailto transport or mail connectors such as gmail connector outlook connector and add the configuration in the default section in the configured switch mediator.
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 noob to that application, but I´ve been trying some tutorials and all of them had no response, nothing happens. I just send a request and nothing. I deployed and all looks as the tutorials explained, but when I try to execute, nothing appears in my browse or curl.
Here is a example:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/healthcare" name="HealthcareAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" uri-template="/querydoctor/{category}">
<inSequence>
<log description="RequestLog"/>
<send/>
</inSequence>
<outSequence>
<log description="ResponseLog"/>
<send/>
</outSequence>
<faultSequence>
<log description="ErrorLog"/>
</faultSequence>
</resource>
<resource methods="POST" uri-template=" /categories/{category}/reserve">
<inSequence>
<property description="GetHospital" expression="json-eval($.hospital)" name="Hospital" scope="default" type="STRING"/>
<switch source="get-property('Hospital')">
<case regex="grand oak community hospital">
<log description="GrandOakLog" level="custom">
<property expression="fn:concat('Routing to ', get-property('Hospital'))" name="message"/>
</log>
<send/>
</case>
<case regex="clemency medical center">
<log description="ClemencyLog" level="custom">
<property expression="fn:concat('Routing to ', get-property('Hospital'))" name="message"/>
</log>
<send/>
</case>
<case regex="pine valley community hospital">
<log description="PineValleyLog" level="custom">
<property expression="fn:concat('Routing to ', get-property('Hospital'))" name="message"/>
</log>
<send/>
</case>
<default>
<log description="ErrorLog" level="custom">
<property expression="fn:concat('Invalid hospital - ', get-property('Hospital'))" name="message"/>
</log>
<respond description="RespondError"/>
</default>
</switch>
</inSequence>
<outSequence/>
<faultSequence>
<log description="ErrorLog"/>
</faultSequence>
</resource>
</api>
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="ClemencyEP" xmlns="http://ws.apache.org/ns/synapse">
<http method="post" uri-template="http://wso2training-restsamples.wso2apps.com/clemency/categories/{uri.var.category}/reserve"/>
</endpoint>
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="GrandOakEP" xmlns="http://ws.apache.org/ns/synapse">
<http method="post" uri-template="http://wso2training-restsamples.wso2apps.com/grandoaks/categories/{uri.var.category}/reserve"/>
</endpoint>
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="PineValleyEP" xmlns="http://ws.apache.org/ns/synapse">
<http method="post" uri-template="http://wso2training-restsamples.wso2apps.com/pinevalley/categories/{uri.var.category}/reserve"/>
</endpoint>
And here is the request to make that application work:
{
"patient": {
"name": "John Doe",
"dob": "1940-03-19",
"ssn": "234-23-525",
"address": "California",
"phone": "8770586755",
"email": "johndoe#gmail.com"
},
"doctor": "thomas collins",
"hospital": "grand oak community hospital"
}
You should have the endpoint call in the send mediator
<case regex="grand oak community hospital">
<log description="GrandOakLog" level="custom">
<property expression="fn:concat('Routing to ', get-property('Hospital'))" name="message"/>
</log>
<send>
<endpoint name="GrandOakEP" xmlns="http://ws.apache.org/ns/synapse">
<http method="post" uri-template="http://wso2training-restsamples.wso2apps.com/grandoaks/categories/{uri.var.category}/reserve"/>
</endpoint>
</send>
</case>
And also the outSequence should have a <send/> mediator
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"/>