You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@olingo.apache.org by Tom van Wietmarschen <aa...@gmail.com> on 2017/07/18 12:47:37 UTC

Olingo client, stream properties and the EDM

Hi,

We have an OData service built with OLingo. This service has a few properties of type Edm.Stream, they do not show up in the output when metadata=minimal and only as "image@odata.type" : "#Stream" when metadata=full. As far as I can tell this is correct according to the OData v4 spec.

When I try to consume this service using a Olingo generated client, I get the following exception: 

java.lang.IllegalArgumentException: Cannot build a primitive value for Stream
	at org.apache.olingo.client.core.domain.ClientPrimitiveValueImpl$BuilderImpl.setType(ClientPrimitiveValueImpl.java:60)
	at org.apache.olingo.client.core.domain.ClientPrimitiveValueImpl$BuilderImpl.setType(ClientPrimitiveValueImpl.java:37)
	at org.apache.olingo.client.core.serialization.ODataBinderImpl.getODataValue(ODataBinderImpl.java:898)
	at org.apache.olingo.client.core.serialization.ODataBinderImpl.getODataProperty(ODataBinderImpl.java:811)
	at org.apache.olingo.client.core.serialization.ODataBinderImpl.getODataValue(ODataBinderImpl.java:859)
	at org.apache.olingo.client.core.serialization.ODataBinderImpl.getODataProperty(ODataBinderImpl.java:811)
	at org.apache.olingo.client.core.serialization.ODataBinderImpl.getODataValue(ODataBinderImpl.java:859)
	at org.apache.olingo.client.core.serialization.ODataBinderImpl.getODataProperty(ODataBinderImpl.java:811)
	at org.apache.olingo.client.core.serialization.ODataBinderImpl.getODataEntity(ODataBinderImpl.java:726)
	at org.apache.olingo.client.core.serialization.ODataBinderImpl.getODataEntitySet(ODataBinderImpl.java:427)
	at org.apache.olingo.client.core.communication.request.retrieve.ODataEntitySetRequestImpl$ODataEntitySetResponseImpl.getBody(ODataEntitySetRequestImpl.java:85)
	at org.apache.olingo.client.core.communication.request.retrieve.ODataEntitySetRequestImpl$ODataEntitySetResponseImpl.getBody(ODataEntitySetRequestImpl.java:68)
(etc.)

Could this be caused by a problem in our server-side implementation or does the OLingo client not support any services that use Stream properties ? I would have understood it not supporting that type of property and it just ignoring it or giving an error when trying to read the property value, but not being able to access anything just because one of the (many) properties of an Entity is a Stream seems a bit harsh. 

Another few related questions:

When testing the OData client, we encountered a few errors (actually a nullpointer somewhere deep in the OLingo client code) because the output of our Olingo service contained "@odata.type" : "#null" entries for all ComplexValue's when metadata=full. Turns out I have to specify the FQN for each property when creating Entities for serialisation, otherwise the types are null. Why is this ? The types are already specified in the EDM which I have to supply to the serialiser. Same goes for the client, why is it even looking at @odata.type if it already has the EDM to supply type information ? Isn't the EDM supposed to be the single source of truth for type information in an OData service ? Also, how come it's not using the type information from the EDM for creating ComplexValue's, but somehow it is able to add the type information for a property I don't even add during Entity creation ? What is the point of supplying redundant type information to properties ?

/Tom

Re: Olingo client, stream properties and the EDM

Posted by Tom van Wietmarschen <aa...@gmail.com>.
> On 19 Jul 2017, at 10:28, Tiwari, Rajnish <ra...@sap.com> wrote:
> 
> Hi Tom,
> 
> Can you share you code snippet ? 

As this is a proprietary codebase I can share a few lines at most, but which lines would even be relevant here ? On the server side, everything looks fine, the output is exactly as I'd expect from reading the OData v4 specs. On the client side, all I'm doing is asking the client library for the entities in my entity-set and it crashes with the exception I posted before on deserialising the very first entry. It works client-side if I include a 'select' statement which leaves out the Stream property. 

This is what the client code looks like (snippet from a unit test)

		final EdmEnabledODataClient client = clientWrapper.getClient(); // clientWrapper configures the server URL and auth.
		final URI documentsUri = client.newURIBuilder() //
		    .appendEntitySetSegment(SESSIONS_ENTITY_NAME) //
		    .build();
		
		// Get response
		final ODataRetrieveResponse<ClientEntitySet> response = client.getRetrieveRequestFactory() //
		    .getEntitySetRequest(documentsUri) //
		    .execute();
		assertNotNull(response);
		final ClientEntitySet entities = response.getBody();


The exception occurs in the call to getBody()

If I add
		    .select("sessionId")

to the URIBuilder, the call to getBody works as expected.

I'm not even sure why the "image@odata.type <ma...@odata.type>" appears in the output as I never even add that property to the entity (only to the EDM) and for every property I *do* add the type is only shown if I explicitly add it to the Property, if I set it to 'null' there is no @odata.type generated even though the type info is in the EDM I supply to the serialiser. So for the fields where I would expect it to automatically insert the type data it doesn't (why is there even an option to specify it when instantiating a Property?) , and for the fields where I expect it to do nothing, it magically inserts type data. 

> Also you can try the properties Edm.Binary  once instead of Edm.Stream.

Not sure what it would accomplish, even if it works, as it's not a valid alternative. These streams are only needed occasionally and the binaries are relatively expensive to produce, I don't want them in every response, streams would be perfect because they can be loaded on-demand.

/Tom

> 
> 
> 
> Regards,
> Rajnish
> 
> -----Original Message-----
> From: Tom van Wietmarschen [mailto:aaargh@gmail.com] 
> Sent: Tuesday, July 18, 2017 6:18 PM
> To: user@olingo.apache.org
> Subject: Olingo client, stream properties and the EDM
> 
> Hi,
> 
> We have an OData service built with OLingo. This service has a few properties of type Edm.Stream, they do not show up in the output when metadata=minimal and only as "image@odata.type" : "#Stream" when metadata=full. As far as I can tell this is correct according to the OData v4 spec.
> 
> When I try to consume this service using a Olingo generated client, I get the following exception: 
> 
> java.lang.IllegalArgumentException: Cannot build a primitive value for Stream
> 	at org.apache.olingo.client.core.domain.ClientPrimitiveValueImpl$BuilderImpl.setType(ClientPrimitiveValueImpl.java:60)
> 	at org.apache.olingo.client.core.domain.ClientPrimitiveValueImpl$BuilderImpl.setType(ClientPrimitiveValueImpl.java:37)
> 	at org.apache.olingo.client.core.serialization.ODataBinderImpl.getODataValue(ODataBinderImpl.java:898)
> 	at org.apache.olingo.client.core.serialization.ODataBinderImpl.getODataProperty(ODataBinderImpl.java:811)
> 	at org.apache.olingo.client.core.serialization.ODataBinderImpl.getODataValue(ODataBinderImpl.java:859)
> 	at org.apache.olingo.client.core.serialization.ODataBinderImpl.getODataProperty(ODataBinderImpl.java:811)
> 	at org.apache.olingo.client.core.serialization.ODataBinderImpl.getODataValue(ODataBinderImpl.java:859)
> 	at org.apache.olingo.client.core.serialization.ODataBinderImpl.getODataProperty(ODataBinderImpl.java:811)
> 	at org.apache.olingo.client.core.serialization.ODataBinderImpl.getODataEntity(ODataBinderImpl.java:726)
> 	at org.apache.olingo.client.core.serialization.ODataBinderImpl.getODataEntitySet(ODataBinderImpl.java:427)
> 	at org.apache.olingo.client.core.communication.request.retrieve.ODataEntitySetRequestImpl$ODataEntitySetResponseImpl.getBody(ODataEntitySetRequestImpl.java:85)
> 	at org.apache.olingo.client.core.communication.request.retrieve.ODataEntitySetRequestImpl$ODataEntitySetResponseImpl.getBody(ODataEntitySetRequestImpl.java:68)
> (etc.)
> 
> Could this be caused by a problem in our server-side implementation or does the OLingo client not support any services that use Stream properties ? I would have understood it not supporting that type of property and it just ignoring it or giving an error when trying to read the property value, but not being able to access anything just because one of the (many) properties of an Entity is a Stream seems a bit harsh. 
> 
> Another few related questions:
> 
> When testing the OData client, we encountered a few errors (actually a nullpointer somewhere deep in the OLingo client code) because the output of our Olingo service contained "@odata.type" : "#null" entries for all ComplexValue's when metadata=full. Turns out I have to specify the FQN for each property when creating Entities for serialisation, otherwise the types are null. Why is this ? The types are already specified in the EDM which I have to supply to the serialiser. Same goes for the client, why is it even looking at @odata.type if it already has the EDM to supply type information ? Isn't the EDM supposed to be the single source of truth for type information in an OData service ? Also, how come it's not using the type information from the EDM for creating ComplexValue's, but somehow it is able to add the type information for a property I don't even add during Entity creation ? What is the point of supplying redundant type information to properties ?
> 
> /Tom


RE: Olingo client, stream properties and the EDM

Posted by "Tiwari, Rajnish" <ra...@sap.com>.
Hi Tom,

Can you share you code snippet ? 

Also you can try the properties Edm.Binary  once instead of Edm.Stream.




Regards,
Rajnish

-----Original Message-----
From: Tom van Wietmarschen [mailto:aaargh@gmail.com] 
Sent: Tuesday, July 18, 2017 6:18 PM
To: user@olingo.apache.org
Subject: Olingo client, stream properties and the EDM

Hi,

We have an OData service built with OLingo. This service has a few properties of type Edm.Stream, they do not show up in the output when metadata=minimal and only as "image@odata.type" : "#Stream" when metadata=full. As far as I can tell this is correct according to the OData v4 spec.

When I try to consume this service using a Olingo generated client, I get the following exception: 

java.lang.IllegalArgumentException: Cannot build a primitive value for Stream
	at org.apache.olingo.client.core.domain.ClientPrimitiveValueImpl$BuilderImpl.setType(ClientPrimitiveValueImpl.java:60)
	at org.apache.olingo.client.core.domain.ClientPrimitiveValueImpl$BuilderImpl.setType(ClientPrimitiveValueImpl.java:37)
	at org.apache.olingo.client.core.serialization.ODataBinderImpl.getODataValue(ODataBinderImpl.java:898)
	at org.apache.olingo.client.core.serialization.ODataBinderImpl.getODataProperty(ODataBinderImpl.java:811)
	at org.apache.olingo.client.core.serialization.ODataBinderImpl.getODataValue(ODataBinderImpl.java:859)
	at org.apache.olingo.client.core.serialization.ODataBinderImpl.getODataProperty(ODataBinderImpl.java:811)
	at org.apache.olingo.client.core.serialization.ODataBinderImpl.getODataValue(ODataBinderImpl.java:859)
	at org.apache.olingo.client.core.serialization.ODataBinderImpl.getODataProperty(ODataBinderImpl.java:811)
	at org.apache.olingo.client.core.serialization.ODataBinderImpl.getODataEntity(ODataBinderImpl.java:726)
	at org.apache.olingo.client.core.serialization.ODataBinderImpl.getODataEntitySet(ODataBinderImpl.java:427)
	at org.apache.olingo.client.core.communication.request.retrieve.ODataEntitySetRequestImpl$ODataEntitySetResponseImpl.getBody(ODataEntitySetRequestImpl.java:85)
	at org.apache.olingo.client.core.communication.request.retrieve.ODataEntitySetRequestImpl$ODataEntitySetResponseImpl.getBody(ODataEntitySetRequestImpl.java:68)
(etc.)

Could this be caused by a problem in our server-side implementation or does the OLingo client not support any services that use Stream properties ? I would have understood it not supporting that type of property and it just ignoring it or giving an error when trying to read the property value, but not being able to access anything just because one of the (many) properties of an Entity is a Stream seems a bit harsh. 

Another few related questions:

When testing the OData client, we encountered a few errors (actually a nullpointer somewhere deep in the OLingo client code) because the output of our Olingo service contained "@odata.type" : "#null" entries for all ComplexValue's when metadata=full. Turns out I have to specify the FQN for each property when creating Entities for serialisation, otherwise the types are null. Why is this ? The types are already specified in the EDM which I have to supply to the serialiser. Same goes for the client, why is it even looking at @odata.type if it already has the EDM to supply type information ? Isn't the EDM supposed to be the single source of truth for type information in an OData service ? Also, how come it's not using the type information from the EDM for creating ComplexValue's, but somehow it is able to add the type information for a property I don't even add during Entity creation ? What is the point of supplying redundant type information to properties ?

/Tom