Search in sources :

Example 11 with MessageDrivenBean

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

the class QuartzMdbContainerTest method test.

public void test() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // Setup the descriptor information
    CronBean.lifecycle.clear();
    final AppModule app = new AppModule(this.getClass().getClassLoader(), "testapp");
    final Connector connector = new Connector("email-ra");
    final ResourceAdapter adapter = new ResourceAdapter(QuartzResourceAdapter.class);
    connector.setResourceAdapter(adapter);
    final InboundResourceadapter inbound = adapter.setInboundResourceAdapter(new InboundResourceadapter());
    final MessageAdapter messageAdapter = inbound.setMessageAdapter(new MessageAdapter());
    final MessageListener listener = messageAdapter.addMessageListener(new MessageListener(Job.class, JobSpec.class));
    listener.getActivationSpec().addRequiredConfigProperty("cronExpression");
    app.getConnectorModules().add(new ConnectorModule(connector));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new MessageDrivenBean(CronBean.class));
    app.getEjbModules().add(new EjbModule(ejbJar));
    final AppInfo appInfo = config.configureApplication(app);
    assembler.createApplication(appInfo);
    assertTrue(CronBean.latch.await(5, TimeUnit.SECONDS));
    final Stack<Lifecycle> lifecycle = CronBean.lifecycle;
    final List expected = Arrays.asList(Lifecycle.values());
    Assert.assertEquals(expected.get(0), lifecycle.get(0));
    Assert.assertEquals(expected.get(1), lifecycle.get(1));
}
Also used : Connector(org.apache.openejb.jee.Connector) MessageAdapter(org.apache.openejb.jee.MessageAdapter) AppModule(org.apache.openejb.config.AppModule) MessageListener(org.apache.openejb.jee.MessageListener) EjbModule(org.apache.openejb.config.EjbModule) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) ConnectorModule(org.apache.openejb.config.ConnectorModule) AppInfo(org.apache.openejb.assembler.classic.AppInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) QuartzResourceAdapter(org.apache.openejb.resource.quartz.QuartzResourceAdapter) ResourceAdapter(org.apache.openejb.jee.ResourceAdapter) List(java.util.List) Assembler(org.apache.openejb.assembler.classic.Assembler) JobSpec(org.apache.openejb.resource.quartz.JobSpec) InboundResourceadapter(org.apache.openejb.jee.InboundResourceadapter) Job(org.apache.openejb.quartz.Job) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 12 with MessageDrivenBean

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

the class CheckInvalidAsynchronousAnnotationsTest method ejbJarWithMessageDrivenBean.

private static EjbJar ejbJarWithMessageDrivenBean(final Class<?> beanClass) {
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new MessageDrivenBean(beanClass));
    return ejbJar;
}
Also used : MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) EjbJar(org.apache.openejb.jee.EjbJar)

Example 13 with MessageDrivenBean

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

the class CheckAnnotationTest method testWebServiceWithMessageDriven.

@Keys({ @Key(value = "annotation.invalid.messagedriven.webservice", type = KeyType.WARNING) })
public AppModule testWebServiceWithMessageDriven() {
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new MessageDrivenBean(Yellow.class));
    final EjbModule ejbModule = new EjbModule(ejbJar);
    ejbModule.setFinder(new AnnotationFinder(new ClassesArchive(Yellow.class)).link());
    final AppModule appModule = new AppModule(ejbModule);
    return appModule;
}
Also used : AppModule(org.apache.openejb.config.AppModule) Yellow(org.apache.openejb.test.annotated.Yellow) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) EjbModule(org.apache.openejb.config.EjbModule) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) AnnotationFinder(org.apache.xbean.finder.AnnotationFinder) EjbJar(org.apache.openejb.jee.EjbJar)

Example 14 with MessageDrivenBean

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

the class AutoConfig method processActivationConfig.

/**
     * Set destination, destinationType, clientId and subscriptionName in the MDB activation config.
     */
private void processActivationConfig(final EjbModule ejbModule) throws OpenEJBException {
    final OpenejbJar openejbJar;
    if (ejbModule.getOpenejbJar() != null) {
        openejbJar = ejbModule.getOpenejbJar();
    } else {
        openejbJar = new OpenejbJar();
        ejbModule.setOpenejbJar(openejbJar);
    }
    final Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
    for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
        if (bean instanceof MessageDrivenBean) {
            final MessageDrivenBean mdb = (MessageDrivenBean) bean;
            if (mdb.getActivationConfig() == null) {
                mdb.setActivationConfig(new ActivationConfig());
            }
            if (!isJms(mdb)) {
                continue;
            }
            final EjbDeployment ejbDeployment = deployments.get(bean.getEjbName());
            if (ejbDeployment == null) {
                throw new OpenEJBException("No ejb deployment found for ejb " + bean.getEjbName());
            }
            final Properties properties = mdb.getActivationConfig().toProperties();
            String destination = properties.getProperty("destinationName", properties.getProperty("destinationLookup"));
            if (destination != null) {
                if (destination.startsWith("openejb:Resource/")) {
                    destination = destination.substring("openejb:Resource/".length());
                }
                if (destination.startsWith("java:openejb/Resource/")) {
                    destination = destination.substring("java:openejb/Resource/".length());
                }
                mdb.getActivationConfig().addProperty("destination", destination);
                // Remove destinationName as it is not in the standard ActivationSpec 
                final List<ActivationConfigProperty> list = mdb.getActivationConfig().getActivationConfigProperty();
                final Iterator<ActivationConfigProperty> iterator = list.iterator();
                while (iterator.hasNext()) {
                    final ActivationConfigProperty configProperty = iterator.next();
                    final String activationConfigPropertyName = configProperty.getActivationConfigPropertyName();
                    if (activationConfigPropertyName.equals("destinationName") || activationConfigPropertyName.equals("destinationLookup")) {
                        iterator.remove();
                        // we suppose we have only one of both we should be the case
                        break;
                    }
                }
            } else {
                destination = properties.getProperty("destination");
            }
            if (destination == null) {
                // EE 7/EJB 3.2
                destination = properties.getProperty("destinationLookup");
            }
            //                String destination = properties.getProperty("destination", properties.getProperty("destinationName"));
            if (destination == null) {
                destination = ejbDeployment.getDeploymentId();
                mdb.getActivationConfig().addProperty("destination", destination);
            }
            // destination identifier
            ResourceLink link = ejbDeployment.getResourceLink("openejb/destination");
            if (link == null && mdb.getMessageDestinationLink() == null) {
                link = new ResourceLink();
                link.setResId(destination);
                link.setResRefName("openejb/destination");
                ejbDeployment.addResourceLink(link);
            }
            // destination type
            String destinationType = properties.getProperty("destinationType");
            if (destinationType == null && mdb.getMessageDestinationType() != null) {
                destinationType = mdb.getMessageDestinationType();
                mdb.getActivationConfig().addProperty("destinationType", destinationType);
            }
            if (mdb.getMessageDestinationType() == null) {
                mdb.setMessageDestinationType(destinationType);
            }
            // topics need a clientId and subscriptionName
            if ("javax.jms.Topic".equals(destinationType)) {
                if (Boolean.parseBoolean(SystemInstance.get().getProperty("openejb.activemq.deploymentId-as-clientId", ejbModule.getProperties().getProperty("openejb.activemq.deploymentId-as-clientId", "true"))) && !properties.containsKey("clientId")) {
                    mdb.getActivationConfig().addProperty("clientId", ejbDeployment.getDeploymentId());
                }
                if (!properties.containsKey("subscriptionName")) {
                    mdb.getActivationConfig().addProperty("subscriptionName", ejbDeployment.getDeploymentId() + "_subscription");
                }
            }
        }
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) Properties(java.util.Properties) SuperProperties(org.apache.openejb.util.SuperProperties) 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) ResourceLink(org.apache.openejb.jee.oejb3.ResourceLink) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment)

Example 15 with MessageDrivenBean

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

the class AutoConfig method getUsableContainer.

private String getUsableContainer(final Class<? extends ContainerInfo> containerInfoType, final Object bean, final AppResources appResources) {
    if (MessageDrivenBean.class.isInstance(bean)) {
        final MessageDrivenBean messageDrivenBean = (MessageDrivenBean) bean;
        final String messagingType = messageDrivenBean.getMessagingType();
        final List<String> containerIds = appResources.containerIdsByType.get(messagingType);
        if (containerIds != null && !containerIds.isEmpty()) {
            return containerIds.get(0);
        }
    }
    String containerInfo = matchContainer(containerInfoType, bean, appResources.getContainerInfos());
    if (containerInfo == null) {
        // avoid to build configFactory.getContainerInfos() if not needed
        containerInfo = matchContainer(containerInfoType, bean, configFactory.getContainerInfos());
    }
    if (containerInfo != null) {
        return containerInfo;
    }
    return null;
}
Also used : MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean)

Aggregations

MessageDrivenBean (org.apache.openejb.jee.MessageDrivenBean)26 EjbJar (org.apache.openejb.jee.EjbJar)13 Properties (java.util.Properties)9 Assembler (org.apache.openejb.assembler.classic.Assembler)8 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)8 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)8 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)7 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)7 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)7 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)6 MessageDrivenBeanInfo (org.apache.openejb.assembler.classic.MessageDrivenBeanInfo)5 List (java.util.List)4 OpenEJBException (org.apache.openejb.OpenEJBException)4 ActivationConfig (org.apache.openejb.jee.ActivationConfig)4 ActivationConfigProperty (org.apache.openejb.jee.ActivationConfigProperty)4 AppModule (org.apache.openejb.config.AppModule)3 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)3 EjbModule (org.apache.openejb.config.EjbModule)3 AppModuleBuilder (org.apache.openejb.core.builder.AppModuleBuilder)3 MdbBuilder (org.apache.openejb.core.builder.MdbBuilder)3