0
votes

I am pretty new in WSO2 EI and I am finding some problem trying to call a DSS service from an API defined in my ESB flow.

I have done in this way:

1) Into the agrimarketprice-dss.dbs file related to my DSS service I have this operation:

<operation name="GetCommodityDetails">
    <call-query href="SelectCommodityDetails">
        <with-param name="commodity_details_id" query-param="commodity_details_id"/>
    </call-query>
</operation>

that calls a query having id=commodity_details_id. It works fine, I tested it with the Try It tool and I obtain the expected result set.

2) Then I have defined this API defined by this ESB flow:

<?xml version="1.0" encoding="UTF-8"?>
<api context="/commodity_details" name="commodity_details" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="GET" protocol="http" uri-template="/{commodityId}">
        <inSequence>
            <property expression="get-property('uri.var.commodityId')" name="commodityId" scope="default" type="STRING"/>
            <log level="custom"/>
            <log description="commodity_details" level="custom" separator="-">
                <property name="commodity_details" value="'commodity_details START'"/>
            </log>
            <log level="custom">
                <property expression="$ctx:commodityId" name="COMMODITY ID"/>
            </log>

            <property name="messageType" scope="axis2" type="STRING" value="application/xml"/>
            <payloadFactory media-type="xml">
                <format>
                    <ds:GetCommodityDetails xmlns:ds="http://ws.wso2.org/dataservice">
                        <ds:commodity_details_id>$1</ds:commodity_details_id>
                    </ds:GetCommodityDetails>
                </format>
                <args>
                    <arg evaluator="xml" expression="$ctx:commodityId" xmlns:ds="http://ws.wso2.org/dataservice" xmlns:ns="http://org.apache.synapse/xsd"/>
                </args>
            </payloadFactory>
            <header name="Action" scope="default" value="urn:GetCommodityDetails"/>
            <call>
                <endpoint key="agrimarketprice_Endpoint"/>
            </call>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </resource>
</api>

As you can see in the previous ESB flow I am trying to call the previous previous operation defined into my DSS service in this way:

<property name="messageType" scope="axis2" type="STRING" value="application/xml"/>
<payloadFactory media-type="xml">
    <format>
        <ds:GetCommodityDetails xmlns:ds="http://ws.wso2.org/dataservice">
            <ds:commodity_details_id>$1</ds:commodity_details_id>
        </ds:GetCommodityDetails>
    </format>
    <args>
        <arg evaluator="xml" expression="$ctx:commodityId" xmlns:ds="http://ws.wso2.org/dataservice" xmlns:ns="http://org.apache.synapse/xsd"/>
    </args>
</payloadFactory>
<header name="Action" scope="default" value="urn:GetCommodityDetails"/>
<call>
    <endpoint key="agrimarketprice_Endpoint"/>
</call>

So I am creating a payload containing the retrieved ID represented by the $ctx:commodityId (it contains the correct value because I logged it). Then I set the header with the name of the operation that have to be executed ("urn:GetCommodityDetails"). Finnaly I perform the call toward the agrimarketprice_Endpoint that contains the details of the previous DSS service, this is the content:

<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="agrimarketprice_Endpoint" xmlns="http://ws.apache.org/ns/synapse">
    <address uri="http://localhost:8280/services/agrimarketprice-dss"/>
</endpoint> 

This endpoint is correct because I used it for another query in another API (but it have a different logic because in this other query I am extracting the parameters from a JSON document).

The provlem is that when I call my API I am obtaining the following error message into the Carbon log (I think when it try to perform the call that execute my query):

TID: [-1234] [] [2017-10-03 11:55:16,574]  INFO {org.apache.synapse.mediators.builtin.LogMediator} -   {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2017-10-03 11:55:16,574]  INFO {org.apache.synapse.mediators.builtin.LogMediator} -  commodity_details = 'commodity_details START' {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2017-10-03 11:55:16,575]  INFO {org.apache.synapse.mediators.builtin.LogMediator} -  COMMODITY ID = 1 {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2017-10-03 11:55:16,597]  INFO {org.apache.synapse.core.axis2.TimeoutHandler} -  This engine will expire all callbacks after GLOBAL_TIMEOUT: 120 seconds, irrespective of the timeout action, after the specified or optional timeout {org.apache.synapse.core.axis2.TimeoutHandler}
TID: [-1234] [] [2017-10-03 11:55:16,637] ERROR {org.apache.axis2.engine.AxisEngine} -  The endpoint reference (EPR) for the Operation not found is /services/agrimarketprice-dss/1 and the WSA Action = null. If this EPR was previously reachable, please contact the server administrator. {org.apache.axis2.engine.AxisEngine}
org.apache.axis2.AxisFault: The endpoint reference (EPR) for the Operation not found is /services/agrimarketprice-dss/1 and the WSA Action = null. If this EPR was previously reachable, please contact the server administrator.
        at org.apache.axis2.engine.DispatchPhase.checkPostConditions(DispatchPhase.java:102)
        at org.apache.axis2.engine.Phase.invoke(Phase.java:329)
        at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:261)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:167)
        at org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosingRESTHandler(ServerWorker.java:326)
        at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:158)
        at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
TID: [-1234] [] [2017-10-03 11:55:16,642] ERROR {org.apache.synapse.transport.passthru.ServerWorker} -  Error processing GET request for : /services/agrimarketprice-dss/1 {org.apache.synapse.transport.passthru.ServerWorker}
org.apache.axis2.AxisFault: The endpoint reference (EPR) for the Operation not found is /services/agrimarketprice-dss/1 and the WSA Action = null. If this EPR was previously reachable, please contact the server administrator.
        at org.apache.axis2.engine.DispatchPhase.checkPostConditions(DispatchPhase.java:102)
        at org.apache.axis2.engine.Phase.invoke(Phase.java:329)
        at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:261)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:167)
        at org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosingRESTHandler(ServerWorker.java:326)
        at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:158)
        at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
TID: [-1] [] [2017-10-03 11:58:16,778]  INFO {org.apache.synapse.transport.passthru.SourceHandler} -  Writer null when calling informWriterError {org.apache.synapse.transport.passthru.SourceHandler}
TID: [-1] [] [2017-10-03 11:58:16,780]  WARN {org.apache.synapse.transport.passthru.SourceHandler} -  Connection time out after request is read: http-incoming-6 Socket Timeout : 180000 Remote Address : /168.202.253.227:62418 {org.apache.synapse.transport.passthru.SourceHandler}

It seems to me that this error should be related to this log information:

The endpoint reference (EPR) for the Operation not found is /services/agrimarketprice-dss/1 and the WSA Action = null

It seems that it is tryng to append the passed id (1) to the agrimarketprice-dss (that is the service name) ignorning the operation (that is GetCommodityDetails and that I specified in the header).

So what is wrong? What am I missing? How can I try to fix this error?

EDIT-1: I tried another way: the API doesn't retrieve the commodity_id from the URL path but from a JSON document like this in the request:

{
"commodity_id": 1
}

So, changing the API in this way it works fine, the query is correctly performed (but I need to retrieve the commodity_id from the URL and use it as query parameter (so it could be only a workaround):

<?xml version="1.0" encoding="UTF-8"?>
<api context="/commodity_details" name="commodity_details" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="POST" protocol="http" uri-template="/">
        <inSequence>
            <log level="full"/>
            <log level="custom">
                <property expression="json-eval($.commodity_id)" name="Commodity ID"/>
            </log>
            <property expression="json-eval($.commodity_id)" name="CommodityId" scope="default" type="STRING"/>
            <property name="messageType" scope="axis2" type="STRING" value="application/xml"/>
            <payloadFactory media-type="xml">
                <format>
                    <ds:GetCommodityDetails xmlns:ds="http://ws.wso2.org/dataservice">
                        <ds:commodity_details_id>$1</ds:commodity_details_id>
                    </ds:GetCommodityDetails>
                </format>
                <args>
                    <arg evaluator="json" expression="$.commodity_id"/>
                </args>
            </payloadFactory>
            <header name="Action" scope="default" value="urn:GetCommodityDetails"/>
            <call>
                <endpoint key="agrimarketprice_Endpoint"/>
            </call>

            <send/>
        </inSequence>
        <outSequence>
            <send/>
        </outSequence>
        <faultSequence/>
    </resource>
</api>

So in this way the DSS service is correctly called, the query performed and the API send back to the client the expected output.

But why retrieving the ID from the JSON document in the POST request it works fine but it doesn't work retrieving it from the URL?

1
Remove Action header. <header name="Action" value="" />simar

1 Answers

0
votes

Set the soapAction header as below before the call mediator. You can verify whether the SOAPAction header has been set in the request to dataservice by enabling wirelogs

<property name="SOAPAction" scope="transport" value="urn:GetCommodityDetails"/>