【问题标题】:Mulesoft: Using MEL to access an array in JSON payloadMulesoft:使用 MEL 访问 JSON 有效负载中的数组
【发布时间】:2016-08-31 18:53:20
【问题描述】:

我正在尝试调用 MySQL DB 上的存储过程,但我的 MEL 表达式不起作用。 我已经引用了-https://docs.mulesoft.com/mule-user-guide/v/3.7/json-module-reference

My setup
**********************************************************************
* Mule Runtime and Integration Platform                              *
* Version: 3.8.0 Build: 9461215f                                     *
* MuleSoft, Inc.                                                     *
* For more information go to                                         *
* http://www.mulesoft.com/mule-esb-enterprise                        *
*                                                                    *
* Server started: 8/31/16 11:23 AM                                   *
* JDK: 1.8.0_91 (mixed mode)                                         *
* OS: Mac OS X (10.11.6, x86_64)                                     *
* Host: AMAC02PF791G3QC (10.13.164.24)                               *
**********************************************************************

错误

Message               : Execution of the expression "message.payload.lines[0].SKU" failed. (org.mule.api.expression.ExpressionRuntimeException).
Payload               : {
                          "po_id": 1234,
                          "lines": [
                            {
                              "SKU": "1000",
                              "Primary SSA": "990471-Franjo",
                              "pre_pro": 1,
                              "pre_pro_need_by": "01/01/2016",
                              "top": 0,
                              "top_need_by": "01/01/2016",
                              "sample_size:": "small"
                            },
                            {
                              "SKU": "1000",
                              "Primary SSA": "990471-Franjo",
                              "pre_pro": 1,
                              "pre_pro_need_by": "01/01/2016",
                              "top": 0,
                              "top_need_by": "01/01/2016",
                              "sample_size:": "small"
                            }
                          ]
                        }
Payload Type          : java.lang.String
Element               : /post:\/samples:application\/json:api-config/processors/0 @ r-exp-1.3:api.xml:193
Element XML           : <db:stored-procedure config-ref="MySQL_Configuration" doc:name="Create Samples">
                        <db:parameterized-query>call  P_CREATE_SAMPLE_WRAP (@requestID,:primarySsa,:purchaseOrderId,:sku1,:sampleSize,:sampleColors,:createdBy,:lastUpdatedBy,:preProNeedBy,:preProType,:topNeedBy,:topType);</db:parameterized-query>
                        <db:in-param name="primarySsa" type="VARCHAR" value="'990471'"></db:in-param>
                        <db:in-param name="purchaseOrderId" type="INTEGER" value="#[message.payload.po_id]"></db:in-param>
                        <db:in-param name="sku1" type="INTEGER" value="#[message.payload.lines[0].SKU]"></db:in-param>
                        <db:in-param name="sampleSize" type="VARCHAR" value="#[message.payload.lines[0].sample_size]"></db:in-param>
                        <db:in-param name="sampleColors" type="VARCHAR" value="null"></db:in-param>
                        <db:in-param name="lastUpdatedBy" type="VARCHAR" value="null"></db:in-param>
                        <db:in-param name="createdBy" type="VARCHAR" value="null"></db:in-param>
                        <db:in-param name="preProNeedBy" type="DATE" value="#[message.payload.lines[0].pre_pro_need_by]"></db:in-param>
                        <db:in-param name="preProType" type="VARCHAR" value="null"></db:in-param>
                        <db:in-param name="topNeedBy" type="DATE" value="#[message.payload.lines[0].top_need_by]"></db:in-param>
                        <db:in-param name="topType" type="VARCHAR" value="null"></db:in-param>
                        <db:out-param name="requestID" type="INTEGER"></db:out-param>
                        </db:stored-procedure>I’ve also tried this expression with the same payload

我也试过

Message               : Execution of the expression "message.payload.lines[0]/SKU" failed. (org.mule.api.expression.ExpressionRuntimeException).

我只使用 mulesoft 2 周,因此非常感谢任何建议。 谢谢!

【问题讨论】:

    标签: mule


    【解决方案1】:

    发生错误是因为payload是String形式,执行message.payload.lines[0]/SKU失败。

    因为消息格式是JSON,那你可以试试用json:lines[0]/SKU代替

    【讨论】:

      【解决方案2】:

      您的有效负载是字符串类型。将其转换为 json 或 java 对象,然后您可以使用相同的方式访问它。

      【讨论】:

        【解决方案3】:

        MEL 不支持 JSON。 要访问 Json 的任何字段,您可以使用以下表达式:

        [dw('message.payload.lines[0].SKU')]
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-04-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多