0
votes

I used WSO2 Publisher application to create & publish an API with following configs:

Context = a
Version = v1.0
URL Pattern: /b/{bId}/c/{cId}
HTTP Verb: GET
Endpoint Type: HTTP Endpoint
Production Endpoint: http://backendserver:port/services/rest/GetXYZ

In the store I subscribed to the API, generated an application token and invoked the API with following URL:

https://gatewayserver:port/a/v1.0/b/123/c/456

However, when the gateway calls the backend service it somehow automatically changes the endpoint to the following:

http://backendserver:port/services/rest/456

instead of the expected:

http://backendserver:port/services/rest/GetXYZ

I verified the synapse config of the API and it captured the endpoint correctly as defined. what changes that backend endpoint automatically? How can it be avoided?

1
Can you share the synapse config of the api?harsha89
Can't put the entire synapse config. Here is the insequence: <resource methods="GET" uri-template="/b/{bId}/c/{cId}" faultSequence="fault"> <inSequence> <filter source="$ctx:AM_KEY_TYPE" regex="PRODUCTION"> <then> <property name="api.ut.backendRequestTime" expression="get-property('SYSTEM_TIME')"/> <send> <endpoint name="publisher--GetXYZ_APIproductionEndpoint_0"> <http uri-template="server:port/rest/model/services/getXYZ"> </endpoint> </send> </then>Nike

1 Answers

1
votes

What version of Api manager are you using? if It is API manager 1.10, you would get a request to backend like this for default http endpoint

GET /services/rest/GetXYZ/b/123/c/456

The default behavior is appending the resource path to the backend endpoint when request is going out from the api manager

ex: if endpoint is http://test.com/abc and api has a resource defined as /testresource/123 then the request would be http://test.com/abc/testresource/123 to the backend with the default endpoint type (HTTP endpoint)

If you want to call the backend without appending the resource to the request, you can add the following property to the synapse configuration.

<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>

You can do this by using the mediator extension feature provided in API manager. see https://docs.wso2.com/display/AM1100/Adding+Mediation+Extensions.

following is a sample extension file

<sequence xmlns="http://ws.apache.org/ns/synapse" name="removeresource">
    <property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
</sequence>

Upload this and then import this to the 'IN flow' sequence in the api. see https://docs.wso2.com/display/AM1100/Change+the+Default+Mediation+Flow+of+API+Requests