1

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.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();                
        }
    }    
Emre Yazici
  • 10,136
  • 6
  • 48
  • 55
SBerg413
  • 14,515
  • 6
  • 62
  • 88

1 Answers1

3

To log all http traffic:

ODataConsumer.dump.all(true);

Let me know what you find out.

Hope that helps,
- john

John Spurlock
  • 1,723
  • 1
  • 13
  • 12
  • Thanks John - now I have a different issue. It seems as though the post xml structure is missing the "category" child of the entry. This is required to be able to post by the server. I've been pulling my hair out trying to figure out how to inject this using any of the odata4j methods. Any ideas? – SBerg413 Jun 15 '11 at 19:45
  • 1
    John - posted another question about this. May want to answer it there. – SBerg413 Jun 15 '11 at 20:06