Repository: activemq-artemis
Updated Branches:
  refs/heads/master cafc42cc2 -> 7dc159070


ARTEMIS-1024 Management operation causes ClassNotFoundException

Artemis expose createQueue() method to management console like Jon.
If the queue to be created already exists it throws an ActiveMQException
back to the console, which will get a ClassNotFoundException when
deserializing the exception.
The same issue goes also with AddressControl.sendMessage() method.

To fix that it should throw a common java exception like IllegalStateException.


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/6e02caa5
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/6e02caa5
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/6e02caa5

Branch: refs/heads/master
Commit: 6e02caa53eab9c3451919cfd62d08bb0fafcc116
Parents: cafc42c
Author: Howard Gao <howard....@gmail.com>
Authored: Thu Mar 9 21:22:18 2017 +0800
Committer: Howard Gao <howard....@gmail.com>
Committed: Thu Mar 9 21:22:18 2017 +0800

----------------------------------------------------------------------
 .../impl/ActiveMQServerControlImpl.java         |   6 ++
 .../management/impl/AddressControlImpl.java     |  55 +++++-----
 .../ManagementExceptionHandlingTest.java        | 103 +++++++++++++++++++
 3 files changed, 139 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6e02caa5/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java
----------------------------------------------------------------------
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java
index 1640ef9..9c8c66f 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java
@@ -47,6 +47,7 @@ import java.util.stream.Collectors;
 
 import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
 import 
org.apache.activemq.artemis.api.core.ActiveMQAddressDoesNotExistException;
+import org.apache.activemq.artemis.api.core.ActiveMQException;
 import org.apache.activemq.artemis.api.core.SimpleString;
 import org.apache.activemq.artemis.api.core.TransportConfiguration;
 import org.apache.activemq.artemis.api.core.management.ActiveMQServerControl;
@@ -669,6 +670,8 @@ public class ActiveMQServerControlImpl extends 
AbstractControl implements Active
       clearIO();
       try {
          server.removeAddressInfo(new SimpleString(name), null);
+      } catch (ActiveMQException e) {
+         throw new IllegalStateException(e.getMessage());
       } finally {
          blockOnIO();
       }
@@ -738,6 +741,7 @@ public class ActiveMQServerControlImpl extends 
AbstractControl implements Active
                              int maxConsumers,
                              boolean purgeOnNoConsumers,
                              boolean autoCreateAddress) throws Exception {
+      System.out.println("Target===================================called!");
       checkStarted();
 
       clearIO();
@@ -750,6 +754,8 @@ public class ActiveMQServerControlImpl extends 
AbstractControl implements Active
 
          final Queue queue = 
server.createQueue(SimpleString.toSimpleString(address), 
RoutingType.valueOf(routingType.toUpperCase()), new SimpleString(name), filter, 
durable, false, maxConsumers, purgeOnNoConsumers, autoCreateAddress);
          return QueueTextFormatter.Long.format(queue, new 
StringBuilder()).toString();
+      } catch (ActiveMQException e) {
+         throw new IllegalStateException(e.getMessage());
       } finally {
          blockOnIO();
       }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6e02caa5/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java
----------------------------------------------------------------------
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java
index 31e056c..37756dc 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java
@@ -25,6 +25,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.activemq.artemis.api.core.ActiveMQException;
 import org.apache.activemq.artemis.api.core.RoutingType;
 import org.apache.activemq.artemis.api.core.SimpleString;
 import org.apache.activemq.artemis.api.core.management.AddressControl;
@@ -266,35 +267,39 @@ public class AddressControlImpl extends AbstractControl 
implements AddressContro
                              boolean durable,
                              final String user,
                              final String password) throws Exception {
-      securityStore.check(addressInfo.getName(), CheckType.SEND, new 
SecurityAuth() {
-         @Override
-         public String getUsername() {
-            return user;
-         }
+      try {
+         securityStore.check(addressInfo.getName(), CheckType.SEND, new 
SecurityAuth() {
+            @Override
+            public String getUsername() {
+               return user;
+            }
 
-         @Override
-         public String getPassword() {
-            return password;
-         }
+            @Override
+            public String getPassword() {
+               return password;
+            }
 
-         @Override
-         public RemotingConnection getRemotingConnection() {
-            return null;
+            @Override
+            public RemotingConnection getRemotingConnection() {
+               return null;
+            }
+         });
+         CoreMessage message = new CoreMessage(storageManager.generateID(), 
50);
+         for (String header : headers.keySet()) {
+            message.putStringProperty(new SimpleString(header), new 
SimpleString(headers.get(header)));
          }
-      });
-      CoreMessage message = new CoreMessage(storageManager.generateID(), 50);
-      for (String header : headers.keySet()) {
-         message.putStringProperty(new SimpleString(header), new 
SimpleString(headers.get(header)));
-      }
-      message.setType((byte) type);
-      message.setDurable(durable);
-      message.setTimestamp(System.currentTimeMillis());
-      if (body != null) {
-         message.getBodyBuffer().writeBytes(Base64.decode(body));
+         message.setType((byte) type);
+         message.setDurable(durable);
+         message.setTimestamp(System.currentTimeMillis());
+         if (body != null) {
+            message.getBodyBuffer().writeBytes(Base64.decode(body));
+         }
+         message.setAddress(addressInfo.getName());
+         postOffice.route(message, true);
+         return "" + message.getMessageID();
+      } catch (ActiveMQException e) {
+         throw new IllegalStateException(e.getMessage());
       }
-      message.setAddress(addressInfo.getName());
-      postOffice.route(message, true);
-      return "" + message.getMessageID();
    }
 
    @Override

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6e02caa5/tests/extra-tests/src/test/java/org/apache/activemq/artemis/tests/extras/byteman/ManagementExceptionHandlingTest.java
----------------------------------------------------------------------
diff --git 
a/tests/extra-tests/src/test/java/org/apache/activemq/artemis/tests/extras/byteman/ManagementExceptionHandlingTest.java
 
b/tests/extra-tests/src/test/java/org/apache/activemq/artemis/tests/extras/byteman/ManagementExceptionHandlingTest.java
new file mode 100644
index 0000000..8c79bf6
--- /dev/null
+++ 
b/tests/extra-tests/src/test/java/org/apache/activemq/artemis/tests/extras/byteman/ManagementExceptionHandlingTest.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.tests.extras.byteman;
+
+import org.apache.activemq.artemis.api.core.ActiveMQException;
+import org.apache.activemq.artemis.core.server.ActiveMQServer;
+import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
+import org.jboss.byteman.contrib.bmunit.BMRule;
+import org.jboss.byteman.contrib.bmunit.BMRules;
+import org.jboss.byteman.contrib.bmunit.BMUnitRunner;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.RuntimeMBeanException;
+import java.lang.management.ManagementFactory;
+import java.util.HashMap;
+
+@RunWith(BMUnitRunner.class)
+public class ManagementExceptionHandlingTest extends ActiveMQTestBase {
+
+   protected ActiveMQServer server = null;
+
+   @Override
+   @Before
+   public void setUp() throws Exception {
+      super.setUp();
+      server = createServer(createDefaultNettyConfig());
+      server.getConfiguration().setJMXManagementEnabled(true);
+
+      server.start();
+   }
+
+   @Override
+   @After
+   public void tearDown() throws Exception {
+      if (server != null) {
+         server.stop();
+      }
+      super.tearDown();
+   }
+
+   @Test
+   @BMRules(
+           rules = {@BMRule(
+                   name = "checking ActiveMQServerControl methods",
+                   targetClass = 
"org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl",
+                   targetMethod = 
"createQueue(org.apache.activemq.artemis.api.core.SimpleString, 
org.apache.activemq.artemis.api.core.RoutingType, 
org.apache.activemq.artemis.api.core.SimpleString, 
org.apache.activemq.artemis.api.core.SimpleString, boolean, boolean, int, 
boolean, boolean)",
+                   targetLocation = "EXIT",
+                   action = "throw new 
org.apache.activemq.artemis.api.core.ActiveMQException(\"gotcha\")")})
+   public void testActiveMQServerControl() throws Exception {
+      try {
+         server.getActiveMQServerControl().createQueue("some.address", 
"ANYCAST", "some.queue", "filter", true, -1, false, true);
+         fail("test should have gotten an exception!");
+      } catch (ActiveMQException e) {
+         fail("Wrong exception got!");
+      } catch (IllegalStateException e) {
+         assertEquals("gotcha", e.getMessage());
+      }
+   }
+
+   @Test
+   @BMRules(
+           rules = {@BMRule(
+                   name = "checking ActiveMQServerControl methods",
+                   targetClass = 
"org.apache.activemq.artemis.core.postoffice.impl.PostOfficeImpl",
+                   targetMethod = 
"route(org.apache.activemq.artemis.api.core.Message, boolean)",
+                   targetLocation = "ENTRY",
+                   action = "throw new 
org.apache.activemq.artemis.api.core.ActiveMQException(\"gotcha\")")})
+   public void testAddressControl() throws Exception {
+      server.getActiveMQServerControl().createAddress("test.address", 
"ANYCAST");
+      MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+      System.out.println("server is " + mbs);
+      ObjectName objectName = new 
ObjectName("org.apache.activemq.artemis:broker=\"localhost\",component=addresses,address=\"test.address\"");
+      Object[] params = new Object[] {new HashMap(), 3, "aGVsbG8=", true, 
null, null};
+      String[] signature = new String[] {"java.util.Map", "int", 
"java.lang.String", "boolean", "java.lang.String", "java.lang.String"};
+      try {
+         mbs.invoke(objectName, "sendMessage", params, signature);
+         fail("test should have gotten an exception!");
+      } catch (RuntimeMBeanException ex) {
+         assertTrue(ex.getCause() instanceof IllegalStateException);
+         IllegalStateException e = (IllegalStateException) ex.getCause();
+         assertEquals("gotcha", e.getMessage());
+      }
+   }
+}

Reply via email to