You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2016/03/31 22:53:03 UTC
activemq git commit: https://issues.apache.org/jira/browse/AMQ-6228
Repository: activemq
Updated Branches:
refs/heads/master 0fb24cc4c -> 98165c4b6
https://issues.apache.org/jira/browse/AMQ-6228
Create a better error message that for the invalid frame size error.
Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/98165c4b
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/98165c4b
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/98165c4b
Branch: refs/heads/master
Commit: 98165c4b69f0a5df93a7c964b9b9e143c7f7a083
Parents: 0fb24cc
Author: Timothy Bish <ta...@gmail.com>
Authored: Thu Mar 31 16:52:34 2016 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Thu Mar 31 16:52:34 2016 -0400
----------------------------------------------------------------------
.../transport/amqp/AmqpFrameParser.java | 3 +-
.../activemq/openwire/OpenWireFormat.java | 5 +--
.../activemq/util/IOExceptionSupport.java | 33 ++++++++++++++++++++
3 files changed, 38 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq/blob/98165c4b/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpFrameParser.java
----------------------------------------------------------------------
diff --git a/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpFrameParser.java b/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpFrameParser.java
index 247a5e9..06bc97b 100644
--- a/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpFrameParser.java
+++ b/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpFrameParser.java
@@ -21,6 +21,7 @@ import java.nio.ByteBuffer;
import org.apache.activemq.transport.amqp.AmqpWireFormat.ResetListener;
import org.apache.activemq.transport.tcp.TcpTransport;
+import org.apache.activemq.util.IOExceptionSupport;
import org.fusesource.hawtbuf.Buffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -84,7 +85,7 @@ public class AmqpFrameParser {
}
if (frameSize > maxFrameSize) {
- throw new IOException("Frame size of " + frameSize + " larger than max allowed " + maxFrameSize);
+ throw IOExceptionSupport.createFrameSizeException(frameSize, maxFrameSize);
}
}
http://git-wip-us.apache.org/repos/asf/activemq/blob/98165c4b/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java b/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java
index f70bff8..c1297a2 100755
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java
@@ -30,6 +30,7 @@ import org.apache.activemq.util.ByteSequence;
import org.apache.activemq.util.ByteSequenceData;
import org.apache.activemq.util.DataByteArrayInputStream;
import org.apache.activemq.util.DataByteArrayOutputStream;
+import org.apache.activemq.util.IOExceptionSupport;
import org.apache.activemq.wireformat.WireFormat;
/**
@@ -193,7 +194,7 @@ public final class OpenWireFormat implements WireFormat {
}
if (size > maxFrameSize) {
- throw new IOException("Frame size of " + (size / (1024 * 1024)) + " MB larger than max allowed " + (maxFrameSize / (1024 * 1024)) + " MB");
+ throw IOExceptionSupport.createFrameSizeException(size, maxFrameSize);
}
}
@@ -266,7 +267,7 @@ public final class OpenWireFormat implements WireFormat {
if (!sizePrefixDisabled) {
int size = dis.readInt();
if (size > maxFrameSize) {
- throw new IOException("Frame size of " + (size / (1024 * 1024)) + " MB larger than max allowed " + (maxFrameSize / (1024 * 1024)) + " MB");
+ throw IOExceptionSupport.createFrameSizeException(size, maxFrameSize);
}
// int size = dis.readInt();
// byte[] data = new byte[size];
http://git-wip-us.apache.org/repos/asf/activemq/blob/98165c4b/activemq-client/src/main/java/org/apache/activemq/util/IOExceptionSupport.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/util/IOExceptionSupport.java b/activemq-client/src/main/java/org/apache/activemq/util/IOExceptionSupport.java
index ed0925f..7aa2fc4 100755
--- a/activemq-client/src/main/java/org/apache/activemq/util/IOExceptionSupport.java
+++ b/activemq-client/src/main/java/org/apache/activemq/util/IOExceptionSupport.java
@@ -17,6 +17,7 @@
package org.apache.activemq.util;
import java.io.IOException;
+import java.math.BigInteger;
public final class IOExceptionSupport {
@@ -47,4 +48,36 @@ public final class IOExceptionSupport {
return exception;
}
+ public static IOException createFrameSizeException(int size, long maxSize) {
+ return new IOException("Frame size of " + toHumanReadableSizeString(size) +
+ " larger than max allowed " + toHumanReadableSizeString(maxSize));
+ }
+
+ private static String toHumanReadableSizeString(final int size) {
+ return toHumanReadableSizeString(BigInteger.valueOf(size));
+ }
+
+ private static String toHumanReadableSizeString(final long size) {
+ return toHumanReadableSizeString(BigInteger.valueOf(size));
+ }
+
+ private static String toHumanReadableSizeString(final BigInteger size) {
+ String displaySize;
+
+ final BigInteger ONE_KB_BI = BigInteger.valueOf(1024);
+ final BigInteger ONE_MB_BI = ONE_KB_BI.multiply(ONE_KB_BI);
+ final BigInteger ONE_GB_BI = ONE_KB_BI.multiply(ONE_MB_BI);
+
+ if (size.divide(ONE_GB_BI).compareTo(BigInteger.ZERO) > 0) {
+ displaySize = String.valueOf(size.divide(ONE_GB_BI)) + " GB";
+ } else if (size.divide(ONE_MB_BI).compareTo(BigInteger.ZERO) > 0) {
+ displaySize = String.valueOf(size.divide(ONE_MB_BI)) + " MB";
+ } else if (size.divide(ONE_KB_BI).compareTo(BigInteger.ZERO) > 0) {
+ displaySize = String.valueOf(size.divide(ONE_KB_BI)) + " KB";
+ } else {
+ displaySize = String.valueOf(size) + " bytes";
+ }
+
+ return displaySize;
+ }
}