jsonwso2wso2-enterprise-integratorwso2-data-services-server

WSO2 EI - Input parameter on DSS Query with REST


I tried to follow this tutorial to create a DSS with a JSON output: https://docs.wso2.com/display/EI620/Using+JSON+with+Data+Services

It works fine with a simple query and I can format the output without problems.

Now I am trying to add an input parameter to filter records by the ID but it doesn't work for me. My REST, as described in the tutorial, is: GET http://{server_host}/services/Promemoria_PROMEMORIA_Tools/getCount/2

The response is:

Error processing GET request for : /services/Promemoria_PROMEMORIA_Tools/getCount/2</p><p>DS Code: INCOMPATIBLE_PARAMETERS_ERROR
Nested Exception:-
javax.xml.stream.XMLStreamException: DS Fault Message: Error in 'CallQuery.extractParams', cannot find parameter with type:query-param name:idp
DS Code: INCOMPATIBLE_PARAMETERS_ERROR
Source Data Service:-
Name: Promemoria_PROMEMORIA_Tools
Location: /Promemoria_PROMEMORIA_Tools.dbs
Description: Tool per permettere ad Amenta di inserire le pratiche fatte a mano.
Default Namespace: http://ws.wso2.org/dataservice
Current Request Name: _getgetcount_idp
Current Params: {}

I also tryed with: GET http://{server_host}/services/Promemoria_PROMEMORIA_Tools/getCount?idp=2 But it is wrong because the Operation isn't recognized.

I put the attribute defaultValue="3" on idp in the query definition and it starts working...but it ignores the value in the REST.

What it's wrong? This is my DSS code

<data name="Promemoria_PROMEMORIA_Tools" transports="http https local">
   <description>Tool per permettere di inserire le pratiche fatte a mano.</description>
   <config enableOData="false" id="OracleServizio_Promemoria2">
      <property name="carbon_datasource_name">OracleServizio_Promemoria2</property>
   </config>
   <query id="getByCF" useConfig="OracleServizio_Promemoria2">
      <sql>SELECT ID_ABILITAZIONE, ID_SERVIZIO, DESCR_SERVIZIO, CF_UTENTE, ID_CANALE_NOTIFICA, CANALE_NOTIFICA, ID_CONTATTO, CONTATTO, CANALE_ACQ, DATA_ACQ, CF_ACQ, PROTOCOLLO, DATA_PROT, PROV_UFF FROM SERVIZIO_PROMEMORIA.SE_MI_SCORDO_ABIL_SPORTELLO a where a.CF_UTENTE = :cf union all SELECT ID_ABILITAZIONE, ID_SERVIZIO, DESCR_SERVIZIO, CF_UTENTE, ID_CANALE_NOTIFICA, CANALE_NOTIFICA, ID_CONTATTO, CONTATTO, CANALE_ACQ, DATA_ACQ, CF_ACQ, PROTOCOLLO, DATA_PROT, PROV_UFF FROM SERVIZIO_PROMEMORIA.SE_MI_SCORDO_ABIL b where b.CF_UTENTE = :cf and b.CF_ACQ &lt;&gt; 'BATCH'</sql>
      <result escapeNonPrintableChar="true" outputType="json">{&#xd;    "list": {&#xd;      "item": [{&#xd;         "id": "$ID_ABILITAZIONE",&#xd;          "service": {&#xd;               "id": "$ID_SERVIZIO",&#xd;              "info": "$DESCR_SERVIZIO"&#xd;          },&#xd;         "cfUser": "$CF_UTENTE",&#xd;            "channel": {&#xd;               "id": "$ID_CANALE_NOTIFICA",&#xd;               "info": "$CANALE_NOTIFICA"&#xd;         },&#xd;         "address": {&#xd;               "id": "$ID_CONTATTO",&#xd;              "info": "$CONTATTO"&#xd;            }&#xd;      }]&#xd; }&#xd;}</result>
      <param name="cf" sqlType="STRING"/>
   </query>
   <query id="getCount" useConfig="OracleServizio_Promemoria2">
      <sql>SELECT ID_SERVIZIO, DESCR_SERVIZIO, ID_CANALE_NOTIFICA, CANALE_NOTIFICA, count(*) as recno FROM SERVIZIO_PROMEMORIA.SE_MI_SCORDO_ABIL_SPORTELLO a where a.ID_SERVIZIO=:idp group by ID_SERVIZIO, DESCR_SERVIZIO, ID_CANALE_NOTIFICA, CANALE_NOTIFICA</sql>
      <param name="idp" paramType="SCALAR" sqlType="INTEGER"/>
      <result escapeNonPrintableChar="true" outputType="json">{&#xd;    "list": {&#xd;      "item": [{&#xd;         "items": "$recno",&#xd;         "service": {&#xd;               "id": "$ID_SERVIZIO",&#xd;              "info": "$DESCR_SERVIZIO"&#xd;          },&#xd;         "channel": {&#xd;               "id": "$ID_CANALE_NOTIFICA",&#xd;               "info": "$CANALE_NOTIFICA"&#xd;         }&#xd;      }]&#xd; }&#xd;}</result>
   </query>
   <resource method="GET" path="getByCF/{cf}">
      <call-query href="getByCF">
         <with-param name="cf" query-param="cf"/>
      </call-query>
   </resource>
   <resource method="GET" path="getCount/{idp}">
      <call-query href="getCount">
         <with-param name="idp" query-param="idp"/>
      </call-query>
   </resource>
</data>

Roberto


Solution

  • I solved the problem but I am not quite sure how :) I try to explain it from the beginning. I made the service by the WSO2 console creation wizard which builded a SOAP service. Then I edited the service with the online xml editor and I converted it to REST. It works fine in select and the outputs are right but I was unable to use the input params (as decribed above).

    During my tests I changed the "getCount" operation to POST, with no result, but when I putted it back to GET it started working magically. The other operation still not working.

    I thought that somewhere the WSO2 stored a wrong config maybe made by the wizard. I completely removed the service and restarted from an empty .dbs file, writing it manualy. I loaded it into the WSO2 with the "upload" and it work fine. I edited it with the on-line xml editor and it still works well.

    That's all.