Client-side API documentation seems to be ignored by Olingo. But in the sample / client there is an example in the GIT repository .
Basically for GET you do the following:
String serviceUrl = "http://localhost:9080/odata-server-sample/cars.svc" String entitySetName = "Manufacturers"; ODataClient client = ODataClientFactory.getClient(); URI absoluteUri = client.newURIBuilder(serviceUri).appendEntitySetSegment(entitySetName).build(); ODataEntitySetIteratorRequest<ClientEntitySet, ClientEntity> request = client.getRetrieveRequestFactory().getEntitySetIteratorRequest(absoluteUri); // odata4 sample/server limitation not handling metadata=full request.setAccept("application/json;odata.metadata=minimal"); ODataRetrieveResponse<ClientEntitySetIterator<ClientEntitySet, ClientEntity>> response = request.execute(); ClientEntitySetIterator<ClientEntitySet, ClientEntity> iterator = response.getBody(); while (iterator.hasNext()) { ClientEntity ce = iterator.next(); System.out.println("Manufacturer name: " + ce.getProperty("Name").getPrimitiveValue()); }
Take a look at the sample in the Olingo code base for more information on how to get metadata, handle all properties, etc.
To do a POST, you can do the following. (Note that this is not verified code, and the Car service sample is read-only.) First, you create the data as ClientEntity. You for example with
ClientComplexValue manufacturer = of.newComplexValue("Manufacturer"); manufacturer.add(of.newPrimitiveProperty("Name", of.newPrimitiveValueBuilder().buildString("Ford")));
Then you send a POST request
ODataEntityCreateRequest<ClientEntity> request = client.getCUDRequestFactory().getEntityCreateRequest(absoluteUri, manufacturer); ODataEntityCreateResponse<ClientEntity> response = request.execute();
So this is not with POJO classes - the result type is ClientEntity, which represents the data as name / value maps. There is already another unresolved question about this specific topic in Olingo - the creation of strongly typed POJOs for the OData client service library and I suggest that we go there to follow up on this.
source share