How to use the same payload factory JSON multiple times

I have a payload factory in the requestpayloadsequence file in the WSO2 project. I have to use the same payload factory multiple times using some filter. Currently i have to repeat the same piece of code (shown below) for each filter. Is there any way that i can use the same payload factory without using the same code multiple times. Is there any way i can set this payload factory to some parameter value. Could any body help how to achieve this.Below is the payloadfacotry code I am currently using.

<payloadFactory media-type="json">
                    <format> {
                        "1st": "$1",
                        "2nd": "$2",
                        "3rd": "$3",
                        "4th": "$4",
                         }
                </format>
                    <args>
                        <arg evaluator="xml" expression="get-property('1')"/>
                        <arg evaluator="xml" expression="get-property('2')"/>

                        <arg evaluator="xml" expression="get-property('3')"/>
                        <arg evaluator="xml" expression="get-property('4')"/>

                    </args>
</payloadFactory>

Answers


You can use a sequence template :

<template xmlns="http://ws.apache.org/ns/synapse" name="PayloadTemplate">
    <parameter name="P1"/>
    <parameter name="P2"/>
    <parameter name="P3"/>
    <parameter name="P4"/>
    <sequence>
        <payloadFactory media-type="json">
            <format> {
                        "1st": "$1",
                        "2nd": "$2",
                        "3rd": "$3",
                        "4th": "$4",
                         }
                </format>
            <args>
                <arg evaluator="xml" expression="$func:P1"/>
                <arg evaluator="xml" expression="$func:P2"/>
                <arg evaluator="xml" expression="$func:P3"/>
                <arg evaluator="xml" expression="$func:P4"/>
            </args>
        </payloadFactory>
    </sequence>
</template>

Call this template in your mediation :

<call-template target="PayloadTemplate">
    <with-param name="P1" value="{get-property('WWW')}"/>
    <with-param name="P2" value="{get-property('XXX')}"/>
    <with-param name="P3" value="{get-property('YYY')}"/>
    <with-param name="P4" value="{get-property('ZZZ')}"/>
</call-template>

Try using Clone Mediator

URL :

https://docs.wso2.com/display/ESB403/Clone+Mediator


Need Your Help

Python PIL ImageTk.PhotoImage() is giving me a bus error?

python image python-imaging-library bus

So I am running python 2.6 on a macbook pro and trying to write the code in python to display an image from a file in a label on a tkinter gui. The image is called image.png. The program runs without

Nested WHILE loops in Python

python for-loop while-loop nested-loops

I am a beginner with Python and trying few programs. I have something like the following WHILE loop construct in Python (not exact).