0

There is Hello World API is onboarded into WSO2 APIm 4.1.0 GA release. I added JSONtoXML policy from policy List to Response flow by follows steps provided in WSO2 APIM Doc and deployed in DEV portal by clicking save and deploy option

JsonToXML.j2 - Policy file Content:

<property name="messageType" value="application/xml" scope="axis2"/>

Policy in publisher:

Policy in publisher

When I Try out this API in DEV portal or via postman, it is still giving response as JSON format, not in XML

WSO2 DEV Portal - TRY IT OUT:

WSO2 DEV Portal

POSTMAN:

postman

As suggested below - API Gateway Sequence Hit:

api gateway sequence test

CURL Request like below:

curl -k "https://127.0.0.1:9443/api/am/gateway/v2/sequence?apiName=HelloWorld&version=1.0.0" -H "Authorization: Bearer eyJ4NXQiOiJOMkpqTWpOaU0xxx" 

Note: valid token is passed in above curl Request, same token used when calling apim url which gives backend response

Did I miss anything or if not why this policy enablement is not working in WSO2 APIM? Please clarify on the same

Justin
  • 855
  • 2
  • 11
  • 30

2 Answers2

0

I just followed the same flow to the Pizzashack API in the APIM 4.1.0 GA pack. It worked as expected without any issue. enter image description here

Can you confirm that you have created a new revision after this policy addition and deployed it in the gateway?

If you have done that as well, shall we use the gateway Rest API and check the sequences for the HelloAPI. There should be a new sequence with the above policy attached.

Edit:

If the sequence call does not contain a response, that means the policy has not been deployed properly. To apply the policy properly, create a new revision and deploy that revision in the gateway.

Lakshitha
  • 1,021
  • 1
  • 6
  • 15
  • Hi @Lakshitha, Yes deployed as new revision, As you suggested tested curl request via postman to check the sequence which gives 401 ERROR. curl -k "https://127.0.0.1:9443/api/am/gateway/v2/sequence?apiName=HelloWorld&version=1.0.0" -H "Authorization: Bearer eyJ4NXQiOiJOMkpqTWpOaU0xxx" Note: valid token passed in header section and the same token is used when calling apim url. Added image in question – Justin Jan 29 '23 at 16:02
  • Use basic auth with admin credentials for this API request. Default "Authorization: Basic YWRtaW46YWRtaW4=" – Lakshitha Jan 29 '23 at 16:06
  • Hi @Lakshitha, Thanks for suggestion, after using basic Auth, sequence is empty, got below Response. { "sequences": [] } – Justin Jan 29 '23 at 16:08
  • 1
    This means the policy has not been applied. Shall we create another revision and deploy? Let's check the sequence after that as well. Also please verify that the policy is already applied to the correct resource and the API is saved. – Lakshitha Jan 29 '23 at 16:09
  • @Justin I have updated the answer with these steps. – Lakshitha Jan 29 '23 at 16:59
-1

As suggested by @Lakshitha, i followed below STEPS and working as expected.

  • Restarted WSO2 APIm standalone server
  • Added policy in GET resourse of HelloWorld API
  • Deployed as new Revision
  • In DEV Portal, API tested via TRY OUT option and got XML response now DEV Postal Response

Gateway API also given sequence response like BELOW

Gateway sequence API

Justin
  • 855
  • 2
  • 11
  • 30