powered by Jive Software

Presence Mirroring using Packet Interceptor

I am trying to write a plugin to mirror presence packets to an external component. I implemented Packet Interceptor

public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) throws PacketRejectedException {

if (packet instanceof Presence) {
((Presence)packet).setTo(getMirrorToJID());
Log.debug(((Presence)packet).toString());

router.route(((Presence)packet));
}
}

The router created is a PresenceRouter, I get the following error below at runtime. I would appreciate any help. Thanks

Logging Error: Unknown error writing event.
java.lang.StackOverflowErrorLogging Error: Unknown error writing event.
java.lang.StackOverflowError
at org.jivesoftware.util.log.format.ExtendedPatternFormatter.getMethod(ExtendedPat ternFormatter.java:90)
at org.jivesoftware.util.log.format.ExtendedPatternFormatter.formatPatternRun(Exte ndedPatternFormatter.java:65)
at org.jivesoftware.util.log.format.PatternFormatter.format(PatternFormatter.java: 360)
at org.jivesoftware.util.log.output.AbstractOutputTarget.format(AbstractOutputTarg et.java:113)
at org.jivesoftware.util.log.output.AbstractOutputTarget.doProcessEvent(AbstractOu tputTarget.java:80)
at org.jivesoftware.util.log.output.AbstractTarget.processEvent(AbstractTarget.jav a:62)
at org.jivesoftware.util.log.Logger.fireEvent(Logger.java:535)
at org.jivesoftware.util.log.Logger.output(Logger.java:515)
at org.jivesoftware.util.log.Logger.output(Logger.java:501)
at org.jivesoftware.util.log.Logger.error(Logger.java:186)
at org.jivesoftware.util.Log.error(Log.java:339)
at org.jivesoftware.openfire.interceptor.InterceptorManager.invokeInterceptors(Int erceptorManager.java:240)
at org.jivesoftware.openfire.PresenceRouter.route(PresenceRouter.java:68)
at org.jivesoftware.openfire.plugin.PresenceMirrorPlugin.interceptPacket(PresenceM irrorPlugin.java:77)
at org.jivesoftware.openfire.interceptor.InterceptorManager.invokeInterceptors(Int erceptorManager.java:228)
at org.jivesoftware.openfire.PresenceRouter.route(PresenceRouter.java:68)
at org.jivesoftware.openfire.plugin.PresenceMirrorPlugin.interceptPacket(PresenceM irrorPlugin.java:77)
at org.jivesoftware.openfire.interceptor.InterceptorManager.invokeInterceptors(Int erceptorManager.java:228)
at org.jivesoftware.openfire.PresenceRouter.route(PresenceRouter.java:68)
at org.jivesoftware.openfire.plugin.PresenceMirrorPlugin.interceptPacket(PresenceM irrorPlugin.java:77)
at org.jivesoftware.openfire.interceptor.InterceptorManager.invokeInterceptors(Int erceptorManager.java:228)
at org.jivesoftware.openfire.PresenceRouter.route(PresenceRouter.java:68)
at org.jivesoftware.openfire.plugin.PresenceMirrorPlugin.interceptPacket(PresenceM irrorPlugin.java:77)
at org.jivesoftware.openfire.interceptor.InterceptorManager.invokeInterceptors(Int erceptorManager.java:228)
at org.jivesoftware.openfire.PresenceRouter.route(PresenceRouter.java:68)
at org.jivesoftware.openfire.plugin.PresenceMirrorPlugin.interceptPacket(PresenceM irrorPlugin.java:77)
at org.jivesoftware.openfire.interceptor.InterceptorManager.invokeInterceptors(Int erceptorManager.java:228)
at org.jivesoftware.openfire.PresenceRouter.route(PresenceRouter.java:68)
at org.jivesoftware.openfire.plugin.PresenceMirrorPlugin.interceptPacket(PresenceM irrorPlugin.java:77)
at org.jivesoftware.openfire.interceptor.InterceptorManager.invokeInterceptors(Int erceptorManager.java:228)
at org.jivesoftware.openfire.PresenceRouter.route(PresenceRouter.java:68)
at org.jivesoftware.openfire.plugin.PresenceMirrorPlugin.interceptPacket(PresenceM irrorPlugin.java:77)
at org.jivesoftware.openfire.interceptor.InterceptorManager.invokeInterceptors(Int erceptorManager.java:228)
at org.jivesoftware.openfire.PresenceRouter.route(PresenceRouter.java:68)
at org.jivesoftware.openfire.plugin.PresenceMirrorPlugin.interceptPacket(PresenceM irrorPlugin.java:77)
at org.jivesoftware.openfire.interceptor.InterceptorManager.invokeInterceptors(Int erceptorManager.java:228)
at org.jivesoftware.openfire.PresenceRouter.route(PresenceRouter.java:68)
at org.jivesoftware.openfire.plugin.PresenceMirrorPlugin.interceptPacket(PresenceM irrorPlugin.java:77)
at org.jivesoftware.openfire.interceptor.InterceptorManager.invokeInterceptors(Int erceptorManager.java:228)
at org.jivesoftware.openfire.PresenceRouter.route(PresenceRouter.java:68)
at org.jivesoftware.openfire.plugin.PresenceMirrorPlugin.interceptPacket(PresenceM irrorPlugin.java:77)
at org.jivesoftware.openfire.interceptor.InterceptorManager.invokeInterceptors(Int erceptorManager.java:228)
at org.jivesoftware.openfire.PresenceRouter.route(PresenceRouter.java:68)
at org.jivesoftware.openfire.plugin.PresenceMirrorPlugin.interceptPacket(PresenceM irrorPlugin.java:77)
at org.jivesoftware.openfire.interceptor.InterceptorManager.invokeInterceptors(Int erceptorManager.java:228)
at org.jivesoftware.openfire.PresenceRouter.route(PresenceRouter.java:68)
at org.jivesoftware.openfire.plugin.PresenceMirrorPlugin.interceptPacket(PresenceM irrorPlugin.java:77)
at org.jivesoftware.openfire.interceptor.InterceptorManager.invokeInterceptors(Int erceptorManager.java:228)
at org.jivesoftware.openfire.PresenceRouter.route(PresenceRouter.java:68)
at org.jivesoftware.openfire.plugin.PresenceMirrorPlugin.interceptPacket(PresenceM irrorPlugin.java:77)
at org.jivesoftware.openfire.interceptor.InterceptorManager.invokeInterceptors(Int erceptorManager.java:228)
at org.jivesoftware.openfire.PresenceRouter.route(PresenceRouter.java:68)
at org.jivesoftware.openfire.plugin.PresenceMirrorPlugin.interceptPacket(PresenceM irrorPlugin.java:77)
at org.jivesoftware.openfire.interceptor.InterceptorManager.invokeInterceptors(Int erceptorManager.java:228)
at org.jivesoftware.openfire.PresenceRouter.route(PresenceRouter.java:68)
at org.jivesoftware.openfire.plugin.PresenceMirrorPlugin.interceptPacket(PresenceM irrorPlugin.java:77)
at org.jivesoftware.openfire.interceptor.InterceptorManager.invokeInterceptors(Int erceptorManager.java:228)
at org.jivesoftware.openfire.PresenceRouter.route(PresenceRouter.java:68)
at org.jivesoftware.openfire.plugin.PresenceMirrorPlugin.interceptPacket(PresenceM irrorPlugin.java:77)
at org.jivesoftware.openfire.interceptor.InterceptorManager.invokeInterceptors(Int erceptorManager.java:228)
at org.jivesoftware.openfire.PresenceRouter.route(PresenceRouter.java:68)
at org.jivesoftware.openfire.plugin.PresenceMirrorPlugin.interceptPacket(PresenceM irrorPlugin.java:77)
at org.jivesoftware.openfire.interceptor.InterceptorManager.invokeInterceptors(Int erceptorManager.java:228)
at org.jivesoftware.openfire.PresenceRouter.route(PresenceRouter.java:68)
at org.jivesoftware.openfire.plugin.PresenceMirrorPlugin.interceptPacket(PresenceM irrorPlugin.java:77)
at org.jivesoftware.openfire.interceptor.InterceptorManager.invokeInterceptors(Int erceptorManager.java:228)
at org.jivesoftware.openfire.PresenceRouter.route(PresenceRouter.java:68)
at org.jivesoftware.openfire.plugin.PresenceMirrorPlugin.interceptPacket(PresenceM irrorPlugin.java:77)
at org.jivesoftware.openfire.interceptor.InterceptorManager.invokeInterceptors(Int erceptorManager.java:228)
at org.jivesoftware.openfire.PresenceRouter.route(PresenceRouter.java:68)
at org.jivesoftware.openfire.plugin.PresenceMirrorPlugin.interceptPacket(PresenceM irrorPlugin.java:77)
at org.jivesoftware.openfire.interceptor.InterceptorManager.invokeInterceptors(Int erceptorManager.java:228)
at org.jivesoftware.openfire.PresenceRouter.route(PresenceRouter.java:68)
at org.jivesoftware.openfire.plugin.PresenceMirrorPlugin.interceptPacket(PresenceM irrorPlugin.java:77)
at org.jivesoftware.openfire.interceptor.InterceptorManager.invokeInterceptors(Int erceptorManager.java:228)
at org.jivesoftware.openfire.PresenceRouter.route(PresenceRouter.java:68)

OK, I think I found the cause of the recursice calls, Packet Interceptor was intercepting the calls i sent out with the Presence Router. This was my fix

public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) throws PacketRejectedException {
if (processed) {
return;
}

   if (packet instanceof Presence) {
       if (packet.getTo() == null || !packet.getTo().toString().equalsIgnoreCase(getMirrorToJID())) {
           Presence presencePacket = (Presence) packet;
           Log.debug("The PRESENCE packet being processed " + presencePacket.toString());
           presencePacket.setTo(getMirrorToJID());
           Log.debug("The PRESENCE packet sent to external component " + presencePacket.toString());
           router.route(presencePacket);
       }
   }

}