Hi,
I am trying to use Apache Olingo library(java based) for consuming the DSS REST API. I am not able to find any examples or documentation to do that. Wanted to check if someone has used this before.
Code Sample:
Just doing a POC to write an equivalent code using Apache Olingo for the below DSS2Java Example
/**
* This is a composite On Demand Extraction Request
*
* Here is the reference doc for the Async mechanism:
* https://hosted.datascopeapi.reuters.com/RestApi.Help/Home/KeyMechanisms#sectionAsync
*
*/
public void compositeRequest() {
try {
HttpPost httppost = new HttpPost(urlHost + "/Extractions/ExtractWithNotes");
httppost.addHeader("content-type", "application/json;odata.metadata=minimal");
httppost.addHeader("Authorization", "Token " + sessionToken);
// Use the 1st line for your program, the 2nd line to test a timeout (HTTP status 202):
httppost.addHeader("Prefer", "respond-async");
//httppost.addHeader("Prefer", "respond-async, wait=5");
JSONOrderedObject compositeExtractJSONObject = new JSONOrderedObject()
.put("ExtractionRequest", new JSONOrderedObject()
.put("@odata.type", "#ThomsonReuters.Dss.Api.Extractions.ExtractionRequests.CompositeExtractionRequest")
.put("ContentFieldNames", new JSONArray()
.put("RIC")
.put("CUSIP")
.put("ISIN")
.put("SEDOL")
.put("Issuer OrgID")
.put("Currency Code")
.put("Annualized Dividend Period Start Date")
.put("Annualized Dividend Adjusted Gross Amount")
.put("Balance Sheet - Enterprise Value")
.put("Balance Sheet - Market Value"))
.put("IdentifierList", new JSONOrderedObject()
.put("@odata.type", "#ThomsonReuters.Dss.Api.Extractions.ExtractionRequests.InstrumentIdentifierList")
.put("InstrumentIdentifiers", new JSONArray()
.put(new JSONObject()
.put("Identifier", "00209tab1")
.put("IdentifierType", "Cusip"))
.put(new JSONObject()
.put("Identifier", "IBM.N")
.put("IdentifierType", "Ric"))
.put(new JSONObject()
.put("Identifier", "US4592001014")
.put("IdentifierType", "Isin"))
.put(new JSONObject()
.put("Identifier", "B1YW440")
.put("IdentifierType", "Sedol")))));
System.out.println("Composite extraction JSON request content:\n"+ compositeExtractJSONObject.toString() +"\n");
StringEntity requestBody = new StringEntity(compositeExtractJSONObject.toString());
httppost.setEntity(requestBody);
// NOTE: If the extraction request takes more than 30 seconds the async mechanism will be used.
System.out.println("We submit the request, a response should arrive in approximately 30 seconds ...\n");
HttpResponse response = httpclient.execute(httppost);
StringBuffer result = new StringBuffer();
// Get the response status code
int respStatusCode = response.getStatusLine().getStatusCode();
Sample Code using Olingo: (Snapshot)
ODataClient client = ODataClientFactory.getClient();
client.getConfiguration()
.setHttpClientFactory(new BasicAuthHttpClientFactory("<username>", "<password>"));
ODataRetrieveRequest<ClientEntitySet> request = client.getRetrieveRequestFactory()
.getEntitySetRequest(client.newURIBuilder(urlHost)
.appendActionCallSegment("Extractions/CompositeExtractionRequest")
.build());
/request.addCustomHeader("Authorization", "Token <token>");
final ODataRetrieveResponse<ClientEntitySet> response = request.execute();
final ClientEntitySet entitySet = response.getBody();
System.out.println(entitySet);