powered by Jive Software

Xmpp.getinstance

Hello guys, I am still very new to openfire and I wanted to ask a question about the xmpp.getinstance method. From what I can see in the docs, this will return an instance of the xmpp server if it is null and is also a singletone.

  1. I would like to know how to connect to an already running openfire instance. I know if i download and install openfire, it will create its own instance and run in jetty. That means its in a different VM so there is no way to connect to that since my servlet is running in another vm. If I want to connect to that instance, how do I proceed? Do i need to build the source, get a jar/war and stick in jboss/tomcat where I am running my servlet?

Openfire does not run inside an Jetty instance, it’s a standalone Java application. However, it does start an Jetty instance to provide the webinterface (admin console).

If you want to connect a servlet running on Tomcat with Openfire I see some possible ways:

  1. Put your servlet in an Openfire plugin and use Openfire’s Jetty instance instead of Tomcat. My GoogleWebToolkit example plugin might help here, since GWT does also create a servlet designed for Tomcat.

  2. You could create a plugin for Openfire with provides some kind of API interface, which you can access in your Tomcat servlet. E.g. an HTTP-based interface would be relativly easy. Something XMPP based would be faster, but a bit more compilcated.

What exactly do you want to do?

Basically, i want to close some of the sessions that are active in openfire when my http session dies. I have a servlet and a servlet filter for that and I want to check:

if httpsession == null

then

getxmppserver.getinstance() and then get the session manager and close the appropriate session so that the user doesn;t stay active on the openfire session. I just don’t now which instance of openfire the getxmppserver is getting. Is it creating a new one ?

Thanks. greatly appreciated.

There is no getxmppserver.getinstance() and no xmpp.getinstance method, just an static method XMPPServer.getInstance(). I think that’s what you mean.

The server is unique in the JVM and could be obtained by using the
getInstance() method.
You wont be able to access this singleton directly from Tomcat.

However, since your problem does not require an callback this should be relativly simple:

  1. Create an Openfire Plugin which provides an servlet. The servlet’s doGet()-method does simply close the user’s session and provides an empty page then.

  2. In your Tomcat-Servlet execute an HTTP-Request on http://localhost:9090/plugins/YOUR-PLUGIN/YOUR-SERVLET?user=foobar

It is needless to say that it is wise to protect your Session-Close-Servlet from unauthorized users.

Thanks for your help, so basically , i just expose a servlet via the plugin interface and access it via my custom servlet.

Oh 1 more thing, since you are so knowledgeable, do you mind me asking why the xmpp.client.idle doesn’t work everytime ? i.e sometimes it disconnects the user and sometimes it doesn’t, I tried setting it to 300,000 as in 300000 ms which is rougly 5 mins but that doesn’t seem to kick the user out from the server.

Thanks.

Thanks for your help, so basically , i just expose a servlet via the plugin interface and access it via my custom servlet.
Correct. Might not be the “best” way, but the simplest to implement.

do you mind me asking why the xmpp.client.idle doesn’t work everytime ?
no, I don’t know why this does not work for you. I had problems with that, too.

Message was edited by: Coolcat

Message was edited by: Coolcat

Ah ok thanks. So basically you faced the same issues. Many thanks for your help.