wso2 / product-apim

Welcome to the WSO2 API Manager source code! For info on working with the WSO2 API Manager repository and contributing code, click the link below.
http://wso2.github.io/
Apache License 2.0
853 stars 787 forks source link

Response Caching is Not Working with the Integrated Try Out Console using Firefox Browser #12742

Open hisanhunais opened 2 years ago

hisanhunais commented 2 years ago

Description:

When testing the response caching mechanism through the integrated try out console in the developer portal using Google Chrome browser or using curl command through the terminal, it is working as expected.

But, when testing out the response caching mechanism through the integrated try out console in the developer portal using the Firefox browser(98.0.1 (64-bit)), the response caching is not working properly. (The API invocation reaches the backend) and the following error gets logged in the server console.

ERROR - SequenceMediator {api:api3:v1.0.0} Runtime error occurred while mediating the message
java.lang.NullPointerException: null
    at org.apache.synapse.util.MessageHelper.cloneSOAPEnvelope(MessageHelper.java:563) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.wso2.carbon.mediator.cache.CacheMediator.replaceEnvelopeWithCachedResponse(CacheMediator.java:353) ~[org.wso2.carbon.mediator.cache_4.7.130.jar:?]
    at org.wso2.carbon.mediator.cache.CacheMediator.processResponseMessage(CacheMediator.java:455) ~[org.wso2.carbon.mediator.cache_4.7.130.jar:?]
    at org.wso2.carbon.mediator.cache.CacheMediator.mediate(CacheMediator.java:251) ~[org.wso2.carbon.mediator.cache_4.7.130.jar:?]
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:110) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:72) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.api.Resource.process(Resource.java:342) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.api.API.process(API.java:416) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.api.AbstractApiHandler.apiProcessNonDefaultStrategy(AbstractApiHandler.java:107) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.api.AbstractApiHandler.identifyAPI(AbstractApiHandler.java:127) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.api.AbstractApiHandler.dispatchToAPI(AbstractApiHandler.java:54) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.api.rest.RestRequestHandler.dispatchToAPI(RestRequestHandler.java:90) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.api.rest.RestRequestHandler.process(RestRequestHandler.java:63) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:54) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:344) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:627) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:208) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180) ~[axis2_1.6.1.wso2v80.jar:?]
    at org.wso2.carbon.core.multitenancy.MultitenantMessageReceiver.processResponse(MultitenantMessageReceiver.java:192) ~[org.wso2.carbon.core_4.6.3.jar:?]
    at org.wso2.carbon.core.multitenancy.MultitenantMessageReceiver.receive(MultitenantMessageReceiver.java:92) ~[org.wso2.carbon.core_4.6.3.jar:?]
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180) ~[axis2_1.6.1.wso2v80.jar:?]
    at org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:298) ~[synapse-nhttp-transport_2.1.7.wso2v270.jar:?]
    at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172) ~[axis2_1.6.1.wso2v80.jar:?]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[?:1.8.0_241]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[?:1.8.0_241]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_241]
[2022-03-22 19:13:06,415] ERROR - api3 Runtime error occurred while mediating the message
java.lang.NullPointerException: null
    at org.apache.synapse.util.MessageHelper.cloneSOAPEnvelope(MessageHelper.java:563) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.wso2.carbon.mediator.cache.CacheMediator.replaceEnvelopeWithCachedResponse(CacheMediator.java:353) ~[org.wso2.carbon.mediator.cache_4.7.130.jar:?]
    at org.wso2.carbon.mediator.cache.CacheMediator.processResponseMessage(CacheMediator.java:455) ~[org.wso2.carbon.mediator.cache_4.7.130.jar:?]
    at org.wso2.carbon.mediator.cache.CacheMediator.mediate(CacheMediator.java:251) ~[org.wso2.carbon.mediator.cache_4.7.130.jar:?]
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:110) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:72) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.api.Resource.process(Resource.java:342) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.api.API.process(API.java:416) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.api.AbstractApiHandler.apiProcessNonDefaultStrategy(AbstractApiHandler.java:107) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.api.AbstractApiHandler.identifyAPI(AbstractApiHandler.java:127) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.api.AbstractApiHandler.dispatchToAPI(AbstractApiHandler.java:54) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.api.rest.RestRequestHandler.dispatchToAPI(RestRequestHandler.java:90) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.api.rest.RestRequestHandler.process(RestRequestHandler.java:63) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:54) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:344) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:627) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:208) ~[synapse-core_2.1.7.wso2v270.jar:2.1.7-wso2v270]
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180) ~[axis2_1.6.1.wso2v80.jar:?]
    at org.wso2.carbon.core.multitenancy.MultitenantMessageReceiver.processResponse(MultitenantMessageReceiver.java:192) ~[org.wso2.carbon.core_4.6.3.jar:?]
    at org.wso2.carbon.core.multitenancy.MultitenantMessageReceiver.receive(MultitenantMessageReceiver.java:92) ~[org.wso2.carbon.core_4.6.3.jar:?]
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180) ~[axis2_1.6.1.wso2v80.jar:?]
    at org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:298) ~[synapse-nhttp-transport_2.1.7.wso2v270.jar:?]
    at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172) ~[axis2_1.6.1.wso2v80.jar:?]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[?:1.8.0_241]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[?:1.8.0_241]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_241]
[2022-03-22 19:13:06,415]  INFO - LogMediator {api:api3:v1.0.0} STATUS = Executing default 'fault' sequence, ERROR_CODE = 0, ERROR_MESSAGE = Runtime error occurred while mediating the message

Steps to reproduce:

Followed the response caching documentation [1]

  1. Log in to the Publisher Portal
  2. Created an API and enabled Response Caching by providing cache timeout value as 100 seconds.
  3. Deployed and Published the API
  4. Log in to the Developer Portal
  5. Created a new application and generated keys
  6. Subscribed the created API to this application and generated an access token
  7. Moved to the try out tab and pasted the generated access token in the Access Token field.
  8. Expanded a resources and executed it several times with a small gap in between each execution

The above mentioned error gets printed in the server console. It can be noticed that the backend also has been called. (I had added a print statement when the backend is called)

[1] https://apim.docs.wso2.com/en/4.1.0/deploy-and-publish/deploy-on-gateway/api-gateway/response-caching/#enabling-response-caching-for-an-api

Environment details (with versions):

hisanhunais commented 2 years ago

I have attached enabled the synapse-wire logs and attached the logs. I invoked the API two times.

Firefox browser

  1. First API invocation: firstcallfirefox.txt
  2. Second API invocation: secondcallfirefox.txt

Google Chrome browser

  1. First API invocation: firstcallchrome.txt
  2. Second API invocation: secondcallchrome.txt