No feedback when a packet is rejected before being sent

Openfire 4.6.0

The Javadoc for PacketInterceptor indicate :

An exception can only be thrown when processed is false which means that the read packet has not been processed yet or the packet was not sent yet. If the exception is thrown with a “read” packet then the sender of the packet will receive an answer with an error. But if the exception is thrown with a “sent” packet then nothing will happen.

To summarize the PacketInterceptor.interceptPacket is called 4 times :
incoming true + processed false = feedback
incoming true + processed true = no feedback
incoming false + processed false = no feeback
incoming false + processed true = no feedback

So, if the status incoming is false (the message is being sent) and the status processed is false, the message has not been processed.
In that particular case, shouldn’t the exception return an answer with an error to the sender as well?

In your text, you seem to have highlighted a different rule in your summary than what your text appears to refer to. Can you clarify that please?

Sorry, you are right, I should have highlighted incoming false + processed false = no feeback

To put some context, I made a plugin which :

  • When the message is incoming true and processed false : verifies if the sender is allowed to send the message and, if he isn’t, returns an error saying something like :

insufficient right to send the message

  • When the message is incoming false and processed false : verifies if the recipient is allowed to receive the message. If he isn’t, I want to inform the sender with an error like :

Recipient isn’t allowed to receive this message

I can’t do both verifications in the first iteration because, for a message sent in a MUC, I want to verify if all the particpants are allowed to receive the message.

Sending a feedback when an error occurs while the message is being sent but hasn’t been processed yet would be a nice addition.

You’re right in the sense that Openfire currently:

  • does return an error to the sender of the rejected stanza when the stanza is rejected in the incoming/not yet processed phase.
  • does not return an error to the sender of the rejected stanza when the stanza is rejected in the outgoing/not yet processed phase.

I’m not exactly sure why this is - I can imagine that this is a safeguard against the sender being able to determine something about the state of the intended recipient, or maybe we can’t guarantee that the original sender is still accessible at that point in the processing. In any case, I’m reluctant to change this behavior, as it appears to be put in place on purpose.

If you’re interested in sending such a notification back to the sender, you could sent it yourself, in the code that generates the PacketRejectedException. Would that suffice?

Thank you for the explanation.
Yes it would suffice to send the message myself as it’s done in the MessageRouter when a PacketRejectedException occurs.
The code here if someone has the same needs :

Message reply = new Message();
reply.setID(packet.getID());
reply.setTo(session.getAddress());
reply.setFrom(packet.getTo());
reply.setType(packet.getType());
reply.setThread(packet.getThread());
reply.setBody("Recipient isn’t allowed to receive this message");
session.process(reply);