Я работаю над WSO2 EI версия 6.1.1 , и я нахожу большую проблему, пытаясь реализовать простой DSS INSERT-запрос, который нужно вставитьновая запись в таблице, допускающая, что некоторые поля имеют значение null .
Это мой код DSS , связанный с этим определением запроса spwcific и соответствующей операцией:
<query id="insert_user" returnGeneratedKeys="true" useConfig="user_db">
<sql>
insert into User(
application_UID,
country_id,
localization_id,
local_user_id,
isActive,
isFullProfile,
birth_date,
gender,
prefix
)
values(
:application_UID,
:country_id,
:localization_id,
:local_user_id,
:is_active,
:is_full_profile,
:birth_date,
:gender,
:prefix
)
</sql>
<result element="GeneratedKeys" rowName="Entry" useColumnNumbers="true">
<element column="1" name="ID" xsdType="integer"/>
</result>
<param name="application_UID" sqlType="STRING"/>
<param name="country_id" sqlType="BIGINT"/>
<param name="localization_id" sqlType="BIGINT"/>
<param name="local_user_id" sqlType="BIGINT"/>
<param name="is_active" sqlType="BIT"/>
<param name="is_full_profile" sqlType="BIT"/>
<param defaultValue="#{NULL}" name="birth_date" sqlType="STRING"/>
<param defaultValue="#{NULL}" name="gender" sqlType="STRING"/>
<param defaultValue="#{NULL}" name="prefix" sqlType="STRING"/>
</query>
<operation name="AddUser">
<call-query href="insert_user">
<with-param name="application_UID" query-param="application_UID"/>
<with-param name="country_id" query-param="country_id"/>
<with-param name="localization_id" query-param="localization_id"/>
<with-param name="local_user_id" query-param="local_user_id"/>
<with-param name="is_active" query-param="is_active"/>
<with-param name="is_full_profile" query-param="is_full_profile"/>
<with-param name="birth_date" query-param="birth_date"/>
<with-param name="gender" query-param="gender"/>
<with-param name="prefix" query-param="prefix"/>
</call-query>
</operation>
Последние 3 файла обнуляются в моей БД, и, как вы можете видеть, я определил эти поля таким образом (я использовал defaultValue = "# {NULL}" чтобы эти поля можно было обнулять):
<param defaultValue="#{NULL}" name="birth_date" sqlType="STRING"/>
<param defaultValue="#{NULL}" name="gender" sqlType="STRING"/>
<param defaultValue="#{NULL}" name="prefix" sqlType="STRING"/>
Проблема в том, что если я войду в инструмент try it и выполню этот запрос:
<body>
<p:AddUser xmlns:p="http://ws.wso2.org/dataservice">
<!--Exactly 1 occurrence-->
<p:application_UID>xxx</p:application_UID>
<!--Exactly 1 occurrence-->
<p:country_id>1</p:country_id>
<!--Exactly 1 occurrence-->
<p:localization_id>1</p:localization_id>
<!--Exactly 1 occurrence-->
<p:local_user_id>1</p:local_user_id>
<!--Exactly 1 occurrence-->
<p:is_active>true</p:is_active>
<!--Exactly 1 occurrence-->
<p:is_full_profile>true</p:is_full_profile>
<!--Exactly 1 occurrence-->
<p:birth_date>?</p:birth_date>
<!--Exactly 1 occurrence-->
<p:gender>?</p:gender>
<!--Exactly 1 occurrence-->
<p:prefix>?</p:prefix>
</p:AddUser>
</body>
(как вы можете видеть, яя не устанавливаю значения последних 3 полей, которые могут быть обнулены) Я получаю это сообщение об ошибке в выходных данных инструмента Try It:
<soapenv:Fault xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Code>
<soapenv:Value>axis2ns393:DATABASE_ERROR</soapenv:Value>
</soapenv:Code>
<soapenv:Reason>
<soapenv:Text xml:lang="en-US">DS Code: DATABASE_ERROR Nested Exception:- javax.xml.stream.XMLStreamException: DS Fault Message: Error in 'SQLQuery.processPreNormalQuery': Data truncation: Incorrect date value: '?' for column 'birth_date' at row 1 DS Code: DATABASE_ERROR Source Data Service:- Name: user-dss Location: /opt/wso2/wso2ei/wso2/tmp/carbonapps/-1234/1524668046564userreg-cap_1.0.0.car/user-dss_1.0.0/user-dss-1.0.0.dbs Description: N/A Default Namespace: http://ws.wso2.org/dataservice Current Request Name: AddUser Current Params: {local_user_id=1, is_active=true, gender=?, prefix=?, birth_date=?, is_full_profile=true, application_UID=xxx, country_id=1, localization_id=1} Nested Exception:- com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value: '?' for column 'birth_date' at row 1 </soapenv:Text>
</soapenv:Reason>
<soapenv:Detail>
<axis2ns392:DataServiceFault xmlns:axis2ns392="http://ws.wso2.org/dataservice">
<axis2ns392:current_params>{local_user_id=1, is_active=true, gender=?, prefix=?, birth_date=?, is_full_profile=true, application_UID=xxx, country_id=1, localization_id=1}</axis2ns392:current_params>
<axis2ns392:source_data_service>
<axis2ns392:data_service_name>user-dss</axis2ns392:data_service_name>
<axis2ns392:description>N/A</axis2ns392:description>
<axis2ns392:location>/opt/wso2/wso2ei/wso2/tmp/carbonapps/-1234/1524668046564userreg-cap_1.0.0.car/user-dss_1.0.0/user-dss-1.0.0.dbs</axis2ns392:location>
<axis2ns392:default_namespace>http://ws.wso2.org/dataservice</axis2ns392:default_namespace>
</axis2ns392:source_data_service>
<axis2ns392:ds_code>DATABASE_ERROR</axis2ns392:ds_code>
<axis2ns392:nested_exception>com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value: '?' for column 'birth_date' at row 1</axis2ns392:nested_exception>
<axis2ns392:current_request_name>AddUser</axis2ns392:current_request_name>
</axis2ns392:DataServiceFault>
</soapenv:Detail>
</soapenv:Fault>
и в моем журнале Carbon у меня есть что-то вроде этого:
TID: [-1234] [] [2018-04-25 16:57:13,853] ERROR {org.wso2.carbon.dataservices.core.DBInOutMessageReceiver} - Error in in-out message receiver {org.wso2.carbon.dataservices.core.DBInOutMessageReceiver}
DS Code: DATABASE_ERROR
Nested Exception:-
javax.xml.stream.XMLStreamException: DS Fault Message: Error in 'SQLQuery.processPreNormalQuery': Data truncation: Incorrect date value: '?' for column 'birth_date' at row 1
DS Code: DATABASE_ERROR
Source Data Service:-
Name: user-dss
Location: /opt/wso2/wso2ei/wso2/tmp/carbonapps/-1234/1524668046564userreg-cap_1.0.0.car/user-dss_1.0.0/user-dss-1.0.0.dbs
Description: N/A
Default Namespace: http://ws.wso2.org/dataservice
Current Request Name: AddUser
Current Params: {local_user_id=1, is_active=true, gender=?, prefix=?, birth_date=?, is_full_profile=true, application_UID=xxx, country_id=1, localization_id=1}
Nested Exception:-
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value: '?' for column 'birth_date' at row 1
at org.wso2.carbon.dataservices.core.dispatch.SingleDataServiceRequest.processRequest(SingleDataServiceRequest.java:75)
at org.wso2.carbon.dataservices.core.dispatch.DataServiceRequest.dispatch(DataServiceRequest.java:357)
at org.wso2.carbon.dataservices.core.DataServiceProcessor.dispatch(DataServiceProcessor.java:41)
at org.wso2.carbon.dataservices.core.DBInOutMessageReceiver.invokeBusinessLogic(DBInOutMessageReceiver.java:57)
at org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver.invokeBusinessLogic(AbstractInOutSyncMessageReceiver.java:42)
at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:110)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:404)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:151)
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)
Caused by: javax.xml.stream.XMLStreamException: DS Fault Message: Error in 'SQLQuery.processPreNormalQuery': Data truncation: Incorrect date value: '?' for column 'birth_date' at row 1
DS Code: DATABASE_ERROR
Source Data Service:-
Name: user-dss
Location: /opt/wso2/wso2ei/wso2/tmp/carbonapps/-1234/1524668046564userreg-cap_1.0.0.car/user-dss_1.0.0/user-dss-1.0.0.dbs
Description: N/A
Default Namespace: http://ws.wso2.org/dataservice
Current Request Name: AddUser
Current Params: {local_user_id=1, is_active=true, gender=?, prefix=?, birth_date=?, is_full_profile=true, application_UID=xxx, country_id=1, localization_id=1}
Nested Exception:-
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value: '?' for column 'birth_date' at row 1
at org.wso2.carbon.dataservices.core.engine.DSOMDataSource.execute(DSOMDataSource.java:102)
at org.wso2.carbon.dataservices.core.dispatch.SingleDataServiceRequest.processRequest(SingleDataServiceRequest.java:73)
... 12 more
TID: [-1234] [] [2018-04-25 16:57:13,855] ERROR {org.apache.synapse.transport.passthru.ServerWorker} - Error processing POST request for : /services/user-dss.SOAP12Endpoint/AddUser {org.apache.synapse.transport.passthru.ServerWorker}
org.apache.axis2.AxisFault: DS Code: DATABASE_ERROR
Nested Exception:-
javax.xml.stream.XMLStreamException: DS Fault Message: Error in 'SQLQuery.processPreNormalQuery': Data truncation: Incorrect date value: '?' for column 'birth_date' at row 1
DS Code: DATABASE_ERROR
Source Data Service:-
Name: user-dss
Location: /opt/wso2/wso2ei/wso2/tmp/carbonapps/-1234/1524668046564userreg-cap_1.0.0.car/user-dss_1.0.0/user-dss-1.0.0.dbs
Description: N/A
Default Namespace: http://ws.wso2.org/dataservice
Current Request Name: AddUser
Current Params: {local_user_id=1, is_active=true, gender=?, prefix=?, birth_date=?, is_full_profile=true, application_UID=xxx, country_id=1, localization_id=1}
Nested Exception:-
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value: '?' for column 'birth_date' at row 1
at org.wso2.carbon.dataservices.core.DBUtils.createAxisFault(DBUtils.java:740)
at org.wso2.carbon.dataservices.core.DBInOutMessageReceiver.invokeBusinessLogic(DBInOutMessageReceiver.java:67)
at org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver.invokeBusinessLogic(AbstractInOutSyncMessageReceiver.java:42)
at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:110)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:404)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:151)
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)
Caused by: javax.xml.stream.XMLStreamException: DS Fault Message: Error in 'SQLQuery.processPreNormalQuery': Data truncation: Incorrect date value: '?' for column 'birth_date' at row 1
DS Code: DATABASE_ERROR
Source Data Service:-
Name: user-dss
Location: /opt/wso2/wso2ei/wso2/tmp/carbonapps/-1234/1524668046564userreg-cap_1.0.0.car/user-dss_1.0.0/user-dss-1.0.0.dbs
Description: N/A
Default Namespace: http://ws.wso2.org/dataservice
Current Request Name: AddUser
Current Params: {local_user_id=1, is_active=true, gender=?, prefix=?, birth_date=?, is_full_profile=true, application_UID=xxx, country_id=1, localization_id=1}
Nested Exception:-
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value: '?' for column 'birth_date' at row 1
at org.wso2.carbon.dataservices.core.engine.DSOMDataSource.execute(DSOMDataSource.java:102)
at org.wso2.carbon.dataservices.core.dispatch.SingleDataServiceRequest.processRequest(SingleDataServiceRequest.java:73)
at org.wso2.carbon.dataservices.core.dispatch.DataServiceRequest.dispatch(DataServiceRequest.java:357)
at org.wso2.carbon.dataservices.core.DataServiceProcessor.dispatch(DataServiceProcessor.java:41)
at org.wso2.carbon.dataservices.core.DBInOutMessageReceiver.invokeBusinessLogic(DBInOutMessageReceiver.java:57)
... 9 more
Появляется похожая ошибка, если я использую запрос, подобный этому:
<body>
<p:AddUser xmlns:p="http://ws.wso2.org/dataservice">
<!--Exactly 1 occurrence-->
<p:application_UID>xxx</p:application_UID>
<!--Exactly 1 occurrence-->
<p:country_id>1</p:country_id>
<!--Exactly 1 occurrence-->
<p:localization_id>1</p:localization_id>
<!--Exactly 1 occurrence-->
<p:local_user_id>1</p:local_user_id>
<!--Exactly 1 occurrence-->
<p:is_active>true</p:is_active>
<!--Exactly 1 occurrence-->
<p:is_full_profile>true</p:is_full_profile>
<!--Exactly 1 occurrence-->
<p:birth_date></p:birth_date>
<!--Exactly 1 occurrence-->
<p:gender></p:gender>
<!--Exactly 1 occurrence-->
<p:prefix></p:prefix>
</p:AddUser>
</body>
Также пробовал в тЕго способ получить ту же проблему:
<body>
<p:AddUser xmlns:p="http://ws.wso2.org/dataservice">
<!--Exactly 1 occurrence-->
<p:application_UID>xxx</p:application_UID>
<!--Exactly 1 occurrence-->
<p:country_id>1</p:country_id>
<!--Exactly 1 occurrence-->
<p:localization_id>1</p:localization_id>
<!--Exactly 1 occurrence-->
<p:local_user_id>1</p:local_user_id>
<!--Exactly 1 occurrence-->
<p:is_active>true</p:is_active>
<!--Exactly 1 occurrence-->
<p:is_full_profile>true</p:is_full_profile>
<!--Exactly 1 occurrence-->
<p:birth_date>null</p:birth_date>
<!--Exactly 1 occurrence-->
<p:gender>null</p:gender>
<!--Exactly 1 occurrence-->
<p:prefix>null</p:prefix>
</p:AddUser>
</body>
Единственный способ, которым я обнаружил вок - это выполнить запрос, исключающий эти параметры, с помощью этого запроса он прекрасно работает:
<body>
<p:AddUser xmlns:p="http://ws.wso2.org/dataservice">
<!--Exactly 1 occurrence-->
<p:application_UID>xxx</p:application_UID>
<!--Exactly 1 occurrence-->
<p:country_id>1</p:country_id>
<!--Exactly 1 occurrence-->
<p:localization_id>1</p:localization_id>
<!--Exactly 1 occurrence-->
<p:local_user_id>1</p:local_user_id>
<!--Exactly 1 occurrence-->
<p:is_active>true</p:is_active>
<!--Exactly 1 occurrence-->
<p:is_full_profile>true</p:is_full_profile>
</p:AddUser>
</body>
Вэтот случай работает, и запись корректно вставляется в мою таблицу БД, но я не могу использовать это, потому что мне приходится вызывать эту службу DSS из потока ESB и работать с использованием всех параметров (если параметр не установлен или имеет значение null) он должен вставить ноль.
Почему?Как я могу исправить этот запрос и вызвать его со значениями NULL , сохранив NULL в качестве значения моего поля, допускающего пустые значения?