How to define ​condition for multiple JavaScript,Extract Variable and Assign Message Policy.

Hi All,

I have a usecase where I have more than one JavaScript, Extract Variable and Assign Message Policies.

But on every request my JavaScript-1.js, Extract Variable-1 and Assign Message-1 is executing.

Below is a code which I used to manage conditions:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <Description/>
    <FaultRules/>
    <PreFlow name="PreFlow">
        <Request>
            <Step>
                <Name>JavaScript-1</Name>
                <Condition>(request.header.Content-type = "application/json")</Condition>
            </Step>
            <Step>
                <Name>Extract-Variables-1</Name>
                <Condition>(request.header.Content-type = "application/json")</Condition>
            </Step>
            <Step>
                <Name>JavaScript-2</Name>
                <Condition>(request.header.Content-type = "application/xml")</Condition>
            </Step>
            <Step>
                <Name>Extract-Variables-2</Name>
                <Condition>(request.header.Content-type = "application/xml")</Condition>
            </Step>
        </Request>
        <Response>
            <Step>
                <Name>Assign-Message-1</Name>
                <Condition>(response.header.Content-type = "application/xml")</Condition>
            </Step>
            <Step>
                <Name>Assign-Message-2</Name>
                <Condition>(response.header.Content-type = "application/json")</Condition>
            </Step>
        </Response>
    </PreFlow>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <Flows/>
    <HTTPProxyConnection>
        <BasePath>/v3/jsonmergexml</BasePath>
        <Properties/>
        <VirtualHost>default</VirtualHost>
        <VirtualHost>secure</VirtualHost>
    </HTTPProxyConnection>
    <RouteRule name="default">
        <TargetEndpoint>default</TargetEndpoint>
    </RouteRule>
</ProxyEndpoint>

Any Advice what i'm doing wrong in condition flow?

Thanks and Regards

Rishika

@Anil Sagar @ Google,@Dino-at-Google,@Brendan,@deboraelkin,@Siddharth Barahalikar,@Priyadarshi Ajitav Jena,@Anil Sagar,@sudheendras,@Mukundha Madhavan

0 4 481
4 REPLIES 4

Hi @Rishika Kumari, I replicated above code into a sample proxy and tested myself, conditions are fine and it works for me, so AFAIK nothing wrong in your conditions at least; Can you enable trace and see what is the value of `request.header.Content-type` and `response.header.Content-type` ?

@Rishika Kumari - what evidence leads you to conclude that those three policies are being executed for all requests regardless of the content-type header? On what basis are you concluding that?

What you describe is highly unusual. Therefore I think it is highly unlikely. Maybe there is a misunderstanding somewhere.

Can you post your trace?

Not applicable

@Rishika Kumari I tried taking the same configurations and policies. For me with condition javascript and extract variable policy work as expected. The assign message policy is at response side, so it depends upon the content type of the response. as my backend was sending JSON content for me assign message-2 was executing every time. For me, your conditions are working fine. Below is my code extracted from your code.

 <PreFlow name="PreFlow">
        <Request>
            <Step>
               <Name>JavaScript-1</Name>
               <Condition>(request.header.Content-type = "application/json")</Condition>
            </Step>
            <Step>
               <Name>Extract-Variables-1</Name>
               <Condition>(request.header.Content-type = "application/json")</Condition>
            </Step>
            <Step>
               <Name>JavaScript-2</Name>
               <Condition>(request.header.Content-type = "application/xml")</Condition>
            </Step>
            <Step>
               <Name>Extract-Variables-2</Name>
               <Condition>(request.header.Content-type = "application/xml")</Condition>
            </Step>
        </Request>
        <Response>
            <Step>
               <Name>Assign-Message-1</Name>
               <Condition>(response.header.Content-type = "application/xml")</Condition>
            </Step>
            <Step>
              <Name>Assign-Message-2</Name>
              <Condition>(response.header.Content-type = "application/json")</Condition>
            </Step>
        </Response>
    </PreFlow>

Can you share your trace, that may help more?