OData's official tutorial shows how to create an entity: http://www.odata.org/getting-started/basic-tutorial/#create
I want to reproduce this within Apache Olingo using Templier's tutorial on manipulating data of OData v4 services with Olingo (https://templth.wordpress.com/2014/12/05/manipulating-data-of-odata-v4-services-with-olingo/)
Unfortunately, this tutorial is outdated and I am not able to create a successful POST
request. Trying to execute my code yields HTTP/1.1 500 Internal Server Error
.
This is my code so far:
String serviceRoot = "http://services.odata.org/V4/TripPinService/";
String namespace = "Microsoft.OData.SampleService.Models.TripPin";
URI personURI = client.newURIBuilder(serviceRoot)
.appendEntitySetSegment("People").build();
FullQualifiedName personFqn = new FullQualifiedName(namespace, "Person");
ClientEntity personEntity = client.getObjectFactory().newEntity(personFqn);
personEntity.getProperties().add(
client.getObjectFactory().newPrimitiveProperty(
"username",
client.getObjectFactory().newPrimitiveValueBuilder()
.buildString("MaryGilbert")));
//same procedure for "FirstName" and "LastName", which are obligatory fields
ODataEntityCreateRequest<ClientEntity> req = client.getCUDRequestFactory().getEntityCreateRequest(personURI,personEntity);
ODataEntityCreateResponse<ClientEntity> res = req.execute();
What am I doing wrong? What can I do, to further identify/ debug the problem?
Thank you very much.
I think that property names are case-sensitive, so try using UserName instead of username. Also, you could use Fiddler in order to debug your issues. This is the error for your use case:
HTTP/1.1 500 Internal Server Error - {"error":{"code":"InternalServerError","message":"The property 'UserName[Nullable=False]' of type 'Edm.String' has a null value