Search code examples
javaodataodata4j

406 Not acceptable while performing post on ODATA4j


Am a newbie in odata4j concepts. Using odata4j Library odata4j-0.5-nojpabundle.jar launched producer on tomcat using link http://code.google.com/p/odata4j/wiki/Tomcat. My producer is modified to give an large list of integers as an entity-set called "Integers" I could retreive the serviceDoc,collection and can apply filters. Now trying to perform post on this service doc[trying to add one more entry with same schema ].

Doing post for http://localhost:8080/OData/example.svc/Integers with post body :

    <?xml version="1.0" encoding="utf-8" ?>  <edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"> <entry>   <id>http://localhost:8080/OData/example.svc/Integers(100)</id>  
<title type="text" />   
<updated>2011-12-29T10:50:33Z</updated>
<author>   <name />    </author>
<link rel="edit" title="Integers" href="Integers(100)" />  
<category term="example.Integers" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> 
<content type="application/xml"> 
 <m:properties>  
 <d:EntityId m:type="Edm.Int32">100</d:EntityId>    </m:properties>  
 </content>  
 </entry>

am getting 406 not Acceptable Unknown content type application/xml;charset=UTF-8. Int collection content type is application/xml. Still not able to find out why is this response is obtained. Does anyone know what i am missing here.

Thanks in Advance.


Solution

    1. Use application/atom+xml as the Content-Type
    2. Entry should be the document element (your xml above is not well-formed)

    See: http://www.odata.org/developers/protocols/operations#CreatingnewEntries

    Hope that helps,
    - john