Layer7 API Management

 View Only
  • 1.  Route via HTTP(s) assertion

    Posted Jun 11, 2015 05:11 PM

    Is it possible to set a variable/property for the Route via HTTP(s) assertion that would take a list of URLs instead of having to set them via the connection tab?

    When setting it to a multivalued context variable all the values get set as a single URL.



  • 2.  Re: Route via HTTP(s) assertion

    Posted Jun 11, 2015 07:24 PM

    What are you trying to accomplish here?

    1. Are you trying to Round-Robin the URL's
    2. Send the same request to all the endpoints
    3. Apply some other Load Sharing Algorithm to the URL's


  • 3.  Re: Route via HTTP(s) assertion

    Posted Jun 11, 2015 07:27 PM

    yup, trying to Round-Robin the URL's.



  • 4.  Re: Route via HTTP(s) assertion

    Posted Jun 12, 2015 12:12 AM

    in the routing assertion, check out the 'Connection' tab, here you can use the 'use multiple URLs' option and have a few 'Algorithm/Failover Strategies', of which 'Round Robin' is one of them.

    HTTP_S__Routing_Properties_and_CA_API_Gateway_-_Policy_Manager.png



  • 5.  Re: Route via HTTP(s) assertion

    Posted Jun 12, 2015 02:40 AM

    The way I understand the question is that he wants to use a variable to populate that field. Which would be useful to make the policy portable between environments and use a cluster variable to set the correct group of endpoints.



  • 6.  Re: Route via HTTP(s) assertion

    Posted Jun 12, 2015 01:43 PM

    yes, exactly, I was hoping to be able to populate the multiple urls property via a single parameter/cluster property that is a list.



  • 7.  Re: Route via HTTP(s) assertion

    Posted Jun 17, 2015 02:50 AM

    Hi, if I understand the need correctly which is to enable feeding in the list of route-to url at runtime; I hope this snippet of policy can provide a useful idea -

     

     

     

     

     

     

     

     

     

     

    Policy export corresponding to above:

     

    <?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:SetVariable>

                <L7p:AssertionComment assertionComment="included">

                    <L7p:Properties mapValue="included">

                        <L7p:entry>

                            <L7p:key stringValue="RIGHT.COMMENT"/>

                            <L7p:value stringValue="// set your list of urls here; comma separated"/>

                        </L7p:entry>

                    </L7p:Properties>

                </L7p:AssertionComment>

                <L7p:Base64Expression stringValue="aHR0cDovLzE5Mi4xNjguMTMzLjEzMDo2MDYwL0FDTUVXYXJlaG91c2Uvc2VydmljZXMvV2FyZWhvdXNlU29hcD93c2RsLGh0dHA6Ly8xOTIuMTY4LjEzMy4xMzA6NjA2MC9BQ01FV2FyZWhvdXNlL3NlcnZpY2VzL1dhcmVob3VzZVNvYXA/d3NkbCxodHRwOi8vMTkyLjE2OC4xMzMuMTMwOjYwNjAvQUNNRVdhcmVob3VzZS9zZXJ2aWNlcy9XYXJlaG91c2VTb2FwP3dzZGw="/>

                <L7p:VariableToSet stringValue="backend-url-list"/>

            </L7p:SetVariable>

            <L7p:Split>

                <L7p:InputVariable stringValue="backend-url-list"/>

                <L7p:OutputVariable stringValue="backend-url-mv-ctx-var"/>

            </L7p:Split>

            <L7p:ForEachLoop L7p:Usage="Required"

                loopVariable="backend-url-mv-ctx-var" variablePrefix="target">

                <wsp:OneOrMore wsp:Usage="Required">

                    <wsp:All wsp:Usage="Required">

                        <L7p:HttpRoutingAssertion>

                            <L7p:AssertionComment assertionComment="included">

                                <L7p:Properties mapValue="included">

                                    <L7p:entry>

                                        <L7p:key stringValue="RIGHT.COMMENT"/>

                                        <L7p:value stringValue="// make sure to mark Assertion Outcome to &quot;Never fail as long as target returns an anwser&quot; in the &quot;Other&quot; tab of the properties dialog"/>

                                    </L7p:entry>

                                </L7p:Properties>

                            </L7p:AssertionComment>

                            <L7p:ProtectedServiceUrl stringValue="${target.current]"/>

                            <L7p:ProxyPassword stringValueNull="null"/>

                            <L7p:ProxyUsername stringValueNull="null"/>

                            <L7p:RequestHeaderRules httpPassthroughRuleSet="included">

                                <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:Rules httpPassthroughRules="included">

                                    <L7p:item httpPassthroughRule="included">

                                        <L7p:Name stringValue="Set-Cookie"/>

                                    </L7p:item>

                                </L7p:Rules>

                            </L7p:ResponseHeaderRules>

                        </L7p:HttpRoutingAssertion>

                        <L7p:SetVariable>

                            <L7p:AssertionComment assertionComment="included">

                                <L7p:Properties mapValue="included">

                                    <L7p:entry>

                                        <L7p:key stringValue="RIGHT.COMMENT"/>

                                        <L7p:value stringValue="// routed successfully: no need to try next url - exit the loop"/>

                                    </L7p:entry>

                                </L7p:Properties>

                            </L7p:AssertionComment>

                            <L7p:Base64Expression stringValue="dHJ1ZQ=="/>

                            <L7p:VariableToSet stringValue="target.break"/>

                        </L7p:SetVariable>

                    </wsp:All>

                    <L7p:AuditDetailAssertion>

                        <L7p:Detail stringValue="Failed routing to ${target.current}; trying next one..."/>

                        <L7p:Level stringValue="WARNING"/>

                    </L7p:AuditDetailAssertion>

                </wsp:OneOrMore>

            </L7p:ForEachLoop>

            <wsp:OneOrMore wsp:Usage="Required">

                <wsp:All wsp:Usage="Required">

                    <L7p:ComparisonAssertion>

                        <L7p:Expression1 stringValue="${http.routing.status}"/>

                        <L7p:Expression2 stringValue="200"/>

                        <L7p:Predicates predicates="included">

                            <L7p:item binary="included">

                                <L7p:RightValue stringValue="200"/>

                            </L7p:item>

                        </L7p:Predicates>

                    </L7p:ComparisonAssertion>

                    <L7p:assertionComment>

                        <L7p:Properties mapValue="included">

                            <L7p:entry>

                                <L7p:key stringValue="RIGHT.COMMENT"/>

                                <L7p:value stringValue="// check that the loop exited for happy path"/>

                            </L7p:entry>

                        </L7p:Properties>

                    </L7p:assertionComment>

                </wsp:All>

                <L7p:AuditDetailAssertion>

                    <L7p:AssertionComment assertionComment="included">

                        <L7p:Properties mapValue="included">

                            <L7p:entry>

                                <L7p:key stringValue="RIGHT.COMMENT"/>

                                <L7p:value stringValue="// not happy path - handle it"/>

                            </L7p:entry>

                        </L7p:Properties>

                    </L7p:AssertionComment>

                    <L7p:Detail stringValue="handle failure for zero successful route to any url on backend-url-list..."/>

                    <L7p:Level stringValue="WARNING"/>

                </L7p:AuditDetailAssertion>

            </wsp:OneOrMore>

        </wsp:All>

    </wsp:Policy>



  • 8.  Re: Route via HTTP(s) assertion

    Posted Jun 17, 2015 02:54 AM

    Typo

     



  • 9.  Re: Route via HTTP(s) assertion

    Posted Jun 18, 2015 12:42 PM

    Thanks for the snippet Shing. I had thought about doing this as well but it won't work because I want to Round Robin the urls in the list.