Reputation: 19
I used code in resource
<resource faultSequence="fault_simple" methods="GET" protocol="https" uri-template="/all">
<inSequence>
<property expression="get-property('SYSTEM_TIME')" name="REQUEST_TIMESTAMP" scope="default" type="STRING"/>
<send>
<endpoint key="get_balancing"/>
</send>
</inSequence>
<outSequence>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<property expression="get-property('SYSTEM_TIME')" name="RESPONSE_TIMESTAMP" scope="default" type="STRING"/>
<script language="js"><![CDATA[var requestTimeStamp = mc.getProperty("REQUEST_TIMESTAMP");
var responseTimeStamp = mc.getProperty("RESPONSE_TIMESTAMP");
var responseTime = (responseTimeStamp - requestTimeStamp)/1000;
mc.setProperty("RESPONSE_TIME", responseTime);]]>
</script>
<log>
<property expression="$ctx:RESPONSE_TIMESTAMP" name="RESPONSE_TIMESTAMP"/>
<property expression="$ctx:REQUEST_TIMESTAMP" name="REQUEST_TIMESTAMP"/>
<property expression="$ctx:RESPONSE_TIME" name="RESPONSE_TIME"/>
</log>
<send/>
</outSequence>
</resource>
When send in endpoint working < 1 second, this works as well, But if send working more than 8-9 seconds I have a mistake
INFO {org.apache.synapse.mediators.builtin.LogMediator} - To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:613d12e7-d692-4ac7-8a20-6b798f811edb, Direction: response, RESPONSE_TIMESTAMP = 1592573342279, REQUEST_TIMESTAMP = 1592573333377
ERROR {org.apache.synapse.mediators.bsf.ScriptMediator} - The script engine returned an Exception executing the external js script : null function mediate java.lang.IllegalArgumentException: out of range index
INFO {org.apache.synapse.mediators.builtin.LogMediator} - To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:613d12e7-d692-4ac7-8a20-6b798f811edb, Direction: response, MESSAGE = Executing default 'fault' sequence, ERROR_CODE = 0, ERROR_MESSAGE = The script engine returned an Exception executing the external js script : null function mediate
When i remove mediator script from code, sevice working as well (send working more than 8-9 sec)
p.s. I tried use JS/Groovy/Python - result is the same.
Upvotes: 0
Views: 714
Reputation: 19
This error occurs due to the script mediator trying to read a large array of the response (always).
The solution is as follows:
<resource faultSequence="fault_simple" methods="GET" protocol="https" uri-template="/all">
<inSequence>
<property expression="get-property('SYSTEM_TIME')" name="REQUEST_TIMESTAMP" scope="default" type="STRING"/>
<send>
<endpoint key="get_balancing"/>
</send>
</inSequence>
<outSequence>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<property expression="get-property('SYSTEM_TIME')" name="RESPONSE_TIMESTAMP" scope="default" type="STRING"/>
<property name="RESPONSE_TIME" scope="default" expression="$ctx:RESPONSE_TIMESTAMP - $ctx:REQUEST_TIMESTAMP"/>
<log>
<property expression="$ctx:RESPONSE_TIMESTAMP" name="RESPONSE_TIMESTAMP"/>
<property expression="$ctx:REQUEST_TIMESTAMP" name="REQUEST_TIMESTAMP"/>
<property expression="$ctx:RESPONSE_TIME" name="RESPONSE_TIME"/>
</log>
<send/>
</outSequence>
</resource>
instead JS script - this
<property name="RESPONSE_TIME" scope="default" expression="$ctx:RESPONSE_TIMESTAMP - $ctx:REQUEST_TIMESTAMP"/>
Upvotes: 1