diff options
author | Danny van Heumen <danny@dannyvanheumen.nl> | 2015-05-06 22:10:46 +0200 |
---|---|---|
committer | Danny van Heumen <danny@dannyvanheumen.nl> | 2015-05-06 22:10:46 +0200 |
commit | 826df1b6002d4ad280af5953cab871bc5341f0c1 (patch) | |
tree | a479e84737ac2a82a7a22ef2681a706049604939 /src/net/java/sip | |
parent | b6c4451f6bd9308896989781ad299ba825b0b6f6 (diff) | |
download | jitsi-826df1b6002d4ad280af5953cab871bc5341f0c1.zip jitsi-826df1b6002d4ad280af5953cab871bc5341f0c1.tar.gz jitsi-826df1b6002d4ad280af5953cab871bc5341f0c1.tar.bz2 |
Throw OperationFailedException in case of too large message and fire message delivery failed event.
Diffstat (limited to 'src/net/java/sip')
-rw-r--r-- | src/net/java/sip/communicator/impl/protocol/irc/MessageManager.java | 36 | ||||
-rw-r--r-- | src/net/java/sip/communicator/impl/protocol/irc/OperationSetBasicInstantMessagingIrcImpl.java | 6 |
2 files changed, 36 insertions, 6 deletions
diff --git a/src/net/java/sip/communicator/impl/protocol/irc/MessageManager.java b/src/net/java/sip/communicator/impl/protocol/irc/MessageManager.java index 0cf55e3..3443d3f 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/MessageManager.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/MessageManager.java @@ -234,24 +234,39 @@ public class MessageManager * * @param chatroom The chat room to send the message to. * @param message The message to send. + * @throws OperationFailedException OperationFailedException is thrown when + * message is too large to be processed by IRC server. */ public void message(final ChatRoomIrcImpl chatroom, final String message) + throws OperationFailedException { if (!this.connectionState.isConnected()) { throw new IllegalStateException("Not connected to an IRC server."); } final String target = chatroom.getIdentifier(); - // message format as forwarded by IRC server: + // message format as forwarded by IRC server to clients: // :<user> PRIVMSG <nick> :<message> final int maxMsgSize = calculateMaximumMessageSize(0, target); if (maxMsgSize < message.length()) { LOGGER.warn("Message for " + target - + " is too large. At best only sent message up to: " + + " is too large. At best you can send the message up to: " + message.substring(0, maxMsgSize)); + throw new OperationFailedException( + "Message is too large for this IRC server.", + OperationFailedException.ILLEGAL_ARGUMENT); + } + try + { + this.irc.message(target, message); + LOGGER.trace("Message delivered to server successfully."); + } + catch (RuntimeException e) + { + LOGGER.trace("Failed to deliver message: " + e.getMessage(), e); + throw e; } - this.irc.message(target, message); } /** @@ -259,22 +274,31 @@ public class MessageManager * * @param contact The contact to send the message to. * @param message The message to send. + * @throws OperationFailedException OperationFailedException is thrown when + * message is too large to be processed by IRC server. */ public void message(final Contact contact, final Message message) + throws OperationFailedException { if (!this.connectionState.isConnected()) { throw new IllegalStateException("Not connected to an IRC server."); } final String target = contact.getAddress(); - // message format as forwarded by IRC server: - //:<user> PRIVMSG <nick> :<message> + // message format as forwarded by IRC server to clients: + // :<user> PRIVMSG <nick> :<message> final int maxMsgSize = calculateMaximumMessageSize(0, target); if (maxMsgSize < message.getContent().length()) { + // Message is definitely too large to be sent to a standard IRC + // network. Sending is not attempted, since we would send a partial + // message, even though the user is not informed of this. LOGGER.warn("Message for " + target - + " is too large. At best only sent message up to: " + + " is too large. At best you can send the message up to: " + message.getContent().substring(0, maxMsgSize)); + throw new OperationFailedException( + "Message is too large for this IRC server.", + OperationFailedException.ILLEGAL_ARGUMENT); } try { diff --git a/src/net/java/sip/communicator/impl/protocol/irc/OperationSetBasicInstantMessagingIrcImpl.java b/src/net/java/sip/communicator/impl/protocol/irc/OperationSetBasicInstantMessagingIrcImpl.java index 9f33ca8..23c96ba 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/OperationSetBasicInstantMessagingIrcImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/OperationSetBasicInstantMessagingIrcImpl.java @@ -190,6 +190,12 @@ public class OperationSetBasicInstantMessagingIrcImpl } fireMessageDelivered(original, to); } + catch (OperationFailedException e) + { + // Message delivery failed. Most obvious possibility is that the + // message was too large for the IRC network to handle. + fireMessageDeliveryFailed(original, to, e.getErrorCode()); + } catch (RuntimeException e) { LOGGER.warn("Failed to deliver message: " + original, e); |