Layer7 API Management

 View Only
Expand all | Collapse all

Replace on string in message response containing a space not working

  • 1.  Replace on string in message response containing a space not working

    Posted Sep 23, 2020 03:03 PM
    Dear Broadcomm,

    I am trying to run through a service response from a backend service to replace all responses matching a pattern.
    The response is a list of restful endpoints and i am modifying them to be non-indicative of the actual internal endpoint.
    When trying to match the response pattern, and that response pattern contains a space, the Evaluate Regular Expression fails.
    I have tried the space outright, replacing the space with the ascii code equivalent, and tried building the string to match dynamically with the same issue.
    I have also tried to override the character encoding in the regular expression.
    The match pattern containing the space works properly in the 'test' option of the regular expression but not when running dynamically.
    Could you kindly take a look and see what is the best way to accomplish this.
    Thanks!
    Dan Camerota

    Here is the fragment xml:
    <?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:Split>
    <L7p:InputVariable stringValue="gitHubSpecialReplacementUrls"/>
    <L7p:OutputVariable stringValue="gitHubSpecialReplacementUrlsValues"/>
    </L7p:Split>
    <L7p:CommentAssertion>
    <L7p:Comment stringValue="For each of the GitHub special host replacement values, replace the value of the current host"/>
    </L7p:CommentAssertion>
    <L7p:CommentAssertion>
    <L7p:Comment stringValue="with the appropriate External service endpoint value."/>
    </L7p:CommentAssertion>
    <wsp:All wsp:Usage="Required">
    <L7p:ForEachLoop L7p:Usage="Required"
    loopVariable="gitHubSpecialReplacementUrlsValues" variablePrefix="gitHubSpecialReplacementUrlsValue">
    <wsp:OneOrMore wsp:Usage="Required">
    <wsp:All wsp:Usage="Required">
    <L7p:ComparisonAssertion>
    <L7p:CaseSensitive booleanValue="false"/>
    <L7p:Expression1 stringValue="${response.mainpart}"/>
    <L7p:Operator operatorNull="null"/>
    <L7p:Predicates predicates="included">
    <L7p:item dataType="included">
    <L7p:Type variableDataType="string"/>
    </L7p:item>
    <L7p:item binary="included">
    <L7p:CaseSensitive booleanValue="false"/>
    <L7p:Operator operator="CONTAINS"/>
    <L7p:RightValue stringValue="${gitHubSpecialReplacementUrlsValue.current}"/>
    </L7p:item>
    </L7p:Predicates>
    </L7p:ComparisonAssertion>
    <L7p:SetVariable>
    <L7p:Base64Expression stringValue="JHtnaXRIdWJTcGVjaWFsUmVwbGFjZW1lbnRVcmxzVmFsdWUuY3VycmVudH0iOiUyMCJodHRwczovL3NvbWVleHRlcm5hbC5lbmRwb2ludC5jb20vdjEvc29tZXNlcnZpY2Uv"/>
    <L7p:VariableToSet stringValue="respTextToReplace"/>
    </L7p:SetVariable>
    <L7p:Regex>
    <L7p:AutoTarget booleanValue="false"/>
    <L7p:CaseInsensitive booleanValue="true"/>
    <L7p:PatternContainsVariables booleanValue="true"/>
    <L7p:Regex stringValue="${respTextToReplace}"/>
    <L7p:Replace booleanValue="true"/>
    <L7p:Replacement stringValue="${gitHubSpecialReplacementUrlsValue.current}&quot;:%20&quot;https://someNEWexternal.endpoint.com/v1/someNEWservice/"/>
    <L7p:Target target="RESPONSE"/>
    </L7p:Regex>
    </wsp:All>
    <L7p:TrueAssertion/>
    </wsp:OneOrMore>
    </L7p:ForEachLoop>
    <L7p:assertionComment>
    <L7p:Properties mapValue="included">
    <L7p:entry>
    <L7p:key stringValue="RIGHT.COMMENT"/>
    <L7p:value stringValue="Authorization for Webseal Consumers"/>
    </L7p:entry>
    </L7p:Properties>
    </L7p:assertionComment>
    </wsp:All>
    </wsp:All>
    </wsp:Policy>

    ------------------------------
    Application Development Senior Advisor
    Cigna
    ------------------------------


  • 2.  RE: Replace on string in message response containing a space not working

    Posted Sep 28, 2020 07:09 AM
    You can remove URL Encoding by passing you response attribute to URL Decode and then try to add you filter


    May I get a sample input and expected output so can provide a better solution

    ------------------------------
    Pre-Sales Consultant
    CA Southern Africa
    ------------------------------