Hi people!
Ummmm.. do you need somevalue of session? or only the name of the user, to be used at the chat activitiy?
In any case, I would implement:
- Java (web server, I guess) sends a token to browser. In this context, token is a random key (a GUID, maybe). Java web server keeps a weak dictionary (or something more elaborated, with time expiration) that associate key with the data you want to keep track.
- Web browser send the token to node, in a Socket.IO message
- Node save the token in the client socket object, if you need it more than one time
- Node call a simplre REST service at Java web server, sending the receiving context. If you need more that one data piece, maybe you can send an additional parameter like "email", or "firstName", specifying what you want to get.
- Java web server query the weak dictionary using the token as key, retrieving the required data, and sending it in the response
- You can add security measures to keep the REST service only accesible from your Nodejs machine
- A weak dictionary prevents Java application to hold for ever the data
Another approach:
- Java server sends the token to the web browser
- Java server call a REST service AT NODE JS server, sending the token, and the data you will be use at chat flow (that is, in the case the data you need is known in advance, and you don't need to send data from Node.js to Java)
- Node.js save the info in a dictionary (a simple javascrip object)
- Web browser send the token to node.js/
socket.io during chat activity
- Node.js retrieved the rest of the data using the dictionary
- You must provide something to prune the dictionary (every token/key could have a "limit life" of 10 minutes, or delete the key if it is not used after X minutes)
Using the token, no sensible information is send to the browser. Having a random token, prevents cheating from a client.
You could use session.getId() as the key
Angel "Java" Lopez
@ajlopez
gh:ajlopez
hello everyone i have made a nodejs chat app with express and io. i want to integrate it with existing java application which is mode on java spring.
flow will be like that when user login the application i want to get the session of java in my nodejs to get user online.