我正在尝试使用 odata4j 库将 OData 发布到客户端的服务器。我通过创建自定义 CursorWrapper 来获取每列的类型来实现这一点。似乎无论我做什么,我都会收到“406 Not Acceptable ”错误。
odata4j javadocs 不是最好的,并且在 odata4j 网站和一般的谷歌搜索中都严重缺乏示例。我什至不确定如何记录发布到 OData 服务器的内容(我确信这会使错误变得清晰)。似乎没有明显的函数可以将 xml post 转换为字符串。
所以,我的问题是一个由两部分组成的问题: 1. 如何记录 odata4j 库中的事务? 2. 如果有的话,我使用 odata4j 发布 OData 的逻辑有什么错误?
我在下面包含了一个代码 fragment 。任何帮助将不胜感激。
// Create the ODataConsumer with the appropriate credentials
OClientBehavior basicAuth = new BasicAuthenticationBehavior(Config.dbfile +
"\\" + Config.username, Config.password);
ODataConsumer consumer = ODataConsumer.create(url, basicAuth);
// Make sure there are results in the cursor
if ( cursorWrapper.moveToFirst() ){
// create the new product
OCreateRequest<OEntity> newMaterial =
consumer.createEntity( "ESvcOrderTrans" );
// Iterate through each cursor's row
while (cursorWrapper.isAfterLast() == false) {
// Iterate through each cursor's columns
for ( int i=1; i < cursorWrapper.getColumnCount(); i++ ){
// Determine type of key
switch ( cursorWrapper.getType(i) ){
case CustomCursorWrapper.FIELD_TYPE_INTEGER :
if (cursorWrapper.isNull(i)){
createRequest.properties(OProperties.null_(
cursorWrapper.getColumnName(i),
"Edm.Int32"));
} else {
createRequest.properties( OProperties.int32(
cursorWrapper.getColumnName(i),
cursorWrapper.getInt(i)));
}
break;
case CustomCursorWrapper.FIELD_TYPE_STRING :
if (cursorWrapper.isNull(i)){
createRequest.properties(OProperties.null_(
cursorWrapper.getColumnName(i),
"Edm.String"));
} else {
createRequest.properties(OProperties.string(
cursorWrapper.getColumnName(i),
cursorWrapper.getString(i)));
}
break;
case CustomCursorWrapper.FIELD_TYPE_FLOAT :
if (cursorWrapper.isNull(i)){
createRequest.properties(OProperties.null_(
cursorWrapper.getColumnName(i),
"Edm.Double"));
} else {
createRequest.properties(OProperties.decimal(
cursorWrapper.getColumnName(i),
cursorWrapper.getFloat(i)));
}
break;
case CustomCursorWrapper.FIELD_TYPE_BLOB :
if (cursorWrapper.isNull(i)){
createRequest.properties(OProperties.null_(
cursorWrapper.getColumnName(i),
"Edm.Binary"));
} else {
createRequest.properties(OProperties.binary(
cursorWrapper.getColumnName(i),
cursorWrapper.getBlob(i)));
}
break;
case CustomCursorWrapper.FIELD_TYPE_NULL :
break;
}
}
// Execute the OData post
newMaterial.execute();
// Move to the next cursor
cursorWrapper.moveToNext();
}
}
最佳答案
记录所有 http 流量:
ODataConsumer.dump.all(true);
让我知道你发现了什么。
希望对你有帮助,
- 约翰
关于java - 尝试在 android/java 中使用 odata4j 向 odata 服务器发帖时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6228156/