use of org.apache.openejb.assembler.classic.EnterpriseBeanInfo 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("");
}
}
use of org.apache.openejb.assembler.classic.EnterpriseBeanInfo in project tomee by apache.
the class EjbJarInfoBuilder method buildInfo.
public EjbJarInfo buildInfo(final EjbModule jar) throws OpenEJBException {
deploymentIds.clear();
securityRoles.clear();
final Map<String, EjbDeployment> ejbds = jar.getOpenejbJar().getDeploymentsByEjbName();
final int beansDeployed = jar.getOpenejbJar().getEjbDeploymentCount();
final int beansInEjbJar = jar.getEjbJar().getEnterpriseBeans().length;
if (beansInEjbJar != beansDeployed) {
for (final EnterpriseBean bean : jar.getEjbJar().getEnterpriseBeans()) {
if (!ejbds.containsKey(bean.getEjbName())) {
ConfigUtils.logger.warning("conf.0018", bean.getEjbName(), jar.getJarLocation());
}
}
final String message = messages.format("conf.0008", jar.getJarLocation(), String.valueOf(beansInEjbJar), String.valueOf(beansDeployed));
logger.warning(message);
throw new OpenEJBException(message);
}
final Map<String, EnterpriseBeanInfo> infos = new HashMap<>();
final Map<String, EnterpriseBean> items = new HashMap<>();
final EjbJarInfo ejbJar = new EjbJarInfo();
ejbJar.path = jar.getJarLocation();
ejbJar.moduleUri = jar.getModuleUri();
ejbJar.moduleId = jar.getModuleId();
if (jar.getEjbJar() != null && jar.getEjbJar().getModuleName() != null) {
ejbJar.moduleName = jar.getEjbJar().getModuleName();
} else {
ejbJar.moduleName = jar.getModuleId();
}
ejbJar.watchedResources.addAll(jar.getWatchedResources());
ejbJar.properties.putAll(jar.getProperties());
ejbJar.properties.putAll(jar.getOpenejbJar().getProperties());
for (final EnterpriseBean bean : jar.getEjbJar().getEnterpriseBeans()) {
final EnterpriseBeanInfo beanInfo;
if (bean instanceof SessionBean) {
beanInfo = initSessionBean((SessionBean) bean, ejbJar, ejbds);
} else if (bean instanceof EntityBean) {
beanInfo = initEntityBean((EntityBean) bean, ejbds);
} else if (bean instanceof MessageDrivenBean) {
beanInfo = initMessageBean((MessageDrivenBean) bean, ejbds);
} else {
throw new OpenEJBException("Unknown bean type: " + bean.getClass().getName());
}
ejbJar.enterpriseBeans.add(beanInfo);
if (deploymentIds.contains(beanInfo.ejbDeploymentId)) {
final String message = messages.format("conf.0100", beanInfo.ejbDeploymentId, jar.getJarLocation(), beanInfo.ejbName);
logger.warning(message);
throw new OpenEJBException(message);
}
deploymentIds.add(beanInfo.ejbDeploymentId);
beanInfo.codebase = jar.getJarLocation();
infos.put(beanInfo.ejbName, beanInfo);
items.put(beanInfo.ejbName, bean);
if (bean.getSecurityIdentity() != null) {
beanInfo.runAs = bean.getSecurityIdentity().getRunAs();
final EjbDeployment deployment = ejbds.get(beanInfo.ejbName);
if (deployment != null) {
for (final RoleMapping mapping : deployment.getRoleMapping()) {
if (mapping.getRoleName().equals(beanInfo.runAs)) {
beanInfo.runAsUser = mapping.getPrincipalName();
break;
}
}
}
}
initJndiNames(ejbds, beanInfo);
}
if (jar.getEjbJar().getAssemblyDescriptor() != null) {
initInterceptors(jar, ejbJar);
initSecurityRoles(jar, ejbJar);
initMethodPermissions(jar, ejbds, ejbJar);
initExcludesList(jar, ejbds, ejbJar);
initMethodTransactions(jar, ejbds, ejbJar);
initMethodConcurrency(jar, ejbds, ejbJar);
initApplicationExceptions(jar, ejbJar);
for (final EnterpriseBeanInfo bean : ejbJar.enterpriseBeans) {
resolveRoleLinks(bean, items.get(bean.ejbName));
}
}
if (jar.getEjbJar().getRelationships() != null) {
initRelationships(jar, infos);
}
final Beans beans = jar.getBeans();
if (beans != null) {
ejbJar.beans = new BeansInfo();
ejbJar.beans.version = beans.getVersion();
ejbJar.beans.discoveryMode = beans.getBeanDiscoveryMode();
if (beans.getScan() != null) {
for (final Beans.Scan.Exclude exclude : beans.getScan().getExclude()) {
final ExclusionInfo exclusionInfo = new ExclusionInfo();
for (final Object config : exclude.getIfClassAvailableOrIfClassNotAvailableOrIfSystemProperty()) {
if (Beans.Scan.Exclude.IfAvailableClassCondition.class.isInstance(config)) {
exclusionInfo.availableClasses.add(Beans.Scan.Exclude.ClassCondition.class.cast(config).getName());
} else if (Beans.Scan.Exclude.IfNotAvailableClassCondition.class.isInstance(config)) {
exclusionInfo.notAvailableClasses.add(Beans.Scan.Exclude.ClassCondition.class.cast(config).getName());
} else if (Beans.Scan.Exclude.IfSystemProperty.class.isInstance(config)) {
final Beans.Scan.Exclude.IfSystemProperty systemProperty = Beans.Scan.Exclude.IfSystemProperty.class.cast(config);
if (systemProperty.getValue() == null) {
exclusionInfo.systemPropertiesPresence.add(systemProperty.getName());
} else {
exclusionInfo.systemProperties.put(systemProperty.getName(), systemProperty.getValue());
}
} else {
throw new IllegalArgumentException("Not supported: " + config);
}
}
final BeansInfo.ExclusionEntryInfo exclusionEntryInfo = new BeansInfo.ExclusionEntryInfo();
exclusionEntryInfo.name = exclude.getName();
exclusionEntryInfo.exclusion = exclusionInfo;
ejbJar.beans.excludes.add(exclusionEntryInfo);
}
}
ejbJar.beans.duplicatedAlternativeClasses.addAll(beans.getDuplicatedAlternatives().getClasses());
ejbJar.beans.duplicatedAlternativeStereotypes.addAll(beans.getDuplicatedAlternatives().getStereotypes());
ejbJar.beans.duplicatedInterceptors.addAll(beans.getDuplicatedInterceptors());
ejbJar.beans.duplicatedDecorators.addAll(beans.getDuplicatedDecorators());
ejbJar.beans.startupClasses.addAll(beans.getStartupBeans());
final Map<URL, String> discoveryModeByUrl = new HashMap<>();
final CompositeBeans composite;
final boolean isComposite = CompositeBeans.class.isInstance(beans);
if (isComposite) {
composite = CompositeBeans.class.cast(beans);
discoveryModeByUrl.putAll(composite.getDiscoveryByUrl());
} else {
composite = null;
URL key = DEFAULT_BEANS_XML_KEY;
if (beans.getUri() != null) {
try {
key = new URL(beans.getUri());
} catch (final MalformedURLException e) {
// no-op
}
}
discoveryModeByUrl.put(key, beans.getBeanDiscoveryMode());
}
for (final Map.Entry<URL, List<String>> next : beans.getManagedClasses().entrySet()) {
final URL key = next.getKey();
final BeansInfo.BDAInfo bdaInfo = new BeansInfo.BDAInfo();
bdaInfo.discoveryMode = discoveryModeByUrl.get(key);
merge(composite, key == null ? DEFAULT_BEANS_XML_KEY : key, bdaInfo, next.getValue());
ejbJar.beans.bdas.add(bdaInfo);
}
for (final Map.Entry<URL, List<String>> next : beans.getNotManagedClasses().entrySet()) {
final URL key = next.getKey();
final BeansInfo.BDAInfo bdaInfo = new BeansInfo.BDAInfo();
bdaInfo.discoveryMode = BeanArchiveService.BeanDiscoveryMode.ANNOTATED.name();
merge(composite, key == null ? DEFAULT_BEANS_XML_KEY : key, bdaInfo, next.getValue());
ejbJar.beans.noDescriptorBdas.add(bdaInfo);
}
// app composer case mainly,we should really not use it anywhere else
if (composite == null && ejbJar.beans.bdas.size() == 1) {
final BeansInfo.BDAInfo bda = ejbJar.beans.bdas.iterator().next();
bda.alternatives.addAll(beans.getAlternativeClasses());
bda.interceptors.addAll(beans.getInterceptors());
bda.decorators.addAll(beans.getDecorators());
bda.stereotypeAlternatives.addAll(beans.getAlternativeStereotypes());
}
}
return ejbJar;
}
use of org.apache.openejb.assembler.classic.EnterpriseBeanInfo in project tomee by apache.
the class JndiEncInfoBuilder method buildEjbRefs.
private void buildEjbRefs(final JndiConsumer jndiConsumer, final URI moduleUri, final String moduleId, final String ejbName, final JndiEncInfo moduleJndiEnc, final JndiEncInfo compJndiEnc) throws OpenEJBException {
final Collection<EjbRef> ejbRefs = jndiConsumer.getEjbRef();
final Collection<EjbLocalRef> ejbLocalRefs = jndiConsumer.getEjbLocalRef();
final List<EjbReference> references = new ArrayList<EjbReference>(ejbRefs.size() + ejbLocalRefs.size());
references.addAll(ejbRefs);
references.addAll(ejbLocalRefs);
for (final EjbReference ref : references) {
final EjbReferenceInfo info = new EjbReferenceInfo();
info.homeClassName = ref.getHome();
info.interfaceClassName = ref.getInterface();
info.referenceName = ref.getName();
info.link = ref.getEjbLink();
info.location = buildLocationInfo(ref);
info.targets.addAll(buildInjectionInfos(ref));
info.localbean = isIntefaceLocalBean(info.interfaceClassName);
if (info.location != null) {
if (ref.getRefType() == EjbReference.Type.LOCAL) {
insert(toLocal(info), appInfo.globalJndiEnc.ejbLocalReferences, appInfo.appJndiEnc.ejbLocalReferences, moduleJndiEnc.ejbLocalReferences, compJndiEnc.ejbLocalReferences);
} else {
insert(info, appInfo.globalJndiEnc.ejbReferences, appInfo.appJndiEnc.ejbReferences, moduleJndiEnc.ejbReferences, compJndiEnc.ejbReferences);
}
continue;
}
final EjbResolver ejbResolver = getEjbResolver(moduleId);
final String deploymentId = ejbResolver.resolve(new Ref(ref), moduleUri);
info.ejbDeploymentId = deploymentId;
if (info.ejbDeploymentId == null) {
if (info.link != null) {
logger.warning("config.noBeanFoundEjbLink", ref.getName(), ejbName, ref.getEjbLink());
} else {
logger.warning("config.noBeanFound", ref.getName(), ejbName, ref.getEjbLink());
}
} else {
final EjbResolver.Scope scope = ejbResolver.getScope(deploymentId);
info.externalReference = scope != EAR && scope != EJBJAR;
if (ref.getRefType() == EjbReference.Type.UNKNOWN) {
final EnterpriseBeanInfo otherBean = ejbResolver.getEnterpriseBeanInfo(deploymentId);
if (otherBean != null) {
if (otherBean.businessLocal.contains(ref.getInterface()) || otherBean.ejbClass.equals(ref.getInterface())) {
ref.setRefType(EjbReference.Type.LOCAL);
ejbRefs.remove(ref);
ejbLocalRefs.add(new EjbLocalRef(ref));
} else {
ref.setRefType(EjbReference.Type.REMOTE);
}
}
}
}
if (ref.getRefType() == EjbReference.Type.LOCAL) {
insert(toLocal(info), appInfo.globalJndiEnc.ejbLocalReferences, appInfo.appJndiEnc.ejbLocalReferences, moduleJndiEnc.ejbLocalReferences, compJndiEnc.ejbLocalReferences);
} else {
insert(info, appInfo.globalJndiEnc.ejbReferences, appInfo.appJndiEnc.ejbReferences, moduleJndiEnc.ejbReferences, compJndiEnc.ejbReferences);
}
}
}
use of org.apache.openejb.assembler.classic.EnterpriseBeanInfo in project tomee by apache.
the class ListEjbMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
final Deployer deployer = (Deployer) lookup("openejb/DeployerBusinessRemote");
final Collection<AppInfo> infos = deployer.getDeployedApps();
final Lines lines = new Lines();
lines.add(new Line("Name", "Class", "Interface Type", "Bean Type"));
for (final AppInfo info : infos) {
for (final EjbJarInfo ejbJar : info.ejbJars) {
for (final EnterpriseBeanInfo bean : ejbJar.enterpriseBeans) {
lines.add(new Line(bean.ejbDeploymentId, bean.ejbClass, getType(bean), componentType(bean)));
}
}
}
lines.print(new LogPrinterStream(getLog()));
}
use of org.apache.openejb.assembler.classic.EnterpriseBeanInfo in project tomee by apache.
the class PropertiesPropogationTest method test.
public void test() throws Exception {
EjbServer ejbServer = new EjbServer();
Properties initProps = new Properties();
initProps.setProperty("openejb.deployments.classpath.include", "");
initProps.setProperty("openejb.deployments.classpath.filter.descriptors", "true");
OpenEJB.init(initProps, new ServerFederation());
ejbServer.init(new Properties());
ServicePool pool = new ServicePool(ejbServer, 10);
ServiceDaemon serviceDaemon = new ServiceDaemon(pool, 0, "localhost");
serviceDaemon.start();
int port = serviceDaemon.getPort();
Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
ConfigurationFactory config = new ConfigurationFactory();
EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
EjbJar ejbJar = ejbModule.getEjbJar();
OpenejbJar openejbJar = ejbModule.getOpenejbJar();
StatelessBean statelessBean = ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
EjbDeployment deployment = openejbJar.addEjbDeployment(statelessBean);
deployment.getProperties().put("color", "orange");
deployment.getProperties().put("openejb.client.color", "red");
EjbJarInfo ejbJarInfo = config.configureApplication(ejbModule);
EnterpriseBeanInfo beanInfo = ejbJarInfo.enterpriseBeans.get(0);
assertTrue(beanInfo.properties.containsKey("color"));
assertTrue(beanInfo.properties.containsKey("openejb.client.color"));
assertEquals("orange", beanInfo.properties.get("color"));
assertEquals("red", beanInfo.properties.get("openejb.client.color"));
assembler.createApplication(ejbJarInfo);
ContainerSystem cs = SystemInstance.get().getComponent(ContainerSystem.class);
BeanContext info = cs.getBeanContext("WidgetBean");
assertNotNull(info);
assertTrue(info.getProperties().containsKey("color"));
assertTrue(info.getProperties().containsKey("openejb.client.color"));
assertEquals("orange", info.getProperties().get("color"));
assertEquals("red", info.getProperties().get("openejb.client.color"));
Properties props = new Properties();
props.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
props.put("java.naming.provider.url", "ejbd://127.0.0.1:" + port);
Context context = new InitialContext(props);
Widget remote = (Widget) context.lookup("WidgetBeanRemote");
InvocationHandler handler = ProxyManager.getInvocationHandler(remote);
EJBObjectHandler objectHandler = EJBObjectHandler.class.cast(handler);
Properties properties = objectHandler.getEjb().getProperties();
// Should only contain "openejb.client.*" properties
assertFalse(properties.containsKey("color"));
// The openejb.client.color property should have been propogated
assertTrue(properties.containsKey("openejb.client.color"));
assertEquals("red", properties.getProperty("openejb.client.color"));
serviceDaemon.stop();
OpenEJB.destroy();
}
Aggregations