Categories
android java rest server-sent-events spring

Spring rest service with SseEmitter

I’m trying to notify a simple html page when I call a controller on my server. I have an android application who calls my controller and when this is done I would like to notify my webpage that the controller was called.

Here is some of my code:

    @RequestMapping("/user") 
public class UserController {
/**
* Returns user by id.
*
* @param user IMEI
* @return
*/
@RequestMapping(value = "/{imei}", method = RequestMethod.GET)
public User getUser(@PathVariable String imei) {
User myUser = null;
try {
myUser = DbConnector.getUserWithImei(imei);
} catch (Exception e) {
System.out.println("Couldn't get user from database");
e.printStackTrace();
}
SseEmitter emitter = new SseEmitter();
try {
emitter.send("Hallokes");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
emitter.complete();
return myUser;
}
}

All tutorials I see, the controller returns SseEmitter but I have to return a User. Must I make another controller with another mapping and listen on that url? How would I call that controller method within my existing controller?
To what URL must my EventSource listen?

Thanks in advance for your help!

Kind regards.