carlos-silva
carlos-silva

Reputation: 95

Custom Policies API Manager

I tried to create a custom policy, with a purpose a mask of service:

Original Services in API:

http://API/v1/profile
http://API/v1/account

With mask:

http://API/v1/user-profile
http://API/v1/user-account

And combination the answer of User Bee this a solution for this problem:

<switch source="get-property('axis2', 'REST_URL_POSTFIX')">
    <case regex="/v1/kyc-profile">
        <property name="REST_URL_POSTFIX" value="/v1/profile" scope="axis2"/>
    </case>
    <case regex="/v1/kyc-account">
        <property name="REST_URL_POSTFIX" value="/v1/account" scope="axis2"/>
    </case>
</switch>

But this solution only works where the services is static, but I have others services, similar to:

http://API/v1/user-profile/{id-user}/details
http://API/v1/user-profile/{id-user}?expand=some_information

For the last service I have this:

<switch source="get-property('axis2', 'REST_URL_POSTFIX')">
   <case regex="v1/user-profile/[\/\w\W]*">
        <property name="REST_URL_POSTFIX" value="/v2/cliente/{id-user}?expand=some_information" scope="axis2"/>
   </case>
</switch>

[/\w\W]* This part is regular expression for {id-user}?expand=some_information and similar.

The problem is: I need put dynamic value because the property value (<property name="REST_URL_POSTFIX" value="THIS" scope="axis2"/>) takes this text, example:

Service before to policie

http://API/v1/user-profile/1?expand=some_information

Service after to policie

http://API/v1/user-profile/{id-user}?expand=some_information

My questions are:

  1. How to put a dynamic value for the services similar to: http://API/v1/user-profile/{id-user}?expand=some_information?
  2. For the other service, http://API/v1/user-profile/{id-user}/details I have the similar situacion, How a resolve?

Upvotes: 1

Views: 94

Answers (1)

menaka_
menaka_

Reputation: 1100

In your mediation sequence, try changing the backend URL as follows.

http://API/v1/user-profile/{uri.var.id-user}?expand=some_information

Example:

<switch source="get-property('axis2', 'REST_URL_POSTFIX')">
   <case regex="v1/user-profile/[\/\w\W]*">
        <property name="REST_URL_POSTFIX" value="/v2/cliente/{uri.var.id-user}?expand=some_information" scope="axis2"/>
   </case>
</switch>

Upvotes: 1

Related Questions