我正在尝试使用odata4j lib向客户端的服务器发送OData帖子。我这样做是通过创建自定义CursorWrapper来获取每列的类型。似乎无论我做什么,我都会收到“406 Not Acceptable”错误。
odata4j javadocs并不是最好的,并且在odata4j网站以及一般的谷歌搜索中都存在严重缺乏的例子。我甚至不确定如何记录发布到OData服务器的内容(我确信这会使错误清除)。似乎没有明显的功能将xml帖子转换为字符串。
所以,我的问题是一个2部分的问题: 1.如何从odata4j lib中记录事务? 2.使用odata4j制作OData帖子的逻辑中有什么错误?
我在下面附上了一个代码段。任何帮助将不胜感激。
// 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();
}
}
答案 0 :(得分:3)
记录所有http流量:
ODataConsumer.dump.all(true);
让我知道你发现了什么。
希望有所帮助,
- 约翰