diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java index 5a7a5263fa..e951e6ac9d 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java @@ -122,6 +122,9 @@ public final class JsonUtil { if (innerVal instanceof JsonArray) { innerVal = fromJsonArray(((JsonArray) innerVal)); } + else if (innerVal instanceof JsonString) { + innerVal = ((JsonString)innerVal).getString(); + } else if (innerVal instanceof JsonObject) { Map innerMap = new HashMap<>(); JsonObject o = (JsonObject) innerVal; @@ -139,7 +142,8 @@ public final class JsonUtil { Object[] data = (Object[]) innerVal; CompositeData[] cds = new CompositeData[data.length]; for (int i1 = 0; i1 < data.length; i1++) { - ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(Base64.decode((data[i1].toString())))); + String dataConverted = convertJsonValue(data[i1], String.class).toString(); + ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(Base64.decode(dataConverted))); cds[i1] = (CompositeDataSupport) ois.readObject(); } innerVal = cds; @@ -191,7 +195,7 @@ public final class JsonUtil { jsonObjectBuilder.add(key, (Short) param); } else if (param instanceof Byte) { - //?? + jsonObjectBuilder.add(key, ((Byte) param).shortValue()); } else if (param instanceof SimpleString) { jsonObjectBuilder.add(key, param.toString()); @@ -225,7 +229,7 @@ public final class JsonUtil { jsonArrayBuilder.add((Short) param); } else if (param instanceof Byte) { - //?? + jsonArrayBuilder.add(((Byte) param).shortValue()); } else { throw ActiveMQClientMessageBundle.BUNDLE.invalidManagementParam(param.getClass().getName()); diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/management/JMSManagementHelper.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/management/JMSManagementHelper.java index 33b902b32c..2e785df352 100644 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/management/JMSManagementHelper.java +++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/api/jms/management/JMSManagementHelper.java @@ -138,7 +138,17 @@ public class JMSManagementHelper { * and the result will be a String corresponding to the server exception. */ public static Object getResult(final Message message) throws Exception { - return ManagementHelper.getResult(JMSManagementHelper.getCoreMessage(message)); + return getResult(message, null); + } + + /** + * Returns the result of an operation invocation or an attribute value. + *
+ * If an error occurred on the server, {@link #hasOperationSucceeded(Message)} will return {@code false}. + * and the result will be a String corresponding to the server exception. + */ + public static Object getResult(final Message message, Class desiredType) throws Exception { + return ManagementHelper.getResult(JMSManagementHelper.getCoreMessage(message), desiredType); } private JMSManagementHelper() { diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/server/management/JMSMessagingProxy.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/server/management/JMSMessagingProxy.java index 2606b31542..6042f2e9d2 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/server/management/JMSMessagingProxy.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/server/management/JMSMessagingProxy.java @@ -57,23 +57,30 @@ public class JMSMessagingProxy { // Protected ----------------------------------------------------- public Object retrieveAttributeValue(final String attributeName) { + return retrieveAttributeValue(attributeName, null); + } + + public Object retrieveAttributeValue(final String attributeName, final Class desiredType) { try { Message m = session.createMessage(); JMSManagementHelper.putAttribute(m, resourceName, attributeName); Message reply = requestor.request(m); - return JMSManagementHelper.getResult(reply); + return JMSManagementHelper.getResult(reply, desiredType); } catch (Exception e) { throw new IllegalStateException(e); } } - public Object invokeOperation(final String operationName, final Object... args) throws Exception { + return invokeOperation(null, operationName, args); + } + + public Object invokeOperation(final Class desiredType, final String operationName, final Object... args) throws Exception { Message m = session.createMessage(); JMSManagementHelper.putOperationInvocation(m, resourceName, operationName, args); Message reply = requestor.request(m); if (JMSManagementHelper.hasOperationSucceeded(reply)) { - return JMSManagementHelper.getResult(reply); + return JMSManagementHelper.getResult(reply, desiredType); } else { throw new Exception((String) JMSManagementHelper.getResult(reply)); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/server/management/JMSQueueControlUsingJMSTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/server/management/JMSQueueControlUsingJMSTest.java index 1443a4f7d4..a7af35f260 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/server/management/JMSQueueControlUsingJMSTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/server/management/JMSQueueControlUsingJMSTest.java @@ -96,7 +96,7 @@ public class JMSQueueControlUsingJMSTest extends JMSQueueControlTest { @Override public int changeMessagesPriority(final String filter, final int newPriority) throws Exception { - return (Integer) proxy.invokeOperation("changeMessagesPriority", filter, newPriority); + return (Integer) proxy.invokeOperation(Integer.class, "changeMessagesPriority", filter, newPriority); } @Override @@ -111,12 +111,12 @@ public class JMSQueueControlUsingJMSTest extends JMSQueueControlTest { @Override public int expireMessages(final String filter) throws Exception { - return (Integer) proxy.invokeOperation("expireMessages", filter); + return (Integer) proxy.invokeOperation(Integer.class, "expireMessages", filter); } @Override public int getConsumerCount() { - return (Integer) proxy.retrieveAttributeValue("consumerCount"); + return (Integer) proxy.retrieveAttributeValue("consumerCount", Integer.class); } @Override @@ -136,7 +136,7 @@ public class JMSQueueControlUsingJMSTest extends JMSQueueControlTest { @Override public int getDeliveringCount() { - return (Integer) proxy.retrieveAttributeValue("deliveringCount"); + return (Integer) proxy.retrieveAttributeValue("deliveringCount", Integer.class); } @Override @@ -166,7 +166,7 @@ public class JMSQueueControlUsingJMSTest extends JMSQueueControlTest { @Override public long getMessagesAdded() { - return (Integer) proxy.retrieveAttributeValue("messagesAdded"); + return (Integer) proxy.retrieveAttributeValue("messagesAdded", Integer.class); } @Override @@ -210,7 +210,7 @@ public class JMSQueueControlUsingJMSTest extends JMSQueueControlTest { @Override public int retryMessages() throws Exception { - return (Integer) proxy.invokeOperation("retryMessages"); + return (Integer) proxy.invokeOperation("retryMessages", Integer.class); } @Override @@ -267,12 +267,12 @@ public class JMSQueueControlUsingJMSTest extends JMSQueueControlTest { @Override public int moveMessages(String filter, String otherQueueName, boolean rejectDuplicates) throws Exception { - return (Integer) proxy.invokeOperation("moveMessages", filter, otherQueueName, rejectDuplicates); + return (Integer) proxy.invokeOperation(Integer.class, "moveMessages", filter, otherQueueName, rejectDuplicates); } @Override public int moveMessages(final String filter, final String otherQueueName) throws Exception { - return (Integer) proxy.invokeOperation("moveMessages", filter, otherQueueName); + return (Integer) proxy.invokeOperation(Integer.class, "moveMessages", filter, otherQueueName); } @Override @@ -282,7 +282,7 @@ public class JMSQueueControlUsingJMSTest extends JMSQueueControlTest { @Override public int removeMessages(final String filter) throws Exception { - return (Integer) proxy.invokeOperation("removeMessages", filter); + return (Integer) proxy.invokeOperation(Integer.class, "removeMessages", filter); } @Override @@ -297,7 +297,7 @@ public class JMSQueueControlUsingJMSTest extends JMSQueueControlTest { @Override public int sendMessagesToDeadLetterAddress(final String filterStr) throws Exception { - return (Integer) proxy.invokeOperation("sendMessagesToDeadLetterAddress", filterStr); + return (Integer) proxy.invokeOperation(Integer.class, "sendMessagesToDeadLetterAddress", filterStr); } @Override