Discover Refinitiv
MyRefinitiv Refinitiv Perspectives Careers
Created with Sketch.
All APIs Questions & Answers  Register |  Login
Ask a question
  • Questions
  • Tags
  • Badges
  • Unanswered
Search:
  • Home /
  • TREP APIs /
avatar image
Question by shyam.sanghvi · Dec 27, 2019 at 01:31 PM · javarestapiretrieve data

not able to rerurn JSON aaray in RESTAPI (local host )

public void onTextMessage(WebSocket websocket, String message) throws JSONException {
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 .

People who like this

0 Show 0
Comment
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

6 Replies

  • Sort: 
avatar image
REFINITIV
Best Answer
Answer by jirapongse.phuriphanvichai · Dec 30, 2019 at 06:34 AM

@shyam.sanghvi

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.



1577687258359.png (33.0 KiB)
Comment

People who like this

0 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

avatar image
REFINITIV
Answer by wasin.waeosri · Dec 30, 2019 at 07:51 AM

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
}
Comment

People who like this

0 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

avatar image
Answer by shyam.sanghvi · Dec 30, 2019 at 08:10 AM

@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

Comment

People who like this

0 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

avatar image
Answer by shyam.sanghvi · Dec 30, 2019 at 08:14 AM

Hi @jirapongse.phuriphanvichai

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.

Comment

People who like this

0 Show 1 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

avatar image
REFINITIV
jirapongse.phuriphanvichai ♦♦ · Dec 30, 2019 at 09:10 AM 0
Share

@shyam.sanghvi

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?


avatar image
Answer by shyam.sanghvi · Dec 30, 2019 at 03:14 PM

@jirapongse.phuriphanvichai

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.

Comment

People who like this

0 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

avatar image
Answer by shyam.sanghvi · Dec 30, 2019 at 03:14 PM

@Wasin Waeosri

Thank You

I was able to retrieve the data in my rest local host through QUEUE implementation.


Comment

People who like this

0 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Watch this question

Add to watch list
Add to your watch list to receive emailed updates for this question. Too many emails? Change your settings >
9 People are following this question.

Related Questions

EmaConfig.xml when using Java - problem

Need help with TREP contribution

Publishing using NIP ETA library (F10: Not In Cache error when consuming)

lock on request

Parsing View Response Data

  • Feedback
  • Copyright
  • Cookie Policy
  • Privacy Statement
  • Terms of Use
  • Careers
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Alpha
  • App Studio
  • Block Chain
  • Bot Platform
  • Calais
  • Connected Risk APIs
  • DSS
  • Data Fusion
  • Data Model Discovery
  • Datastream
  • Eikon COM
  • Eikon Data APIs
  • Elektron
    • EMA
    • ETA
    • WebSocket API
  • Legal One
  • Messenger Bot
  • Messenger Side by Side
  • ONESOURCE
    • Indirect Tax
  • Open PermID
    • Entity Search
  • Org ID
  • PAM
    • PAM - Logging
  • ProView
  • ProView Internal
  • Product Insight
  • Project Tracking
  • Refinitiv Data Platform
    • Refinitiv Data Platform Libraries
  • Rose's Space
  • Screening
    • Qual-ID API
    • Screening Deployed
    • Screening Online
    • World-Check One
    • World-Check One Zero Footprint
  • Side by Side Integration API
  • TR Knowledge Graph
  • TREP APIs
    • CAT
    • DACS Station
    • Open DACS
    • RFA
    • UPA
  • TREP Infrastructure
  • TRIT
  • TRKD
  • TRTH
  • Thomson One Smart
  • Transactions
    • REDI API
  • Velocity Analytics
  • Wealth Management Web Services
  • World-Check Data File
  • Explore
  • Tags
  • Questions
  • Badges