Search in sources :

Example 1 with MessageListener$JAXB.writeMessageListener

use of org.apache.openejb.jee.MessageListener$JAXB.writeMessageListener 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 2 with MessageListener$JAXB.writeMessageListener

use of org.apache.openejb.jee.MessageListener$JAXB.writeMessageListener in project tomee by apache.

the class MessageAdapter$JAXB method _write.

public static final void _write(final XoXMLStreamWriter writer, final MessageAdapter messageAdapter, RuntimeContext context) throws Exception {
    if (messageAdapter == null) {
        writer.writeXsiNil();
        return;
    }
    if (context == null) {
        context = new RuntimeContext();
    }
    if (MessageAdapter.class != messageAdapter.getClass()) {
        context.unexpectedSubclass(writer, messageAdapter, MessageAdapter.class);
        return;
    }
    context.beforeMarshal(messageAdapter, LifecycleCallback.NONE);
    // ATTRIBUTE: id
    final String idRaw = messageAdapter.id;
    if (idRaw != null) {
        String id = null;
        try {
            id = Adapters.collapsedStringAdapterAdapter.marshal(idRaw);
        } catch (final Exception e) {
            context.xmlAdapterError(messageAdapter, "id", CollapsedStringAdapter.class, String.class, String.class, e);
        }
        writer.writeAttribute("", "", "id", id);
    }
    // ELEMENT: messageListener
    final List<MessageListener> messageListener = messageAdapter.messageListener;
    if (messageListener != null) {
        for (final MessageListener messageListenerItem : messageListener) {
            if (messageListenerItem != null) {
                writer.writeStartElementWithAutoPrefix("http://java.sun.com/xml/ns/javaee", "messagelistener");
                writeMessageListener(writer, messageListenerItem, context);
                writer.writeEndElement();
            } else {
                context.unexpectedNullValue(messageAdapter, "messageListener");
            }
        }
    }
    context.afterMarshal(messageAdapter, LifecycleCallback.NONE);
}
Also used : CollapsedStringAdapter(javax.xml.bind.annotation.adapters.CollapsedStringAdapter) MessageListener$JAXB.readMessageListener(org.apache.openejb.jee.MessageListener$JAXB.readMessageListener) MessageListener$JAXB.writeMessageListener(org.apache.openejb.jee.MessageListener$JAXB.writeMessageListener) RuntimeContext(org.metatype.sxc.jaxb.RuntimeContext)

Example 3 with MessageListener$JAXB.writeMessageListener

use of org.apache.openejb.jee.MessageListener$JAXB.writeMessageListener in project tomee by apache.

the class MessageAdapter$JAXB method _read.

public static final MessageAdapter _read(final XoXMLStreamReader reader, RuntimeContext context) throws Exception {
    // Check for xsi:nil
    if (reader.isXsiNil()) {
        return null;
    }
    if (context == null) {
        context = new RuntimeContext();
    }
    final MessageAdapter messageAdapter = new MessageAdapter();
    context.beforeUnmarshal(messageAdapter, LifecycleCallback.NONE);
    List<MessageListener> messageListener = null;
    // Check xsi:type
    final QName xsiType = reader.getXsiType();
    if (xsiType != null) {
        if (("messageadapterType" != xsiType.getLocalPart()) || ("http://java.sun.com/xml/ns/javaee" != xsiType.getNamespaceURI())) {
            return context.unexpectedXsiType(reader, MessageAdapter.class);
        }
    }
    // Read attributes
    for (final Attribute attribute : reader.getAttributes()) {
        if (("id" == attribute.getLocalName()) && (("" == attribute.getNamespace()) || (attribute.getNamespace() == null))) {
            // ATTRIBUTE: id
            final String id = Adapters.collapsedStringAdapterAdapter.unmarshal(attribute.getValue());
            context.addXmlId(reader, id, messageAdapter);
            messageAdapter.id = id;
        } else if (XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI != attribute.getNamespace()) {
            context.unexpectedAttribute(attribute, new QName("", "id"));
        }
    }
    // Read elements
    for (final XoXMLStreamReader elementReader : reader.getChildElements()) {
        if (("messagelistener" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: messageListener
            final MessageListener messageListenerItem = readMessageListener(elementReader, context);
            if (messageListener == null) {
                messageListener = messageAdapter.messageListener;
                if (messageListener != null) {
                    messageListener.clear();
                } else {
                    messageListener = new ArrayList<MessageListener>();
                }
            }
            messageListener.add(messageListenerItem);
        } else {
            context.unexpectedElement(elementReader, new QName("http://java.sun.com/xml/ns/javaee", "messagelistener"));
        }
    }
    if (messageListener != null) {
        messageAdapter.messageListener = messageListener;
    }
    context.afterUnmarshal(messageAdapter, LifecycleCallback.NONE);
    return messageAdapter;
}
Also used : Attribute(org.metatype.sxc.util.Attribute) QName(javax.xml.namespace.QName) MessageListener$JAXB.readMessageListener(org.apache.openejb.jee.MessageListener$JAXB.readMessageListener) MessageListener$JAXB.writeMessageListener(org.apache.openejb.jee.MessageListener$JAXB.writeMessageListener) RuntimeContext(org.metatype.sxc.jaxb.RuntimeContext) XoXMLStreamReader(org.metatype.sxc.util.XoXMLStreamReader)

Example 4 with MessageListener$JAXB.writeMessageListener

use of org.apache.openejb.jee.MessageListener$JAXB.writeMessageListener in project tomee by apache.

the class AppInfoBuilder method buildConnectorModules.

private void buildConnectorModules(final AppModule appModule, final AppInfo appInfo) throws OpenEJBException {
    final String appId = appModule.getModuleId();
    for (final ConnectorModule connectorModule : appModule.getConnectorModules()) {
        //
        // DEVELOPERS NOTE:  if you change the id generation code here, you must change
        // the id generation code in AutoConfig$AppResources
        //
        final Connector connector = connectorModule.getConnector();
        final ConnectorInfo connectorInfo = new ConnectorInfo();
        connectorInfo.description = connector.getDescription();
        connectorInfo.displayName = connector.getDisplayName();
        connectorInfo.path = connectorModule.getJarLocation();
        connectorInfo.moduleId = connectorModule.getModuleId();
        connectorInfo.watchedResources.addAll(connectorModule.getWatchedResources());
        connectorInfo.validationInfo = ValidatorBuilder.getInfo(connectorModule.getValidationConfig());
        connectorInfo.uniqueId = connectorModule.getUniqueId();
        connectorInfo.mbeans = connectorModule.getMbeans();
        final List<URL> libraries = connectorModule.getLibraries();
        for (final URL url : libraries) {
            final File file = toFile(url);
            try {
                connectorInfo.libs.add(file.getCanonicalPath());
            } catch (final IOException e) {
                throw new IllegalArgumentException("Invalid application lib path " + file.getAbsolutePath());
            }
        }
        final ResourceAdapter resourceAdapter = connector.getResourceAdapter();
        if (resourceAdapter.getResourceAdapterClass() != null) {
            final String id = this.getId(connectorModule);
            final String className = resourceAdapter.getResourceAdapterClass();
            final ServiceProvider provider = new ServiceProvider(className, id, "Resource");
            provider.getTypes().add(className);
            ServiceUtils.registerServiceProvider(appId, provider);
            final Resource resource = new Resource(id, className, appId + "#" + id);
            for (final ConfigProperty property : resourceAdapter.getConfigProperty()) {
                final String name = property.getConfigPropertyName();
                final String value = property.getConfigPropertyValue();
                if (value != null) {
                    resource.getProperties().setProperty(name, value);
                }
            }
            connectorInfo.resourceAdapter = this.configFactory.configureService(resource, ResourceInfo.class);
        }
        final OutboundResourceAdapter outbound = resourceAdapter.getOutboundResourceAdapter();
        if (outbound != null) {
            String transactionSupport = "none";
            final TransactionSupportType transactionSupportType = outbound.getTransactionSupport();
            if (transactionSupportType != null) {
                switch(transactionSupportType) {
                    case LOCAL_TRANSACTION:
                        transactionSupport = "local";
                        break;
                    case NO_TRANSACTION:
                        transactionSupport = "none";
                        break;
                    case XA_TRANSACTION:
                        transactionSupport = "xa";
                        break;
                }
            }
            for (final ConnectionDefinition connection : outbound.getConnectionDefinition()) {
                final String id = this.getId(connection, outbound, connectorModule);
                final String className = connection.getManagedConnectionFactoryClass();
                final String type = connection.getConnectionFactoryInterface();
                final ServiceProvider provider = new ServiceProvider(className, id, "Resource");
                provider.getTypes().add(type);
                ServiceUtils.registerServiceProvider(appId, provider);
                final Resource resource = new Resource(id, type, appId + "#" + id);
                final Properties properties = resource.getProperties();
                for (final ConfigProperty property : connection.getConfigProperty()) {
                    final String name = property.getConfigPropertyName();
                    final String value = property.getConfigPropertyValue();
                    if (value != null) {
                        properties.setProperty(name, value);
                    }
                }
                properties.setProperty("TransactionSupport", transactionSupport);
                if (connectorInfo.resourceAdapter != null) {
                    properties.setProperty("ResourceAdapter", connectorInfo.resourceAdapter.id);
                }
                final ResourceInfo resourceInfo = this.configFactory.configureService(resource, ResourceInfo.class);
                connectorInfo.outbound.add(resourceInfo);
            }
        }
        final InboundResourceadapter inbound = resourceAdapter.getInboundResourceAdapter();
        if (inbound != null) {
            for (final MessageListener messageListener : inbound.getMessageAdapter().getMessageListener()) {
                final String id = this.getId(messageListener, inbound, connectorModule);
                final Container container = new Container(id, "MESSAGE", null);
                final Properties properties = container.getProperties();
                properties.setProperty("ResourceAdapter", connectorInfo.resourceAdapter.id);
                properties.setProperty("MessageListenerInterface", messageListener.getMessageListenerType());
                properties.setProperty("ActivationSpecClass", messageListener.getActivationSpec().getActivationSpecClass());
                final MdbContainerInfo mdbContainerInfo = this.configFactory.configureService(container, MdbContainerInfo.class);
                connectorInfo.inbound.add(mdbContainerInfo);
            }
        }
        for (final AdminObject adminObject : resourceAdapter.getAdminObject()) {
            final String id = this.getId(adminObject, resourceAdapter, connectorModule);
            final String className = adminObject.getAdminObjectClass();
            final String type = adminObject.getAdminObjectInterface();
            final ServiceProvider provider = new ServiceProvider(className, id, "Resource");
            provider.getTypes().add(type);
            ServiceUtils.registerServiceProvider(appId, provider);
            final Resource resource = new Resource(id, type, appId + "#" + id);
            final Properties properties = resource.getProperties();
            for (final ConfigProperty property : adminObject.getConfigProperty()) {
                final String name = property.getConfigPropertyName();
                final String value = property.getConfigPropertyValue();
                if (value != null) {
                    properties.setProperty(name, value);
                }
            }
            final ResourceInfo resourceInfo = this.configFactory.configureService(resource, ResourceInfo.class);
            connectorInfo.adminObject.add(resourceInfo);
        }
        appInfo.connectors.add(connectorInfo);
    }
}
Also used : Connector(org.apache.openejb.jee.Connector) ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) ConnectionDefinition(org.apache.openejb.jee.ConnectionDefinition) ConnectorInfo(org.apache.openejb.assembler.classic.ConnectorInfo) TransactionSupportType(org.apache.openejb.jee.TransactionSupportType) Resource(org.apache.openejb.config.sys.Resource) MessageListener(org.apache.openejb.jee.MessageListener) IOException(java.io.IOException) Properties(java.util.Properties) URL(java.net.URL) Container(org.apache.openejb.config.sys.Container) ServiceProvider(org.apache.openejb.config.sys.ServiceProvider) ConfigProperty(org.apache.openejb.jee.ConfigProperty) MdbContainerInfo(org.apache.openejb.assembler.classic.MdbContainerInfo) OutboundResourceAdapter(org.apache.openejb.jee.OutboundResourceAdapter) ResourceAdapter(org.apache.openejb.jee.ResourceAdapter) InboundResourceadapter(org.apache.openejb.jee.InboundResourceadapter) URLs.toFile(org.apache.openejb.util.URLs.toFile) File(java.io.File) OutboundResourceAdapter(org.apache.openejb.jee.OutboundResourceAdapter) AdminObject(org.apache.openejb.jee.AdminObject)

Example 5 with MessageListener$JAXB.writeMessageListener

use of org.apache.openejb.jee.MessageListener$JAXB.writeMessageListener in project tomee by apache.

the class CustomMdbContainerTest 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
    EmailBean.lifecycle.clear();
    final AppModule app = new AppModule(this.getClass().getClassLoader(), "testapp");
    final Connector connector = new Connector("email-ra");
    final ResourceAdapter adapter = new ResourceAdapter(EmailResourceAdapter.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(EmailConsumer.class, EmailAccountInfo.class));
    listener.getActivationSpec().addRequiredConfigProperty("address");
    app.getConnectorModules().add(new ConnectorModule(connector));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new MessageDrivenBean(EmailBean.class));
    app.getEjbModules().add(new EjbModule(ejbJar));
    final AppInfo appInfo = config.configureApplication(app);
    assembler.createApplication(appInfo);
    final InitialContext initialContext = new InitialContext();
    final EmailResourceAdapter ra = (EmailResourceAdapter) initialContext.lookup("java:openejb/Resource/email-raRA");
    final Properties headers = new Properties();
    headers.put("To", "dblevins@apache.org");
    headers.put("From", "dblevins@visi.com");
    headers.put("Subject", "Hello");
    ra.deliverEmail(headers, "How's it going?");
    final Stack<Lifecycle> lifecycle = EmailBean.lifecycle;
    final List expected = Arrays.asList(Lifecycle.values());
    Assert.assertEquals(Join.join("\n", expected), Join.join("\n", lifecycle));
}
Also used : Connector(org.apache.openejb.jee.Connector) 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) Properties(java.util.Properties) ConnectorModule(org.apache.openejb.config.ConnectorModule) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) ResourceAdapter(org.apache.openejb.jee.ResourceAdapter) List(java.util.List) InboundResourceadapter(org.apache.openejb.jee.InboundResourceadapter) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar) MessageAdapter(org.apache.openejb.jee.MessageAdapter) InitialContext(javax.naming.InitialContext) AppInfo(org.apache.openejb.assembler.classic.AppInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) Assembler(org.apache.openejb.assembler.classic.Assembler)

Aggregations

Connector (org.apache.openejb.jee.Connector)3 InboundResourceadapter (org.apache.openejb.jee.InboundResourceadapter)3 MessageListener (org.apache.openejb.jee.MessageListener)3 ResourceAdapter (org.apache.openejb.jee.ResourceAdapter)3 List (java.util.List)2 Properties (java.util.Properties)2 AppInfo (org.apache.openejb.assembler.classic.AppInfo)2 Assembler (org.apache.openejb.assembler.classic.Assembler)2 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)2 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)2 AppModule (org.apache.openejb.config.AppModule)2 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)2 ConnectorModule (org.apache.openejb.config.ConnectorModule)2 EjbModule (org.apache.openejb.config.EjbModule)2 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)2 EjbJar (org.apache.openejb.jee.EjbJar)2 MessageAdapter (org.apache.openejb.jee.MessageAdapter)2 MessageDrivenBean (org.apache.openejb.jee.MessageDrivenBean)2 MessageListener$JAXB.readMessageListener (org.apache.openejb.jee.MessageListener$JAXB.readMessageListener)2 MessageListener$JAXB.writeMessageListener (org.apache.openejb.jee.MessageListener$JAXB.writeMessageListener)2