not able to rerurn JSON aaray in RESTAPI (local host )
if(!message.isEmpty()) {
System.out.println("RECEIVED:");
JSONArray jsonArray = new JSONArray(message);
System.out.println(jsonArray.toString(2));
for (int i = 0; i < jsonArray.length(); ++i)
processMessage(websocket, jsonArray.getJSONObject(i));
}
}
i am able retrieve JSON from method, but not able to show it on webservice , as this is void methos plus its in anonymous class ,returning JSON from this and showing it in rest webservice is very difficult and i am unable to do that . i took that JSON array in list or map , but am unable to return that list with JSON ARRAY an show it on my localhost of webservice .This is only in case of JAVA .
Best Answer
-
I assume that you are referring to a Java example that uses nv-websocket-client to retrieve the data. The example just demonstrates how to use WebSocket API to retrieve the data from TREP. Handling and processing the data depends on the application.
From the example, the onTextMessage callback function is called a thread internally created by the nv-websocket-client library while the main thread has slept.
Therefore, you need to process the data inside this callback or put the data into a queue to be processed by another thread. I suggest putting the data into a queue to be processed by another thread to avoid a slow consumer problem.
0
Answers
-
Hello @shyam.sanghvi
Even though the nv-websocket-client WebSocket onTextMessage callback is a void method but you can call other methods or put data in to queue/others process/threads via on onTextMessage method as suggest by my colleague above.
Additionally, I did a quick test for by global variable scenario by creating an ArrayList object to keep each JSONArray object to process later. The code can add all received JSONArray object into an ArrayList and get each JSON message back from an ArrayList object.
public static ArrayList jsonArrayList = new ArrayList<JSONArray>();
...
public void onTextMessage(WebSocket websocket, String message) {
System.out.println("RECEIVED:");
JSONArray jsonArray = new JSONArray(message);
jsonArrayList.add(jsonArray);
...
}
//Later use
JSONArray laterJsonArray;
Iterator<JSONArray> iter = jsonArrayList.iterator();
while(iter.hasNext()){
laterJsonArray = iter.next();
// Process JSON message in laterJsonArray object
}0 -
@Wasin Waeosri Thanks For precious inputs .
Only these methods looks Feasible as said by your collegue (queue/others process/threads ).
Below method which you have tested , i have tried all the things , it doesnt work in restcontroller class , i have also created POJO and put the bid price and ask price in setter , added in map , It doent work still.
I don know how it worked for you , could you please try your example( used iterator ) in rest webservice.
Could you please give any example of adding it in queue ,or thread or process.
Thank you Wasin Waeosri
0 -
Thanks for the valuable inputs
Adding it queue is the only way i havent tried .
Could you please guve example on how to use it with my Controller class
Thanks again brother .
I am really stuck in this since 2 weeks .
Not able to process data with rest webservice.
I am pointing on REST because ( through local host URL). i will be able fetch that URL in my front end which is in React jS.
Please let me know how to add queues in controller class.
0 -
From my understanding, you need a synchronous function that accepts RIC and fields, and this function returns JSONObject to the caller. Therefore, the controller can call this function to retrieve the data. For example:
public JSONObject GetData(String Ric, String[] fields) {
}Moreover, you just require the latest data, not tick by tick data. Is this correct?
0 -
Wasin Waeosri
Thanks alot for inputs.
I was able to retrieve the data in my rest local host through QUEUE implementation.
Thank you Guys! Cheers
happy New Year.
0 -
@Wasin Waeosri
Thank You
I was able to retrieve the data in my rest local host through QUEUE implementation.
0
Categories
- All Categories
- 6 AHS
- 39 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 370 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 60 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛