Commit 81abbd83 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Modified to send a message notifying the packet rejection with a custom body. JM-313


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1565 b35dd754-fafc-0310-a699-88a17e54d16e
parent a1c95125
......@@ -27,6 +27,12 @@ public class PacketRejectedException extends Exception {
private Throwable nestedThrowable = null;
/**
* Text to include in a message that will be sent to the sender of the packet that got
* rejected. If no text is specified then no message will be sent to the user.
*/
private String rejectionMessage;
public PacketRejectedException() {
super();
}
......@@ -64,4 +70,27 @@ public class PacketRejectedException extends Exception {
nestedThrowable.printStackTrace(pw);
}
}
/**
* Retuns the text to include in a message that will be sent to the sender of the packet
* that got rejected or <tt>null</tt> if none was defined. If no text was specified then
* no message will be sent to the sender of the rejected packet.
*
* @return the text to include in a message that will be sent to the sender of the packet
* that got rejected or <tt>null</tt> if none was defined.
*/
public String getRejectionMessage() {
return rejectionMessage;
}
/**
* Sets the text to include in a message that will be sent to the sender of the packet
* that got rejected or <tt>null</tt> if no message will be sent to the sender of the
* rejected packet. Bt default, no message will be sent.
*
* @param rejectionMessage the text to include in the notification message for the rejection.
*/
public void setRejectionMessage(String rejectionMessage) {
this.rejectionMessage = rejectionMessage;
}
}
......@@ -265,6 +265,15 @@ public abstract class SocketReader implements Runnable {
reply.setFrom(packet.getTo());
reply.setError(PacketError.Condition.not_allowed);
session.process(reply);
// Check if a message notifying the rejection should be sent
if (e.getRejectionMessage() != null && e.getRejectionMessage().trim().length() > 0) {
// A message for the rejection will be sent to the sender of the rejected packet
Message notification = new Message();
notification.setTo(session.getAddress());
notification.setFrom(packet.getTo());
notification.setBody(e.getRejectionMessage());
session.process(notification);
}
}
}
......@@ -298,6 +307,15 @@ public abstract class SocketReader implements Runnable {
reply.setFrom(packet.getTo());
reply.setError(PacketError.Condition.not_allowed);
session.process(reply);
// Check if a message notifying the rejection should be sent
if (e.getRejectionMessage() != null && e.getRejectionMessage().trim().length() > 0) {
// A message for the rejection will be sent to the sender of the rejected packet
Message notification = new Message();
notification.setTo(session.getAddress());
notification.setFrom(packet.getTo());
notification.setBody(e.getRejectionMessage());
session.process(notification);
}
}
}
......@@ -324,15 +342,20 @@ public abstract class SocketReader implements Runnable {
session.incrementClientPacketCount();
}
catch (PacketRejectedException e) {
// An interceptor rejected this packet so answer a not_allowed error
// An interceptor rejected this packet
if (e.getRejectionMessage() != null && e.getRejectionMessage().trim().length() > 0) {
// A message for the rejection will be sent to the sender of the rejected packet
Message reply = new Message();
reply.setID(packet.getID());
reply.setTo(session.getAddress());
reply.setFrom(packet.getTo());
reply.setError(PacketError.Condition.not_allowed);
reply.setType(packet.getType());
reply.setThread(packet.getThread());
reply.setBody(e.getRejectionMessage());
session.process(reply);
}
}
}
/**
* Returns true if a received packet of an unkown type (i.e. not a Message, Presence
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment