[英]WSO2 MI How to create an Insert or Update PUT resource?
我想在 WSO2 Micro Integrator 中创建一个 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>'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.