Search in sources :

Example 1 with MessageAdapter$JAXB.writeMessageAdapter

use of org.apache.openejb.jee.MessageAdapter$JAXB.writeMessageAdapter 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 MessageAdapter$JAXB.writeMessageAdapter

use of org.apache.openejb.jee.MessageAdapter$JAXB.writeMessageAdapter in project tomee by apache.

the class InboundResourceadapter$JAXB method _read.

public static final InboundResourceadapter _read(final XoXMLStreamReader reader, RuntimeContext context) throws Exception {
    // Check for xsi:nil
    if (reader.isXsiNil()) {
        return null;
    }
    if (context == null) {
        context = new RuntimeContext();
    }
    final InboundResourceadapter inboundResourceadapter = new InboundResourceadapter();
    context.beforeUnmarshal(inboundResourceadapter, LifecycleCallback.NONE);
    // Check xsi:type
    final QName xsiType = reader.getXsiType();
    if (xsiType != null) {
        if (("inbound-resourceadapterType" != xsiType.getLocalPart()) || ("http://java.sun.com/xml/ns/javaee" != xsiType.getNamespaceURI())) {
            return context.unexpectedXsiType(reader, InboundResourceadapter.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, inboundResourceadapter);
            inboundResourceadapter.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 (("messageadapter" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: messageAdapter
            final MessageAdapter messageAdapter = readMessageAdapter(elementReader, context);
            inboundResourceadapter.messageAdapter = messageAdapter;
        } else {
            context.unexpectedElement(elementReader, new QName("http://java.sun.com/xml/ns/javaee", "messageadapter"));
        }
    }
    context.afterUnmarshal(inboundResourceadapter, LifecycleCallback.NONE);
    return inboundResourceadapter;
}
Also used : MessageAdapter$JAXB.readMessageAdapter(org.apache.openejb.jee.MessageAdapter$JAXB.readMessageAdapter) MessageAdapter$JAXB.writeMessageAdapter(org.apache.openejb.jee.MessageAdapter$JAXB.writeMessageAdapter) Attribute(org.metatype.sxc.util.Attribute) QName(javax.xml.namespace.QName) RuntimeContext(org.metatype.sxc.jaxb.RuntimeContext) XoXMLStreamReader(org.metatype.sxc.util.XoXMLStreamReader)

Example 3 with MessageAdapter$JAXB.writeMessageAdapter

use of org.apache.openejb.jee.MessageAdapter$JAXB.writeMessageAdapter in project tomee by apache.

the class InboundResourceadapter$JAXB method _write.

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

Example 4 with MessageAdapter$JAXB.writeMessageAdapter

use of org.apache.openejb.jee.MessageAdapter$JAXB.writeMessageAdapter 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

List (java.util.List)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 Connector (org.apache.openejb.jee.Connector)2 EjbJar (org.apache.openejb.jee.EjbJar)2 InboundResourceadapter (org.apache.openejb.jee.InboundResourceadapter)2 MessageAdapter (org.apache.openejb.jee.MessageAdapter)2 MessageAdapter$JAXB.readMessageAdapter (org.apache.openejb.jee.MessageAdapter$JAXB.readMessageAdapter)2 MessageAdapter$JAXB.writeMessageAdapter (org.apache.openejb.jee.MessageAdapter$JAXB.writeMessageAdapter)2 MessageDrivenBean (org.apache.openejb.jee.MessageDrivenBean)2 MessageListener (org.apache.openejb.jee.MessageListener)2 ResourceAdapter (org.apache.openejb.jee.ResourceAdapter)2 RuntimeContext (org.metatype.sxc.jaxb.RuntimeContext)2