调用数据服务时,WSO2 EI序列失败

时间:2018-12-05 12:28:57

标签: wso2 wso2esb wso2dss wso2ei

运行WSO2 EI 6.2.0

我的序列很简单:

  1. 从初始请求中接收1个参数(mac)
  2. 调用DS提取第二个参数(time_hour)
  3. 使用参数(mac)和(time_hour)调用DS

手动调用两个DS时,效果很好。

通过ESB调用第二个DS时,出现一个奇怪的错误。

顺序:

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="udp_nxt_gethfcprofilecapacity" 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://rhtdflow001.corporativo.pt:8290/services/udp_nxt/gethfcprofilecapacity_hour?mac={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://rhtdflow001.corporativo.pt:8290/services/udp_nxt/gethfcprofilecapacity?mac={uri.var.mac}&amp;hour={time_hour}"/>
        </endpoint>
    </call>
    <log level="custom">
        <property name="xxx" value="FIM"/>
    </log>
    <respond/>
</sequence>

我尝试在调用DS之前记录参数,并正确打印它们,但是当我在DS Call中使用它们时,hour={time_hour}参数为空。

输出和错误:

(...)
TID: [-1234] [] [2018-12-05 12:24:02,562]  INFO {org.apache.synapse.mediators.builtin.LogMediator} -  mac = 0003081B9E70 {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: udp_nxt
Location: /udp_nxt.dbs
Description: UDP Call to NXT
Default Namespace: http://ws.wso2.org/dataservice
Current Request Name: _getgethfcprofilecapacity
Current Params: {hour=, mac=0003081B9E70}
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

来自WSO2 Documentation

  

URI模板允许RESTful URI包含可以为   使用其名称的属性值在中介运行时期间填充   具有“ uri.var”前缀

根据Jan的回复而起作用的最终序列:

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="udp_nxt_gethfcprofilecapacity" 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://rhtdflow001.corporativo.pt:8290/services/udp_nxt/gethfcprofilecapacity_hour?mac={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://rhtdflow001.corporativo.pt:8290/services/udp_nxt/gethfcprofilecapacity?mac={uri.var.mac}&amp;hour={uri.var.time_hour}"/>
            <property name="time_h" value="{time_hour}"/>
        </endpoint>
    </call>
    <respond/>
</sequence>

1 个答案:

答案 0 :(得分:2)

它需要'uri.var'作为变量名,才能用作uri-template变量。

因此,使用当前时间创建一个属性。 (让我感到惊讶的是,'time_hour'为您工作,在我使用SYSTEM_DATE的情况下,time_hour恢复为'null')

<property expression="get-property('SYSTEM_DATE')" name="uri.var.time_hour"/>

并在端点中使用它。

相关问题