WSO2 MI如何创建Insert或Update PUT资源?



我想在WSO2 microintegrator中创建一个PUT资源,这样我就可以插入或更新事件记录,但它甚至不接受我的http请求。你能帮我正确配置这个吗?

我所期望的是,当我调用这样的东西时,它会批量插入到数据库中。

curl --location --request PUT 'http://wso2-mi.mkwtf.com/services/APIDataService/eventRecord?calendar_date=2022-12-01' 
--header 'Content-Type: application/xml' 
--data-raw '
<event_record_list>
<event_record>
<event_type>1000124</event_type>
<event_count>217140</event_count>
</event_record>
<event_record>
<event_type>1000127</event_type>
<event_count>1567</event_count>
<event_record>
</event_record>
<event_type>1000129</event_type>
<event_count>31</event_count>
</event_record>
</event_record_list>'

但实际上它是这样回应的:

<axis2ns52:DataServiceFault xmlns:axis2ns52="http://ws.wso2.org/dataservice">
<axis2ns52:current_params>{event_type=1000124, event_count=217140}</axis2ns52:current_params>
<axis2ns52:source_data_service>
<axis2ns52:data_service_name>APIDataService</axis2ns52:data_service_name>
<axis2ns52:description></axis2ns52:description>
<axis2ns52:location>/home/wso2/qa/wso2mi/tmp/carbonapps/-1234/1671624403635APICompositeExporter_1.0.0.car/APIDataService_1.0.0/APIDataService-1.0.0.dbs</axis2ns52:location>
<axis2ns52:default_namespace>http://ws.wso2.org/dataservice</axis2ns52:default_namespace>
</axis2ns52:source_data_service>
<axis2ns52:ds_code>INCOMPATIBLE_PARAMETERS_ERROR</axis2ns52:ds_code>
<axis2ns52:current_request_name>_puteventrecord</axis2ns52:current_request_name>
</axis2ns52:DataServiceFault>

然而,当我发出这个请求时,我能够发出请求,它返回给我202,但是我一次只能插入或更新一行。

curl --location --request PUT 'http://wso2-mi.mkwtf.com/services/APIDataService/eventRecord?calendar_date=2022-12-01&event_type=1000124&event_count=217140' 
--header 'Content-Type: application/x-www-form-urlencoded' 
--data-urlencode 'calendar_date=2022-12-01' 
--data-urlencode 'event_type=1000124' 
--data-urlencode 'event_count=217140'

下面是数据服务的定义:

<data name="APIDataService" serviceNamespace="" serviceGroup="" transports="http https local">
<description />

<config id="postgresDataService">
<property name="carbon_datasource_name">APIPostgres</property>
</config>

<query id="eventRecord" useConfig="postgresDataService">
<sql>
INSERT INTO event_record(calendar_date, event_type, event_count)
VALUES (:calendar_date, :event_type, :event_count)
ON CONFLICT (calendar_date, event_type)
DO UPDATE SET event_count = EXCLUDED.event_count
</sql>

<param name="calendar_date" sqlType="date"    />
<param name="event_type"    sqlType="integer" />
<param name="event_count"   sqlType="integer" />

<properties>
<property name="forceJDBCBatchRequests">true</property>
</properties>
</query>
<resource method="PUT" path="eventRecord">
<call-query href="eventRecord">
<with-param name="calendar_date" query-param="calendar_date" />
<with-param name="event_type"    query-param="event_type"    />
<with-param name="event_count"   query-param="event_count"   />
</call-query>
</resource>
</data>

由于MI[1]的限制,您不能同时使用请求体和URL参数来调用数据服务。当在请求中设置内容类型时,它会尝试根据请求体将其分派给数据服务操作,并忽略URL参数。因此,您将观察到INCOMPATIBLE_PARAMETERS_ERROR错误。因此,您需要在请求体中传递eventRecord操作所需的所有参数。你可以试着发送如下请求吗?

curl --location --request PUT 'http://wso2-mi.mkwtf.com/services/APIDataService/eventRecord' 
--header 'Content-Type: application/xml' 
--data-raw '
<event_record_list>
<event_record>
<calendar_date>2022-12-01</calendar_date>
<event_type>1000124</event_type>
<event_count>217140</event_count>
</event_record>
<event_record>
<calendar_date>2022-12-01</calendar_date>
<event_type>1000127</event_type>
<event_count>1567</event_count>
<event_record>
</event_record>
<calendar_date>2022-12-01</calendar_date>
<event_type>1000129</event_type>
<event_count>31</event_count>
</event_record>
</event_record_list>'

[1] - https://github.com/wso2/product-ei/issues/2811

最新更新