Search in sources :

Example 96 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class RESTService method afterApplicationCreated.

public void afterApplicationCreated(@Observes final AssemblerAfterApplicationCreated event) {
    if (!enabled)
        return;
    final AppInfo appInfo = event.getApp();
    if ("false".equalsIgnoreCase(appInfo.properties.getProperty("openejb.jaxrs.on", "true"))) {
        return;
    }
    quickCheckIfOldDeploymentShouldBeUsedFromEjbConfig(appInfo);
    if (deployedApplications.add(appInfo)) {
        if (appInfo.webApps.size() == 0) {
            final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
            final ClassLoader appClassLoader = getClassLoader(containerSystem.getAppContext(appInfo.appId).getClassLoader());
            Thread.currentThread().setContextClassLoader(appClassLoader);
            try {
                final Map<String, EJBRestServiceInfo> restEjbs = getRestEjbs(appInfo, null);
                if (restEjbs.isEmpty()) {
                    return;
                }
                final Collection<Object> providers;
                if (useDiscoveredProviders(appInfo)) {
                    providers = appProviders(appInfo.jaxRsProviders, appClassLoader);
                } else {
                    providers = new ArrayList<>();
                }
                if ("true".equalsIgnoreCase(appInfo.properties.getProperty(OPENEJB_USE_APPLICATION_PROPERTY, APPLICATION_DEPLOYMENT))) {
                    final Application application = new InternalApplication(null);
                    addEjbToApplication(application, restEjbs);
                    // merge configurations at app level since a single deployment is available
                    final List<IdPropertiesInfo> pojoConfigurations = new ArrayList<>();
                    BeanContext comp = null;
                    for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
                        for (final EnterpriseBeanInfo bean : ejbJar.enterpriseBeans) {
                            if (comp != null) {
                                break;
                            }
                            if (bean.ejbClass.equals(BeanContext.Comp.class.getName())) {
                                comp = containerSystem.getBeanContext(bean.ejbDeploymentId);
                                break;
                            }
                        }
                        if (ejbJar.pojoConfigurations != null) {
                            pojoConfigurations.addAll(ejbJar.pojoConfigurations);
                        }
                    }
                    if (appInfo.pojoConfigurations != null) {
                        pojoConfigurations.addAll(appInfo.pojoConfigurations);
                    }
                    final Map.Entry<String, EJBRestServiceInfo> next = restEjbs.entrySet().iterator().next();
                    if (comp == null) {
                        comp = next.getValue().context;
                    }
                    deployApplication(appInfo, next.getValue().path, restEjbs, comp.getClassLoader(), comp.getInjections(), containerSystem.getAppContext(appInfo.appId).getWebBeansContext(), comp.getJndiContext(), providers, pojoConfigurations, application, wildcard);
                } else {
                    for (final Map.Entry<String, EJBRestServiceInfo> ejb : restEjbs.entrySet()) {
                        final BeanContext ctx = ejb.getValue().context;
                        if (BeanType.MANAGED.equals(ctx.getComponentType())) {
                            deployPojo(appInfo.appId, "", ejb.getValue().path, ctx.getBeanClass(), null, ctx.getClassLoader(), ctx.getInjections(), ctx.getJndiContext(), containerSystem.getAppContext(appInfo.appId).getWebBeansContext(), providers, new ServiceConfiguration(ctx.getProperties(), appInfo.services));
                        } else {
                            deployEJB(appInfo.appId, "", ejb.getValue().path, ctx, providers, appInfo.services);
                        }
                    }
                }
            } finally {
                Thread.currentThread().setContextClassLoader(oldLoader);
            }
        } else {
            for (final WebAppInfo webApp : appInfo.webApps) {
                afterApplicationCreated(appInfo, webApp);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) BeanContext(org.apache.openejb.BeanContext) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) ServiceConfiguration(org.apache.openejb.assembler.classic.util.ServiceConfiguration) IdPropertiesInfo(org.apache.openejb.assembler.classic.IdPropertiesInfo) Application(javax.ws.rs.core.Application) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) Map(java.util.Map) HashMap(java.util.HashMap)

Example 97 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class ReloadingLoaderTest method initContext.

@Before
public void initContext() throws LifecycleException {
    final OpenEjbConfiguration configuration = new OpenEjbConfiguration();
    configuration.facilities = new FacilitiesInfo();
    final CoreContainerSystem containerSystem = new CoreContainerSystem(new IvmJndiFactory());
    SystemInstance.get().setComponent(OpenEjbConfiguration.class, configuration);
    SystemInstance.get().setComponent(ContainerSystem.class, containerSystem);
    SystemInstance.get().setComponent(WebAppEnricher.class, new WebAppEnricher() {

        @Override
        public URL[] enrichment(final ClassLoader webappClassLaoder) {
            return new URL[0];
        }
    });
    parentInstance = new AtomicReference<>(ParentClassLoaderFinder.Helper.get());
    loader = new TomEEWebappClassLoader(parentInstance.get()) {

        @Override
        public ClassLoader getInternalParent() {
            return parentInstance.get();
        }

        @Override
        protected void clearReferences() {
        // no-op: this test should be reworked to support it but in real life a loader is not stopped/started
        }
    };
    loader.init();
    final StandardRoot resources = new StandardRoot();
    loader.setResources(resources);
    resources.setContext(new StandardContext() {

        @Override
        public String getDocBase() {
            final File file = new File("target/foo");
            file.mkdirs();
            return file.getAbsolutePath();
        }

        @Override
        public String getMBeanKeyProperties() {
            return "foo";
        }

        {
        }
    });
    resources.start();
    loader.start();
    info = new AppInfo();
    info.appId = "test";
    context = new AppContext(info.appId, SystemInstance.get(), loader, new IvmContext(), new IvmContext(), true);
    containerSystem.addAppContext(context);
    final WebContext webDeployment = new WebContext(context);
    webDeployment.setId(context.getId());
    webDeployment.setClassLoader(loader);
    containerSystem.addWebContext(webDeployment);
}
Also used : IvmContext(org.apache.openejb.core.ivm.naming.IvmContext) WebContext(org.apache.openejb.core.WebContext) AppContext(org.apache.openejb.AppContext) StandardRoot(org.apache.catalina.webresources.StandardRoot) IvmJndiFactory(org.apache.openejb.core.ivm.naming.IvmJndiFactory) TomEEWebappClassLoader(org.apache.tomee.catalina.TomEEWebappClassLoader) CoreContainerSystem(org.apache.openejb.core.CoreContainerSystem) WebAppEnricher(org.apache.openejb.classloader.WebAppEnricher) OpenEjbConfiguration(org.apache.openejb.assembler.classic.OpenEjbConfiguration) AppInfo(org.apache.openejb.assembler.classic.AppInfo) FacilitiesInfo(org.apache.openejb.assembler.classic.FacilitiesInfo) StandardContext(org.apache.catalina.core.StandardContext) TomEEWebappClassLoader(org.apache.tomee.catalina.TomEEWebappClassLoader) URLClassLoader(java.net.URLClassLoader) File(java.io.File) Before(org.junit.Before)

Example 98 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class HessianService method start.

@Override
public void start() throws ServiceException {
    SystemInstance.get().addObserver(this);
    SystemInstance.get().setComponent(HessianService.class, this);
    registry = setRegistry();
    final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    if (assembler != null) {
        for (final AppInfo appInfo : assembler.getDeployedApplications()) {
            deploy(new AssemblerAfterApplicationCreated(appInfo, SystemInstance.get().getComponent(ContainerSystem.class).getAppContext(appInfo.appId), null));
        }
    }
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) AssemblerAfterApplicationCreated(org.apache.openejb.assembler.classic.event.AssemblerAfterApplicationCreated) Assembler(org.apache.openejb.assembler.classic.Assembler) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 99 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class WsService method stop.

@Override
public void stop() throws ServiceException {
    if (assembler != null) {
        SystemInstance.get().removeObserver(this);
        for (final AppInfo appInfo : new ArrayList<AppInfo>(deployedApplications.keySet())) {
            undeploy(new AssemblerBeforeApplicationDestroyed(appInfo, null));
        }
        assembler = null;
        if (SystemInstance.get().getComponent(WsService.class) == this) {
            SystemInstance.get().removeComponent(WsService.class);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) AssemblerBeforeApplicationDestroyed(org.apache.openejb.assembler.classic.event.AssemblerBeforeApplicationDestroyed) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 100 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class WsService method start.

@Override
public void start() throws ServiceException {
    wsRegistry = SystemInstance.get().getComponent(WsRegistry.class);
    if (wsRegistry == null && SystemInstance.get().getComponent(HttpListenerRegistry.class) != null) {
        wsRegistry = new OpenEJBHttpWsRegistry();
    }
    if (portAddressRegistry == null) {
        portAddressRegistry = new PortAddressRegistryImpl();
        SystemInstance.get().setComponent(PortAddressRegistry.class, portAddressRegistry);
    }
    containerSystem = (CoreContainerSystem) SystemInstance.get().getComponent(ContainerSystem.class);
    portAddressRegistry = SystemInstance.get().getComponent(PortAddressRegistry.class);
    assembler = SystemInstance.get().getComponent(Assembler.class);
    SystemInstance.get().setComponent(WsService.class, this);
    if (assembler != null) {
        SystemInstance.get().addObserver(this);
        for (final AppInfo appInfo : assembler.getDeployedApplications()) {
            final AppContext appContext = containerSystem.getAppContext(appInfo.appId);
            deploy(new AssemblerAfterApplicationCreated(appInfo, appContext, null));
        }
    }
}
Also used : AppContext(org.apache.openejb.AppContext) PortAddressRegistryImpl(org.apache.openejb.core.webservices.PortAddressRegistryImpl) AssemblerAfterApplicationCreated(org.apache.openejb.assembler.classic.event.AssemblerAfterApplicationCreated) Assembler(org.apache.openejb.assembler.classic.Assembler) PortAddressRegistry(org.apache.openejb.core.webservices.PortAddressRegistry) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Aggregations

AppInfo (org.apache.openejb.assembler.classic.AppInfo)106 File (java.io.File)50 Assembler (org.apache.openejb.assembler.classic.Assembler)46 Test (org.junit.Test)31 HashMap (java.util.HashMap)29 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)25 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)16 OpenEJBException (org.apache.openejb.OpenEJBException)15 AppModule (org.apache.openejb.config.AppModule)14 Map (java.util.Map)13 EjbJar (org.apache.openejb.jee.EjbJar)13 ContainerSystem (org.apache.openejb.spi.ContainerSystem)13 Properties (java.util.Properties)10 EjbModule (org.apache.openejb.config.EjbModule)10 Persistence (org.apache.openejb.jee.jpa.unit.Persistence)10 ArrayList (java.util.ArrayList)9 PersistenceUnit (org.apache.openejb.jee.jpa.unit.PersistenceUnit)9 IOException (java.io.IOException)8 URL (java.net.URL)8 InitialContext (javax.naming.InitialContext)8