FluentHelperByKey and FluentHelperCreate are returning different objects

54 Views Asked by At

When checking the response of a request executed with Cloud SDK, we see that FluentHelperByKey does not have any headers. FluentHelperByKey is returned for successful requests. For erroneous ones, we receive FluentHelperCreate which includes headers.

I would expect both objects to be aligned. Either both returned headers or only one of them is used.

The request is referring to the executeRequest method within different FluentHelpers. e.g.

FluentHelperByKey -> EntityT
FluentHelperRead -> List<EntityT>
FluentHelperCreate -> ModificationResponse<EntityT>

In the first two variants we only get the result as defined Entities, whereas in the third option we also get access to further response attributes such as headers and status code. Would it be possible to provide a common access point to retrieve generic request/response attributes in all kinds of FluentHelpers like in the FluentHelperCreate?

1

There are 1 best solutions below

0
Alexander Dümont On

Would it be possible to provide a common access point to retrieve generic request/response attributes in all kinds of FluentHelpers like in the FluentHelperCreate?

Yes, this is the Generic OData Client. Let's motivate the use case...

Suggestion

If you want both executions to return your target T entity, please consider casting to Generic OData Client:

HttpDestination destination;
FluentHelperBasic fluentHelper;
// fluentHelper = service.getEntityByKey("Foo");
// fluentHelper = service.createEntity(entity);

HttpClient httpClient = HttpClientAccessor.getHttpClient(destination);

ODataRequestResultGeneric result = fluentHelper.toRequest().execute(httpClient);
EntityT result = result.as(EntityT.class);
Map<String, Iterable<String>> allHeaders = result.getAllHeaderValues();

Please find other options for deserialization, header- and error-handling in the ODataRequestResultGeneric object.

API definition

For OData V2

  • FluentHelperCreate<?,T>#executeRequest(..) returns ModificationResponse<T>
  • FluentHelperByKey<?,T>#executeRequest(..) returns T

For OData V4

  • CreateRequestBuilder<T>#execute(..) returns ModificationResponse<T>
  • GetByKeyRequestBuilder<T>#execute(..) returns T

For Generic OData Client

  • ODataRequestCreate#execute(..) returns ODataRequestResultGeneric
  • ODataRequestReadByKey#execute(..) returns ODataRequestResultGeneric
  • ODataRequestResultGeneric#as(ClassT.class) returns T <-- YOU WANT THIS

Casting from OData V2 to Generic OData Client:

  • FluentHelperCreate<?,T>#toRequest() returns ODataRequestCreate
  • FluentHelperByKey<?,T>#toRequest() returns ODataRequestReadByKey

Casting from OData V4 to Generic OData Client:

  • FluentHelperCreate<?,T>#toRequest() returns ODataRequestCreate
  • FluentHelperByKey<?,T>#toRequest() returns ODataRequestReadByKey

Outlook

We will likely not change the API for OData v2 and OData v4 anytime soon. In cases like this we recommend (casting to) the Generic OData Client.