jkirbyster
jkirbyster

Reputation: 1

WSO2 Data Service Not Binding Inputs

I've trying to create a simple data service that inserts an entry in our database with the following definition:

<data name="RESTLoggerDataService" serviceNamespace="" transports="http https">
  <config id="default">
    <property name="driverClassName">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
    <property name="url">jdbc:sqlserver://SERVER:1433;databaseName=DB</property>
    <property name="username">user</property>
    <property name="password">pass</property>
  </config> 
  <query id="CreateLog" useConfig="default">
    <sql>INSERT INTO Log (Date, Username, ServiceID) VALUES (?,?,?)</sql>
    <param name="Date" paramType="SCALAR" sqlType="STRING" type="IN" ordinal="1"/>
    <param name="Username" paramType="SCALAR" sqlType="STRING" type="IN" ordinal="2"/>
    <param name="ServiceID" paramType="SCALAR" sqlType="STRING" type="IN" ordinal="3"/>
  </query>
  <resource method="POST" path="Log">
    <call-query href="CreateLog">
      <with-param name="Date" query-param="Date"/>
      <with-param name="Username" query-param="Username"/>
      <with-param name="ServiceID" query-param="ServiceID"/>
    </call-query>
  </resource>
 </data>

It seems this is not quite valid as none of the parameters I'm passing in via a CURL call are binding. I've tried:

curl -X POST -H 'Accept: application/xml'  -H 'Content-Type: application/xml' --data "@test.xml" http://localhost:90/services/RESTLoggerDataService/Log

with the following XML:

<_postlog>
    <Date>2020-09-15 09:06:00.000</Date>
    <Username>KIRBJJ</Username>
    <ServiceID>WA233</ServiceID>
</_postlog>

but get the following back:

curl: (52) Empty reply from server
curl: (52) Empty reply from server
<axis2ns19:DataServiceFault xmlns:axis2ns19="http://ws.wso2.org/dataservice"><axis2ns19:current_params>{Username=null, Date=null, ServiceID=null}</axis2ns19:current_params><axis2ns19:source_data_service><axis2ns19:data_service_name>RESTLoggerDataService</axis2ns19:data_service_name><axis2ns19:description>Exposing the data service as a REST service.</axis2ns19:description><axis2ns19:location>C:\PROGRA~1\WSO2\ENTERP~1\7154FB~1.0\MICRO-~1\bin\..\tmp\carbonapps\-1234\1600259919991RestLoggerCompositeExporter_1.0.0.car\RESTDataService_1.0.0\RESTDataService-1.0.0.dbs</axis2ns19:location><axis2ns19:default_namespace>http://ws.wso2.org/dataservice</axis2ns19:default_namespace></axis2ns19:source_data_service><axis2ns19:ds_code>DATABASE_ERROR</axis2ns19:ds_code><axis2ns19:nested_exception>com.microsoft.sqlserver.jdbc.SQLServerException: Cannot insert the value NULL into column 'Date', table 'LOGS.dbo.LogEntry'; column does not allow nulls. INSERT fails.</axis2ns19:nested_exception><axis2ns19:current_request_name>_postlog</axis2ns19:current_request_name></axis2ns19:DataServiceFault>
<axis2ns8:DataServiceFault xmlns:axis2ns8="http://ws.wso2.org/dataservice">
   <axis2ns8:current_params>{}</axis2ns8:current_params>
   <axis2ns8:source_data_service>
      <axis2ns8:data_service_name>RESTLoggerDataService</axis2ns8:data_service_name>
      <axis2ns8:description>Exposing the data service as a REST service.</axis2ns8:description>
      <axis2ns8:location>C:\PROGRA~1\WSO2\ENTERP~1\7154FB~1.0\MICRO-~1\bin\..\tmp\carbonapps\-1234\1600263784524RestLoggerCompositeExporter_1.0.0.car\RESTDataService_1.0.0\RESTDataService-1.0.0.dbs</axis2ns8:location>
      <axis2ns8:default_namespace>http://ws.wso2.org/dataservice/LoggingAPI</axis2ns8:default_namespace>
   </axis2ns8:source_data_service>
   <axis2ns8:ds_code>INCOMPATIBLE_PARAMETERS_ERROR</axis2ns8:ds_code>
   <axis2ns8:current_request_name>_postlog</axis2ns8:current_request_name>
</axis2ns8:DataServiceFault>

It appears the input parameters are not binding correctly. Can anybody see what I'm doing wrong?

Upvotes: 0

Views: 131

Answers (1)

Dilan Premarathna
Dilan Premarathna

Reputation: 1294

I have created a similar data service with MySQL and did not face any issues. Could you please try the following and see if it makes any changes. Change the payload by adding namespaces as follows and try the same mediation.

<p:_postlog xmlns:p="http://ws.wso2.org/dataservice">
    <xs:Date xmlns:xs="http://ws.wso2.org/dataservice">2020-09-15 09:06:00.000</xs:Date>
    <xs:Username xmlns:xs="http://ws.wso2.org/dataservice">KIRBJJ</xs:Username>
    <xs:ServiceID xmlns:xs="http://ws.wso2.org/dataservice">WA233</xs:ServiceID>
</p:_postlog>

If this does not work please enable wire logs and confirm that the correct payload is passed to the data service.

Upvotes: 1

Related Questions