use of org.apache.openejb.jee.MessageDrivenBean$JAXB.readMessageDrivenBean 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;
}
use of org.apache.openejb.jee.MessageDrivenBean$JAXB.readMessageDrivenBean in project tomee by apache.
the class EjbJar$JAXB method _write.
public static final void _write(final XoXMLStreamWriter writer, final EjbJar ejbJar, RuntimeContext context) throws Exception {
if (ejbJar == null) {
writer.writeXsiNil();
return;
}
if (context == null) {
context = new RuntimeContext();
}
final String prefix = writer.getUniquePrefix("http://java.sun.com/xml/ns/javaee");
if (EjbJar.class != ejbJar.getClass()) {
context.unexpectedSubclass(writer, ejbJar, EjbJar.class);
return;
}
context.beforeMarshal(ejbJar, LifecycleCallback.NONE);
// ATTRIBUTE: id
final String idRaw = ejbJar.id;
if (idRaw != null) {
String id = null;
try {
id = Adapters.collapsedStringAdapterAdapter.marshal(idRaw);
} catch (final Exception e) {
context.xmlAdapterError(ejbJar, "id", CollapsedStringAdapter.class, String.class, String.class, e);
}
writer.writeAttribute("", "", "id", id);
}
// ATTRIBUTE: metadataComplete
final Boolean metadataComplete = ejbJar.metadataComplete;
if (metadataComplete != null) {
writer.writeAttribute("", "", "metadata-complete", Boolean.toString(metadataComplete));
}
// ATTRIBUTE: version
final String versionRaw = ejbJar.version;
if (versionRaw != null) {
String version = null;
try {
version = Adapters.collapsedStringAdapterAdapter.marshal(versionRaw);
} catch (final Exception e) {
context.xmlAdapterError(ejbJar, "version", CollapsedStringAdapter.class, String.class, String.class, e);
}
writer.writeAttribute("", "", "version", version);
}
// ELEMENT: moduleName
final String moduleNameRaw = ejbJar.moduleName;
String moduleName = null;
try {
moduleName = Adapters.collapsedStringAdapterAdapter.marshal(moduleNameRaw);
} catch (final Exception e) {
context.xmlAdapterError(ejbJar, "moduleName", CollapsedStringAdapter.class, String.class, String.class, e);
}
if (moduleName != null) {
writer.writeStartElement(prefix, "module-name", "http://java.sun.com/xml/ns/javaee");
writer.writeCharacters(moduleName);
writer.writeEndElement();
}
// ELEMENT: descriptions
Text[] descriptions = null;
try {
descriptions = ejbJar.getDescriptions();
} catch (final Exception e) {
context.getterError(ejbJar, "descriptions", EjbJar.class, "getDescriptions", e);
}
if (descriptions != null) {
for (final Text descriptionsItem : descriptions) {
if (descriptionsItem != null) {
writer.writeStartElement(prefix, "description", "http://java.sun.com/xml/ns/javaee");
writeText(writer, descriptionsItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(ejbJar, "descriptions");
}
}
}
// ELEMENT: displayNames
Text[] displayNames = null;
try {
displayNames = ejbJar.getDisplayNames();
} catch (final Exception e) {
context.getterError(ejbJar, "displayNames", EjbJar.class, "getDisplayNames", e);
}
if (displayNames != null) {
for (final Text displayNamesItem : displayNames) {
if (displayNamesItem != null) {
writer.writeStartElement(prefix, "display-name", "http://java.sun.com/xml/ns/javaee");
writeText(writer, displayNamesItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(ejbJar, "displayNames");
}
}
}
// ELEMENT: icon
final LocalCollection<Icon> icon = ejbJar.icon;
if (icon != null) {
for (final Icon iconItem : icon) {
if (iconItem != null) {
writer.writeStartElement(prefix, "icon", "http://java.sun.com/xml/ns/javaee");
writeIcon(writer, iconItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(ejbJar, "icon");
}
}
}
// ELEMENT: enterpriseBeans
EnterpriseBean[] enterpriseBeans = null;
try {
enterpriseBeans = ejbJar.getEnterpriseBeans();
} catch (final Exception e) {
context.getterError(ejbJar, "enterpriseBeans", EjbJar.class, "getEnterpriseBeans", e);
}
writer.writeStartElement(prefix, "enterprise-beans", "http://java.sun.com/xml/ns/javaee");
if (enterpriseBeans != null) {
for (final EnterpriseBean enterpriseBeansItem : enterpriseBeans) {
if (enterpriseBeansItem instanceof org.apache.openejb.jee.EntityBean) {
final org.apache.openejb.jee.EntityBean EntityBean = ((org.apache.openejb.jee.EntityBean) enterpriseBeansItem);
writer.writeStartElement(prefix, "entity", "http://java.sun.com/xml/ns/javaee");
writeEntityBean(writer, EntityBean, context);
writer.writeEndElement();
} else if (enterpriseBeansItem instanceof org.apache.openejb.jee.SessionBean) {
final org.apache.openejb.jee.SessionBean SessionBean = ((org.apache.openejb.jee.SessionBean) enterpriseBeansItem);
writer.writeStartElement(prefix, "session", "http://java.sun.com/xml/ns/javaee");
writeSessionBean(writer, SessionBean, context);
writer.writeEndElement();
} else if (enterpriseBeansItem instanceof org.apache.openejb.jee.MessageDrivenBean) {
final org.apache.openejb.jee.MessageDrivenBean MessageDrivenBean = ((org.apache.openejb.jee.MessageDrivenBean) enterpriseBeansItem);
writer.writeStartElement(prefix, "message-driven", "http://java.sun.com/xml/ns/javaee");
writeMessageDrivenBean(writer, MessageDrivenBean, context);
writer.writeEndElement();
} else if (enterpriseBeansItem == null) {
context.unexpectedNullValue(ejbJar, "enterpriseBeans");
} else {
context.unexpectedElementType(writer, ejbJar, "enterpriseBeans", enterpriseBeansItem, org.apache.openejb.jee.EntityBean.class, org.apache.openejb.jee.SessionBean.class, org.apache.openejb.jee.MessageDrivenBean.class);
}
}
}
writer.writeEndElement();
// ELEMENT: interceptors
final Interceptors interceptors = ejbJar.interceptors;
if (interceptors != null) {
writer.writeStartElement(prefix, "interceptors", "http://java.sun.com/xml/ns/javaee");
writeInterceptors(writer, interceptors, context);
writer.writeEndElement();
}
// ELEMENT: relationships
final Relationships relationships = ejbJar.relationships;
if (relationships != null) {
writer.writeStartElement(prefix, "relationships", "http://java.sun.com/xml/ns/javaee");
writeRelationships(writer, relationships, context);
writer.writeEndElement();
}
// ELEMENT: assemblyDescriptor
final AssemblyDescriptor assemblyDescriptor = ejbJar.assemblyDescriptor;
if (assemblyDescriptor != null) {
writer.writeStartElement(prefix, "assembly-descriptor", "http://java.sun.com/xml/ns/javaee");
writeAssemblyDescriptor(writer, assemblyDescriptor, context);
writer.writeEndElement();
}
// ELEMENT: ejbClientJar
final String ejbClientJarRaw = ejbJar.ejbClientJar;
String ejbClientJar = null;
try {
ejbClientJar = Adapters.collapsedStringAdapterAdapter.marshal(ejbClientJarRaw);
} catch (final Exception e) {
context.xmlAdapterError(ejbJar, "ejbClientJar", CollapsedStringAdapter.class, String.class, String.class, e);
}
if (ejbClientJar != null) {
writer.writeStartElement(prefix, "ejb-client-jar", "http://java.sun.com/xml/ns/javaee");
writer.writeCharacters(ejbClientJar);
writer.writeEndElement();
}
context.afterMarshal(ejbJar, LifecycleCallback.NONE);
}
use of org.apache.openejb.jee.MessageDrivenBean$JAXB.readMessageDrivenBean in project tomee by apache.
the class MdbBuilder 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);
return bean;
}
use of org.apache.openejb.jee.MessageDrivenBean$JAXB.readMessageDrivenBean 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));
}
use of org.apache.openejb.jee.MessageDrivenBean$JAXB.readMessageDrivenBean in project tomee by apache.
the class JmsMdbContainerTest 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();
// define props for RA in order to change the default activeMQ port
final Properties props = new Properties();
final String brokerAddress = NetworkUtil.getLocalAddress("tcp://", "");
final String brokerXmlConfig = "broker:(" + brokerAddress + ")?useJmx=false";
props.put("BrokerXmlConfig", brokerXmlConfig);
props.put("StartupTimeout", 10000);
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
assembler.createResource(config.configureService(ResourceInfo.class, "Default Unmanaged JDBC Database", new Properties(), "Default Unmanaged JDBC Database", "DataSource"));
assembler.createResource(config.configureService(ResourceInfo.class, "Default JMS Resource Adapter", props, "Default JMS Resource Adapter", "ActiveMQResourceAdapter"));
// Setup the descriptor information
WidgetBean.lifecycle.clear();
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new MessageDrivenBean(WidgetBean.class));
assembler.createApplication(config.configureApplication(ejbJar));
final InitialContext initialContext = new InitialContext();
final ConnectionFactory connectionFactory = (ConnectionFactory) initialContext.lookup("java:openejb/Resource/Default JMS Connection Factory");
sendMessage(connectionFactory, "WidgetBean", "test");
final Stack<Lifecycle> lifecycle = WidgetBean.lifecycle;
final List expected = Arrays.asList(Lifecycle.values());
assertEquals(join("\n", expected), join("\n", lifecycle));
}
Aggregations