use of org.apache.openejb.jee.oejb2.Jndi in project tomee by apache.
the class JndiNameTest method testOpenejbJar2.
public void testOpenejbJar2() throws Exception {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
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));
// containers
final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
assembler.createContainer(statelessContainerInfo);
// Setup the descriptor information
final EjbModule ejbModule = new EjbModule(new EjbJar(), null);
ejbModule.getEjbJar().addEnterpriseBean(new StatelessBean(FooBean.class));
final OpenejbJarType v2 = new OpenejbJarType();
final SessionBeanType ejbDeployment = new SessionBeanType();
ejbDeployment.setEjbName("FooBean");
ejbDeployment.getJndi().add(new org.apache.openejb.jee.oejb2.Jndi("thename", "Local"));
ejbDeployment.getJndi().add(new org.apache.openejb.jee.oejb2.Jndi("anothername", "Remote"));
ejbDeployment.getJndi().add(new org.apache.openejb.jee.oejb2.Jndi("loldstyle", "LocalHome"));
ejbDeployment.getJndi().add(new org.apache.openejb.jee.oejb2.Jndi("roldstyle", "RemoteHome"));
v2.getEnterpriseBeans().add(ejbDeployment);
ejbModule.getAltDDs().put("openejb-jar.xml", v2);
assembler.createApplication(config.configureApplication(ejbModule));
final InitialContext initialContext = new InitialContext();
assertName(initialContext, Orange.class, "thename");
assertName(initialContext, Red.class, "anothername");
assertName(initialContext, LHYellow.class, "loldstyle");
assertName(initialContext, RHGreen.class, "roldstyle");
}
use of org.apache.openejb.jee.oejb2.Jndi 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<String>();
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.oejb2.Jndi in project tomee by apache.
the class MappedNameBuilder method deploy.
public AppModule deploy(final AppModule appModule) throws OpenEJBException {
for (final EjbModule ejbModule : appModule.getEjbModules()) {
final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
if (openejbJar == null) {
return appModule;
}
final Map<String, EjbDeployment> ejbDeployments = openejbJar.getDeploymentsByEjbName();
for (final EnterpriseBean enterpriseBean : ejbModule.getEjbJar().getEnterpriseBeans()) {
final EjbDeployment ejbDeployment = ejbDeployments.get(enterpriseBean.getEjbName());
if (ejbDeployment == null) {
continue;
}
final String mappedName = enterpriseBean.getMappedName();
if (mappedName != null && mappedName.length() > 0) {
ejbDeployment.getJndi().add(new Jndi(mappedName, "Remote"));
}
}
}
return appModule;
}
use of org.apache.openejb.jee.oejb2.Jndi in project tomee by apache.
the class MappedNameBuilderTest method testShouldCreateJndiEntryForBeanWithMappedName.
public void testShouldCreateJndiEntryForBeanWithMappedName() throws Exception {
AppModule appModule = new AppModule(new FakeClassLoader(), "");
final EjbJar ejbJar = new EjbJar();
final OpenejbJar openejbJar = new OpenejbJar();
final SessionBean sessionBean = new SessionBean("SessionBean", "org.superbiz.SessionBean", SessionType.STATELESS);
sessionBean.setMappedName("MappedName");
ejbJar.addEnterpriseBean(sessionBean);
final EjbDeployment ejbDeployment = new EjbDeployment("containerId", "deploymentId", "SessionBean");
openejbJar.addEjbDeployment(ejbDeployment);
appModule.getEjbModules().add(new EjbModule(ejbJar, openejbJar));
appModule = new MappedNameBuilder().deploy(appModule);
final EjbDeployment retrievedDeployment = appModule.getEjbModules().get(0).getOpenejbJar().getDeploymentsByEjbName().get("SessionBean");
final List<Jndi> jndiList = retrievedDeployment.getJndi();
assertNotNull(jndiList);
assertEquals(1, jndiList.size());
assertEquals("MappedName", jndiList.get(0).getName());
assertEquals("Remote", jndiList.get(0).getInterface());
}
use of org.apache.openejb.jee.oejb2.Jndi in project tomee by apache.
the class JndiNameTest 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.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
// containers
final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
assembler.createContainer(statelessContainerInfo);
// Setup the descriptor information
final EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
ejbModule.getEjbJar().addEnterpriseBean(new StatelessBean(FooBean.class));
final EjbDeployment ejbDeployment = new EjbDeployment(null, "FooBean", "FooBean");
ejbDeployment.getJndi().add(new Jndi("thename", "Local"));
ejbDeployment.getJndi().add(new Jndi("anothername", "Remote"));
ejbDeployment.getJndi().add(new Jndi("loldstyle", "LocalHome"));
ejbDeployment.getJndi().add(new Jndi("roldstyle", "RemoteHome"));
ejbModule.getOpenejbJar().addEjbDeployment(ejbDeployment);
assembler.createApplication(config.configureApplication(ejbModule));
final InitialContext initialContext = new InitialContext();
assertName(initialContext, Orange.class, "thename");
assertName(initialContext, Red.class, "anothername");
assertName(initialContext, LHYellow.class, "loldstyle");
assertName(initialContext, RHGreen.class, "roldstyle");
}
Aggregations