Home > database >  Unable to get pass iterate mediator in wso2
Unable to get pass iterate mediator in wso2

Time:01-24

I am writing an iterate mediator, the code is going in the sequence written in that iterate mediator, it is completing too (read through logs) however, it is not going to next step. Please help me with what wrong am I doing.

        <iterate expression="//mpesa/prov">
            <target>
                <sequence>
                    <sequence key="ProvMapperQueue"/>
                </sequence>
            </target>
        </iterate>
        <log level="custom">
            <property name="After" value="Sequence"/>
        </log>

It is now printing the logs neither is API getting a response, its stuck after sequence last line is logged.

For further information copying the sequence below too:

<sequence name="ProvMapperQueue" one rror="ProvMapperQueue_Error" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
    <log level="custom">
        <property expression="$ctx:uri.var.msisdn" name="Msisdn"/>
        <property name="ProvMapperQueue Sequence" value="Started"/>
    </log>
    <property name="messageType" scope="axis2" type="STRING" value="text/xml"/>
    <property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
    <call>
        <endpoint key="OBD_EP"/>
    </call>
    <log level="custom">
        <property expression="$ctx:uri.var.msisdn" name="Msisdn"/>
        <property name="After Calling" value=" ProvMapperQueue EP"/>
        <property name="ProvMapperQueue Sequence" value="Ended"/>
    </log>
    <respond/>
</sequence>

Logs printing are below :

[2023-01-24 00:14:07,883]  INFO {LogMediator} - {api:OBD} Msisdn = 110000171, ProvMapperQueue Sequence = Started
[2023-01-24 00:14:07,893]  INFO {TimeoutHandler} - This engine will expire all callbacks after GLOBAL_TIMEOUT: 120 seconds, irrespective of the timeout action, after the specified or optional timeout
[2023-01-24 00:14:08,181]  INFO {LogMediator} - {api:OBD} Msisdn = 110000171, After Calling =  ProvMapperQueue EP, ProvMapperQueue Sequence = Ended
[2023-01-24 00:17:06,839]  INFO {SourceHandler} - Writer null when calling informWriterError
[2023-01-24 00:17:06,841]  WARN {SourceHandler} - STATE_DESCRIPTION = Socket Timeout occurred after accepting the request headers and the request body, INTERNAL_STATE = REQUEST_DONE, DIRECTION = REQUEST, CAUSE_OF_ERROR = Connection between the client and the EI timeouts, HTTP_URL = /obd/prov/msisdn/110000171, HTTP_METHOD = GET, SOCKET_TIMEOUT = 180000, CLIENT_ADDRESS = /127.0.0.1:59198, CONNECTION http-incoming-4

Any help would mean a lot.

CodePudding user response:

I think the problem is with the <respond/> mediator that you have added towards the end of the ProvMapperQueue sequence. This will stop further processing of a message and send the message back to the client[1]. That means, after it, the rest of the sequence logic will not be executed including the log mediator outside the iterate mediator.

[1] - https://docs.wso2.com/display/EI611/Respond Mediator

CodePudding user response:

Few issues with your integration. You need to remove the respond mediator from the Iterate sequence, as responding per iteration doesn't make sense. So, I believe what you need is to iterate over the entries and once done, respond back to the client. In order to wait for all the Iterations to finish you need to couple the iterate mediator with an aggregate mediator. Hence update the sequences like below.

<sequence name="ProvMapperQueue" one rror="ProvMapperQueue_Error" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
    <log level="custom">
        <property expression="$ctx:uri.var.msisdn" name="Msisdn"/>
        <property name="ProvMapperQueue Sequence" value="Started"/>
    </log>
    <property name="messageType" scope="axis2" type="STRING" value="text/xml"/>
    <property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
    <call>
        <endpoint key="OBD_EP"/>
    </call>
    <log level="custom">
        <property expression="$ctx:uri.var.msisdn" name="Msisdn"/>
        <property name="After Calling" value=" ProvMapperQueue EP"/>
        <property name="ProvMapperQueue Sequence" value="Ended"/>
    </log>
</sequence>
<iterate expression="//mpesa/prov" id="iterateid">
    <target>
        <sequence>
            <sequence key="ProvMapperQueue"/>
        </sequence>
    </target>
</iterate>
<aggregate id="iterateid">
    <completeCondition>
        <messageCount max="-1" min="-1"/>
    </completeCondition>
    <onComplete expression="$body/*[1]">
        <payloadFactory media-type="xml">
        <format>
            <payload xmlns="">
                <response>Done</response>
            </payload>
        </format>
        <args/>
        </payloadFactory>
        <respond/>
    </onComplete>
</aggregate>

Update

The issue is you have set the OUT_ONLY property in your sequence hence the aggregate is never completed since callbacks are not registered. Instead of Iterate Mediator use the Foreach Mediator for your usecase. Check the example below.

<foreach expression="//mpesa/prov">
    <sequence>
        <sequence key="ProvMapperQueue"/>
    </sequence>
</foreach>
<log level="custom">
    <property name="After" value="Sequence"/>
</log>
<payloadFactory media-type="xml">
    <format>
        <payload xmlns="">
            <response>Done</response>
        </payload>
    </format>
    <args/>
</payloadFactory>
<respond/>
  • Related