Search in sources :

Example 26 with ContainerSystem

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());
    }
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) AppContext(org.apache.openejb.AppContext)

Example 27 with ContainerSystem

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);
    }
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) BeanContext(org.apache.openejb.BeanContext) EJBMetaDataImpl(org.apache.openejb.client.EJBMetaDataImpl) InterfaceType(org.apache.openejb.InterfaceType) ArrayList(java.util.ArrayList)

Example 28 with ContainerSystem

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);
    }
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) BeanContext(org.apache.openejb.BeanContext) EJBMetaDataImpl(org.apache.openejb.client.EJBMetaDataImpl) InterfaceType(org.apache.openejb.InterfaceType) ArrayList(java.util.ArrayList)

Example 29 with ContainerSystem

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();
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) InitialContext(javax.naming.InitialContext) BeanContext(org.apache.openejb.BeanContext) Context(javax.naming.Context) ServerFederation(org.apache.openejb.core.ServerFederation) ServicePool(org.apache.openejb.server.ServicePool) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) BeanContext(org.apache.openejb.BeanContext) StatelessBean(org.apache.openejb.jee.StatelessBean) ServiceDaemon(org.apache.openejb.server.ServiceDaemon) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 30 with ContainerSystem

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);
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) DiscoveryAgent(org.apache.openejb.server.DiscoveryAgent) SecurityService(org.apache.openejb.spi.SecurityService) EJBDSerializer(org.apache.openejb.client.serializer.EJBDSerializer)

Aggregations

ContainerSystem (org.apache.openejb.spi.ContainerSystem)64 Assembler (org.apache.openejb.assembler.classic.Assembler)31 BeanContext (org.apache.openejb.BeanContext)22 HashMap (java.util.HashMap)20 Map (java.util.Map)19 File (java.io.File)17 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)13 Context (javax.naming.Context)12 EjbJar (org.apache.openejb.jee.EjbJar)11 StatelessBean (org.apache.openejb.jee.StatelessBean)11 AppContext (org.apache.openejb.AppContext)10 AppInfo (org.apache.openejb.assembler.classic.AppInfo)10 Properties (java.util.Properties)9 EjbModule (org.apache.openejb.config.EjbModule)9 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)9 ArrayList (java.util.ArrayList)8 NamingException (javax.naming.NamingException)8 WebContext (org.apache.openejb.core.WebContext)8 InitialContext (javax.naming.InitialContext)7 NameNotFoundException (javax.naming.NameNotFoundException)6