Layer7 API Management

  • 1.  How to send different responses for a same request??

    Posted Dec 14, 2017 02:04 AM

    Hello All,

    I have one scenario where i need to send a different responses for a same request(i.e) for first hit of the request i need to send a different response , second hit i need to send a different response and finally for third hit i need to send different response. So for one particular request i need to send three different responses.

     

    Transport Protocol: Http/s



  • 2.  Re: How to send different responses for a same request??

    Posted Dec 14, 2017 09:40 AM

    Hi Ragul,

     

    My first though would be to use a cache to store the number of requests from a client. This way you can also easily set a time for the requests and you don't need to build up some kind of external solution. But the cache also has some limitations: it is single node and won't survive a gateway restart. But if that's not a problem, I think the cache can be a solution.

     

    Regards,

    Michiel



  • 3.  Re: How to send different responses for a same request??

    Posted Dec 14, 2017 10:09 AM

    I am not very clear as to what is the condition that must be met for a different response to be sent. If the requirement is

     

    1st Hit à Response 1

    2nd Hit à Response 2

    3rd Hit à Response 3

     

    I would start a counter in a variable and keep increasing it for each hit. Then forward the request to another service within the same gateway or another gateway.

     

    Regards

    Seenu Mathew



  • 4.  Re: How to send different responses for a same request??

    Posted Dec 14, 2017 10:17 AM

    Hi Seenu,

     

    I assume you would have to keep that counter in a cluster property or external in a DB to have it available across requests, right?

    My concern would be that you probably have to start a counter for each client, resulting in a hug list of cluster properties which you probably also want to clean up automatically at some point. By using the client-id or some other identifier as the cache key, you could easily achieve this.

     

    In the end the best answer all depends on the details of the requirements.

     

    Regards,

    Michiel



  • 5.  Re: How to send different responses for a same request??

    Posted Dec 19, 2017 02:49 AM

    HI Michiel,

     

    Please find below the details of my requirement:

     

    User will be logging in with invalid credential for three times. For first two times, i need to send a error message as a response and for the third time i need to send another error message as response.

     

    As I am quite new to CA i don't know how to use cache. It would be a great help for me if you tell me how to use that.(In this case i know the exact email id what user going to give in the request.)



  • 6.  Re: How to send different responses for a same request??

    Posted Dec 19, 2017 02:55 AM

    Thanks Seenu. You are right. I have explained my requirements to Michiel.

    Please find below the details of my requirement:

    User will be logging in with invalid credential for three times. For first two times, i need to send a error message as a response and for the third time i need to send another error message as response.

    If we use a counter variable will it no get reset whenever the gateway closes?? My question might be silly.. Since i am new to Service Virtualization i want to understand how this variable thing works.

     

    Regards,

    Ragul Murugesh.



  • 7.  Re: How to send different responses for a same request??
    Best Answer

    Posted Dec 20, 2017 04:10 AM

    Hi Ragul,

     

    Here is a good description about how the Cache assertion works

     

    https://docops.ca.com/ca-api-gateway/9-1/en/policy-assertions/assertion-palette/service-availability-assertions/store-to-cache-assertion

     

    Regards

    Seenu Mathew 



  • 8.  Re: How to send different responses for a same request??

    Posted Dec 20, 2017 10:07 AM

    Thanks Seenu.. So for the above mentioned scenario using cache is the only method or is there any other method we can try??



  • 9.  Re: How to send different responses for a same request??

    Broadcom Employee
    Posted Dec 20, 2017 07:20 PM

    Dear Ragul ,

    I agree with MichielHelder , cache assertion is not cluster-wide, using it as counter may not be accurate.

    You may think of remote cache (which is a tactical assertion, you can open a support ticket to ask for it), or you can persist the counter to database using jdbc connection.

     

    Regards,

    Mark