Alexandre Juma
Alexandre Juma

Reputation: 3333

WSO2 EI Sequence failing when calling a Data Service

Running WSO2 EI 6.2.0

My sequence is very simple:

  1. Receive 1 parameter (mac) from initial request
  2. Call a DS to extract a second parameter (time_hour)
  3. Call a DS with both parameters (mac) and (time_hour)

When calling both DS manually, it works perfectly.

When calling the second DS through ESB I get a strange error.

The sequence:

<?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}&amp;hour={time_hour}"/>
        </endpoint>
    </call>
    <log level="custom">
        <property name="xxx" value="FIM"/>
    </log>
    <respond/>
</sequence>

I try to log the parameters before calling the DS and they are correctly printed, but when I use it in the DS Call, the hour={time_hour} parameter is empty.

The output and error:

(...)
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
(...)

Anyone knows how to correctly reference the time_hour parameter to the data services in the ESB Sequence?

Explanation of why the variable time_hour was not being evaluated

From WSO2 Documentation:

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.

The Final Sequence that is working based on Jan's response:

<?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}&amp;hour={uri.var.time_hour}"/>
            <property name="time_h" value="{time_hour}"/>
        </endpoint>
    </call>
    <respond/>
</sequence>

Upvotes: 2

Views: 1116

Answers (1)

Jan
Jan

Reputation: 653

It needs 'uri.var' as variable name for it to be usable as uri-template variable.

So create a property with the current time. (I'm surprised btw that 'time_hour' works for you, in my case I used SYSTEM_DATE, time_hour reverts to 'null' )

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

and use that in your endpoint.

Upvotes: 2

Related Questions