Search in sources :

Example 11 with AddressControl

use of org.apache.activemq.artemis.api.core.management.AddressControl in project wildfly by wildfly.

the class AddressControlHandler method handleGetRolesAsJson.

private void handleGetRolesAsJson(final OperationContext context, final ModelNode operation) {
    final AddressControl addressControl = getAddressControl(context, operation);
    try {
        String json = addressControl.getRolesAsJSON();
        reportRolesAsJSON(context, json);
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        context.getFailureDescription().set(e.getLocalizedMessage());
    }
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 12 with AddressControl

use of org.apache.activemq.artemis.api.core.management.AddressControl in project wildfly by wildfly.

the class ActiveMQServerResource method getCoreAddressNames.

private Set<String> getCoreAddressNames() {
    final ManagementService managementService = getManagementService();
    if (managementService == null) {
        return Collections.emptySet();
    } else {
        Set<String> result = new HashSet<String>();
        for (Object obj : managementService.getResources(AddressControl.class)) {
            AddressControl ac = AddressControl.class.cast(obj);
            result.add(ac.getAddress());
        }
        return result;
    }
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) ManagementService(org.apache.activemq.artemis.core.server.management.ManagementService) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 13 with AddressControl

use of org.apache.activemq.artemis.api.core.management.AddressControl in project wildfly by wildfly.

the class SecurityRoleReadAttributeHandler method executeRuntimeStep.

@Override
public void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    final String attributeName = operation.require(ModelDescriptionConstants.NAME).asString();
    PathAddress pathAddress = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
    String addressName = pathAddress.getElement(pathAddress.size() - 2).getValue();
    String roleName = pathAddress.getLastElement().getValue();
    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName);
    ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
    AddressControl control = AddressControl.class.cast(server.getManagementService().getResource(ResourceNames.ADDRESS + addressName));
    if (control == null) {
        PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
        throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
    }
    try {
        String rolesAsJSON = control.getRolesAsJSON();
        ModelNode res = ModelNode.fromJSONString(rolesAsJSON);
        ModelNode roles = ManagementUtil.convertSecurityRole(res);
        ModelNode matchedRole = findRole(roleName, roles);
        if (matchedRole == null || !matchedRole.hasDefined(attributeName)) {
            throw MessagingLogger.ROOT_LOGGER.unsupportedAttribute(attributeName);
        }
        boolean value = matchedRole.get(attributeName).asBoolean();
        context.getResult().set(value);
    } catch (Exception e) {
        context.getFailureDescription().set(e.getLocalizedMessage());
    }
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 14 with AddressControl

use of org.apache.activemq.artemis.api.core.management.AddressControl in project activemq-artemis by apache.

the class JMSMessageTypesTest method testAddressControlSendMessage.

@Test(timeout = 60000)
public void testAddressControlSendMessage() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    server.createQueue(address, RoutingType.ANYCAST, address, null, true, false);
    AddressControl addressControl = ManagementControlHelper.createAddressControl(address, mBeanServer);
    Assert.assertEquals(1, addressControl.getQueueNames().length);
    addressControl.sendMessage(null, org.apache.activemq.artemis.api.core.Message.BYTES_TYPE, Base64.encodeBytes("test".getBytes()), false, fullUser, fullPass);
    Wait.assertEquals(1, addressControl::getMessageCount);
    Connection connection = createConnection("myClientId");
    try {
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        javax.jms.Queue queue = session.createQueue(address.toString());
        MessageConsumer consumer = session.createConsumer(queue);
        Message message = consumer.receive(5000);
        assertNotNull(message);
        byte[] buffer = new byte[(int) ((BytesMessage) message).getBodyLength()];
        ((BytesMessage) message).readBytes(buffer);
        assertEquals("test", new String(buffer));
        session.close();
        connection.close();
    } finally {
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) Queue(javax.jms.Queue) MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) StreamMessage(javax.jms.StreamMessage) MapMessage(javax.jms.MapMessage) ObjectMessage(javax.jms.ObjectMessage) BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) BytesMessage(javax.jms.BytesMessage) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Session(javax.jms.Session) Test(org.junit.Test)

Example 15 with AddressControl

use of org.apache.activemq.artemis.api.core.management.AddressControl in project activemq-artemis by apache.

the class ActiveMQServerControlImpl method getAddressNames.

@Override
public String[] getAddressNames() {
    checkStarted();
    clearIO();
    try {
        Object[] addresses = server.getManagementService().getResources(AddressControl.class);
        String[] names = new String[addresses.length];
        for (int i = 0; i < addresses.length; i++) {
            AddressControl address = (AddressControl) addresses[i];
            names[i] = address.getAddress();
        }
        return names;
    } finally {
        blockOnIO();
    }
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) JsonObject(javax.json.JsonObject) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Aggregations

AddressControl (org.apache.activemq.artemis.api.core.management.AddressControl)29 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)21 Test (org.junit.Test)18 HashSet (java.util.HashSet)5 Connection (javax.jms.Connection)5 Session (javax.jms.Session)5 JsonString (javax.json.JsonString)5 RandomUtil.randomString (org.apache.activemq.artemis.tests.util.RandomUtil.randomString)5 OperationFailedException (org.jboss.as.controller.OperationFailedException)5 ManagementService (org.apache.activemq.artemis.core.server.management.ManagementService)4 PathAddress (org.jboss.as.controller.PathAddress)4 TextMessage (javax.jms.TextMessage)3 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)3 ModelNode (org.jboss.dmr.ModelNode)3 ServiceName (org.jboss.msc.service.ServiceName)3 BytesMessage (javax.jms.BytesMessage)2 MapMessage (javax.jms.MapMessage)2 Message (javax.jms.Message)2 MessageConsumer (javax.jms.MessageConsumer)2 ObjectMessage (javax.jms.ObjectMessage)2