powered by Jive Software

Using PacketError

What do I need to do to handle Packets with PacketErrors in them? I have a PacketInterceptor, and I tried the following on an incoming, unprocessed message:

packet.setError(new PacketError(



At this point, it seems to me that Openfire should route the message back to the client, but my client is never seeing the message come back. It seems to be swallowed up by Openfire.

Ideally, I’'d like the message to come back, and display within the same chat window with the error description.

I don’‘t think packets ever send themselves. You’'ll have to use XMPPConnection.sendPacket

I was thinking about doing that, but I wanted to find out if Openfire will “see” the PacketError and re-route the packet back to the client on its own.

It wouldn’‘t do that automatically because you might also want to call other methods such as setProperty before sending. There’‘s also a good chance you’'ll need to create a completely new packet with the to and from reversed , and set the error on that, so that it goes back where it came from.

Since I’'m intercepting this packet before Openfire processes it (processed = false), what happens during the processing stage once the message contains a PacketError? Something difference is definitely happening, because the message is not being delivered to the destination client.

Message was edited by: jdouglas

I looked more into the docs, and I think the way to handle this is to throw a new PacketRejectedException.

According to the API: “If the packet was received then it will not be processed and a not_allowed error will be sent back to the sender of the packet. If the packet was going to be sent then the sending will be aborted.”

I tried this, and the packet rejection message is not being sent back to the sender. I tried waiting until processed==true to throw the packet rejection, but that just breaks Openfire because it cannot reject a packet after it’'s been processed.

Why is no message sent to the sender when I throw a packet rejection before processed==true?

Message was edited by: jdouglas

I think you’‘re on the right track with throwing the PacketRejectedException. Have you checked the traffic window in spark? It’‘s possible that it’‘s being sent but that Spark doesn’'t do anything with it.

Yes, and that’'s how I know the packet is never coming back to the sender.

I found the problem.

When you construct a new PacketRejectedException(“This is some info about etc…”), the String in the constructor is setting the detailMessage property of Exception, not the rejectedMessage property of PacketRejectedException.

When MessageRouter processes the PacketRejectedException, it checks to see if getRejectedMessage() returns a String or null. If null, no response is sent to the original sender.

To solve the problem, you must construct a new PacketRejectedException() and explicitly call setRejectedMessage(“this is my message etc…”)