use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.
the class BeanProperties method deploy.
@Override
public AppModule deploy(final AppModule appModule) throws OpenEJBException {
final Properties base = new Properties();
base.putAll(SystemInstance.get().getProperties());
base.putAll(appModule.getProperties());
for (final EjbModule module : appModule.getEjbModules()) {
final Properties overrides = new SuperProperties().caseInsensitive(true);
overrides.putAll(base);
overrides.putAll(module.getProperties());
if (module.getOpenejbJar() == null) {
module.setOpenejbJar(new OpenejbJar());
}
final OpenejbJar openejbJar = module.getOpenejbJar();
final Map<String, EjbDeployment> deploymentMap = openejbJar.getDeploymentsByEjbName();
for (final EnterpriseBean bean : module.getEjbJar().getEnterpriseBeans()) {
final SuperProperties properties = new SuperProperties().caseInsensitive(true);
properties.putAll(globalProperties);
final String additionalKey = bean.getEjbName();
if (additionalProperties.containsKey(additionalKey)) {
for (final Map.Entry<Object, Object> entry : additionalProperties.get(additionalKey).entrySet()) {
properties.put(entry.getKey().toString(), entry.getValue().toString());
}
}
final EjbDeployment deployment = deploymentMap.get(bean.getEjbName());
if (deployment != null) {
properties.putAll(deployment.getProperties());
deployment.getProperties().clear();
}
final String id = bean.getEjbName() + ".";
for (final Map.Entry<Object, Object> entry : overrides.entrySet()) {
final String key = entry.getKey().toString();
if (key.startsWith(id)) {
final String property = key.substring(id.length());
if (properties.containsKey(property)) {
log.debug("Overriding ejb " + bean.getEjbName() + " property " + property + "=" + entry.getValue());
} else {
log.debug("Adding ejb " + bean.getEjbName() + " property " + property + "=" + entry.getValue());
}
properties.put(property, entry.getValue());
}
}
if (properties.size() > 0) {
if (deployment == null) {
final EjbDeployment ejbDeployment = openejbJar.addEjbDeployment(bean);
ejbDeployment.getProperties().putAll(properties);
} else {
deployment.getProperties().putAll(properties);
}
}
}
}
// cleanup
additionalProperties.clear();
globalProperties.clear();
return appModule;
}
use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.
the class DebuggableVmHackery method deploy.
public AppModule deploy(final AppModule appModule) throws OpenEJBException {
for (final EjbModule ejbModule : appModule.getEjbModules()) {
final EjbJar ejbJar = ejbModule.getEjbJar();
final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
final Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
ejbJar.setRelationships(null);
final List<String> removed = new ArrayList<>();
for (final EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
final String ejbName = bean.getEjbName();
final EjbDeployment ejbDeployment = deployments.get(ejbName);
pruneRefs(bean, ejbDeployment);
// }
if (!(bean instanceof MessageDrivenBean) && !(bean instanceof EntityBean)) {
continue;
}
ejbJar.removeEnterpriseBean(ejbName);
openejbJar.removeEjbDeployment(ejbDeployment);
removed.add(ejbName);
final AssemblyDescriptor assemblyDescriptor = ejbJar.getAssemblyDescriptor();
if (assemblyDescriptor != null) {
for (final MethodPermission permission : copy(assemblyDescriptor.getMethodPermission())) {
for (final Method method : copy(permission.getMethod())) {
if (method.getEjbName().equals(ejbName)) {
permission.getMethod().remove(method);
}
}
if (permission.getMethod().size() == 0) {
assemblyDescriptor.getMethodPermission().remove(permission);
}
}
for (final ContainerTransaction transaction : copy(assemblyDescriptor.getContainerTransaction())) {
for (final Method method : copy(transaction.getMethod())) {
if (method.getEjbName().equals(ejbName)) {
transaction.getMethod().remove(method);
}
}
if (transaction.getMethod().size() == 0) {
assemblyDescriptor.getContainerTransaction().remove(transaction);
}
}
for (final InterceptorBinding binding : copy(assemblyDescriptor.getInterceptorBinding())) {
if (binding.getEjbName().equals(ejbName)) {
assemblyDescriptor.getInterceptorBinding().remove(binding);
}
}
}
}
// Drop any ejb ref to with an ejb-link to a removed ejb
for (final EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
bean.getEjbLocalRefMap().keySet().removeAll(removed);
bean.getEjbRefMap().keySet().removeAll(removed);
}
for (final Interceptor interceptor : ejbJar.getInterceptors()) {
pruneRefs(interceptor, new EjbDeployment());
}
}
return appModule;
}
use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.
the class DeploymentLoader method addBeansXmls.
private void addBeansXmls(final AppModule appModule) {
final List<URL> urls = appModule.getAdditionalLibraries();
final URLClassLoader loader = new URLClassLoader(urls.toArray(new URL[urls.size()]));
final ArrayList<URL> xmls;
try {
xmls = Collections.list(loader.getResources("META-INF/beans.xml"));
} catch (final IOException e) {
return;
}
final CompositeBeans complete = new CompositeBeans();
for (final URL url : xmls) {
if (url == null) {
continue;
}
mergeBeansXml(complete, url);
}
if (complete.getDiscoveryByUrl().isEmpty()) {
return;
}
complete.removeDuplicates();
ensureContainerUrls();
final List<URL> scannableUrls = new ArrayList<>(this.containerUrls);
SystemInstance.get().fireEvent(new EnhanceScannableUrlsEvent(scannableUrls));
appModule.getScannableContainerUrls().addAll(scannableUrls);
IAnnotationFinder finder;
try {
finder = FinderFactory.createFinder(appModule);
} catch (final Exception e) {
finder = new FinderFactory.ModuleLimitedFinder(new FinderFactory.OpenEJBAnnotationFinder(new WebappAggregatedArchive(appModule.getClassLoader(), appModule.getAltDDs(), xmls)));
}
appModule.setEarLibFinder(finder);
final EjbModule ejbModule = new EjbModule(appModule.getClassLoader(), EAR_SCOPED_CDI_BEANS + appModule.getModuleId(), new EjbJar(), new OpenejbJar());
ejbModule.setBeans(complete);
ejbModule.setFinder(finder);
ejbModule.setEjbJar(new EmptyEjbJar());
appModule.getEjbModules().add(ejbModule);
}
use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.
the class OpenEjb2Conversion method convertEjbRefs.
public final void convertEjbRefs(final EjbJar ejbJar, final OpenejbJar openejbJar, final OpenejbJarType openejbJarType) {
openejbJar.getProperties().putAll(openejbJarType.getProperties());
final Map<String, EnterpriseBean> ejbs = ejbJar.getEnterpriseBeansByEjbName();
final Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
for (final org.apache.openejb.jee.oejb2.EnterpriseBean enterpriseBean : openejbJarType.getEnterpriseBeans()) {
final EnterpriseBean ejb = ejbs.get(enterpriseBean.getEjbName());
if (ejb == null) {
// todo warn no such ejb in the ejb-jar.xml
continue;
}
final Map<String, EjbRef> ejbRefs = ejb.getEjbRefMap();
final EjbDeployment deployment = deployments.get(enterpriseBean.getEjbName());
if (deployment == null) {
// todo warn no such ejb in the ejb-jar.xml
continue;
}
// Add WS Security
if (enterpriseBean instanceof SessionBeanType) {
final SessionBeanType sessionBean = (SessionBeanType) enterpriseBean;
final WebServiceSecurityType webServiceSecurityType = sessionBean.getWebServiceSecurity();
if (webServiceSecurityType != null) {
if (webServiceSecurityType.getRealmName() != null) {
deployment.addProperty("webservice.security.realm", webServiceSecurityType.getRealmName());
}
if (webServiceSecurityType.getSecurityRealmName() != null) {
deployment.addProperty("webservice.security.securityRealm", webServiceSecurityType.getSecurityRealmName());
}
if (webServiceSecurityType.getTransportGuarantee() != null) {
deployment.addProperty("webservice.security.transportGarantee", webServiceSecurityType.getTransportGuarantee().value());
} else {
deployment.addProperty("webservice.security.transportGarantee", "NONE");
}
if (webServiceSecurityType.getAuthMethod() != null) {
deployment.addProperty("webservice.security.authMethod", webServiceSecurityType.getAuthMethod().value());
} else {
deployment.addProperty("webservice.security.authMethod", "NONE");
}
deployment.getProperties().putAll(webServiceSecurityType.getProperties());
}
if (sessionBean.getWebServiceAddress() != null) {
deployment.getProperties().put("openejb.webservice.deployment.address", sessionBean.getWebServiceAddress());
}
}
deployment.getProperties().putAll(enterpriseBean.getProperties());
for (final String name : enterpriseBean.getLocalJndiName()) {
deployment.getJndi().add(new org.apache.openejb.jee.oejb3.Jndi(name, "LocalHome"));
}
for (final String name : enterpriseBean.getJndiName()) {
deployment.getJndi().add(new org.apache.openejb.jee.oejb3.Jndi(name, "RemoteHome"));
}
for (final Jndi jndi : enterpriseBean.getJndi()) {
deployment.getJndi().add(new org.apache.openejb.jee.oejb3.Jndi(jndi.getName(), jndi.getInterface()));
}
final Set<String> ejbLinks = new TreeSet<>();
for (final EjbLink ejbLink : deployment.getEjbLink()) {
ejbLinks.add(ejbLink.getEjbRefName());
}
for (final EjbRefType refType : enterpriseBean.getEjbRef()) {
final String refName = refType.getRefName();
if (ejbLinks.contains(refName)) {
// don't overwrite refs that have been already set
continue;
}
final String nsCorbaloc = refType.getNsCorbaloc();
if (nsCorbaloc != null) {
final EjbRef ref = ejbRefs.get(refName);
if (ref != null) {
ref.setMappedName("jndi:" + nsCorbaloc);
}
} else if (refType.getEjbLink() != null) {
final EjbRef ref = ejbRefs.get(refName);
if (ref != null) {
ref.setEjbLink(refType.getEjbLink());
}
} else {
final PatternType pattern = refType.getPattern();
addEjbLink(deployment, refName, pattern);
}
}
for (final EjbLocalRefType refType : enterpriseBean.getEjbLocalRef()) {
final String refName = refType.getRefName();
if (ejbLinks.contains(refName)) {
// don't overwrite refs that have been already set
continue;
}
if (refType.getEjbLink() != null) {
final EjbRef ref = ejbRefs.get(refName);
if (ref != null) {
ref.setEjbLink(refType.getEjbLink());
}
} else {
final PatternType pattern = refType.getPattern();
addEjbLink(deployment, refName, pattern);
}
}
}
}
use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.
the class DeploymentContextPropertiesTest method testBeanContextProperties.
public void testBeanContextProperties() throws Exception {
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
final EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
final EjbJar ejbJar = ejbModule.getEjbJar();
final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
final StatelessBean statelessBean = ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
final EjbDeployment deployment = openejbJar.addEjbDeployment(statelessBean);
deployment.getProperties().put("color", "orange");
assembler.createApplication(config.configureApplication(ejbModule));
}
final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
final BeanContext beanContext = containerSystem.getBeanContext("WidgetBean");
final Properties properties = beanContext.getProperties();
assertProperty(properties, "color", "orange");
}
Aggregations