I have inherited a plugin that accepts commands as a http servelet.
One of the commands is to set the presence of a user. I use the following code
User user = userManager.getUser(username); JID userjid = new JID(username, server, "Server"); AuthToken token = AuthFactory.authenticate(username, AuthFactory.getPassword(username)); LocalClientSession session = sessionManager.createClientSession(new FakeConnection()); session.setAuthToken(token, "Server"); Presence presence = session.getPresence(); presence.setType(null); presence.setStatus("Online"); presence.setShow(null); presence.setPriority(10); presenceManager.userAvailable(presence); session.setPresence(presence); user.getRoster().broadcastPresence(presence); sessionManager.broadcastPresenceToOtherResources(userjid, presence);
Not showing the exception handeling above.
The FakeConnection is a simple extension of VirtualConnection that does nothing.
In the OpenFire management console, a user is however not shown as online. Is this because of the FakeConnection or because the user is in fact not correctly set as present?
Is there a better way to persistently set a user as present through a plugin?