In Olingo 2 I could do this:
Edm metadataEdm = EntityProvider.readMetadata(metadataInputStream, false); //metadataInputStream is java.io.InputStream
From what I have read in Olingo 4, you can do this:
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
.
From HttpClient
I can get the InputStream
. Is there a way (as shown above for Olingo 2) to get the Edm
object from InputStream in Olingo 4 ?
Yes there is a way to do this in Olingo 4 using the ODataReader
.It accepts input stream in method 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());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.