问题描述
我正在尝试创建一个简单的数据服务,该服务将在数据库中插入具有以下定义的条目:
<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>
这似乎不太有效,因为我通过CURL调用传递的参数都没有绑定。我尝试过:
curl -X POST -H 'Accept: application/xml' -H 'Content-Type: application/xml' --data "@test.xml" http://localhost:90/services/RESTLoggerDataService/Log
具有以下XML:
<_postlog>
<Date>2020-09-15 09:06:00.000</Date>
<Username>KIRBJJ</Username>
<ServiceID>WA233</ServiceID>
</_postlog>
但请返回以下内容:
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>
似乎输入参数未正确绑定。有人可以看到我在做什么错吗?
解决方法
我已经使用MySQL创建了类似的数据服务,并且没有遇到任何问题。您可以尝试以下操作,看看是否进行了任何更改。通过如下添加名称空间来更改有效负载,然后尝试相同的中介。
import React from 'react';
import {RNCamera} from 'react-native-camera';
import Icon from 'react-native-vector-icons/dist/FontAwesome';
import {TouchableOpacity,Alert,StyleSheet} from 'react-native';
export default function Camera({onPicture}) {
let camera;
const [isTakingPicture,setTakePicture] = React.useState(false);
async function takePicture() {
if (camera && !isTakingPicture) {
let options = {
quality: 0.85,fixOrientation: true,forceUpOrientation: true,};
setTakePicture(true);
try {
const data = await camera.takePictureAsync(options);
// Alert.alert('Success',JSON.stringify(data));
onPicture(data);
} catch (err) {
Alert.alert('Error','Failed to take picture: ' + (err.message || err));
return;
} finally {
setTakePicture(false);
}
}
}
return (
<RNCamera
ref={(ref) => (camera = ref)}
captureAudio={false}
style={{flex: 1}}
type={RNCamera.Constants.Type.back}
androidCameraPermissionOptions={{
title: 'Permission to use camera',message: 'We need your permission to use your camera',buttonPositive: 'Ok',buttonNegative: 'Cancel',}}>
<TouchableOpacity
activeOpacity={0.5}
style={styles.btnAlignment}
onPress={takePicture}>
<Icon name="camera" size={50} color="#fff" />
</TouchableOpacity>
</RNCamera>
);
}
const styles = StyleSheet.create({
btnAlignment: {
flex: 1,flexDirection: 'column',justifyContent: 'flex-end',alignItems: 'center',marginBottom: 20,},});
如果这不起作用,请启用线路日志并确认正确的有效负载已传递到数据服务。