use of org.apache.openejb.spi.ContainerSystem in project tomee by apache.
the class ClassLoaderCommand method execute.
@Override
public void execute(final String cmd) {
final String appName = extractAppName(cmd);
final ContainerSystem cs = SystemInstance.get().getComponent(ContainerSystem.class);
for (AppContext ctx : cs.getAppContexts()) {
if (appName.equalsIgnoreCase(ctx.getId())) {
dumpClassLoader(ctx.getClassLoader());
return;
}
}
streamManager.writeErr("can't find app " + appName);
streamManager.writeErr("available apps are:");
for (AppContext ctx : cs.getAppContexts()) {
streamManager.writeErr("- " + ctx.getId());
}
}
use of org.apache.openejb.spi.ContainerSystem in project tomee by apache.
the class ServerSideResolver method resolve.
@Override
public Object resolve(final EJBHomeHandler handler) {
try {
final EJBMetaDataImpl ejb = handler.getEjb();
final InterfaceType interfaceType = (ejb.getRemoteInterfaceClass() == null) ? InterfaceType.BUSINESS_REMOTE_HOME : InterfaceType.EJB_HOME;
final ArrayList<Class> interfaces = new ArrayList<Class>();
if (interfaceType.isBusiness()) {
interfaces.addAll(ejb.getBusinessClasses());
} else {
interfaces.add(ejb.getRemoteInterfaceClass());
}
final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
final BeanContext beanContext = containerSystem.getBeanContext(ejb.getDeploymentID());
return EjbHomeProxyHandler.createHomeProxy(beanContext, interfaceType, interfaces, ejb.getMainInterface());
} catch (Exception e) {
Logger.getInstance(LogCategory.OPENEJB_SERVER_REMOTE, "org.apache.openejb.server.util.resources").error("ServerSideResolver.resolve() failed, falling back to ClientSideResolver: " + e.getClass().getName() + ": " + e.getMessage(), e);
return new EJBHomeProxyHandle.ClientSideResovler().resolve(handler);
}
}
use of org.apache.openejb.spi.ContainerSystem in project tomee by apache.
the class ServerSideResolver method resolve.
@Override
public Object resolve(final EJBObjectHandler handler) {
try {
final EJBMetaDataImpl ejb = handler.getEjb();
final InterfaceType interfaceType = (ejb.getRemoteInterfaceClass() == null) ? InterfaceType.BUSINESS_REMOTE_HOME : InterfaceType.EJB_HOME;
final ArrayList<Class> interfaces = new ArrayList<Class>();
if (interfaceType.isBusiness()) {
interfaces.addAll(ejb.getBusinessClasses());
} else {
interfaces.add(ejb.getRemoteInterfaceClass());
}
final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
final BeanContext beanContext = containerSystem.getBeanContext(ejb.getDeploymentID());
return EjbObjectProxyHandler.createProxy(beanContext, handler.getPrimaryKey(), interfaceType, interfaces, ejb.getMainInterface());
} catch (Exception e) {
Logger.getInstance(LogCategory.OPENEJB_SERVER_REMOTE, "org.apache.openejb.server.util.resources").error("ServerSideResolver.resolve() failed, falling back to ClientSideResolver: " + e.getClass().getName() + ": " + e.getMessage(), e);
return new EJBObjectProxyHandle.ClientSideResovler().resolve(handler);
}
}
use of org.apache.openejb.spi.ContainerSystem 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.spi.ContainerSystem in project tomee by apache.
the class EjbDaemon method init.
public void init(final Properties props) throws Exception {
containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
// deploymentIndex = new DeploymentIndex(containerSystem.deployments());
clientObjectFactory = new ClientObjectFactory(this, props);
ejbHandler = new EjbRequestHandler(this);
jndiHandler = new JndiRequestHandler(this);
authHandler = new AuthRequestHandler(this);
logoutHandler = new LogoutRequestHandler(this);
clusterHandler = new ClusterRequestHandler(this);
gzip = "true".equalsIgnoreCase(props.getProperty("gzip", "false"));
try {
this.timeout = Integer.parseInt(props.getProperty("timeout", "14400000"));
} catch (Exception e) {
//Ignore
}
final String serializer = props.getProperty("serializer", null);
if (serializer != null) {
try {
this.serializer = EJBDSerializer.class.cast(Thread.currentThread().getContextClassLoader().loadClass(serializer).newInstance());
} catch (final ClassNotFoundException | NoClassDefFoundError cnfe) {
// let's try later with app classloader
this.serializer = new ContextualSerializer(serializer);
}
}
final DiscoveryAgent discovery = SystemInstance.get().getComponent(DiscoveryAgent.class);
if (discovery != null) {
discovery.setDiscoveryListener(clusterHandler);
}
countStreams = Boolean.parseBoolean(props.getProperty("stream.count", Boolean.toString(jndiHandler.isDebug())));
securityService = SystemInstance.get().getComponent(SecurityService.class);
}
Aggregations