Package org.apache.openejb.jee

Examples of org.apache.openejb.jee.MessageDrivenBean


        return installResource(beanName, resourceInfo);
    }

    private String getUsableContainer(Class<? extends ContainerInfo> containerInfoType, Object bean, AppResources appResources) {
        if (bean instanceof MessageDrivenBean) {
            MessageDrivenBean messageDrivenBean = (MessageDrivenBean) bean;
            String messagingType = messageDrivenBean.getMessagingType();
            List<String> containerIds = appResources.containerIdsByType.get(messagingType);
            if (containerIds != null && !containerIds.isEmpty()) {
                return containerIds.get(0);
            }
        }

        for (ContainerInfo containerInfo : configFactory.getContainerInfos()) {
            if (containerInfo.getClass().equals(containerInfoType)){
                // MDBs must match message listener interface type
                if (bean instanceof MessageDrivenBean) {
                    MessageDrivenBean messageDrivenBean = (MessageDrivenBean) bean;
                    String messagingType = messageDrivenBean.getMessagingType();
                    if (containerInfo.properties.get("MessageListenerInterface").equals(messagingType)) {
                        return containerInfo.id;
                    }
                } else {
                    return containerInfo.id;
View Full Code Here


                if (bean instanceof MessageDrivenBean) {
                    /*
                     * @ActivationConfigProperty
                     */
                    MessageDrivenBean mdb = (MessageDrivenBean) bean;
                    MessageDriven messageDriven = clazz.getAnnotation(MessageDriven.class);
                    if (messageDriven != null) {
                        ActivationConfig activationConfig = mdb.getActivationConfig();
                        if (activationConfig == null) {
                            activationConfig = new ActivationConfig();
                        }

                        if (!messageDriven.mappedName().isEmpty()) {
                            if (mdb.getActivationConfig() == null) {
                                mdb.setActivationConfig(activationConfig);
                            }
                            activationConfig.addProperty("destinationType", Queue.class.getName());
                            activationConfig.addProperty("destination", messageDriven.mappedName());
                        }

                        javax.ejb.ActivationConfigProperty[] configProperties = messageDriven.activationConfig();
                        if (configProperties != null) {
                            if (mdb.getActivationConfig() == null) {
                                mdb.setActivationConfig(activationConfig);
                            }

                            Properties properties = activationConfig.toProperties();
                            for (javax.ejb.ActivationConfigProperty property : configProperties) {
                                if (!properties.containsKey(property.propertyName())) {
                                    activationConfig.addProperty(property.propertyName(), property.propertyValue());
                                }
                            }
                        }

                        if (mdb.getMessagingType() == null) {
                            Class<?> interfce = messageDriven.messageListenerInterface();
                            if (interfce != null && !interfce.equals(Object.class)) {
                                if (!interfce.isInterface()) {
                                    // TODO: Move this check to o.a.o.c.rules.CheckClasses and do it for all MDBs, annotated or not
                                    throw new OpenEJBException("MessageListenerInterface property of @MessageDriven is not an interface");
                                }
                                mdb.setMessagingType(interfce.getName());
                            }
                        }
                    }

                    /*
                     * Determine the MessageListener interface
                     */
                    if (mdb.getMessagingType() == null) {
                        List<Class<?>> interfaces = new ArrayList<Class<?>>();
                        for (Class<?> intf : clazz.getInterfaces()) {
                            String name = intf.getName();
                            if (!name.equals("java.io.Serializable") &&
                                    !name.equals("java.io.Externalizable") &&
                                    !name.startsWith("javax.ejb.") &&
                                    !intf.isSynthetic()) {
                                interfaces.add(intf);
                            }
                        }

                        if (interfaces.size() != 1) {
                            String msg = "When annotating a bean class as @MessageDriven without declaring messageListenerInterface, the bean must implement exactly one interface, no more and no less. beanClass=" + clazz.getName() + " interfaces=";
                            for (Class<?> intf : interfaces) {
                                msg += intf.getName() + ", ";
                            }
                            // TODO: Make this a validation failure, not an exception
                            throw new IllegalStateException(msg);
                        }
                        mdb.setMessagingType(interfaces.get(0).getName());
                    }
                }

                buildAnnotatedRefs(bean, annotationFinder, classLoader);

View Full Code Here

        // Setup the descriptor information

        WidgetBean.lifecycle.clear();

        EjbJar ejbJar = new EjbJar();
        ejbJar.addEnterpriseBean(new MessageDrivenBean(WidgetBean.class));

        assembler.createApplication(config.configureApplication(ejbJar));

        InitialContext initialContext = new InitialContext();
View Full Code Here

        MessageListener listener = messageAdapter.addMessageListener(new MessageListener(Job.class, JobSpec.class));
        listener.getActivationSpec().addRequiredConfigProperty("cronExpression");
        app.getConnectorModules().add(new ConnectorModule(connector));

        EjbJar ejbJar = new EjbJar();
        ejbJar.addEnterpriseBean(new MessageDrivenBean(CronBean.class));
        app.getEjbModules().add(new EjbModule(ejbJar));

        AppInfo appInfo = config.configureApplication(app);
        assembler.createApplication(appInfo);
View Full Code Here

        MessageListener listener = messageAdapter.addMessageListener(new MessageListener(EmailConsumer.class, EmailAccountInfo.class));
        listener.getActivationSpec().addRequiredConfigProperty("address");
        app.getConnectorModules().add(new ConnectorModule(connector));

        EjbJar ejbJar = new EjbJar();
        ejbJar.addEnterpriseBean(new MessageDrivenBean(EmailBean.class));
        app.getEjbModules().add(new EjbModule(ejbJar));

        AppInfo appInfo = config.configureApplication(app);
        assembler.createApplication(appInfo);
View Full Code Here

     */
    public void testOverrideActivationConfigProperty() throws OpenEJBException {

        // set overrides for destinationType and check
        System.setProperty("ENTERPRISEBEAN.mdb.activation.destinationType", "testString");
        MessageDrivenBean mdb = new MdbBuilder().anMdb().withActivationProperty("destinationType", "stringToBeOverriden").build();
        ActivationConfigPropertyOverride activationPropertyOverride = new ActivationConfigPropertyOverride();
        AppModule appModule = new AppModuleBuilder().anAppModule().withAnMdb(mdb).build();
        activationPropertyOverride.deploy(appModule);

        assertTrue(containsActivationKeyValuePair(mdb, "destinationType", "testString"));
        assertTrue(mdb.getActivationConfig().getActivationConfigProperty().size() == 1);
    }
View Full Code Here

    public void testAddActivationConfigPropertyIfNotAlreadyPresent() throws OpenEJBException {

        // set overrides
        System.setProperty("ENTERPRISEBEAN.mdb.activation.destinationType", "testString");
        // deploy with an mdb that has no "destinationType" activationConfigProp
        MessageDrivenBean mdb = new MdbBuilder().anMdb().build();
        AppModule appModule = new AppModuleBuilder().anAppModule().withAnMdb(mdb).build();
        ActivationConfigPropertyOverride activationPropertyOverride = new ActivationConfigPropertyOverride();
        activationPropertyOverride.deploy(appModule);

        assertTrue(containsActivationKeyValuePair(mdb, "destinationType", "testString"));
        assertTrue(mdb.getActivationConfig().getActivationConfigProperty().size() == 1);
    }
View Full Code Here

    public void testNoOverrideSetShouldNotOverride() throws OpenEJBException {

        System.clearProperty("ENTERPRISEBEAN.mdb.activation.destinationType");

        MessageDrivenBean mdb = new MdbBuilder().anMdb().withActivationProperty("destinationType", "shouldNotBeOverriddenString").build();
        AppModule appModule = new AppModuleBuilder().anAppModule().withAnMdb(mdb).build();
        ActivationConfigPropertyOverride activationPropertyOverride = new ActivationConfigPropertyOverride();
        activationPropertyOverride.deploy(appModule);

        assertTrue(containsActivationKeyValuePair(mdb, "destinationType", "shouldNotBeOverriddenString"));
View Full Code Here

            EjbInfo ejbInfo = null;
            if (bean instanceof SessionBean) {
                SessionBean sbean = (SessionBean)bean;
                ejbInfo = createEjbInfo(sbean, classLoader);
            } else if (bean instanceof MessageDrivenBean) {
                MessageDrivenBean mdbean = (MessageDrivenBean)bean;
                ejbInfo = createEjbInfo(mdbean, classLoader);
            } else {
                continue;
            }
            if (ejbInfo != null) {
View Full Code Here

    context.checking(new Expectations(){{
      one(facade).addClassAnnotation("test.MessageDrivenBean1", MessageDriven.class, createNameValuePair("name", "Test")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    }});

    EjbJar ejbJar = new EjbJar();
    MessageDrivenBean bean = new MessageDrivenBean();
    bean.setEjbName("Test"); //$NON-NLS-1$
    bean.setEjbClass("test.MessageDrivenBean1"); //$NON-NLS-1$
   
    ejbJar.addEnterpriseBean(bean);
   
   
    // execute
View Full Code Here

TOP

Related Classes of org.apache.openejb.jee.MessageDrivenBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.