[英]get Edm from InputStream/String Olingo4
In Olingo 2 I could do this: 在Olingo 2中,我可以这样做:
Edm metadataEdm = EntityProvider.readMetadata(metadataInputStream, false); //metadataInputStream is java.io.InputStream
From what I have read in Olingo 4, you can do this: 根据我在Olingo 4中阅读的内容,可以执行以下操作:
ODataClient client = ODataClientFactory.getClient();
String serviceRoot = "http://services.odata.org/V4/Northwind/Northwind.svc";
EdmMetadataRequest request
= client.getRetrieveRequestFactory().getMetadataRequest(serviceRoot);
ODataRetrieveResponse<Edm> response = request.execute();
But in my project I can only use HTTPClient
for any network calls - which means I can't use ODataClient client
. 但是在我的项目中我只能对任何网络调用使用HTTPClient
这意味着我不能使用ODataClient client
。
From HttpClient
I can get the InputStream
. 从HttpClient
我可以获得InputStream
。 Is there a way (as shown above for Olingo 2) to get the Edm
object from InputStream in Olingo 4 ? 有没有办法(如上面针对Olingo 2所示)从Olingo 4的InputStream获取Edm
对象?
Yes there is a way to do this in Olingo 4 using the ODataReader
.It accepts input stream in method Edm readMetadata(InputStream input);
是的,在Olingo 4中有一种使用ODataReader
进行此操作的ODataReader
它在方法Edm readMetadata(InputStream input);
接受输入流Edm readMetadata(InputStream input);
Your code above can be modified in the following way to achieve the same result. 您可以按照以下方式修改上面的代码以达到相同的结果。
ODataReader reader = ODataClientFactory.getClient().getReader();
String serviceRoot = "http://services.odata.org/V4/Northwind/Northwind.svc/$metadata";
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(serviceRoot);
httpGet.addHeader("Accept", "application/xml"); // Looks like version 4.4.0 of OData client only supports xml format for metadata
HttpResponse response = httpClient.execute(httpGet);
Edm edm = reader.readMetadata(response.getEntity().getContent());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.