Search in sources :

Example 11 with JMSServerManagerImpl

use of org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl in project activemq-artemis by apache.

the class SpawnedJMSServer method startServer.

public static ActiveMQServer startServer() throws Exception {
    if (server == null) {
        Configuration config = new ConfigurationImpl().addAcceptorConfiguration("netty", "tcp://localhost:61616").setSecurityEnabled(false).addConnectorConfiguration("netty", "tcp://localhost:61616");
        File dataPlace = new File("./target/dataJoram");
        FileUtil.deleteDirectory(dataPlace);
        config.setJournalDirectory(new File(dataPlace, "./journal").getAbsolutePath()).setPagingDirectory(new File(dataPlace, "./paging").getAbsolutePath()).setLargeMessagesDirectory(new File(dataPlace, "./largemessages").getAbsolutePath()).setBindingsDirectory(new File(dataPlace, "./bindings").getAbsolutePath()).setPersistenceEnabled(true);
        // disable server persistence since JORAM tests do not restart server
        server = ActiveMQServers.newActiveMQServer(config, useFiles);
        // set DLA and expiry to avoid spamming the log with warnings
        server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setDeadLetterAddress(SimpleString.toSimpleString("DLA")).setExpiryAddress(SimpleString.toSimpleString("Expiry")));
        serverManager = new JMSServerManagerImpl(server);
        serverManager.start();
    }
    return server;
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Configuration(org.apache.activemq.artemis.core.config.Configuration) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) ConfigurationImpl(org.apache.activemq.artemis.core.config.impl.ConfigurationImpl) File(java.io.File)

Example 12 with JMSServerManagerImpl

use of org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl in project activemq-artemis by apache.

the class StompWithClientIdValidationTest method createServer.

@Override
protected JMSServerManager createServer() throws Exception {
    Configuration config = createBasicConfig().setSecurityEnabled(isSecurityEnabled()).setPersistenceEnabled(isPersistenceEnabled()).addAcceptorConfiguration("stomp", "tcp://localhost:61613?enabledProtocols=STOMP").addAcceptorConfiguration(new TransportConfiguration(InVMAcceptorFactory.class.getName()));
    ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), new SecurityConfiguration()) {

        @Override
        public String validateUser(String user, String password, RemotingConnection remotingConnection) {
            String validatedUser = super.validateUser(user, password, remotingConnection);
            if (validatedUser == null) {
                return null;
            }
            if ("STOMP".equals(remotingConnection.getProtocolName())) {
                final String clientId = remotingConnection.getClientID();
                /*
                * perform some kind of clientId validation, e.g. check presence or format
                */
                if (clientId == null || clientId.length() == 0) {
                    System.err.println("ClientID not set!");
                    return null;
                }
            }
            return validatedUser;
        }
    };
    securityManager.getConfiguration().addUser(defUser, defPass);
    ActiveMQServer activeMqServer = addServer(ActiveMQServers.newActiveMQServer(config, ManagementFactory.getPlatformMBeanServer(), securityManager));
    JMSConfiguration jmsConfig = new JMSConfigurationImpl();
    server = new JMSServerManagerImpl(activeMqServer, jmsConfig);
    server.setRegistry(new JndiBindingRegistry(new InVMNamingContext()));
    return server;
}
Also used : JMSConfiguration(org.apache.activemq.artemis.jms.server.config.JMSConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) SecurityConfiguration(org.apache.activemq.artemis.core.config.impl.SecurityConfiguration) JMSConfiguration(org.apache.activemq.artemis.jms.server.config.JMSConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) InVMLoginModule(org.apache.activemq.artemis.spi.core.security.jaas.InVMLoginModule) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) JndiBindingRegistry(org.apache.activemq.artemis.core.registry.JndiBindingRegistry) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) JMSConfigurationImpl(org.apache.activemq.artemis.jms.server.config.impl.JMSConfigurationImpl) SecurityConfiguration(org.apache.activemq.artemis.core.config.impl.SecurityConfiguration) InVMNamingContext(org.apache.activemq.artemis.tests.unit.util.InVMNamingContext)

Example 13 with JMSServerManagerImpl

use of org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl in project activemq-artemis by apache.

the class StompTestBase method createServer.

/**
 * @return
 * @throws Exception
 */
protected JMSServerManager createServer() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put(TransportConstants.PROTOCOLS_PROP_NAME, StompProtocolManagerFactory.STOMP_PROTOCOL_NAME + "," + MQTTProtocolManagerFactory.MQTT_PROTOCOL_NAME);
    params.put(TransportConstants.PORT_PROP_NAME, TransportConstants.DEFAULT_STOMP_PORT);
    params.put(TransportConstants.STOMP_CONSUMERS_CREDIT, "-1");
    if (isEnableStompMessageId()) {
        params.put(TransportConstants.STOMP_ENABLE_MESSAGE_ID, true);
    }
    if (getStompMinLargeMessageSize() != null) {
        params.put(TransportConstants.STOMP_MIN_LARGE_MESSAGE_SIZE, 2048);
    }
    TransportConfiguration stompTransport = new TransportConfiguration(NettyAcceptorFactory.class.getName(), params);
    Configuration config = createBasicConfig().setSecurityEnabled(isSecurityEnabled()).setPersistenceEnabled(isPersistenceEnabled()).addAcceptorConfiguration(stompTransport).addAcceptorConfiguration(new TransportConfiguration(InVMAcceptorFactory.class.getName())).setConnectionTtlCheckInterval(500);
    if (getIncomingInterceptors() != null) {
        config.setIncomingInterceptorClassNames(getIncomingInterceptors());
    }
    if (getOutgoingInterceptors() != null) {
        config.setOutgoingInterceptorClassNames(getOutgoingInterceptors());
    }
    config.setPersistenceEnabled(true);
    ActiveMQServer activeMQServer = addServer(ActiveMQServers.newActiveMQServer(config, defUser, defPass));
    if (isSecurityEnabled()) {
        ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) activeMQServer.getSecurityManager();
        final String role = "testRole";
        securityManager.getConfiguration().addRole(defUser, role);
        config.getSecurityRoles().put("#", new HashSet<Role>() {

            {
                add(new Role(role, true, true, true, true, true, true, true, true, true, true));
            }
        });
    }
    JMSConfiguration jmsConfig = new JMSConfigurationImpl();
    jmsConfig.getQueueConfigurations().add(new JMSQueueConfigurationImpl().setName(getQueueName()).setBindings(getQueueName()));
    jmsConfig.getTopicConfigurations().add(new TopicConfigurationImpl().setName(getTopicName()).setBindings(getTopicName()));
    server = new JMSServerManagerImpl(activeMQServer, jmsConfig);
    server.setRegistry(new JndiBindingRegistry(new InVMNamingContext()));
    return server;
}
Also used : JMSConfiguration(org.apache.activemq.artemis.jms.server.config.JMSConfiguration) JMSConfiguration(org.apache.activemq.artemis.jms.server.config.JMSConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) HashMap(java.util.HashMap) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) NettyAcceptorFactory(org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptorFactory) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) JndiBindingRegistry(org.apache.activemq.artemis.core.registry.JndiBindingRegistry) Role(org.apache.activemq.artemis.core.security.Role) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) JMSConfigurationImpl(org.apache.activemq.artemis.jms.server.config.impl.JMSConfigurationImpl) JMSQueueConfigurationImpl(org.apache.activemq.artemis.jms.server.config.impl.JMSQueueConfigurationImpl) InVMAcceptorFactory(org.apache.activemq.artemis.core.remoting.impl.invm.InVMAcceptorFactory) TopicConfigurationImpl(org.apache.activemq.artemis.jms.server.config.impl.TopicConfigurationImpl) InVMNamingContext(org.apache.activemq.artemis.tests.unit.util.InVMNamingContext)

Example 14 with JMSServerManagerImpl

use of org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl in project activemq-artemis by apache.

the class StompWebSocketTest method createServer.

/**
 * @return
 * @throws Exception
 */
private JMSServerManager createServer() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put(TransportConstants.PROTOCOLS_PROP_NAME, StompProtocolManagerFactory.STOMP_PROTOCOL_NAME);
    params.put(TransportConstants.PORT_PROP_NAME, TransportConstants.DEFAULT_STOMP_PORT + 1);
    TransportConfiguration stompTransport = new TransportConfiguration(NettyAcceptorFactory.class.getName(), params);
    Configuration config = createBasicConfig().addAcceptorConfiguration(stompTransport).addAcceptorConfiguration(new TransportConfiguration(InVMAcceptorFactory.class.getName())).addQueueConfiguration(new CoreQueueConfiguration().setAddress(getQueueName()).setName(getQueueName()).setDurable(false));
    ActiveMQServer activeMQServer = addServer(ActiveMQServers.newActiveMQServer(config));
    JMSConfiguration jmsConfig = new JMSConfigurationImpl();
    server = new JMSServerManagerImpl(activeMQServer, jmsConfig);
    server.setRegistry(null);
    return server;
}
Also used : JMSConfiguration(org.apache.activemq.artemis.jms.server.config.JMSConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) JMSConfiguration(org.apache.activemq.artemis.jms.server.config.JMSConfiguration) CoreQueueConfiguration(org.apache.activemq.artemis.core.config.CoreQueueConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) HashMap(java.util.HashMap) NettyAcceptorFactory(org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptorFactory) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) CoreQueueConfiguration(org.apache.activemq.artemis.core.config.CoreQueueConfiguration) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) JMSConfigurationImpl(org.apache.activemq.artemis.jms.server.config.impl.JMSConfigurationImpl) InVMAcceptorFactory(org.apache.activemq.artemis.core.remoting.impl.invm.InVMAcceptorFactory)

Example 15 with JMSServerManagerImpl

use of org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl in project activemq-artemis by apache.

the class StartStopDeadlockTest method testDeadlock.

/*
   * simple test to make sure connect still works with some network latency  built into netty
   * */
@Test
@BMRules(rules = { @BMRule(name = "Server.start wait-init", targetClass = "org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl", targetMethod = "initialisePart2", targetLocation = "ENTRY", condition = "incrementCounter(\"server-Init\") == 2", action = "System.out.println(\"server backup init\"), waitFor(\"start-init\")"), @BMRule(name = "JMSServer.stop wait-init", targetClass = "org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl", targetMethod = "stop", targetLocation = "ENTRY", action = "signalWake(\"start-init\", true)"), @BMRule(name = "StartStopDeadlockTest tearDown", targetClass = "org.apache.activemq.artemis.tests.extras.byteman.StartStopDeadlockTest", targetMethod = "tearDown", targetLocation = "ENTRY", action = "deleteCounter(\"server-Init\")") })
public void testDeadlock() throws Exception {
    // A live server that will always be crashed
    Configuration confLive = createDefaultNettyConfig().setHAPolicyConfiguration(new SharedStoreMasterPolicyConfiguration());
    final ActiveMQServer serverLive = addServer(ActiveMQServers.newActiveMQServer(confLive));
    serverLive.start();
    // A backup that will be waiting to be activated
    Configuration config = createDefaultNettyConfig().setHAPolicyConfiguration(new SharedStoreSlavePolicyConfiguration());
    final ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(config, true));
    final JMSServerManagerImpl jmsServer = new JMSServerManagerImpl(server);
    final InVMNamingContext context = new InVMNamingContext();
    jmsServer.setRegistry(new JndiBindingRegistry(context));
    jmsServer.start();
    final AtomicInteger errors = new AtomicInteger(0);
    final CountDownLatch align = new CountDownLatch(2);
    final CountDownLatch startLatch = new CountDownLatch(1);
    Thread tCrasher = new Thread("tStart") {

        @Override
        public void run() {
            try {
                align.countDown();
                startLatch.await();
                System.out.println("Crashing....");
                serverLive.fail(true);
            } catch (Exception e) {
                errors.incrementAndGet();
                e.printStackTrace();
            }
        }
    };
    Thread tStop = new Thread("tStop") {

        @Override
        public void run() {
            try {
                align.countDown();
                startLatch.await();
                jmsServer.stop();
            } catch (Exception e) {
                errors.incrementAndGet();
                e.printStackTrace();
            }
        }
    };
    tCrasher.start();
    tStop.start();
    align.await();
    startLatch.countDown();
    tCrasher.join();
    tStop.join();
    assertEquals(0, errors.get());
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Configuration(org.apache.activemq.artemis.core.config.Configuration) SharedStoreMasterPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration) SharedStoreSlavePolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreSlavePolicyConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SharedStoreSlavePolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreSlavePolicyConfiguration) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) SharedStoreMasterPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration) JndiBindingRegistry(org.apache.activemq.artemis.core.registry.JndiBindingRegistry) CountDownLatch(java.util.concurrent.CountDownLatch) InVMNamingContext(org.apache.activemq.artemis.tests.unit.util.InVMNamingContext) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Aggregations

JMSServerManagerImpl (org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl)34 JndiBindingRegistry (org.apache.activemq.artemis.core.registry.JndiBindingRegistry)25 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)22 InVMNamingContext (org.apache.activemq.artemis.tests.unit.util.InVMNamingContext)17 Configuration (org.apache.activemq.artemis.core.config.Configuration)15 Before (org.junit.Before)13 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)11 JMSConfigurationImpl (org.apache.activemq.artemis.jms.server.config.impl.JMSConfigurationImpl)7 ActiveMQJAASSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager)7 HashMap (java.util.HashMap)5 ActiveMQServerImpl (org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl)5 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)5 JMSConfiguration (org.apache.activemq.artemis.jms.server.config.JMSConfiguration)5 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)4 ConnectionFactoryConfiguration (org.apache.activemq.artemis.jms.server.config.ConnectionFactoryConfiguration)4 Test (org.junit.Test)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 FileDeploymentManager (org.apache.activemq.artemis.core.config.FileDeploymentManager)3 SharedStoreMasterPolicyConfiguration (org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration)3 SecurityConfiguration (org.apache.activemq.artemis.core.config.impl.SecurityConfiguration)3