use of org.apache.openejb.assembler.classic.EjbJarInfo in project tomee by apache.
the class Container method deploy.
public AppContext deploy(final String name, final File file, final boolean overrideName) throws OpenEJBException, IOException, NamingException {
final AppContext context;
final AppInfo appInfo;
if (WebAppDeployer.Helper.isWebApp(file)) {
String contextRoot = file.getName();
if (overrideName) {
contextRoot = name;
}
appInfo = SystemInstance.get().getComponent(WebAppDeployer.class).deploy(null, contextRoot, file);
if (appInfo != null) {
context = SystemInstance.get().getComponent(ContainerSystem.class).getAppContext(appInfo.appId);
} else {
context = null;
}
} else {
appInfo = configurationFactory.configureApplication(file);
if (overrideName) {
appInfo.appId = name;
for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
if (file.getName().equals(ejbJar.moduleName)) {
ejbJar.moduleName = name;
ejbJar.moduleId = name;
}
for (final EnterpriseBeanInfo ejb : ejbJar.enterpriseBeans) {
if (BeanContext.Comp.openejbCompName(file.getName()).equals(ejb.ejbName)) {
ejb.ejbName = BeanContext.Comp.openejbCompName(name);
}
}
}
for (final WebAppInfo webApp : appInfo.webApps) {
if (sameApplication(file, webApp)) {
webApp.moduleId = name;
webApp.contextRoot = lastPart(name, webApp.contextRoot);
if ("ROOT".equals(webApp.contextRoot)) {
webApp.contextRoot = "";
}
}
}
}
context = assembler.createApplication(appInfo);
}
moduleIds.put(name, null != appInfo ? appInfo.path : null);
infos.put(name, appInfo);
appContexts.put(name, context);
return context;
}
use of org.apache.openejb.assembler.classic.EjbJarInfo in project tomee by apache.
the class WsService method deployApp.
private void deployApp(final AppInfo appInfo, final Collection<BeanContext> ejbs) {
final Collection<BeanContext> alreadyDeployed = deployedApplications.get(appInfo);
final Map<String, WebAppInfo> webContextByEjb = new HashMap<>();
for (final WebAppInfo webApp : appInfo.webApps) {
for (final String ejb : webApp.ejbWebServices) {
webContextByEjb.put(ejb, webApp);
}
}
final Map<String, String> contextData = new HashMap<>();
contextData.put("appId", appInfo.path);
for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
final Map<String, PortInfo> ports = new TreeMap<>();
for (final PortInfo port : ejbJar.portInfos) {
ports.put(port.serviceLink, port);
}
URL moduleBaseUrl = null;
if (ejbJar.path != null) {
try {
moduleBaseUrl = new File(ejbJar.path).toURI().toURL();
} catch (final MalformedURLException e) {
logger.error("Invalid ejb jar location " + ejbJar.path, e);
}
}
StringTemplate deploymentIdTemplate = this.wsAddressTemplate;
if (ejbJar.properties.containsKey(WS_ADDRESS_FORMAT)) {
final String format = ejbJar.properties.getProperty(WS_ADDRESS_FORMAT);
logger.info("Using " + WS_ADDRESS_FORMAT + " '" + format + "'");
deploymentIdTemplate = new StringTemplate(format);
}
contextData.put("ejbJarId", ejbJar.moduleName);
final String host = host(ejbJar, appInfo);
for (final EnterpriseBeanInfo bean : ejbJar.enterpriseBeans) {
if (bean instanceof StatelessBeanInfo || bean instanceof SingletonBeanInfo) {
final BeanContext beanContext = containerSystem.getBeanContext(bean.ejbDeploymentId);
if (beanContext == null || (ejbs != null && !ejbs.contains(beanContext))) {
continue;
}
final PortInfo portInfo = ports.get(bean.ejbName);
if (portInfo == null || alreadyDeployed.contains(beanContext))
continue;
final ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(beanContext.getClassLoader());
try {
final PortData port = WsBuilder.toPortData(portInfo, beanContext.getInjections(), moduleBaseUrl, beanContext.getClassLoader());
final HttpListener container = createEjbWsContainer(moduleBaseUrl, port, beanContext, new ServiceConfiguration(beanContext.getProperties(), appInfo.services));
// generate a location if one was not assigned
String location = port.getLocation();
if (location == null) {
location = autoAssignWsLocation(bean, port, contextData, deploymentIdTemplate);
}
if (!location.startsWith("/"))
location = "/" + location;
ejbLocations.put(bean.ejbDeploymentId, location);
final ClassLoader classLoader = beanContext.getClassLoader();
if (wsRegistry != null) {
String auth = authMethod;
String realm = realmName;
String transport = transportGuarantee;
if ("BASIC".equals(portInfo.authMethod) || "DIGEST".equals(portInfo.authMethod) || "CLIENT-CERT".equals(portInfo.authMethod)) {
auth = portInfo.authMethod;
realm = portInfo.realmName;
transport = portInfo.transportGuarantee;
}
final WebAppInfo webAppInfo = webContextByEjb.get(bean.ejbClass);
String context = webAppInfo != null ? webAppInfo.contextRoot : null;
String moduleId = webAppInfo != null ? webAppInfo.moduleId : null;
if (context == null && !OLD_WEBSERVICE_DEPLOYMENT) {
context = ejbJar.moduleName;
}
final List<String> addresses = wsRegistry.addWsContainer(container, classLoader, context, host, location, realm, transport, auth, moduleId);
alreadyDeployed.add(beanContext);
// one of the registered addresses to be the canonical address
final String address = HttpUtil.selectSingleAddress(addresses);
if (address != null) {
// register wsdl location
portAddressRegistry.addPort(portInfo.serviceId, portInfo.wsdlService, portInfo.portId, portInfo.wsdlPort, portInfo.seiInterfaceName, address);
setWsdl(container, address);
logger.info("Webservice(wsdl=" + address + ", qname=" + port.getWsdlService() + ") --> Ejb(id=" + portInfo.portId + ")");
ejbAddresses.put(bean.ejbDeploymentId, address);
addressesForApp(appInfo.appId).add(new EndpointInfo(address, port.getWsdlService(), beanContext.getBeanClass().getName()));
}
}
} catch (final Throwable e) {
logger.error("Error deploying JAX-WS Web Service for EJB " + beanContext.getDeploymentID(), e);
} finally {
Thread.currentThread().setContextClassLoader(old);
}
}
}
}
if (ejbs == null || appInfo.webAppAlone) {
for (final WebAppInfo webApp : appInfo.webApps) {
afterApplicationCreated(appInfo, webApp);
}
}
// else called because of ear case where new ejbs are deployed in webapps
}
use of org.apache.openejb.assembler.classic.EjbJarInfo in project tomee by apache.
the class WsService method undeploy.
public void undeploy(@Observes final AssemblerBeforeApplicationDestroyed event) {
final AppInfo appInfo = event.getApp();
if (deployedApplications.remove(appInfo) != null) {
for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
final Map<String, PortInfo> ports = new TreeMap<String, PortInfo>();
for (final PortInfo port : ejbJar.portInfos) {
ports.put(port.serviceLink, port);
}
for (final EnterpriseBeanInfo enterpriseBean : ejbJar.enterpriseBeans) {
if (enterpriseBean instanceof StatelessBeanInfo || enterpriseBean instanceof SingletonBeanInfo) {
final PortInfo portInfo = ports.get(enterpriseBean.ejbName);
if (portInfo == null) {
continue;
}
final BeanContext beanContext = containerSystem.getBeanContext(enterpriseBean.ejbDeploymentId);
if (beanContext == null) {
continue;
}
// remove wsdl addresses from global registry
final String address = ejbAddresses.remove(enterpriseBean.ejbDeploymentId);
addressesForApp(appInfo.appId).remove(new EndpointInfo(address, portInfo.wsdlPort, beanContext.getBeanClass().getName()));
if (address != null) {
portAddressRegistry.removePort(portInfo.serviceId, portInfo.wsdlService, portInfo.portId, portInfo.seiInterfaceName);
}
// remove container from web server
final String location = ejbLocations.get(enterpriseBean.ejbDeploymentId);
if (this.wsRegistry != null && location != null) {
this.wsRegistry.removeWsContainer(location, ejbJar.moduleId);
}
// destroy webservice container
destroyEjbWsContainer(enterpriseBean.ejbDeploymentId);
ejbLocations.remove(enterpriseBean.ejbDeploymentId);
}
}
}
for (final WebAppInfo webApp : appInfo.webApps) {
deployedWebApps.remove(webApp);
final Map<String, PortInfo> ports = new TreeMap<String, PortInfo>();
for (final PortInfo port : webApp.portInfos) {
ports.put(port.serviceLink, port);
}
for (final ServletInfo servlet : webApp.servlets) {
if (servlet.servletClass == null) {
continue;
}
PortInfo portInfo = ports.remove(servlet.servletClass);
if (portInfo == null) {
portInfo = ports.remove(servlet.servletName);
if (portInfo == null) {
continue;
}
}
// remove wsdl addresses from global registry
final String address = servletAddresses.remove(webApp.moduleId + "." + servlet.servletName);
if (address != null) {
portAddressRegistry.removePort(portInfo.serviceId, portInfo.wsdlService, portInfo.portId, portInfo.seiInterfaceName);
}
// clear servlet's reference to the webservice container
if (this.wsRegistry != null) {
try {
this.wsRegistry.clearWsContainer(webApp.contextRoot, host(webApp), servlet, webApp.moduleId);
} catch (final IllegalArgumentException ignored) {
// no-op
}
}
// destroy webservice container
destroyPojoWsContainer(portInfo.serviceLink);
}
addressesByApplication.remove(webApp.moduleId);
}
addressesByApplication.remove(appInfo.appId);
}
}
use of org.apache.openejb.assembler.classic.EjbJarInfo in project tomee by apache.
the class UberInterfaceTest method test.
public void test() throws Exception {
final EjbServer ejbServer = new EjbServer();
final 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());
final ServicePool pool = new ServicePool(ejbServer, 10);
final ServiceDaemon serviceDaemon = new ServiceDaemon(pool, 0, "localhost");
serviceDaemon.start();
final int port = serviceDaemon.getPort();
final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
final ConfigurationFactory config = new ConfigurationFactory();
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);
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());
{
// remote invoke
final 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);
final Context context = new InitialContext(props);
final Everything remote = (Everything) context.lookup("SuperBeanRemote");
final Reference reference = new Reference("test");
assertEquals(reference, remote.echo(reference));
// pass by value
assertNotSame(reference, remote.echo(reference));
}
{
// local invoke
final Properties props = new Properties();
props.put("java.naming.factory.initial", "org.apache.openejb.core.LocalInitialContextFactory");
final Context context = new InitialContext(props);
final Everything local = (Everything) context.lookup("SuperBeanLocal");
final Reference reference = new Reference("test");
assertEquals(reference, local.echo(reference));
// pass by reference
assertSame(reference, local.echo(reference));
}
serviceDaemon.stop();
OpenEJB.destroy();
}
use of org.apache.openejb.assembler.classic.EjbJarInfo in project tomee by apache.
the class InheritenceTest method test.
public void test() throws Exception {
final Assembler assembler = new Assembler();
final ConfigurationFactory config = new ConfigurationFactory();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
assembler.createContainer(config.configureService(StatefulSessionContainerInfo.class));
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatefulBean(Color.class));
ejbJar.addEnterpriseBean(new StatefulBean(Red.class));
final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
final StatefulBeanInfo expected = (StatefulBeanInfo) ejbJarInfo.enterpriseBeans.get(0);
final StatefulBeanInfo actual = (StatefulBeanInfo) ejbJarInfo.enterpriseBeans.get(1);
assertEquals("transactionType", expected.transactionType, actual.transactionType);
assertEquals("runAs", expected.runAs, actual.runAs);
assertEquals("businessLocal", expected.businessLocal, actual.businessLocal);
assertEquals("businessRemote", expected.businessRemote, actual.businessRemote);
assertEquals("local", expected.local, actual.local);
assertEquals("localHome", expected.localHome, actual.localHome);
assertEquals("remote", expected.remote, actual.remote);
assertEquals("home", expected.home, actual.home);
assertEquals("timeout", expected.timeoutMethod, actual.timeoutMethod);
assertCallbackInfos("postActivate", expected.postActivate, actual.postActivate);
assertCallbackInfos("prePassivate", expected.prePassivate, actual.prePassivate);
assertCallbackInfos("postConstruct", expected.postConstruct, actual.postConstruct);
assertCallbackInfos("preDestroy", expected.preDestroy, actual.preDestroy);
assertCallbackInfos("preDestroy", expected.aroundInvoke, actual.aroundInvoke);
assertRemoveMethodInfos("removeMethods", expected.removeMethods, actual.removeMethods);
assertInitMethodInfos("initMethods", expected.initMethods, actual.initMethods);
assertSecurityRoleReferenceInfos("securityRoleReferences", expected.securityRoleReferences, actual.securityRoleReferences);
// comp/ComponentName is different
assertEquals(1, expected.jndiEnc.envEntries.size());
assertEquals(1, actual.jndiEnc.envEntries.size());
assertEquals("comp/ComponentName", expected.jndiEnc.envEntries.get(0).referenceName);
assertEquals("Color", expected.jndiEnc.envEntries.get(0).value);
assertEquals("comp/ComponentName", actual.jndiEnc.envEntries.get(0).referenceName);
assertEquals("Red", actual.jndiEnc.envEntries.get(0).value);
expected.jndiEnc.envEntries.clear();
actual.jndiEnc.envEntries.clear();
assertEquals("jndiEnc", expected.jndiEnc, actual.jndiEnc);
}
Aggregations