Ketika mengirim value json ke dataservice value di encode
Ada request json yang akan dikirim ke dataservice, contoh request :
{
"email": "[email protected]",
"extid": "55192922181742",
"type": "",
"va": "",
"itemtype": "1",
"serviceid": "15",
"shippername": "Fachmi"
}
source code artifact :
<property expression="json-eval($)" name="body_request" scope="default" type="STRING"/>
<sequences>
<dataServiceCall serviceName="webhook">
<operations type="single">
<operation name="updatewebhook">
<param evaluator="xml" expression="get-property('body_request')" name="body_request"/>
</operation>
</operations>
<source type="inline"/>
<target type="body"/>
</dataServiceCall>
</sequences>
untuk dataservicenya :
<data name="webhook" serviceGroup="" transports="http https local">
<description/>
<config enableOData="false" id="dsWebhook">
<property name="carbon_datasource_name">dswebhook</property>
</config>
<query id="q_updatewebhook" useConfig="dsWebhook">
<sql>select * from updatewebhook (?)</sql>
<param name="body_request" sqlType="STRING"/>
</queries>
<operation name="updatewebhook">
<call-query href="q_updatewebhook">
<with-param name="body_request" query-param="body_request"/>
</call-query>
</operation>
</data>
namun ketika coba mengirim data keluar error :
Caused by: DS Fault Message: Error in 'SQLQuery.processPreNormalQuery': ERROR: invalid input syntax for type json
Detail: Token "&" is invalid.
Where: JSON data, line 1: {
&...
PL/pgSQL function updatewebhook(text) line 9 at assignment
DS Code: DATABASE_ERROR
Source Data Service:-
Name: qposinaja_webhook
Location: /home/wso2carbon/wso2mi-4.1.0/tmp/carbonapps/-1234/1680057918218QPosInAjaCompositeExporter-1.0.0.car/webhook_1.0.0/webhook-1.0.0.dbs
Description:
Current Request Name: updatewebhook
Current Params: {body_request={
"email": "[email protected]",
"extid": "QOB55192922181742",
"type": "",
"va": "",
"itemtype": "1",
"serviceid": "240",
"shippername": "Fachmi"
}}
Nested Exception:-
org.postgresql.util.PSQLException: ERROR: invalid input syntax for type json
Detail: Token "&" is invalid.
Where: JSON data, line 1: {
&...
PL/pgSQL function updatewebhook(text) line 9 at assignment
ini dikarenakan evaluator di set xml di <param evaluator="xml" expression="get-property('body_request')" name="body_request"/> sehingga ketika menerima value json diencode.
Solusinya ganti param value menjadi :
<param evaluator="json" expression="json-eval($)" name="body_request"/>
Sehingga seluruh source codenya menjadi seperti dibawah ini :
<property expression="json-eval($)" name="body_request" scope="default" type="STRING"/>
<enrich description="Deploy body">
<source clone="false" property="body_request" type="property"/>
<target type="body"/>
</enrich>
<sequences>
<dataServiceCall serviceName="webhook">
<operations type="single">
<operation name="updatewebhook">
<param evaluator="json" expression="json-eval($)" name="body_request"/>
</operation>
</operations>
<source type="inline"/>
<target type="body"/>
</dataServiceCall>
</sequences>
tetapi ada bug ketika menyimpan di Integration Studio 8.1.0 di bulan maret 2023, file artifact tidak akan tersimpan ketika kita coba save, untuk sementara kita edit menggunakan text editor lain, dan build ulang project di Integration Studio, bug ini sudah dilaporkan ke tim WSO2, sehingga ketika update terbaru, bug ini akan hilang.