Hi,
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();
iqRouter.addHandler(myHandler);
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);
loadBadWordsXML();
Message badWordsHeadline = new Message();
badWordsHeadline.setType(Message.Type.headline);
String[] words = getBadWords();
StringBuffer badWordsStr = new StringBuffer();
for (int z=0; z<words.length; z++) {
badWordsStr.append(words[z]);
if (z<words.length-1) badWordsStr.append(WORD_DELIMITER);
}
badWordsHeadline.setBody(badWordsStr.toString());
badWordsHeadline.setTo(packet.getFrom());
ClientSession session = sessionManager.getSession(packet.getFrom());
// it crashes here ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
badWordsHeadline.setFrom(new JID(null, session.getServerName(), null));
router.route(badWordsHeadline);
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:
badWordsHeadline.setFrom(packet.getFrom());
…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
java.lang.NullPointerException
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,
Darko