diff options
| author | Andrew Donald Kennedy <grkvlt@apache.org> | 2010-08-01 14:20:14 +0000 |
|---|---|---|
| committer | Andrew Donald Kennedy <grkvlt@apache.org> | 2010-08-01 14:20:14 +0000 |
| commit | 3139609929dec233b247393d7738c1ddf9408697 (patch) | |
| tree | ab99071e01ce5513f403288ba7d5c2975bd3a320 /java | |
| parent | 4ab39d38a5553670b1b6211281b09ac29c53efba (diff) | |
| download | qpid-python-3139609929dec233b247393d7738c1ddf9408697.tar.gz | |
QPID-2744: Unify 0-10 and 0-8 error messages for invalid object types in properties
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@981231 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
6 files changed, 35 insertions, 13 deletions
diff --git a/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10.java b/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10.java index 78bdac2680..f9ca9e610c 100644 --- a/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10.java +++ b/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10.java @@ -37,6 +37,7 @@ import javax.jms.MessageNotWriteableException; import javax.jms.Session; import org.apache.qpid.AMQException; +import org.apache.qpid.AMQPInvalidClassException; import org.apache.qpid.collections.ReferenceMap; import org.apache.qpid.client.AMQDestination; import org.apache.qpid.client.AMQSession; @@ -730,22 +731,19 @@ public class AMQMessageDelegate_0_10 extends AbstractAMQMessageDelegate ALLOWED.add(String.class); ALLOWED.add(byte[].class); } - + public void setObjectProperty(String propertyName, Object object) throws JMSException { - checkPropertyName(propertyName); - checkWritableProperties(); if (object == null) { - throw new MessageFormatException("Object is null"); + throw new MessageFormatException(AMQPInvalidClassException.INVALID_OBJECT_MSG + "null"); } else if (!ALLOWED.contains(object.getClass())) { - throw new MessageFormatException - (String.format - ("Cannot set a %s, allowed property types are: %s", - object.getClass(), ALLOWED)); + throw new MessageFormatException(AMQPInvalidClassException.INVALID_OBJECT_MSG + object.getClass()); } + checkPropertyName(propertyName); + checkWritableProperties(); setApplicationHeader(propertyName, object); } diff --git a/java/client/src/main/java/org/apache/qpid/client/message/JMSHeaderAdapter.java b/java/client/src/main/java/org/apache/qpid/client/message/JMSHeaderAdapter.java index ae1f354863..2e4a6eeb6b 100644 --- a/java/client/src/main/java/org/apache/qpid/client/message/JMSHeaderAdapter.java +++ b/java/client/src/main/java/org/apache/qpid/client/message/JMSHeaderAdapter.java @@ -400,7 +400,7 @@ public final class JMSHeaderAdapter } catch (AMQPInvalidClassException aice) { - MessageFormatException mfe = new MessageFormatException("Only Primitives objects allowed Object is:" + (object == null ? "null" : object.getClass())); + MessageFormatException mfe = new MessageFormatException(AMQPInvalidClassException.INVALID_OBJECT_MSG + (object == null ? "null" : object.getClass())); mfe.setLinkedException(aice); mfe.initCause(aice); throw mfe; diff --git a/java/common/src/main/java/org/apache/qpid/AMQPInvalidClassException.java b/java/common/src/main/java/org/apache/qpid/AMQPInvalidClassException.java index a0574efa72..ab5141be9d 100644 --- a/java/common/src/main/java/org/apache/qpid/AMQPInvalidClassException.java +++ b/java/common/src/main/java/org/apache/qpid/AMQPInvalidClassException.java @@ -32,6 +32,9 @@ package org.apache.qpid; */ public class AMQPInvalidClassException extends RuntimeException { + /** Error message text when trying to store an unsupported class or null object */ + public static final String INVALID_OBJECT_MSG = "Only Primitive objects allowed. Object is: "; + public AMQPInvalidClassException(String s) { super(s); diff --git a/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java b/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java index b268d03c3c..22205d49f8 100644 --- a/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java +++ b/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java @@ -673,7 +673,7 @@ public class FieldTable return setBytes(string, (byte[]) object); } - throw new AMQPInvalidClassException("Only Primitives objects allowed Object is:" + (object == null ? "null" : object.getClass())); + throw new AMQPInvalidClassException(AMQPInvalidClassException.INVALID_OBJECT_MSG + (object == null ? "null" : object.getClass())); } public boolean isNullStringValue(String name) diff --git a/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java b/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java index 179d371b1b..d4691ba097 100644 --- a/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java +++ b/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java @@ -529,9 +529,19 @@ public class PropertyFieldTableTest extends TestCase catch (AMQPInvalidClassException aice) { assertEquals("Null values are not allowed to be set", - "Only Primitives objects allowed Object is:null", aice.getMessage()); + AMQPInvalidClassException.INVALID_OBJECT_MSG + "null", aice.getMessage()); } + try + { + table.setObject("Unsupported-object", new Exception()); + fail("Non primitive values are not allowed"); + } + catch (AMQPInvalidClassException aice) + { + assertEquals("Non primitive values are not allowed to be set", + AMQPInvalidClassException.INVALID_OBJECT_MSG + Exception.class, aice.getMessage()); + } Assert.assertEquals((Boolean) true, table.getBoolean("bool")); Assert.assertEquals((Byte) Byte.MAX_VALUE, table.getByte("byte")); diff --git a/java/systests/src/main/java/org/apache/qpid/test/unit/message/JMSPropertiesTest.java b/java/systests/src/main/java/org/apache/qpid/test/unit/message/JMSPropertiesTest.java index 7e029a862f..830421a01f 100644 --- a/java/systests/src/main/java/org/apache/qpid/test/unit/message/JMSPropertiesTest.java +++ b/java/systests/src/main/java/org/apache/qpid/test/unit/message/JMSPropertiesTest.java @@ -55,6 +55,7 @@ public class JMSPropertiesTest extends QpidBrokerTestCase public static final int JMS_DELIV_MODE = 1; public static final String JMS_TYPE = "test.jms.type"; protected static final String NULL_OBJECT_PROPERTY = "NullObject"; + protected static final String INVALID_OBJECT_PROPERTY = "InvalidObject"; protected void setUp() throws Exception { @@ -100,8 +101,18 @@ public class JMSPropertiesTest extends QpidBrokerTestCase catch (MessageFormatException mfe) { // Check the error message - assertEquals("Incorrect error message", - isBroker010() ? "Object is null" : "Only Primitives objects allowed Object is:null", mfe.getMessage()); + assertEquals("Incorrect error message", AMQPInvalidClassException.INVALID_OBJECT_MSG + "null", mfe.getMessage()); + } + + try + { + sentMsg.setObjectProperty(INVALID_OBJECT_PROPERTY, new Exception()); + fail("Non primitive Object Property value set"); + } + catch (MessageFormatException mfe) + { + // Check the error message + assertEquals("Incorrect error message: " + mfe.getMessage(), AMQPInvalidClassException.INVALID_OBJECT_MSG + Exception.class, mfe.getMessage()); } // send it |
