调用数据服务时 WSO2 EI 序列失败
WSO2 EI Sequence failing when calling a Data Service
运行 WSO2 EI 6.2.0
我的顺序很简单:
- 从初始请求接收到 1 个参数 (mac)
- 调用DS提取第二个参数(time_hour)
- 使用两个参数 (mac) 和 (time_hour) 调用 DS
当手动调用两个 DS 时,它工作得很好。
通过 ESB 调用第二个 DS 时出现奇怪的错误。
顺序:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="somesq" trace="enable" xmlns="http://ws.apache.org/ns/synapse">
<property expression="$url:mac" name="uri.var.mac" scope="default"
type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
<property name="mac" scope="default" type="STRING" value="get-property('uri.var.mac')"/>
<call>
<endpoint>
<http method="GET" uri-template="http://somedomain.internal.com/someservice?var={uri.var.mac}"/>
</endpoint>
</call>
<enrich>
<source clone="true" type="body"/>
<target action="replace" property="payload" type="property"/>
</enrich>
<log level="custom">
<property expression="get-property('payload')" name="bbb" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
<property expression="$ctx:payload//ns2:hour" name="time_hour"
scope="default" type="STRING"
xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns2="http://ws.wso2.org/dataservice"/>
<header action="remove" name="Content-Type" scope="transport"/>
<log level="custom">
<property expression="get-property('uri.var.mac')" name="mac" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
<log level="custom">
<property expression="get-property('time_hour')"
name="time_hour" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
<call>
<endpoint>
<http method="GET" uri-template="http://somedomain.internal.com/someservice?var={uri.var.mac}&hour={time_hour}"/>
</endpoint>
</call>
<log level="custom">
<property name="xxx" value="FIM"/>
</log>
<respond/>
</sequence>
我尝试在调用 DS 之前记录参数并且它们被正确打印,但是当我在 DS 调用中使用它时,hour={time_hour}
参数为空。
输出和错误:
(...)
TID: [-1234] [] [2018-12-05 12:24:02,562] INFO {org.apache.synapse.mediators.builtin.LogMediator} - mac = 000000000000 {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2018-12-05 12:24:02,562] INFO {org.apache.synapse.mediators.builtin.LogMediator} - time_hour = 2018-12-03T11:00:00.000+00:00 {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2018-12-05 12:24:02,569] ERROR {org.wso2.carbon.dataservices.core.DBInOutMessageReceiver} - Error in in-out message receiver {org.wso2.carbon.dataservices.core.DBInOutMessageReceiver}
DS Code: DATABASE_ERROR
Nested Exception:-
javax.xml.stream.XMLStreamException: DS Fault Message: Error in 'SQLQuery.processPreNormalQuery': DS Fault Message: Error processing parameter - hour, Error - DS Fault Message: Empty string or null value was found as timeStamp.
DS Code: UNKNOWN_ERROR
DS Code: UNKNOWN_ERROR
Nested Exception:-
DS Fault Message: Empty string or null value was found as timeStamp.
DS Code: UNKNOWN_ERROR
DS Code: DATABASE_ERROR
Source Data Service:-
Name: some_seq
Location: /some_seq.dbs
Description: Some Seq
Default Namespace: http://ws.wso2.org/dataservice
Current Request Name: somesq
Current Params: {hour=, mac=000000000000}
Nested Exception:-
DS Fault Message: Error processing parameter - hour, Error - DS Fault Message: Empty string or null value was found as timeStamp.
DS Code: UNKNOWN_ERROR
(...)
有人知道如何正确地将 time_hour 参数引用到 ESB 序列中的数据服务吗?
变量 time_hour 未被计算的原因的解释
The URI templates allow a RESTful URI to contain variables that can be
populated during mediation runtime using property values whose names
have the "uri.var" prefix.
根据 Jan 的回复工作的最终序列:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="some_seq" trace="enable" xmlns="http://ws.apache.org/ns/synapse">
<property expression="$url:mac" name="uri.var.mac" scope="default"
type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
<call>
<endpoint>
<http method="GET" uri-template="http://somedomain.internal.com/someservice?var=={uri.var.mac}"/>
</endpoint>
</call>
<enrich>
<source clone="true" type="body"/>
<target action="replace" property="payload" type="property"/>
</enrich>
<property expression="$ctx:payload//ns2:hour"
name="uri.var.time_hour" scope="default" type="STRING"
xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns2="http://ws.wso2.org/dataservice"/>
<header action="remove" name="Content-Type" scope="transport"/>
<call>
<endpoint>
<http method="GET" uri-template="http://somedomain.internal.com/someservice?var=={uri.var.mac}&hour={uri.var.time_hour}"/>
<property name="time_h" value="{time_hour}"/>
</endpoint>
</call>
<respond/>
</sequence>
它需要 'uri.var' 作为变量名才能用作 uri 模板变量。
所以用当前时间创建一个属性。 (我很惊讶 'time_hour' 对你有用,在我的例子中我使用了 SYSTEM_DATE,time_hour 恢复为 'null' )
<property expression="get-property('SYSTEM_DATE')" name="uri.var.time_hour"/>
并在您的端点中使用它。
运行 WSO2 EI 6.2.0
我的顺序很简单:
- 从初始请求接收到 1 个参数 (mac)
- 调用DS提取第二个参数(time_hour)
- 使用两个参数 (mac) 和 (time_hour) 调用 DS
当手动调用两个 DS 时,它工作得很好。
通过 ESB 调用第二个 DS 时出现奇怪的错误。
顺序:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="somesq" trace="enable" xmlns="http://ws.apache.org/ns/synapse">
<property expression="$url:mac" name="uri.var.mac" scope="default"
type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
<property name="mac" scope="default" type="STRING" value="get-property('uri.var.mac')"/>
<call>
<endpoint>
<http method="GET" uri-template="http://somedomain.internal.com/someservice?var={uri.var.mac}"/>
</endpoint>
</call>
<enrich>
<source clone="true" type="body"/>
<target action="replace" property="payload" type="property"/>
</enrich>
<log level="custom">
<property expression="get-property('payload')" name="bbb" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
<property expression="$ctx:payload//ns2:hour" name="time_hour"
scope="default" type="STRING"
xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns2="http://ws.wso2.org/dataservice"/>
<header action="remove" name="Content-Type" scope="transport"/>
<log level="custom">
<property expression="get-property('uri.var.mac')" name="mac" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
<log level="custom">
<property expression="get-property('time_hour')"
name="time_hour" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
<call>
<endpoint>
<http method="GET" uri-template="http://somedomain.internal.com/someservice?var={uri.var.mac}&hour={time_hour}"/>
</endpoint>
</call>
<log level="custom">
<property name="xxx" value="FIM"/>
</log>
<respond/>
</sequence>
我尝试在调用 DS 之前记录参数并且它们被正确打印,但是当我在 DS 调用中使用它时,hour={time_hour}
参数为空。
输出和错误:
(...)
TID: [-1234] [] [2018-12-05 12:24:02,562] INFO {org.apache.synapse.mediators.builtin.LogMediator} - mac = 000000000000 {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2018-12-05 12:24:02,562] INFO {org.apache.synapse.mediators.builtin.LogMediator} - time_hour = 2018-12-03T11:00:00.000+00:00 {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2018-12-05 12:24:02,569] ERROR {org.wso2.carbon.dataservices.core.DBInOutMessageReceiver} - Error in in-out message receiver {org.wso2.carbon.dataservices.core.DBInOutMessageReceiver}
DS Code: DATABASE_ERROR
Nested Exception:-
javax.xml.stream.XMLStreamException: DS Fault Message: Error in 'SQLQuery.processPreNormalQuery': DS Fault Message: Error processing parameter - hour, Error - DS Fault Message: Empty string or null value was found as timeStamp.
DS Code: UNKNOWN_ERROR
DS Code: UNKNOWN_ERROR
Nested Exception:-
DS Fault Message: Empty string or null value was found as timeStamp.
DS Code: UNKNOWN_ERROR
DS Code: DATABASE_ERROR
Source Data Service:-
Name: some_seq
Location: /some_seq.dbs
Description: Some Seq
Default Namespace: http://ws.wso2.org/dataservice
Current Request Name: somesq
Current Params: {hour=, mac=000000000000}
Nested Exception:-
DS Fault Message: Error processing parameter - hour, Error - DS Fault Message: Empty string or null value was found as timeStamp.
DS Code: UNKNOWN_ERROR
(...)
有人知道如何正确地将 time_hour 参数引用到 ESB 序列中的数据服务吗?
变量 time_hour 未被计算的原因的解释
The URI templates allow a RESTful URI to contain variables that can be populated during mediation runtime using property values whose names have the "uri.var" prefix.
根据 Jan 的回复工作的最终序列:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="some_seq" trace="enable" xmlns="http://ws.apache.org/ns/synapse">
<property expression="$url:mac" name="uri.var.mac" scope="default"
type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
<call>
<endpoint>
<http method="GET" uri-template="http://somedomain.internal.com/someservice?var=={uri.var.mac}"/>
</endpoint>
</call>
<enrich>
<source clone="true" type="body"/>
<target action="replace" property="payload" type="property"/>
</enrich>
<property expression="$ctx:payload//ns2:hour"
name="uri.var.time_hour" scope="default" type="STRING"
xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns2="http://ws.wso2.org/dataservice"/>
<header action="remove" name="Content-Type" scope="transport"/>
<call>
<endpoint>
<http method="GET" uri-template="http://somedomain.internal.com/someservice?var=={uri.var.mac}&hour={uri.var.time_hour}"/>
<property name="time_h" value="{time_hour}"/>
</endpoint>
</call>
<respond/>
</sequence>
它需要 'uri.var' 作为变量名才能用作 uri 模板变量。
所以用当前时间创建一个属性。 (我很惊讶 'time_hour' 对你有用,在我的例子中我使用了 SYSTEM_DATE,time_hour 恢复为 'null' )
<property expression="get-property('SYSTEM_DATE')" name="uri.var.time_hour"/>
并在您的端点中使用它。