Search in sources :

Example 26 with MessageDrivenBean$JAXB.writeMessageDrivenBean

use of org.apache.openejb.jee.MessageDrivenBean$JAXB.writeMessageDrivenBean 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 27 with MessageDrivenBean$JAXB.writeMessageDrivenBean

use of org.apache.openejb.jee.MessageDrivenBean$JAXB.writeMessageDrivenBean 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)

Example 28 with MessageDrivenBean$JAXB.writeMessageDrivenBean

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

the class ActivationConfigPropertyOverrideTest method testOverrideActivationConfigProperty.

/**
 * System property set should override activationConfigProperty
 *
 * @throws OpenEJBException
 */
@Test
public void testOverrideActivationConfigProperty() throws OpenEJBException {
    // set overrides for destinationType and check
    System.setProperty("ENTERPRISEBEAN.mdb.activation.destinationType", "testString");
    final MessageDrivenBean mdb = new MdbBuilder().anMdb().withActivationProperty("destinationType", "stringToBeOverriden").build();
    final ActivationConfigPropertyOverride activationPropertyOverride = new ActivationConfigPropertyOverride();
    final AppModule appModule = new AppModuleBuilder().anAppModule().withAnMdb(mdb).build();
    activationPropertyOverride.deploy(appModule);
    assertTrue(containsActivationKeyValuePair(mdb, "destinationType", "testString"));
    assertTrue(mdb.getActivationConfig().getActivationConfigProperty().size() == 1);
    System.clearProperty("ENTERPRISEBEAN.mdb.activation.destinationType");
}
Also used : MdbBuilder(org.apache.openejb.core.builder.MdbBuilder) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) AppModuleBuilder(org.apache.openejb.core.builder.AppModuleBuilder) Test(org.junit.Test) ActivationContainerOverwriteBothConfigurationTest(org.apache.openejb.activemq.ActivationContainerOverwriteBothConfigurationTest)

Example 29 with MessageDrivenBean$JAXB.writeMessageDrivenBean

use of org.apache.openejb.jee.MessageDrivenBean$JAXB.writeMessageDrivenBean 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 30 with MessageDrivenBean$JAXB.writeMessageDrivenBean

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

the class EjbJar$JAXB method _write.

public static final void _write(final XoXMLStreamWriter writer, final EjbJar ejbJar, RuntimeContext context) throws Exception {
    if (ejbJar == null) {
        writer.writeXsiNil();
        return;
    }
    if (context == null) {
        context = new RuntimeContext();
    }
    final String prefix = writer.getUniquePrefix("http://java.sun.com/xml/ns/javaee");
    if (EjbJar.class != ejbJar.getClass()) {
        context.unexpectedSubclass(writer, ejbJar, EjbJar.class);
        return;
    }
    context.beforeMarshal(ejbJar, LifecycleCallback.NONE);
    // ATTRIBUTE: id
    final String idRaw = ejbJar.id;
    if (idRaw != null) {
        String id = null;
        try {
            id = Adapters.collapsedStringAdapterAdapter.marshal(idRaw);
        } catch (final Exception e) {
            context.xmlAdapterError(ejbJar, "id", CollapsedStringAdapter.class, String.class, String.class, e);
        }
        writer.writeAttribute("", "", "id", id);
    }
    // ATTRIBUTE: metadataComplete
    final Boolean metadataComplete = ejbJar.metadataComplete;
    if (metadataComplete != null) {
        writer.writeAttribute("", "", "metadata-complete", Boolean.toString(metadataComplete));
    }
    // ATTRIBUTE: version
    final String versionRaw = ejbJar.version;
    if (versionRaw != null) {
        String version = null;
        try {
            version = Adapters.collapsedStringAdapterAdapter.marshal(versionRaw);
        } catch (final Exception e) {
            context.xmlAdapterError(ejbJar, "version", CollapsedStringAdapter.class, String.class, String.class, e);
        }
        writer.writeAttribute("", "", "version", version);
    }
    // ELEMENT: moduleName
    final String moduleNameRaw = ejbJar.moduleName;
    String moduleName = null;
    try {
        moduleName = Adapters.collapsedStringAdapterAdapter.marshal(moduleNameRaw);
    } catch (final Exception e) {
        context.xmlAdapterError(ejbJar, "moduleName", CollapsedStringAdapter.class, String.class, String.class, e);
    }
    if (moduleName != null) {
        writer.writeStartElement(prefix, "module-name", "http://java.sun.com/xml/ns/javaee");
        writer.writeCharacters(moduleName);
        writer.writeEndElement();
    }
    // ELEMENT: descriptions
    Text[] descriptions = null;
    try {
        descriptions = ejbJar.getDescriptions();
    } catch (final Exception e) {
        context.getterError(ejbJar, "descriptions", EjbJar.class, "getDescriptions", e);
    }
    if (descriptions != null) {
        for (final Text descriptionsItem : descriptions) {
            if (descriptionsItem != null) {
                writer.writeStartElement(prefix, "description", "http://java.sun.com/xml/ns/javaee");
                writeText(writer, descriptionsItem, context);
                writer.writeEndElement();
            } else {
                context.unexpectedNullValue(ejbJar, "descriptions");
            }
        }
    }
    // ELEMENT: displayNames
    Text[] displayNames = null;
    try {
        displayNames = ejbJar.getDisplayNames();
    } catch (final Exception e) {
        context.getterError(ejbJar, "displayNames", EjbJar.class, "getDisplayNames", e);
    }
    if (displayNames != null) {
        for (final Text displayNamesItem : displayNames) {
            if (displayNamesItem != null) {
                writer.writeStartElement(prefix, "display-name", "http://java.sun.com/xml/ns/javaee");
                writeText(writer, displayNamesItem, context);
                writer.writeEndElement();
            } else {
                context.unexpectedNullValue(ejbJar, "displayNames");
            }
        }
    }
    // ELEMENT: icon
    final LocalCollection<Icon> icon = ejbJar.icon;
    if (icon != null) {
        for (final Icon iconItem : icon) {
            if (iconItem != null) {
                writer.writeStartElement(prefix, "icon", "http://java.sun.com/xml/ns/javaee");
                writeIcon(writer, iconItem, context);
                writer.writeEndElement();
            } else {
                context.unexpectedNullValue(ejbJar, "icon");
            }
        }
    }
    // ELEMENT: enterpriseBeans
    EnterpriseBean[] enterpriseBeans = null;
    try {
        enterpriseBeans = ejbJar.getEnterpriseBeans();
    } catch (final Exception e) {
        context.getterError(ejbJar, "enterpriseBeans", EjbJar.class, "getEnterpriseBeans", e);
    }
    writer.writeStartElement(prefix, "enterprise-beans", "http://java.sun.com/xml/ns/javaee");
    if (enterpriseBeans != null) {
        for (final EnterpriseBean enterpriseBeansItem : enterpriseBeans) {
            if (enterpriseBeansItem instanceof org.apache.openejb.jee.EntityBean) {
                final org.apache.openejb.jee.EntityBean EntityBean = ((org.apache.openejb.jee.EntityBean) enterpriseBeansItem);
                writer.writeStartElement(prefix, "entity", "http://java.sun.com/xml/ns/javaee");
                writeEntityBean(writer, EntityBean, context);
                writer.writeEndElement();
            } else if (enterpriseBeansItem instanceof org.apache.openejb.jee.SessionBean) {
                final org.apache.openejb.jee.SessionBean SessionBean = ((org.apache.openejb.jee.SessionBean) enterpriseBeansItem);
                writer.writeStartElement(prefix, "session", "http://java.sun.com/xml/ns/javaee");
                writeSessionBean(writer, SessionBean, context);
                writer.writeEndElement();
            } else if (enterpriseBeansItem instanceof org.apache.openejb.jee.MessageDrivenBean) {
                final org.apache.openejb.jee.MessageDrivenBean MessageDrivenBean = ((org.apache.openejb.jee.MessageDrivenBean) enterpriseBeansItem);
                writer.writeStartElement(prefix, "message-driven", "http://java.sun.com/xml/ns/javaee");
                writeMessageDrivenBean(writer, MessageDrivenBean, context);
                writer.writeEndElement();
            } else if (enterpriseBeansItem == null) {
                context.unexpectedNullValue(ejbJar, "enterpriseBeans");
            } else {
                context.unexpectedElementType(writer, ejbJar, "enterpriseBeans", enterpriseBeansItem, org.apache.openejb.jee.EntityBean.class, org.apache.openejb.jee.SessionBean.class, org.apache.openejb.jee.MessageDrivenBean.class);
            }
        }
    }
    writer.writeEndElement();
    // ELEMENT: interceptors
    final Interceptors interceptors = ejbJar.interceptors;
    if (interceptors != null) {
        writer.writeStartElement(prefix, "interceptors", "http://java.sun.com/xml/ns/javaee");
        writeInterceptors(writer, interceptors, context);
        writer.writeEndElement();
    }
    // ELEMENT: relationships
    final Relationships relationships = ejbJar.relationships;
    if (relationships != null) {
        writer.writeStartElement(prefix, "relationships", "http://java.sun.com/xml/ns/javaee");
        writeRelationships(writer, relationships, context);
        writer.writeEndElement();
    }
    // ELEMENT: assemblyDescriptor
    final AssemblyDescriptor assemblyDescriptor = ejbJar.assemblyDescriptor;
    if (assemblyDescriptor != null) {
        writer.writeStartElement(prefix, "assembly-descriptor", "http://java.sun.com/xml/ns/javaee");
        writeAssemblyDescriptor(writer, assemblyDescriptor, context);
        writer.writeEndElement();
    }
    // ELEMENT: ejbClientJar
    final String ejbClientJarRaw = ejbJar.ejbClientJar;
    String ejbClientJar = null;
    try {
        ejbClientJar = Adapters.collapsedStringAdapterAdapter.marshal(ejbClientJarRaw);
    } catch (final Exception e) {
        context.xmlAdapterError(ejbJar, "ejbClientJar", CollapsedStringAdapter.class, String.class, String.class, e);
    }
    if (ejbClientJar != null) {
        writer.writeStartElement(prefix, "ejb-client-jar", "http://java.sun.com/xml/ns/javaee");
        writer.writeCharacters(ejbClientJar);
        writer.writeEndElement();
    }
    context.afterMarshal(ejbJar, LifecycleCallback.NONE);
}
Also used : SessionBean$JAXB.writeSessionBean(org.apache.openejb.jee.SessionBean$JAXB.writeSessionBean) SessionBean$JAXB.readSessionBean(org.apache.openejb.jee.SessionBean$JAXB.readSessionBean) Relationships$JAXB.readRelationships(org.apache.openejb.jee.Relationships$JAXB.readRelationships) Relationships$JAXB.writeRelationships(org.apache.openejb.jee.Relationships$JAXB.writeRelationships) MessageDrivenBean$JAXB.writeMessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean$JAXB.writeMessageDrivenBean) MessageDrivenBean$JAXB.readMessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean$JAXB.readMessageDrivenBean) AssemblyDescriptor$JAXB.writeAssemblyDescriptor(org.apache.openejb.jee.AssemblyDescriptor$JAXB.writeAssemblyDescriptor) AssemblyDescriptor$JAXB.readAssemblyDescriptor(org.apache.openejb.jee.AssemblyDescriptor$JAXB.readAssemblyDescriptor) CollapsedStringAdapter(javax.xml.bind.annotation.adapters.CollapsedStringAdapter) Text$JAXB.readText(org.apache.openejb.jee.Text$JAXB.readText) Text$JAXB.writeText(org.apache.openejb.jee.Text$JAXB.writeText) Interceptors$JAXB.readInterceptors(org.apache.openejb.jee.Interceptors$JAXB.readInterceptors) Interceptors$JAXB.writeInterceptors(org.apache.openejb.jee.Interceptors$JAXB.writeInterceptors) EntityBean$JAXB.writeEntityBean(org.apache.openejb.jee.EntityBean$JAXB.writeEntityBean) EntityBean$JAXB.readEntityBean(org.apache.openejb.jee.EntityBean$JAXB.readEntityBean) Icon$JAXB.readIcon(org.apache.openejb.jee.Icon$JAXB.readIcon) Icon$JAXB.writeIcon(org.apache.openejb.jee.Icon$JAXB.writeIcon) RuntimeContext(org.metatype.sxc.jaxb.RuntimeContext)

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