Search in sources :

Example 6 with MessageDrivenBean$JAXB.writeMessageDrivenBean

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

the class LegacyProcessor method process.

public static void process(final Class<?> clazz, final EnterpriseBean bean) {
    if (bean instanceof SessionBean) {
        final SessionBean sessionBean = (SessionBean) bean;
        if (sessionBean.getSessionType() == STATEFUL && SessionSynchronization.class.isAssignableFrom(clazz)) {
            try {
                sessionBean.getAfterBegin().add(new LifecycleCallback(clazz.getMethod("afterBegin")));
                sessionBean.getBeforeCompletion().add(new LifecycleCallback(clazz.getMethod("beforeCompletion")));
                sessionBean.getAfterCompletion().add(new LifecycleCallback(clazz.getMethod("afterCompletion", boolean.class)));
            } catch (final NoSuchMethodException e) {
            // Ignore, should never happen
            }
        }
        if (javax.ejb.SessionBean.class.isAssignableFrom(clazz)) {
            final ResourceEnvRef ref = new ResourceEnvRef("javax.ejb.SessionBean/sessionContext", SessionContext.class);
            final InjectionTarget target = new InjectionTarget();
            target.setInjectionTargetClass(clazz);
            target.setInjectionTargetName("sessionContext");
            ref.getInjectionTarget().add(target);
            sessionBean.getResourceEnvRef().add(ref);
        }
    }
    if (bean instanceof MessageDrivenBean) {
        final MessageDrivenBean messageDrivenBean = (MessageDrivenBean) bean;
        if (javax.ejb.MessageDrivenBean.class.isAssignableFrom(clazz)) {
            final ResourceEnvRef ref = new ResourceEnvRef("javax.ejb.MessageDrivenBean/messageDrivenContext", MessageDrivenContext.class);
            final InjectionTarget target = new InjectionTarget();
            target.setInjectionTargetClass(clazz);
            target.setInjectionTargetName("messageDrivenContext");
            ref.getInjectionTarget().add(target);
            messageDrivenBean.getResourceEnvRef().add(ref);
        }
    }
}
Also used : SessionSynchronization(javax.ejb.SessionSynchronization) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) InjectionTarget(org.apache.openejb.jee.InjectionTarget) LifecycleCallback(org.apache.openejb.jee.LifecycleCallback) SessionBean(org.apache.openejb.jee.SessionBean) ResourceEnvRef(org.apache.openejb.jee.ResourceEnvRef)

Example 7 with MessageDrivenBean$JAXB.writeMessageDrivenBean

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

the class MdbConfigTest method createJaxbMdb.

private MessageDrivenBean createJaxbMdb(final String ejbName, final String mdbClass, final String messageListenerInterface) {
    final MessageDrivenBean bean = new MessageDrivenBean(ejbName);
    bean.setEjbClass(mdbClass);
    bean.setMessagingType(messageListenerInterface);
    final ActivationConfig activationConfig = new ActivationConfig();
    activationConfig.getActivationConfigProperty().add(new ActivationConfigProperty("destination", ejbName));
    activationConfig.getActivationConfigProperty().add(new ActivationConfigProperty("destinationType", "javax.jms.Queue"));
    bean.setActivationConfig(activationConfig);
    return bean;
}
Also used : ActivationConfigProperty(org.apache.openejb.jee.ActivationConfigProperty) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) ActivationConfig(org.apache.openejb.jee.ActivationConfig)

Example 8 with MessageDrivenBean$JAXB.writeMessageDrivenBean

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

the class ActivationConfigPropertyOverrideTest method testNoOverrideSetShouldNotOverride.

@Test
public void testNoOverrideSetShouldNotOverride() throws OpenEJBException {
    if (SystemInstance.get().getProperties().containsKey("ENTERPRISEBEAN.mdb.activation.destinationType")) {
        SystemInstance.get().getProperties().remove("ENTERPRISEBEAN.mdb.activation.destinationType");
    }
    System.clearProperty("ENTERPRISEBEAN.mdb.activation.destinationType");
    final MessageDrivenBean mdb = new MdbBuilder().anMdb().withActivationProperty("destinationType", "shouldNotBeOverriddenString").build();
    final AppModule appModule = new AppModuleBuilder().anAppModule().withAnMdb(mdb).build();
    final ActivationConfigPropertyOverride activationPropertyOverride = new ActivationConfigPropertyOverride();
    activationPropertyOverride.deploy(appModule);
    assertTrue(containsActivationKeyValuePair(mdb, "destinationType", "shouldNotBeOverriddenString"));
}
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 9 with MessageDrivenBean$JAXB.writeMessageDrivenBean

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

the class ActivationConfigPropertyOverrideTest method testEjbNameOverrideOpenejbJar.

@Test
public void testEjbNameOverrideOpenejbJar() 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 10 with MessageDrivenBean$JAXB.writeMessageDrivenBean

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

the class ActivationConfigPropertyOverrideTest method testAddActivationConfigPropertyIfNotAlreadyPresent.

/**
 * If activation property was not present initially, then add the specified
 * one.
 *
 * @throws OpenEJBException
 */
@Test
public void testAddActivationConfigPropertyIfNotAlreadyPresent() throws OpenEJBException {
    // set overrides
    System.setProperty("ENTERPRISEBEAN.mdb.activation.destinationType", "testString");
    // deploy with an mdb that has no "destinationType" activationConfigProp
    final MessageDrivenBean mdb = new MdbBuilder().anMdb().build();
    final AppModule appModule = new AppModuleBuilder().anAppModule().withAnMdb(mdb).build();
    final ActivationConfigPropertyOverride activationPropertyOverride = new ActivationConfigPropertyOverride();
    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)

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