开发者

Problem attempting to make a post to an odata server using odata4j in android/java

开发者 https://www.devze.com 2023-03-10 09:52 出处:网络
I\'m attempting to use the odata4j lib to make an OData post to a client\'s server.I\'m doing this by creating a custom CursorWrapper to get the type of each column.It seems that no matter what I do,

I'm attempting to use the odata4j lib to make an OData post to a client's server. I'm doing this by creating a custom CursorWrapper to get the type of each column. It seems that no matter what I do, I'm getting a '406 Not Acceptable' error.

The odata4j javadocs aren't the greatest and there is a severe lack of examples both at the odata4j site as well as from general google searches. I'm not even sure how to log what is being posted to the OData server (I'm sure that would make the error clear). There doesn't seem to be an obvious function to get the xml post to a string.

So, my question is a 2 part question: 1. How do you log the the transactions from the odata4j lib? 2. What, if anything, is wrong in my logic to make an OData post using odata4j?

I'm including a code snippet below. Any help would be greatly appreciated.

    // 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.getCo开发者_C百科lumnName(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();                
        }
    }    


To log all http traffic:

ODataConsumer.dump.all(true);

Let me know what you find out.

Hope that helps,
- john

0

精彩评论

暂无评论...
验证码 换一张
取 消