use of org.apache.openejb.assembler.classic.EjbJarInfo in project tomee by apache.
the class UberInterfaceTest method test.
public void test() throws Exception {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final EjbJar ejbJar = new EjbJar();
final StatelessBean bean = ejbJar.addEnterpriseBean(new StatelessBean(SuperBean.class));
final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
final EnterpriseBeanInfo beanInfo = ejbJarInfo.enterpriseBeans.get(0);
assertEquals(asList(Everything.class.getName()), beanInfo.businessLocal);
assertEquals(asList(Everything.class.getName()), beanInfo.businessRemote);
assertEquals(Everything.class.getName(), beanInfo.serviceEndpoint);
assembler.createApplication(ejbJarInfo);
final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
final BeanContext deployment = containerSystem.getBeanContext(beanInfo.ejbDeploymentId);
assertEquals(asList(Everything.class), deployment.getBusinessLocalInterfaces());
assertEquals(asList(Everything.class), deployment.getBusinessRemoteInterfaces());
assertEquals(Everything.class, deployment.getServiceEndpointInterface());
final InitialContext context = new InitialContext();
final Everything local = (Everything) context.lookup("SuperBeanLocal");
final Everything remote = (Everything) context.lookup("SuperBeanRemote");
final Reference reference = new Reference("test");
assertEquals(reference, local.echo(reference));
// pass by reference
assertSame(reference, local.echo(reference));
assertEquals(reference, remote.echo(reference));
// pass by value
assertNotSame(reference, remote.echo(reference));
}
use of org.apache.openejb.assembler.classic.EjbJarInfo in project tomee by apache.
the class XmlOverridesTest method test.
public void test() throws Exception {
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final EjbJar ejbJar = new EjbJar();
final StatefulBean bean = ejbJar.addEnterpriseBean(new StatefulBean(AnnotatedBean.class));
bean.getEjbLocalRef().add(new EjbLocalRef(name("annotatedLocal"), "BarBean"));
bean.getEnvEntry().add(new EnvEntry(name("striing"), "java.lang.Integer", "2"));
bean.getEnvEntry().add(new EnvEntry(name("doouble"), "java.lang.String", "two"));
bean.getEnvEntry().add(new EnvEntry(name("loong"), "java.lang.String", "three"));
bean.getEnvEntry().add(new EnvEntry(name("flooat"), "java.lang.String", "four"));
bean.getEnvEntry().add(new EnvEntry(name("inteeger"), "java.lang.String", "five"));
bean.getEnvEntry().add(new EnvEntry(name("shoort"), "java.lang.String", "six"));
bean.getEnvEntry().add(new EnvEntry(name("booolean"), "java.lang.String", "seven"));
bean.getEnvEntry().add(new EnvEntry(name("byyte"), "java.lang.String", "eight"));
bean.getEnvEntry().add(new EnvEntry(name("chaaracter"), "java.lang.String", "nine"));
final EnvEntry lookupEntry = new EnvEntry(name("lookup"), "java.lang.String", null);
lookupEntry.setLookupName("java:app/AppName");
bean.getEnvEntry().add(lookupEntry);
bean.getResourceRef().add(new ResourceRef(name("daataSource"), DataSource.class.getName(), ResAuth.CONTAINER, ResSharingScope.SHAREABLE));
bean.getPersistenceUnitRef().add(new PersistenceUnitRef(name("emf"), "yellow"));
bean.getPersistenceContextRef().add(new PersistenceContextRef(name("em"), "yellow", PersistenceContextType.TRANSACTION, new ArrayList(Arrays.asList(new Property("zzzz", "AAAA")))));
final org.apache.openejb.jee.jpa.unit.PersistenceUnit persistenceUnit = new org.apache.openejb.jee.jpa.unit.PersistenceUnit("yellow");
final AppModule app = new AppModule(this.getClass().getClassLoader(), "app");
app.getEjbModules().add(new EjbModule(ejbJar));
app.addPersistenceModule(new PersistenceModule("root", new Persistence(persistenceUnit)));
final AppInfo appInfo = config.configureApplication(app);
final EjbJarInfo ejbJarInfo = appInfo.ejbJars.get(0);
final EnterpriseBeanInfo beanInfo = ejbJarInfo.enterpriseBeans.get(0);
final JndiEncInfo enc = beanInfo.jndiEnc;
assertEquals("Enc.ejbLocalReferences.size()", 1, enc.ejbLocalReferences.size());
assertEquals("Enc.ejbLocalReferences.get(0).link", "BarBean", enc.ejbLocalReferences.get(0).link);
assertEquals("Enc.ejbReferences.size()", 0, enc.ejbReferences.size());
// 10 + ComponentName
assertEquals("Enc.envEntries.size()", 11, enc.envEntries.size());
final Map<String, EnvEntryInfo> entries = map(enc.envEntries);
assertEnvEntry(entries, name("striing"), "java.lang.Integer", "2");
assertEnvEntry(entries, name("doouble"), "java.lang.String", "two");
assertEnvEntry(entries, name("loong"), "java.lang.String", "three");
assertEnvEntry(entries, name("flooat"), "java.lang.String", "four");
assertEnvEntry(entries, name("inteeger"), "java.lang.String", "five");
assertEnvEntry(entries, name("shoort"), "java.lang.String", "six");
assertEnvEntry(entries, name("booolean"), "java.lang.String", "seven");
assertEnvEntry(entries, name("byyte"), "java.lang.String", "eight");
assertEnvEntry(entries, name("chaaracter"), "java.lang.String", "nine");
assertEnvEntryLookup(entries, name("lookup"), "java.lang.String", "java:app/AppName");
assertEquals("Enc.persistenceContextRefs.size()", 1, enc.persistenceContextRefs.size());
final PersistenceContextReferenceInfo context = enc.persistenceContextRefs.get(0);
assertEquals("Context.extended", false, context.extended);
assertEquals("Context.persistenceUnitName", "yellow", context.persistenceUnitName);
assertEquals("Context.properties.size()", 1, context.properties.size());
assertEquals("Context.properties.getProperty(\"zzzz\")", "AAAA", context.properties.getProperty("zzzz"));
assertEquals("Enc.persistenceUnitRefs.size()", 1, enc.persistenceUnitRefs.size());
final PersistenceUnitReferenceInfo unit = enc.persistenceUnitRefs.get(0);
assertEquals("Unit.persistenceUnitName", "yellow", unit.persistenceUnitName);
assertEquals("Enc.resourceRefs.size()", 1, enc.resourceRefs.size());
final ResourceReferenceInfo resource = enc.resourceRefs.get(0);
assertEquals("Resource.referenceAuth", "CONTAINER", resource.referenceAuth);
}
use of org.apache.openejb.assembler.classic.EjbJarInfo in project tomee by apache.
the class StatelessInterceptorTest method setUp.
public void setUp() throws Exception {
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
assembler.createContainer(config.configureService(StatelessSessionContainerInfo.class));
final EjbJarInfo ejbJar = config.configureApplication(buildTestApp());
assertNotNull(ejbJar);
assembler.createApplication(ejbJar);
final Properties properties = new Properties(System.getProperties());
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
ctx = new InitialContext(properties);
}
use of org.apache.openejb.assembler.classic.EjbJarInfo in project tomee by apache.
the class CdiScanner method init.
@Override
public void init(final Object object) {
if (!StartupObject.class.isInstance(object)) {
return;
}
containerLoader = ParentClassLoaderFinder.Helper.get();
final StartupObject startupObject = StartupObject.class.cast(object);
final AppInfo appInfo = startupObject.getAppInfo();
final ClassLoader classLoader = startupObject.getClassLoader();
final ClassLoaderComparator comparator;
if (classLoader instanceof ClassLoaderComparator) {
comparator = (ClassLoaderComparator) classLoader;
} else {
comparator = new DefaultClassLoaderComparator(classLoader);
}
final WebBeansContext webBeansContext = startupObject.getWebBeansContext();
final InterceptorsManager interceptorsManager = webBeansContext.getInterceptorsManager();
// app beans
for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
final BeansInfo beans = ejbJar.beans;
if (beans == null || "false".equalsIgnoreCase(ejbJar.properties.getProperty("openejb.cdi.activated"))) {
continue;
}
if (startupObject.isFromWebApp()) {
// deploy only the related ejbmodule
if (!ejbJar.moduleId.equals(startupObject.getWebContext().getId())) {
continue;
}
} else if (ejbJar.webapp && !appInfo.webAppAlone) {
continue;
}
if (appInfo.webAppAlone || !ejbJar.webapp) {
// "manual" extension to avoid to add it through SPI mecanism
classes.addAll(asList(TRANSACTIONAL_INTERCEPTORS));
for (final Class<?> interceptor : TRANSACTIONAL_INTERCEPTORS) {
interceptorsManager.addEnabledInterceptorClass(interceptor);
}
}
// here for ears we need to skip classes in the parent classloader
final ClassLoader scl = ClassLoader.getSystemClassLoader();
final boolean filterByClassLoader = "true".equals(ejbJar.properties.getProperty(OPENEJB_CDI_FILTER_CLASSLOADER, SystemInstance.get().getProperty(OPENEJB_CDI_FILTER_CLASSLOADER, "true")));
final BeanArchiveService beanArchiveService = webBeansContext.getBeanArchiveService();
final boolean openejb = OpenEJBBeanInfoService.class.isInstance(beanArchiveService);
final Map<BeansInfo.BDAInfo, BeanArchiveService.BeanArchiveInformation> infoByBda = new HashMap<>();
for (final BeansInfo.BDAInfo bda : beans.bdas) {
if (bda.uri != null) {
try {
beansXml.add(bda.uri.toURL());
} catch (final MalformedURLException e) {
// no-op
}
}
infoByBda.put(bda, handleBda(startupObject, classLoader, comparator, beans, scl, filterByClassLoader, beanArchiveService, openejb, bda));
}
for (final BeansInfo.BDAInfo bda : beans.noDescriptorBdas) {
// infoByBda.put() not needed since we know it means annotated
handleBda(startupObject, classLoader, comparator, beans, scl, filterByClassLoader, beanArchiveService, openejb, bda);
}
if (startupObject.getBeanContexts() != null) {
for (final BeanContext bc : startupObject.getBeanContexts()) {
final String name = bc.getBeanClass().getName();
if (BeanContext.Comp.class.getName().equals(name)) {
continue;
}
boolean cdi = false;
for (final BeansInfo.BDAInfo bda : beans.bdas) {
final BeanArchiveService.BeanArchiveInformation info = infoByBda.get(bda);
if (info.getBeanDiscoveryMode() == BeanArchiveService.BeanDiscoveryMode.NONE) {
continue;
}
if (bda.managedClasses.contains(name)) {
classes.add(load(name, classLoader));
cdi = true;
break;
}
}
if (!cdi) {
for (final BeansInfo.BDAInfo bda : beans.noDescriptorBdas) {
if (bda.managedClasses.contains(name)) {
classes.add(load(name, classLoader));
break;
}
}
}
}
}
if ("true".equalsIgnoreCase(SystemInstance.get().getProperty("openejb.cdi.debug", "false"))) {
final Logger logger = Logger.getInstance(LogCategory.OPENEJB, CdiScanner.class.getName());
logger.info("CDI beans for " + startupObject.getAppInfo().appId + (startupObject.getWebContext() != null ? " webcontext = " + startupObject.getWebContext().getContextRoot() : ""));
final List<String> names = new ArrayList<>(classes.size());
for (final Class<?> c : classes) {
names.add(c.getName());
}
Collections.sort(names);
for (final String c : names) {
logger.info(" " + c);
}
}
}
}
use of org.apache.openejb.assembler.classic.EjbJarInfo in project tomee by apache.
the class Deploy method print.
private static void print(final AppInfo appInfo) {
System.out.println("App(id=" + appInfo.path + ")");
for (final EjbJarInfo info : appInfo.ejbJars) {
System.out.println(" EjbJar(id=" + info.moduleName + ", path=" + info.path + ")");
for (final EnterpriseBeanInfo beanInfo : info.enterpriseBeans) {
System.out.println(" Ejb(ejb-name=" + beanInfo.ejbName + ", id=" + beanInfo.ejbDeploymentId + ")");
for (final String name : beanInfo.jndiNames) {
System.out.println(" Jndi(name=" + name + ")");
}
System.out.println("");
}
for (final InterceptorInfo interceptorInfo : info.interceptors) {
System.out.println(" Interceptor(class=" + interceptorInfo.clazz + ")");
}
System.out.println("");
}
for (final ClientInfo clientInfo : appInfo.clients) {
System.out.println(" Client(main-class=" + clientInfo.mainClass + ", id=" + clientInfo.moduleId + ", path=" + clientInfo.path + ")");
System.out.println("");
}
for (final ConnectorInfo connectorInfo : appInfo.connectors) {
System.out.println(" Connector(id=" + connectorInfo.moduleId + ", path=" + connectorInfo.path + ")");
System.out.println("");
}
for (final WebAppInfo webAppInfo : appInfo.webApps) {
System.out.println(" WebApp(context-root=" + webAppInfo.contextRoot + ", id=" + webAppInfo.moduleId + ", path=" + webAppInfo.path + ")");
System.out.println("");
}
for (final PersistenceUnitInfo persistenceUnitInfo : appInfo.persistenceUnits) {
System.out.println(" PersistenceUnit(name=" + persistenceUnitInfo.name + ", provider=" + persistenceUnitInfo.provider + ")");
System.out.println("");
}
}
Aggregations