WSO2 ESB / EI-将JSON主体从API传递到DataService

时间:2019-07-29 15:47:57

标签: wso2 wso2esb wso2ei

我正在尝试在Integrator中设置一个针对DataService的API。我已经设置了GET路由,但没有设置PUT路由。

API接受一个大的JSON字符串,我通过请求正文将其传递给API。似乎我无法让DataService直接从主体获取数据,它看起来像是一个查询参数。这很烦人,但我可以解决,所以我尝试将大JSON字符串作为查询参数发送到DataService。

我不知道如何将数据作为JSON字符串发送。我可以很容易地以XML格式发送它,但是DataService抱怨它没有接收到字符串。

那么,如何将其作为JSON字符串发送?甚至更好-有没有办法让DataService接受主体有效载荷而不是专门查询参数?

我也在使用Eclipse,并且json-eval似乎不起作用,因此我一直在避免使用它。希望这不是问题的一部分。

json-eval(.)
Save Failed
com.jayway.jsonpath.JsonPath.compile(Ljava/lang/String;[Lcom/jayway/jsonpath/Predicate;)Lcom/jayway/jsonpath/JsonPath;

我当前在Integrator中使用的API资源:

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="orders.put.IN" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
    <property expression="get-property('query.param.ID')" name="uri.var.id"/>
    <property expression="json-eval($.)" name="uri.var.full_data"/>
    <property value="1" name="uri.var.last_updated_by"/>
    <log level="custom">
        <property name="MESSAGE" value="Executing orders.put.IN sequence"/>
        <property expression="get-property('uri.var.id')" name="ID"/>
        <property expression="get-property('uri.var.full_data')" name="FULL_DATA"/>
        <property expression="get-property('uri.var.last_updated_by')" name="LAST_UPDATED_BY"/>
    </log>
    <property name="messageType" scope="axis2" type="STRING" value="application/json"/>
    <property name="Content-Type" scope="transport" type="STRING" value="application/json"/>
    <send>
        <endpoint name="orders.put.byuserid">
            <http method="put" statistics="enable" trace="enable" 
                uri-template="https://________:8243/services/ORDERS_DataService/{uri.var.id}?LAST_UPDATED_BY={uri.var.last_updated_by}&amp;FULL_DATA={uri.var.full_data}"/>
        </endpoint>
    </send>
</sequence>

我当前的DataService:

<data description="____.ORDERS" disableLegacyBoxcarringMode="false" enableBatchRequests="false" enableBoxcarring="false" name="ORDERS_DataService" serviceNamespace="____" serviceStatus="active" transports="http https">
  <config enableOData="false" id="default">
    <property name="carbon_datasource_name">____</property>
  </config>
  <query id="update_ORDERS_query" useConfig="default">
    <sql>UPDATE ____.ORDERS SET FULL_DATA=?, LAST_UPADTE_DATE=SYSDATE, LAST_UPDATED_BY=? WHERE ID=?</sql>
    <param name="FULL_DATA" ordinal="1" sqlType="STRING"/>
    <param name="LAST_UPDATED_BY" ordinal="2" sqlType="STRING" />
    <param name="ID" ordinal="3" sqlType="STRING"/>
  </query>
  <resource method="PUT" path="/{ID}">
    <call-query href="update_ORDERS_query">
      <with-param name="FULL_DATA" query-param="FULL_DATA" />
      <with-param name="LAST_UPDATED_BY" query-param="LAST_UPDATED_BY" />
      <with-param name="ID" query-param="ID" />
    </call-query>
  </resource>
</data>

完整错误:

java.lang.IllegalArgumentException: Value type miss match, Expected value type - '', but found - 'STRING'
        at org.apache.axis2.json.gson.GsonXMLStreamReader.nextValue(GsonXMLStreamReader.java:750)
        at org.apache.axis2.json.gson.GsonXMLStreamReader.readValue(GsonXMLStreamReader.java:625)
        at org.apache.axis2.json.gson.GsonXMLStreamReader.stateTransition(GsonXMLStreamReader.java:531)
        at org.apache.axis2.json.gson.GsonXMLStreamReader.next(GsonXMLStreamReader.java:177)
        at org.apache.axiom.om.impl.builder.StAXOMBuilder.parserNext(StAXOMBuilder.java:681)
        at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:214)
        at org.apache.axiom.om.impl.llom.OMSerializableImpl.build(OMSerializableImpl.java:78)
        at org.apache.axiom.om.impl.llom.OMElementImpl.build(OMElementImpl.java:722)
        at org.apache.axiom.om.impl.llom.OMElementImpl.detach(OMElementImpl.java:700)
        at org.apache.axiom.om.impl.llom.OMNodeImpl.setParent(OMNodeImpl.java:105)
        at org.apache.axiom.om.impl.llom.OMElementImpl.addChild(OMElementImpl.java:296)
        at org.apache.axiom.om.impl.llom.OMElementImpl.addChild(OMElementImpl.java:212)
        at org.apache.axiom.soap.impl.llom.SOAPBodyImpl.addChild(SOAPBodyImpl.java:231)
        at org.apache.axis2.json.gson.JSONMessageHandler.invoke(JSONMessageHandler.java:84)
        at org.apache.axis2.engine.Phase.invokeHandler(Phase.java:340)
        at org.apache.axis2.engine.Phase.invoke(Phase.java:313)
        at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:261)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:167)
        at org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosingRESTHandler(ServerWorker.java:338)
        at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:383)
        at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:152)
        at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

1 个答案:

答案 0 :(得分:1)

自己找到答案。显然,需要丰富序列并克隆人体。

<enrich description="Get Body Payload from original REST request">
    <source clone="true" type="body"/>
    <target property="payload" type="property"/>
</enrich>

从那里可以将其用作名为“有效载荷”的属性

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