官术网_书友最值得收藏!

  • WSO2 Developer’s Guide
  • Fidel Prieto Estrada Ramón Garrido Lázaro
  • 176字
  • 2021-07-08 10:06:01

The script mediator

We can use different scripting languages to process the payload and get some information or make a transformation, such as JavaScript, Groovy, and Ruby.

Inline script syntax is as follows:

<script language="js">
  <![CDATA[
       //script code
   ]]>
<script/>

This is the registry script syntax:

<script key="path/to/script" language="(js | groovy | rb)" [function="nameOfTheFunction"]>
     [<include key="string"/>]
</script>  

The following is a list of the available methods:

  • getPayloadXML(): Returns the current XML payload.
  • setPayloadXML(payload): Set the body with the content of the payload parameter.
  • addHeader(mustUnderstand, content): Add a new SOAP header.
  • getEnvelopeXML(): Return the full payload.
  • setTo(reference): Set the value of the To header (receiver).
  • setFaultTo(reference): Set the value to the FaultTo header.
  • setFrom(reference): Set the value to the From header (sender).
  • setReplyTo(reference): Set the value to the ReplyTo header.
  • getPayloadJSON(): Return the current JSON payload.
  • setPayloadJSON(payload): Set the body with the content of the payload parameter.
  • getProperty(name): Get the value of a property.
  • setProperty(key, value): Create or update the content of the property from the first param with the value of the second param.

For example, this is the script to print the current value of a property and set the new value:

<script language="js">
   <![CDATA[
     var property = mc.getProperty("static");
     print("property: " + property);
     mc.setProperty("static", "newValue");
   ]]>
</script>
主站蜘蛛池模板: 洛阳市| 麟游县| 深圳市| 新宁县| 明光市| 蛟河市| 咸阳市| 吉水县| 榆林市| 合江县| 凌海市| 宜城市| 固始县| 安溪县| 平湖市| 北京市| 黄冈市| 英超| 偃师市| 佛冈县| 琼海市| 崇阳县| 曲水县| 阿图什市| 黔江区| 三江| 祁东县| 茶陵县| 建瓯市| 兴海县| 米泉市| 平塘县| 吴川市| 长沙市| 兴宁市| 卢氏县| 漳浦县| 太保市| 宜川县| 崇阳县| 永宁县|