Search in sources :

Example 26 with MessageDrivenBean$JAXB.readMessageDrivenBean

use of org.apache.openejb.jee.MessageDrivenBean$JAXB.readMessageDrivenBean in project tomee by apache.

the class ActivationConfigPropertyOverride method deploy.

@Override
public AppModule deploy(final AppModule appModule) throws OpenEJBException {
    final Properties system = new Properties();
    system.putAll(SystemInstance.get().getProperties());
    system.putAll(appModule.getProperties());
    system.putAll(JavaSecurityManagers.getSystemProperties());
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
        final EjbJar ejbJar = ejbModule.getEjbJar();
        final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
        final Properties module = new Properties();
        module.putAll(openejbJar.getProperties());
        module.putAll(system);
        final Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
        for (final EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
            final String ejbName = bean.getEjbName();
            final EjbDeployment ejbDeployment = deployments.get(ejbName);
            if (!(bean instanceof MessageDrivenBean)) {
                continue;
            }
            final Properties properties = new Properties();
            properties.putAll(module);
            properties.putAll(ejbDeployment.getProperties());
            final MessageDrivenBean mdb = (MessageDrivenBean) bean;
            // override with placeholding
            if (mdb.getActivationConfig() != null) {
                for (final ActivationConfigProperty property : mdb.getActivationConfig().getActivationConfigProperty()) {
                    final String originalValue = property.getActivationConfigPropertyValue();
                    final String value = PropertyPlaceHolderHelper.simpleValue(originalValue);
                    if (value != null && !originalValue.equals(value)) {
                        property.setActivationConfigPropertyValue(value);
                    }
                }
            }
            // now try to use special keys
            final Properties overrides = new Properties();
            final MdbContainerDetails mdbContainer = getMdbContainer(appModule, ejbDeployment.getContainerId(), appModule.getModuleId());
            if (mdbContainer != null) {
                overrides.putAll(ConfigurationFactory.getOverrides(properties, "mdb.container." + mdbContainer.getContainerId() + ".activation", "EnterpriseBean"));
                overrides.putAll(ConfigurationFactory.getOverrides(mdbContainer.getProperties(), "activation", "EnterpriseBean"));
            }
            overrides.putAll(ConfigurationFactory.getOverrides(properties, "mdb.activation", "EnterpriseBean"));
            overrides.putAll(ConfigurationFactory.getOverrides(properties, mdb.getMessagingType() + ".activation", "EnterpriseBean"));
            overrides.putAll(ConfigurationFactory.getOverrides(properties, ejbName + ".activation", "EnterpriseBean"));
            overrides.putAll(ConfigurationFactory.getOverrides(properties, ejbDeployment.getDeploymentId() + ".activation", "EnterpriseBean"));
            // If we don't have any overrides, skip to the next
            if (overrides.size() == 0) {
                continue;
            }
            if (mdb.getActivationConfig() == null) {
                mdb.setActivationConfig(new ActivationConfig());
            }
            final List<ActivationConfigProperty> activationConfigList = mdb.getActivationConfig().getActivationConfigProperty();
            for (final Map.Entry<Object, Object> entry : overrides.entrySet()) {
                final Object property = String.valueOf(entry.getKey());
                final Object value = String.valueOf(entry.getValue());
                ActivationConfigProperty activationConfigProperty = this.findActivationProperty(activationConfigList, property.toString());
                if (activationConfigProperty != null) {
                    logger.info(String.format("Found %s bean with activation-config property %s=%s to override", ejbName, activationConfigProperty.getActivationConfigPropertyName(), activationConfigProperty.getActivationConfigPropertyValue()));
                    logger.info(String.format("Overriding %s bean activation-config property.%s=%s", ejbName, property, value));
                    activationConfigProperty.setActivationConfigPropertyValue(entry.getValue().toString());
                } else {
                    logger.info(String.format("Adding %s bean activation-config property %s=%s", ejbName, property, value));
                    activationConfigProperty = new ActivationConfigProperty();
                    activationConfigProperty.setActivationConfigPropertyName(property.toString());
                    activationConfigProperty.setActivationConfigPropertyValue(value.toString());
                    activationConfigList.add(activationConfigProperty);
                }
            }
        }
    }
    return appModule;
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) Properties(java.util.Properties) ActivationConfig(org.apache.openejb.jee.ActivationConfig) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) ActivationConfigProperty(org.apache.openejb.jee.ActivationConfigProperty) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Map(java.util.Map) EjbJar(org.apache.openejb.jee.EjbJar)

Example 27 with MessageDrivenBean$JAXB.readMessageDrivenBean

use of org.apache.openejb.jee.MessageDrivenBean$JAXB.readMessageDrivenBean in project tomee by apache.

the class ActivationConfigPropertyOverrideTest method testNotOverridden.

@Test
public void testNotOverridden() throws Exception {
    SystemInstance.reset();
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new MessageDrivenBean(Orange.class));
    ejbJar.addEnterpriseBean(new MessageDrivenBean(Yellow.class));
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    assertEquals(2, ejbJarInfo.enterpriseBeans.size());
    final MessageDrivenBeanInfo orange = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(0);
    final MessageDrivenBeanInfo yellow = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(1);
    assertEquals("7", orange.activationProperties.get("maxSessions"));
    assertEquals("4", orange.activationProperties.get("maxMessagesPerSessions"));
    assertEquals("javax.jms.Queue", orange.activationProperties.get("destinationType"));
    assertEquals("ORANGE.QUEUE", orange.activationProperties.get("destination"));
    assertEquals("5", yellow.activationProperties.get("maxSessions"));
    assertEquals("10", yellow.activationProperties.get("maxMessagesPerSessions"));
    assertEquals("javax.jms.Topic", yellow.activationProperties.get("destinationType"));
    assertEquals("YELLOW.TOPIC", yellow.activationProperties.get("destination"));
}
Also used : MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) EjbJar(org.apache.openejb.jee.EjbJar) Test(org.junit.Test) ActivationContainerOverwriteBothConfigurationTest(org.apache.openejb.activemq.ActivationContainerOverwriteBothConfigurationTest)

Example 28 with MessageDrivenBean$JAXB.readMessageDrivenBean

use of org.apache.openejb.jee.MessageDrivenBean$JAXB.readMessageDrivenBean in project tomee by apache.

the class ActivationConfigPropertyOverrideTest method testMdbOverrideSystem.

@Test
public void testMdbOverrideSystem() throws Exception {
    SystemInstance.reset();
    final Properties systProps = SystemInstance.get().getProperties();
    final Properties properties = new Properties();
    properties.setProperty("mdb.activation.maxSessions", "20");
    properties.setProperty("mdb.activation.maxMessagesPerSessions", "100");
    properties.setProperty("mdb.activation.destinationType", "javax.jms.Queue");
    properties.setProperty("mdb.activation.destination", "OVERRIDDEN.QUEUE");
    systProps.putAll(properties);
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new MessageDrivenBean(Orange.class));
    ejbJar.addEnterpriseBean(new MessageDrivenBean(Yellow.class));
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    assertEquals(2, ejbJarInfo.enterpriseBeans.size());
    final MessageDrivenBeanInfo orange = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(0);
    final MessageDrivenBeanInfo yellow = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(1);
    assertEquals("20", orange.activationProperties.get("maxSessions"));
    assertEquals("100", orange.activationProperties.get("maxMessagesPerSessions"));
    assertEquals("javax.jms.Queue", orange.activationProperties.get("destinationType"));
    assertEquals("OVERRIDDEN.QUEUE", orange.activationProperties.get("destination"));
    assertEquals("20", yellow.activationProperties.get("maxSessions"));
    assertEquals("100", yellow.activationProperties.get("maxMessagesPerSessions"));
    assertEquals("javax.jms.Queue", yellow.activationProperties.get("destinationType"));
    assertEquals("OVERRIDDEN.QUEUE", yellow.activationProperties.get("destination"));
    for (final String n : properties.stringPropertyNames()) {
        systProps.remove(n);
    }
}
Also used : MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) Properties(java.util.Properties) EjbJar(org.apache.openejb.jee.EjbJar) Test(org.junit.Test) ActivationContainerOverwriteBothConfigurationTest(org.apache.openejb.activemq.ActivationContainerOverwriteBothConfigurationTest)

Example 29 with MessageDrivenBean$JAXB.readMessageDrivenBean

use of org.apache.openejb.jee.MessageDrivenBean$JAXB.readMessageDrivenBean in project tomee by apache.

the class ActivationConfigPropertyOverrideTest method testMdbOverrideOpenejbJar.

@Test
public void testMdbOverrideOpenejbJar() throws Exception {
    SystemInstance.reset();
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    {
        final EjbJar ejbJar = new EjbJar();
        ejbJar.addEnterpriseBean(new MessageDrivenBean(Orange.class));
        ejbJar.addEnterpriseBean(new MessageDrivenBean(Yellow.class));
        final OpenejbJar openejbJar = new OpenejbJar();
        final Properties properties = openejbJar.getProperties();
        properties.setProperty("mdb.activation.maxSessions", "20");
        properties.setProperty("mdb.activation.maxMessagesPerSessions", "100");
        properties.setProperty("mdb.activation.destinationType", "javax.jms.Queue");
        properties.setProperty("mdb.activation.destination", "OVERRIDDEN.QUEUE");
        final EjbModule ejbModule = new EjbModule(ejbJar, openejbJar);
        final EjbJarInfo ejbJarInfo = config.configureApplication(ejbModule);
        assertEquals(2, ejbJarInfo.enterpriseBeans.size());
        final MessageDrivenBeanInfo orange = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(0);
        final MessageDrivenBeanInfo yellow = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(1);
        assertEquals("20", orange.activationProperties.get("maxSessions"));
        assertEquals("100", orange.activationProperties.get("maxMessagesPerSessions"));
        assertEquals("javax.jms.Queue", orange.activationProperties.get("destinationType"));
        assertEquals("OVERRIDDEN.QUEUE", orange.activationProperties.get("destination"));
        assertEquals("20", yellow.activationProperties.get("maxSessions"));
        assertEquals("100", yellow.activationProperties.get("maxMessagesPerSessions"));
        assertEquals("javax.jms.Queue", yellow.activationProperties.get("destinationType"));
        assertEquals("OVERRIDDEN.QUEUE", yellow.activationProperties.get("destination"));
    }
    // Verify the openejb-jar level overrides do not affect other apps
    {
        final EjbJar ejbJar = new EjbJar();
        ejbJar.addEnterpriseBean(new MessageDrivenBean(Orange.class));
        ejbJar.addEnterpriseBean(new MessageDrivenBean(Yellow.class));
        final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
        assertEquals(2, ejbJarInfo.enterpriseBeans.size());
        final MessageDrivenBeanInfo orange = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(0);
        final MessageDrivenBeanInfo yellow = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(1);
        assertEquals("7", orange.activationProperties.get("maxSessions"));
        assertEquals("4", orange.activationProperties.get("maxMessagesPerSessions"));
        assertEquals("javax.jms.Queue", orange.activationProperties.get("destinationType"));
        assertEquals("ORANGE.QUEUE", orange.activationProperties.get("destination"));
        assertEquals("5", yellow.activationProperties.get("maxSessions"));
        assertEquals("10", yellow.activationProperties.get("maxMessagesPerSessions"));
        assertEquals("javax.jms.Topic", yellow.activationProperties.get("destinationType"));
        assertEquals("YELLOW.TOPIC", yellow.activationProperties.get("destination"));
    }
}
Also used : OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) Properties(java.util.Properties) EjbJar(org.apache.openejb.jee.EjbJar) Test(org.junit.Test) ActivationContainerOverwriteBothConfigurationTest(org.apache.openejb.activemq.ActivationContainerOverwriteBothConfigurationTest)

Example 30 with MessageDrivenBean$JAXB.readMessageDrivenBean

use of org.apache.openejb.jee.MessageDrivenBean$JAXB.readMessageDrivenBean in project tomee by apache.

the class ActivationConfigPropertyOverrideTest method testOverrideFromContainerDefinedInAppModule.

@Test
public void testOverrideFromContainerDefinedInAppModule() throws Exception {
    SystemInstance.reset();
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new MessageDrivenBean("Yellow", Orange.class));
    ejbJar.addEnterpriseBean(new MessageDrivenBean("Orange", Yellow.class));
    final AppModule appModule = new AppModule(new EjbModule(ejbJar));
    appModule.setModuleId("mymodule");
    final Container container = new Container();
    container.setId("mycontainer");
    container.setCtype("MESSAGE");
    container.getProperties().setProperty("activation.DeliveryActive", "false");
    appModule.getContainers().add(container);
    final AppInfo appInfo = config.configureApplication(appModule);
    assertEquals(1, appInfo.ejbJars.size());
    final EjbJarInfo ejbJarInfo = appInfo.ejbJars.get(0);
    assertEquals(2, ejbJarInfo.enterpriseBeans.size());
    final MessageDrivenBeanInfo orange = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(0);
    final MessageDrivenBeanInfo yellow = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(1);
    assertEquals("false", orange.activationProperties.get("DeliveryActive"));
    assertEquals("false", yellow.activationProperties.get("DeliveryActive"));
}
Also used : Container(org.apache.openejb.config.sys.Container) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) EjbJar(org.apache.openejb.jee.EjbJar) Test(org.junit.Test) ActivationContainerOverwriteBothConfigurationTest(org.apache.openejb.activemq.ActivationContainerOverwriteBothConfigurationTest)

Aggregations

MessageDrivenBean (org.apache.openejb.jee.MessageDrivenBean)32 EjbJar (org.apache.openejb.jee.EjbJar)17 Properties (java.util.Properties)10 ActivationContainerOverwriteBothConfigurationTest (org.apache.openejb.activemq.ActivationContainerOverwriteBothConfigurationTest)9 Test (org.junit.Test)9 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)7 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)7 EjbModule (org.apache.openejb.config.EjbModule)6 ActivationConfig (org.apache.openejb.jee.ActivationConfig)6 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)6 List (java.util.List)5 OpenEJBException (org.apache.openejb.OpenEJBException)4 Assembler (org.apache.openejb.assembler.classic.Assembler)4 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)4 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)4 AppModule (org.apache.openejb.config.AppModule)4 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)4 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)4 ActivationConfigProperty (org.apache.openejb.jee.ActivationConfigProperty)4 InitialContext (javax.naming.InitialContext)3