I'm using WSO2 API Manager Version 2.0.0. Within the API Publisher, I added a POST endpoint to my API using an in path parameter.
POST /person/{id}
Everything works fine. The path parameter id is added to the endpoint.
But this does not work if the path contains a . character somewhere. Adding POST /cool.person/{id} will result in an empty parameter list. Also, it is not possible to add a parameter manually to this endpoint.
Am I doing something wrong or is this a bug?
According to my knowledge and due my findings on this, both POST /person/{id} and POST /cool.person/{id} are correct.
I think the issue is in your endpoint, your end point is not giving permission to you to add another entry via a POST method.
I followed your path and I couldn't reproduce your situation, but I found that need permission from endpoint to put another entry there.
I'll attach my synaps file and snap shot of the response
<?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse"
name="admin--UrlTest"
context="/paternType/1.0"
version="1.0"
version-type="context">
<resource methods="POST" url-mapping="/persons.list" faultSequence="fault">
<inSequence>
<property name="api.ut.backendRequestTime"
expression="get-property('SYSTEM_TIME')"/>
<filter source="$ctx:AM_KEY_TYPE" regex="PRODUCTION">
<then>
<send>
<endpoint name="admin--UrlTest_APIproductionEndpoint_0">
<http uri-template="http://jsonplaceholder.typicode.com/posts?"/>
<property name="ENDPOINT_ADDRESS"
value="http://jsonplaceholder.typicode.com/posts?"/>
</endpoint>
</send>
</then>
<else>
<send>
<endpoint name="admin--UrlTest_APIsandboxEndpoint_0">
<http uri-template="http://jsonplaceholder.typicode.com/posts?"/>
<property name="ENDPOINT_ADDRESS"
value="http://jsonplaceholder.typicode.com/posts?"/>
</endpoint>
</send>
</else>
</filter>
</inSequence>
<outSequence>
<class name="org.wso2.carbon.apimgt.usage.publisher.APIMgtResponseHandler"/>
<send/>
</outSequence>
</resource>
<resource methods="POST" url-mapping="/persons" faultSequence="fault">
<inSequence>
<property name="api.ut.backendRequestTime"
expression="get-property('SYSTEM_TIME')"/>
<filter source="$ctx:AM_KEY_TYPE" regex="PRODUCTION">
<then>
<send>
<endpoint name="admin--UrlTest_APIproductionEndpoint_1">
<http uri-template="http://jsonplaceholder.typicode.com/posts?"/>
<property name="ENDPOINT_ADDRESS"
value="http://jsonplaceholder.typicode.com/posts?"/>
</endpoint>
</send>
</then>
<else>
<send>
<endpoint name="admin--UrlTest_APIsandboxEndpoint_1">
<http uri-template="http://jsonplaceholder.typicode.com/posts?"/>
<property name="ENDPOINT_ADDRESS"
value="http://jsonplaceholder.typicode.com/posts?"/>
</endpoint>
</send>
</else>
</filter>
</inSequence>
<outSequence>
<class name="org.wso2.carbon.apimgt.usage.publisher.APIMgtResponseHandler"/>
<send/>
</outSequence>
</resource>
<resource methods="GET" url-mapping="/personlist" faultSequence="fault">
<inSequence>
<property name="api.ut.backendRequestTime"
expression="get-property('SYSTEM_TIME')"/>
<filter source="$ctx:AM_KEY_TYPE" regex="PRODUCTION">
<then>
<send>
<endpoint name="admin--UrlTest_APIproductionEndpoint_2">
<http uri-template="http://jsonplaceholder.typicode.com/posts?"/>
<property name="ENDPOINT_ADDRESS"
value="http://jsonplaceholder.typicode.com/posts?"/>
</endpoint>
</send>
</then>
<else>
<send>
<endpoint name="admin--UrlTest_APIsandboxEndpoint_2">
<http uri-template="http://jsonplaceholder.typicode.com/posts?"/>
<property name="ENDPOINT_ADDRESS"
value="http://jsonplaceholder.typicode.com/posts?"/>
</endpoint>
</send>
</else>
</filter>
</inSequence>
<outSequence>
<class name="org.wso2.carbon.apimgt.usage.publisher.APIMgtResponseHandler"/>
<send/>
</outSequence>
</resource>
<handlers>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.common.APIMgtLatencyStatsHandler"/>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.security.CORSRequestHandler">
<property name="apiImplementationType" value="ENDPOINT"/>
</handler>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler"/>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.throttling.ThrottleHandler"/>
<handler class="org.wso2.carbon.apimgt.usage.publisher.APIMgtUsageHandler"/>
<handler class="org.wso2.carbon.apimgt.usage.publisher.APIMgtGoogleAnalyticsTrackingHandler">
<property name="configKey" value="gov:/apimgt/statistics/ga-config.xml"/>
</handler>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler"/>
</handlers>
</api>
Jeewana.
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'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>
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"/>
My Proxy Service deployed on ESB is calling another standalone REST service. This service returns HTTP status 200 along with some data in the response body. My question is how I can retrieve HTTP status from response. Here is my configuration:
<proxy name="CQProxy"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<switch source="get-property('Action')">
<case regex="getTaskTicket">
<sequence key="GetTaskTicket"/>
</case>
<default/>
</switch>
</inSequence>
<outSequence>
<log>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="Status"
expression="get-property('HTTP_SC')"/>
</log>
<send/>
</outSequence>
<faultSequence/>
</target>
<publishWSDL key="gov:/services/cqproxy/CQProxy.wsdl">
<resource location="CQProxy.xsd" key="gov:/services/cqproxy/CQProxy.xsd"/>
</publishWSDL>
</proxy>
<sequence name="GetTaskTicket">
...
<property name="REST_URL_POSTFIX"
value="/16783484?oslc.select=dcterms:title,oslc_cm:status"
scope="axis2"
type="STRING"/>
<property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
<send>
<endpoint>
<address uri="http://.../simpleQuery"
format="rest"/>
<property name="OSLC-Core-Version" value="2.0" scope="transport"/>
<property name="Accept" value="application/rdf+xml" scope="transport"/>
</endpoint>
</send>
</sequence>
...
I tried the following code:
<log>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Status" expression="get-property('HTTP_SC')"/>
</log>
And this one too:
<log>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Status" expression="get-property('axis2', 'HTTP_SC')"/>
</log>
But all of them returned null.
After reading WSO2 documentation in more details, I found the right answer:
<property xmlns:ns="http://org.apache.synapse/xsd" name="Status" expression="$axis2:HTTP_SC"/>
It is weird that the documented get-property('axis2', 'HTTP_SC') does not work.
Posting the solution that worked for me:
<property scope="default" type="STRING" name="HTTP_STATUS_CODE" expression="get-property('axis2', 'HTTP_SC')"/>
<log level="custom">
<property expression="get-property('HTTP_STATUS_CODE')" name="HTTP status code received: "/>
</log>