Layer7 API Management

  • 1.  Can CA API GW cache static or dynamic content?

    Posted Apr 24, 2019 04:19 PM

    Trying to support an Angular project with CA API gateway...

     

    Can or how to cache static files, like, jpg|jpeg|png|gif|ico|css|js in CA API GW?

     

    How about dynamic content?

     

    Any tip will be much appreciated.



  • 2.  Re: Can CA API GW cache static or dynamic content?
    Best Answer

    Broadcom Employee
    Posted Apr 28, 2019 07:03 PM

    Hello @Ikwan-ca,

     

    The API Management Gateway offers the capability of storing and retrieving messages or string in an internal cache on a Gateway node, using the Store to Cache Assertion and Look Up In Cache Assertion.

     

    If you are looking at storing data in other format like files, there is a Tactical Assertion named Remote Cache Assertion which  provides support for storing and retrieving messages from a remote cache server like Memcached, Coherence, Terracota, GemFire as well as Redis.

     

    Please contact CA Support if you need further information about this Tactical Assertion.

     

    Thanks,

    Aryne



  • 3.  RE: Re: Can CA API GW cache static or dynamic content?

    Posted Apr 29, 2020 01:38 PM
    Hi Wan,


    I have a scenario where I need to store oAuth token from External oAuth url to cache which is valid for 1 hr and need to lookup for that token in cache to post message to url.
    Can you please give me sample policy related to this.

    https://send.firefox.com/download/f0dbbffbd57f1b35/#Oydur78cnIprKcAqNWnDIA

    Looking for two sample

    1. Add cache assertions store and lookup token to achive it thru above policy
    2. we also have OTK installed on our side can we achieve it using OTK assertions using above policy
    OTK Cache Look Up
    OTK Cache Store
    OTK Cache Remove
    OTK Cache Flush


  • 4.  RE: Re: Can CA API GW cache static or dynamic content?

    Posted Apr 30, 2020 04:24 AM
    This piece of code will renew salesforce token every 10mns. We store environment (dev, uat, prod) on API Gateway hostname so we can route to corresponding Salesforce environment also. Token is hold into cache.




  • 5.  RE: Re: Can CA API GW cache static or dynamic content?

    Broadcom Employee
    Posted Apr 29, 2020 03:44 PM
    Edited by Jay MacDonald Apr 29, 2020 03:55 PM
    Further to Aryne's comments, the internal cache assertion was originally implemented to cache SOAP messages, but can be applied in a general sense for any content type. As such every cached object is stored as a message type variable with an associated contentType, so if you cache a string type variable then upon retrieval it will be a message type (text/plain) that will need to be converted back to a string variable in policy by referencing ${<varname>.mainpart}. The policy below illustrates this concept.

    <?xml version="1.0" encoding="UTF-8"?>
    <wsp:Policy xmlns:L7p="http://www.layer7tech.com/ws/policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2002/12/policy">
        <wsp:All wsp:Usage="Required">
            <L7p:CommentAssertion>
                <L7p:Comment stringValue="* Internal cache demonstration policy"/>
            </L7p:CommentAssertion>
            <L7p:AuditAssertion/>
            <L7p:SetVariable>
                <L7p:Base64Expression stringValue="U29tZSByYW5kb20gc3RyaW5n"/>
                <L7p:VariableToSet stringValue="foo"/>
            </L7p:SetVariable>
            <L7p:SetVariable>
                <L7p:Base64Expression stringValue="Zm9v"/>
                <L7p:VariableToSet stringValue="cacheKey"/>
            </L7p:SetVariable>
            <L7p:CacheStorage>
                <L7p:AssertionComment assertionComment="included">
                    <L7p:Properties mapValue="included">
                        <L7p:entry>
                            <L7p:key stringValue="RIGHT.COMMENT"/>
                            <L7p:value stringValue="// Store the string to the cache"/>
                        </L7p:entry>
                    </L7p:Properties>
                </L7p:AssertionComment>
                <L7p:CacheEntryKey stringValue="${cacheKey}"/>
                <L7p:OtherTargetMessageVariable stringValue="foo"/>
                <L7p:Target target="OTHER"/>
            </L7p:CacheStorage>
            <L7p:CacheLookup>
                <L7p:AssertionComment assertionComment="included">
                    <L7p:Properties mapValue="included">
                        <L7p:entry>
                            <L7p:key stringValue="RIGHT.COMMENT"/>
                            <L7p:value stringValue="// Retrieve from cache to ${bar}"/>
                        </L7p:entry>
                    </L7p:Properties>
                </L7p:AssertionComment>
                <L7p:CacheEntryKey stringValue="${cacheKey}"/>
                <L7p:ContentTypeOverride stringValue=""/>
                <L7p:OtherTargetMessageVariable stringValue="bar"/>
                <L7p:Target target="OTHER"/>
            </L7p:CacheLookup>
            <L7p:HardcodedResponse>
                <L7p:Base64ResponseBody stringValue="Zm9vPSR7Zm9vfQpiYXI9JHtiYXJ9CmJhci5tYWlucGFydD0ke2Jhci5tYWlucGFydH0KYmFyLmNvbnRlbnRUeXBlPSR7YmFyLmNvbnRlbnRUeXBlfQ=="/>
                <L7p:ResponseContentType stringValue="text/plain; charset=UTF-8"/>
            </L7p:HardcodedResponse>
        </wsp:All>
    </wsp:Policy>


    ------------------------------
    Jay MacDonald - Adoption Architect - Broadcom API Management (Layer 7)
    ------------------------------



  • 6.  RE: Re: Can CA API GW cache static or dynamic content?

    Broadcom Employee
    Posted Apr 29, 2020 03:54 PM

    The following policy illustrates caching image/png (assumes your Gateway can reach Google's servers)

    <?xml version="1.0" encoding="UTF-8"?>
    <wsp:Policy xmlns:L7p="http://www.layer7tech.com/ws/policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2002/12/policy">
        <wsp:All wsp:Usage="Required">
            <L7p:CommentAssertion>
                <L7p:Comment stringValue="* Internal cache demonstration policy"/>
            </L7p:CommentAssertion>
            <L7p:AuditAssertion/>
            <L7p:HttpRoutingAssertion>
                <L7p:ProtectedServiceUrl stringValue="http://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"/>
                <L7p:ProxyPassword stringValueNull="null"/>
                <L7p:ProxyUsername stringValueNull="null"/>
                <L7p:RequestHeaderRules httpPassthroughRuleSet="included">
                    <L7p:ForwardAll booleanValue="true"/>
                    <L7p:Rules httpPassthroughRules="included">
                        <L7p:item httpPassthroughRule="included">
                            <L7p:Name stringValue="Cookie"/>
                        </L7p:item>
                        <L7p:item httpPassthroughRule="included">
                            <L7p:Name stringValue="SOAPAction"/>
                        </L7p:item>
                    </L7p:Rules>
                </L7p:RequestHeaderRules>
                <L7p:RequestParamRules httpPassthroughRuleSet="included">
                    <L7p:ForwardAll booleanValue="true"/>
                    <L7p:Rules httpPassthroughRules="included"/>
                </L7p:RequestParamRules>
                <L7p:ResponseHeaderRules httpPassthroughRuleSet="included">
                    <L7p:ForwardAll booleanValue="true"/>
                    <L7p:Rules httpPassthroughRules="included">
                        <L7p:item httpPassthroughRule="included">
                            <L7p:Name stringValue="Set-Cookie"/>
                        </L7p:item>
                    </L7p:Rules>
                </L7p:ResponseHeaderRules>
                <L7p:ResponseMsgDest stringValue="image"/>
                <L7p:SamlAssertionVersion intValue="2"/>
            </L7p:HttpRoutingAssertion>
            <L7p:SetVariable>
                <L7p:Base64Expression stringValue="Zm9v"/>
                <L7p:VariableToSet stringValue="cacheKey"/>
            </L7p:SetVariable>
            <L7p:CacheStorage>
                <L7p:AssertionComment assertionComment="included">
                    <L7p:Properties mapValue="included">
                        <L7p:entry>
                            <L7p:key stringValue="RIGHT.COMMENT"/>
                            <L7p:value stringValue="// Store the image file to the cache"/>
                        </L7p:entry>
                    </L7p:Properties>
                </L7p:AssertionComment>
                <L7p:CacheEntryKey stringValue="${cacheKey}"/>
                <L7p:OtherTargetMessageVariable stringValue="image"/>
                <L7p:Target target="OTHER"/>
            </L7p:CacheStorage>
            <L7p:CacheLookup>
                <L7p:AssertionComment assertionComment="included">
                    <L7p:Properties mapValue="included">
                        <L7p:entry>
                            <L7p:key stringValue="RIGHT.COMMENT"/>
                            <L7p:value stringValue="// Retrieve from cache to ${cachedImage}"/>
                        </L7p:entry>
                    </L7p:Properties>
                </L7p:AssertionComment>
                <L7p:CacheEntryKey stringValue="${cacheKey}"/>
                <L7p:ContentTypeOverride stringValue=""/>
                <L7p:OtherTargetMessageVariable stringValue="cachedImage"/>
                <L7p:Target target="OTHER"/>
            </L7p:CacheLookup>
            <L7p:HardcodedResponse>
                <L7p:AssertionComment assertionComment="included">
                    <L7p:Properties mapValue="included">
                        <L7p:entry>
                            <L7p:key stringValue="RIGHT.COMMENT"/>
                            <L7p:value stringValue="// Report details about ${cachedImage}"/>
                        </L7p:entry>
                    </L7p:Properties>
                </L7p:AssertionComment>
                <L7p:Base64ResponseBody stringValue="Y2FjaGVkSW1hZ2U9JHtjYWNoZWRJbWFnZX0KY2FjaGVkSW1hZ2UuY29udGVudFR5cGU9JHtjYWNoZWRJbWFnZS5jb250ZW50VHlwZX0KY2FjaGVkSW1hZ2Uuc2l6ZWU9JHtjYWNoZWRJbWFnZS5zaXplfQ=="/>
                <L7p:ResponseContentType stringValue="text/plain; charset=UTF-8"/>
            </L7p:HardcodedResponse>
        </wsp:All>
    </wsp:Policy>


    ------------------------------
    Jay MacDonald - Adoption Architect - Broadcom API Management (Layer 7)
    ------------------------------