【问题标题】:Problem attempting to make a post to an odata server using odata4j in android/java尝试在 android/java 中使用 odata4j 向 odata 服务器发帖时出现问题
【发布时间】:2011-09-07 20:40:03
【问题描述】:

我正在尝试使用 odata4j 库将 OData 发布到客户端的服务器。我通过创建自定义 CursorWrapper 来获取每列的类型来做到这一点。似乎无论我做什么,我都会收到“406 Not Acceptable”错误。

odata4j javadocs 并不是最好的,并且在 odata4j 站点和一般的 google 搜索中都严重缺乏示例。我什至不确定如何记录发布到 OData 服务器的内容(我相信这会使错误变得清晰)。似乎没有明显的功能可以将 xml 帖子转换为字符串。

所以,我的问题分为两部分: 1. 你如何记录来自 odata4j 库的事务? 2. 如果有的话,我使用 odata4j 发布 OData 帖子的逻辑有什么问题?

我在下面包含了一个代码 sn-p。任何帮助将不胜感激。

    // 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();                
        }
    }    

【问题讨论】:

  • 我可以知道上面代码中的 cursorWrapper 是什么吗???

标签: java android odata odata4j


【解决方案1】:

记录所有 http 流量:

ODataConsumer.dump.all(true);

告诉我你发现了什么。

希望对您有所帮助,
- 约翰

【讨论】:

  • 谢谢约翰 - 现在我有一个不同的问题。似乎 post xml 结构缺少条目的“类别”子项。这是服务器发布所必需的。我一直在努力弄清楚如何使用任何 odata4j 方法注入它。有什么想法吗?
  • John - 发布了另一个关于此的问题。可能想在那里回答。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-02-03
  • 2019-05-26
  • 1970-01-01
  • 1970-01-01
  • 2022-11-17
  • 2011-05-22
  • 2011-05-06
相关资源
最近更新 更多