powered by Jive Software

No InetAddress in PacketInterceptor#interceptPacket() intercepted sessions?

Hi all,

Iā€™'ve written a plugin that implements the org.jivesoftware.wildfire.interceptor.PacketInterceptor interface. This was part of my interceptPacket() implementation.

public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) {
   // ...
   final InetAddress inet = session.getConnection().getInetAddress();
   // ...
}

Retrieving the InetAddress like this works in most cases, but in some, but regularly occuring cases, Openfire (3.2.2) throws a NullPointerException (below). Apparently, either the Session object, or session.getConnection() is null in some cases. Is that intended? I was assuming that by the time the packet was intercepted, the Connection on which it came should be available.

2007.03.23 07:43:21 [org.jivesoftware.wildfire.interceptor.InterceptorManager.invokeInterceptors(InterceptorManager.java:239)] Error in interceptor: com.buzzaa.wildfire.plugin.event.EventPlugin@22cc74e7
java.lang.NullPointerException
at com.buzzaa.wildfire.plugin.event.EventPlugin.interceptPacket(EventPlugin.java:312)
at org.jivesoftware.wildfire.interceptor.InterceptorManager.invokeInterceptors(InterceptorManager.java:227)
at org.jivesoftware.wildfire.IQRouter.route(IQRouter.java:84)
at org.jivesoftware.wildfire.spi.PacketRouterImpl.route(PacketRouterImpl.java:67)
at org.jivesoftware.wildfire.net.StanzaHandler.processIQ(StanzaHandler.java:289)
at org.jivesoftware.wildfire.net.ClientStanzaHandler.processIQ(ClientStanzaHandler.java:79)
at org.jivesoftware.wildfire.net.StanzaHandler.process(StanzaHandler.java:254)
at org.jivesoftware.wildfire.net.StanzaHandler.process(StanzaHandler.java:153)
at org.jivesoftware.wildfire.nio.ConnectionHandler.messageReceived(ConnectionHandler.java:131)
at org.apache.mina.common.support.AbstractIoFilterChain$TailFilter.messageReceived(AbstractIoFilterChain.java:703)
at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:362)
at org.apache.mina.common.support.AbstractIoFilterChain.access$1100(AbstractIoFilterChain.java:54)
at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceived(AbstractIoFilterChain.java:800)
at org.apache.mina.filter.codec.support.SimpleProtocolDecoderOutput.flush(SimpleProtocolDecoderOutput.java:62)
at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:192)
at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:362)
at org.apache.mina.common.support.AbstractIoFilterChain.access$1100(AbstractIoFilterChain.java:54)
at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceived(AbstractIoFilterChain.java:800)
at org.apache.mina.filter.executor.ExecutorFilter.processEvent(ExecutorFilter.java:250)
at org.apache.mina.filter.executor.ExecutorFilter$ProcessEventsRunnable.run(ExecutorFilter.java:305)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)

Hey Guus,

ClientSessions are created when the initial stream element is sent by the client. At the moment of the session created a connection is set. Sessions created for clients using http-binding follow this logic too. Moreover, the connection variable is never set to null. Can you add a few System.out to your code to confirm that the NPE is due to a null session or null connection? A possible explanation for this problem could be that SessionManager is failing to find a session for the sender of the packet (see IQRouter line 64 in trunk). If this is the case then we need to find out why is that happening. Any more info on how to reproduce this problem?

Thanks,

ā€“ Gato