[ 
https://issues.apache.org/jira/browse/OLINGO-510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14278737#comment-14278737
 ] 

Christian Holzer commented on OLINGO-510:
-----------------------------------------

Hi Thierry,

you have to change the line 
ODataReferenceAddingRequest req = client.getCUDRequestFactory()
.getReferenceAddingRequest(productCategoriesUri, ref);
 to 
ODataReferenceAddingRequest req = client.getCUDRequestFactory()
.getReferenceAddingRequest(serviceRoot, productCategoriesUri, ref);

The previous implementation sent always an empty body to the server. As 
described in OData speciation (11.4.6.1 and 11.4.6.3), the body must contain, 
in both cases, a single entity reference.

Such a body could look like this:

{
  "@odata.context": "http://host/service/$metadata#$ref";,
  "@odata.id": "Orders(10643)"
}

or

<metadata:ref xmlns:metadata="http://docs.oasis-open.org/odata/ns/metadata";
              metadata:context="http://host/service/$metadata#$ref";
              id="http://host/service/Orders(10643)" />

As mentioned in the OData format documents, the attribute context must be 
provided. So the service root will be used to construct the URI the metadata 
document.

Best Regards,
Christian


> Problem when using the ODataReferenceAddingRequest to add a reference to a 
> property
> -----------------------------------------------------------------------------------
>
>                 Key: OLINGO-510
>                 URL: https://issues.apache.org/jira/browse/OLINGO-510
>             Project: Olingo
>          Issue Type: Bug
>          Components: odata4-client
>    Affects Versions: V4 4.0.0-beta-01
>         Environment: java version : "1.7.0_72"
> Odata v4 service : 
> http://services.odata.org/V4/OData/(S(li4s4wcplcgyiy3uvuog1lxl))/OData.svc
>            Reporter: Thierry Templier
>            Assignee: Christian Amend
>
> When using a ODataReferenceAddingRequest to a reference for a property:
> String serviceRoot = (...);
> URI productCategoriesUri = client.newURIBuilder(serviceRoot)
>     .appendEntitySetSegment("Products")
>     .appendKeySegment(1)
>     .appendNavigationSegment("Categories")
>     .appendRefSegment()
>     .build();
> URI ref = client.newURIBuilder(serviceRoot)
>     .appendEntitySetSegment("Categories")
>     .appendKeySegment(1)
>     .build();
> ODataReferenceAddingRequest req = client.getCUDRequestFactory()
>     .getReferenceAddingRequest(productCategoriesUri, ref);
> ODataReferenceAddingResponse res = req.execute();
> The link of the reference to add isn't sent in the payload of the request.
> Here is the simplified content of the request:
> POST 
> /V4/OData/(S(li4s4wcplcgyiy3uvuog1lxl))/OData.svc/Products(1)/Supplier/$ref
> and the simplified content of the response:
> HTTP/1.1 400 Bad Request
> {
>   "error":{
>     "code":"",
>     "message":"An error occurred while processing this request.",
>     "innererror":{
>       "message":"An unexpected 'EndOfInput' node was found when reading from 
> the JSON reader. A 'StartObject'
>              node was 
> expected.","type":"Microsoft.OData.Core.ODataException","stacktrace":" "
>     }
>   }
> }
> We should have something like this in the payload:
> {
>   "@odata.id":"http://(...)/Suppliers(4)"
> }



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to