ARTEMIS-565 fixing JMS Control stuff

This commit is contained in:
Clebert Suconic 2016-07-27 19:14:32 -04:00
parent 03bb756079
commit 8873744d27
4 changed files with 38 additions and 17 deletions

View File

@ -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<String, Object> 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());

View File

@ -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.
* <br>
* 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() {

View File

@ -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));

View File

@ -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