powered by Jive Software

Problems routing packets in handleIQ


I have problems sending (to be more precise, routing) a message from my plugin. I extend the IQAuthHandler with the intention of intercepting each authentication request from the client, processing it normally, and then sending back to the client a message of type HEADLINE which contains a list of bad words (this is related to my previous post concerning content filtering).

This is the plugin class signature:

public class FileServerPlugin extends IQAuthHandler implements Plugin

I initialize the plugin in the following way:

public void initializePlugin(PluginManager manager, File pluginDirectory) {

myHandler = new org.jivesoftware.messenger.plugin.fileserver.FileServerPlugin();

iqRouter = XMPPServer.getInstance().getIQRouter();


router = XMPPServer.getInstance().getMessageRouter();

sessionManager = XMPPServer.getInstance().getSessionManager();


The problem is that I always get a null sessionManager, and I don’'t have a clue why.

So later, when I handle the Authorization packet:

public IQ handleIQ(IQ packet) throws UnauthorizedException {

// call the original handleIQ, and send the client a HEADLINE mesage

// containing all the bad words.

IQ resultPacket = super.handleIQ(packet);


Message badWordsHeadline = new Message();


String[] words = getBadWords();

StringBuffer badWordsStr = new StringBuffer();

for (int z=0; z<words.length; z++) {


if (z<words.length-1) badWordsStr.append(WORD_DELIMITER);




ClientSession session = sessionManager.getSession(packet.getFrom());

// it crashes here ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

badWordsHeadline.setFrom(new JID(null, session.getServerName(), null));


return resultPacket;


… the action stops when I try to get the session belonging to the sender.

I tried to override the problem by using the same “from” JID as the “to” one:


…but it crashes with the same problem, but now on the router.route() part:

2005.07.18 16:58:26 [org.jivesoftware.messenger.handler.IQHandler.process(IQHandler.java:72)

] Internal server error


at org.jivesoftware.messenger.plugin.fileserver.FileServerPlugin.handleIQ(FileServ erPlugin.java:86)

at org.jivesoftware.messenger.handler.IQHandler.process(IQHandler.java:49)

at org.jivesoftware.messenger.IQRouter.handle(IQRouter.java:202)

at org.jivesoftware.messenger.IQRouter.route(IQRouter.java:73)

at org.jivesoftware.messenger.PacketRouter.route(PacketRouter.java:65)

at org.jivesoftware.messenger.net.SocketReadThread.readStream(SocketReadThread.jav a:285)

at org.jivesoftware.messenger.net.SocketReadThread.run(SocketReadThread.java:105)

I really have no idea why I can’'t get it working with the first variation (using SessionManager). Is there some way - a special procedure? - for getting an instance of the session?

To summarize, my basic question here is:

How do I generate a Message that has a proper “From” equal to the server JID, that can be routed properly back to the client???

Thanks for all help,


try this…

public void initializePlugin(PluginManager manager, File pluginDirectory) {

//myHandler = new org.jivesoftware.messenger.plugin.fileserver.FileServerPlugin();

iqRouter = XMPPServer.getInstance().getIQRouter();


iqRouter.addHandler(this); //add this plugin as IQ handler

router = XMPPServer.getInstance().getMessageRouter();

sessionManager = XMPPServer.getInstance().getSessionManager();


the problem is that you in your initializePlugin method you are creating another instance of the plugin, you would have to call “initializePlugin” on the new instance in order avoid the null pointer. I presume that is not your intention at all.

Hope that helps,


Thanks Conor, you are absolutely right! I forgot to initialize the member in the new instance myHandler, so it’'s no wonder that it crashes later on…

Once again thanks a bunch, you saved me a lot of time and nerves!