【发布时间】:2017-01-23 14:54:31
【问题描述】:
OData官方教程展示了如何创建实体:http://www.odata.org/getting-started/basic-tutorial/#create
我想使用 Templier 关于使用 Olingo (https://templth.wordpress.com/2014/12/05/manipulating-data-of-odata-v4-services-with-olingo/) 操作 OData v4 服务数据的教程在 Apache Olingo 中重现这一点
很遗憾,本教程已过时,我无法创建成功的 POST 请求。尝试执行我的代码会产生HTTP/1.1 500 Internal Server Error。
这是我目前的代码:
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();
我做错了什么?我该怎么做才能进一步识别/调试问题?
非常感谢。
【问题讨论】:
标签: java apache post odata olingo