Search in sources :

Example 91 with Reference

use of javax.naming.Reference in project wildfly by wildfly.

the class InMemoryNamingStoreTestCase method testBindAndLookupResolveResult.

@Test
public void testBindAndLookupResolveResult() throws Exception {
    final Name name = new CompositeName("test");
    final Reference reference = new Reference(Context.class.getName());
    nameStore.bind(name, reference, Context.class);
    final Object result = nameStore.lookup(new CompositeName("test/value"));
    assertTrue(result instanceof ResolveResult);
}
Also used : Context(javax.naming.Context) Reference(javax.naming.Reference) CompositeName(javax.naming.CompositeName) ResolveResult(javax.naming.spi.ResolveResult) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) Test(org.junit.Test)

Example 92 with Reference

use of javax.naming.Reference in project tomee by apache.

the class JndiBuilder method bind.

public void bind(final EjbJarInfo ejbJarInfo, final BeanContext bean, final EnterpriseBeanInfo beanInfo, final JndiNameStrategy strategy) {
    // and we shouldn't need it
    if (BeanContext.Comp.class.equals(bean.getBeanClass())) {
        return;
    }
    final Bindings bindings = new Bindings();
    bean.set(Bindings.class, bindings);
    Reference simpleNameRef = null;
    final Object id = bean.getDeploymentID();
    try {
        if (bean.isLocalbean()) {
            final Class beanClass = bean.getBeanClass();
            final BeanContext.BusinessLocalBeanHome home = bean.getBusinessLocalBeanHome();
            final BusinessLocalBeanReference ref = new BusinessLocalBeanReference(home);
            optionalBind(bindings, ref, "openejb/Deployment/" + format(id, beanClass.getName(), InterfaceType.LOCALBEAN));
            // if the user inject the EJB using a parent class
            if (!bean.getBeanClass().isInterface()) {
                for (Class<?> clazz = bean.getBeanClass().getSuperclass(); !clazz.equals(Object.class); clazz = clazz.getSuperclass()) {
                    optionalBind(bindings, ref, "openejb/Deployment/" + format(id, clazz.getName(), InterfaceType.LOCALBEAN));
                }
            }
            final String internalName = "openejb/Deployment/" + format(id, beanClass.getName(), InterfaceType.BUSINESS_LOCALBEAN_HOME);
            bind(internalName, ref, bindings, beanInfo, beanClass);
            final String name = strategy.getName(beanClass, DEFAULT_NAME_KEY, JndiNameStrategy.Interface.LOCALBEAN);
            bind("openejb/local/" + name, ref, bindings, beanInfo, beanClass);
            bindJava(bean, beanClass, ref, bindings, beanInfo);
            if (USE_OLD_JNDI_NAMES) {
                bean.getModuleContext().getAppContext().getBindings().put(name, ref);
            }
            simpleNameRef = ref;
        }
    } catch (final NamingException e) {
        throw new OpenEJBRuntimeException("Unable to bind business remote deployment in jndi.", e);
    }
    try {
        for (final Class interfce : bean.getBusinessLocalInterfaces()) {
            final BeanContext.BusinessLocalHome home = bean.getBusinessLocalHome(interfce);
            final BusinessLocalReference ref = new BusinessLocalReference(home);
            optionalBind(bindings, ref, "openejb/Deployment/" + format(id, interfce.getName()));
            final String internalName = "openejb/Deployment/" + format(id, interfce.getName(), InterfaceType.BUSINESS_LOCAL);
            bind(internalName, ref, bindings, beanInfo, interfce);
            final String name = strategy.getName(interfce, DEFAULT_NAME_KEY, JndiNameStrategy.Interface.BUSINESS_LOCAL);
            final String externalName = "openejb/local/" + name;
            bind(externalName, ref, bindings, beanInfo, interfce);
            bindJava(bean, interfce, ref, bindings, beanInfo);
            if (USE_OLD_JNDI_NAMES) {
                bean.getModuleContext().getAppContext().getBindings().put(name, ref);
            }
            if (simpleNameRef == null) {
                simpleNameRef = ref;
            }
        }
    } catch (final NamingException e) {
        throw new OpenEJBRuntimeException("Unable to bind business local interface for deployment " + id, e);
    }
    try {
        for (final Class interfce : bean.getBusinessRemoteInterfaces()) {
            final BeanContext.BusinessRemoteHome home = bean.getBusinessRemoteHome(interfce);
            final BusinessRemoteReference ref = new BusinessRemoteReference(home);
            optionalBind(bindings, ref, "openejb/Deployment/" + format(id, interfce.getName(), null));
            final String internalName = "openejb/Deployment/" + format(id, interfce.getName(), InterfaceType.BUSINESS_REMOTE);
            bind(internalName, ref, bindings, beanInfo, interfce);
            final String name = strategy.getName(interfce, DEFAULT_NAME_KEY, JndiNameStrategy.Interface.BUSINESS_REMOTE);
            bind("openejb/local/" + name, ref, bindings, beanInfo, interfce);
            bind("openejb/remote/" + name, ref, bindings, beanInfo, interfce);
            bind("openejb/remote/" + computeGlobalName(bean, interfce), ref, bindings, beanInfo, interfce);
            bindJava(bean, interfce, ref, bindings, beanInfo);
            if (USE_OLD_JNDI_NAMES) {
                bean.getModuleContext().getAppContext().getBindings().put(name, ref);
            }
            if (simpleNameRef == null) {
                simpleNameRef = ref;
            }
        }
    } catch (final NamingException e) {
        throw new OpenEJBRuntimeException("Unable to bind business remote deployment in jndi.", e);
    }
    try {
        final Class localHomeInterface = bean.getLocalHomeInterface();
        if (localHomeInterface != null) {
            final ObjectReference ref = new ObjectReference(bean.getEJBLocalHome());
            String name = strategy.getName(bean.getLocalHomeInterface(), DEFAULT_NAME_KEY, JndiNameStrategy.Interface.LOCAL_HOME);
            bind("openejb/local/" + name, ref, bindings, beanInfo, localHomeInterface);
            optionalBind(bindings, ref, "openejb/Deployment/" + format(id, localHomeInterface.getName(), InterfaceType.EJB_LOCAL_HOME));
            name = "openejb/Deployment/" + format(id, bean.getLocalInterface().getName());
            bind(name, ref, bindings, beanInfo, localHomeInterface);
            name = "openejb/Deployment/" + format(id, bean.getLocalInterface().getName(), InterfaceType.EJB_LOCAL);
            bind(name, ref, bindings, beanInfo, localHomeInterface);
            bindJava(bean, localHomeInterface, ref, bindings, beanInfo);
            if (simpleNameRef == null) {
                simpleNameRef = ref;
            }
        }
    } catch (final NamingException e) {
        throw new OpenEJBRuntimeException("Unable to bind local home interface for deployment " + id, e);
    }
    try {
        final Class homeInterface = bean.getHomeInterface();
        if (homeInterface != null) {
            final ObjectReference ref = new ObjectReference(bean.getEJBHome());
            String name = strategy.getName(homeInterface, DEFAULT_NAME_KEY, JndiNameStrategy.Interface.REMOTE_HOME);
            bind("openejb/local/" + name, ref, bindings, beanInfo, homeInterface);
            bind("openejb/remote/" + name, ref, bindings, beanInfo, homeInterface);
            optionalBind(bindings, ref, "openejb/Deployment/" + format(id, homeInterface.getName(), InterfaceType.EJB_HOME));
            name = "openejb/Deployment/" + format(id, bean.getRemoteInterface().getName());
            bind(name, ref, bindings, beanInfo, homeInterface);
            name = "openejb/Deployment/" + format(id, bean.getRemoteInterface().getName(), InterfaceType.EJB_OBJECT);
            bind(name, ref, bindings, beanInfo, homeInterface);
            bindJava(bean, homeInterface, ref, bindings, beanInfo);
            if (simpleNameRef == null) {
                simpleNameRef = ref;
            }
        }
    } catch (final NamingException e) {
        throw new OpenEJBRuntimeException("Unable to bind remote home interface for deployment " + id, e);
    }
    try {
        if (simpleNameRef != null) {
            bindJava(bean, null, simpleNameRef, bindings, beanInfo);
        }
    } catch (final NamingException e) {
        throw new OpenEJBRuntimeException("Unable to bind simple java:global name in jndi", e);
    }
    try {
        if (MessageListener.class.equals(bean.getMdbInterface())) {
            final String destinationId = bean.getDestinationId();
            final String jndiName = "openejb/Resource/" + destinationId;
            final Reference reference = new IntraVmJndiReference(jndiName);
            final String deploymentId = id.toString();
            bind("openejb/local/" + deploymentId, reference, bindings, beanInfo, MessageListener.class);
            bind("openejb/remote/" + deploymentId, reference, bindings, beanInfo, MessageListener.class);
        }
    } catch (final NamingException e) {
        throw new OpenEJBRuntimeException("Unable to bind mdb destination in jndi.", e);
    } catch (final NoClassDefFoundError ncdfe) {
    // no-op: no jms API
    }
}
Also used : IntraVmJndiReference(org.apache.openejb.core.ivm.naming.IntraVmJndiReference) ObjectReference(org.apache.openejb.core.ivm.naming.ObjectReference) BusinessRemoteReference(org.apache.openejb.core.ivm.naming.BusinessRemoteReference) BusinessLocalBeanReference(org.apache.openejb.core.ivm.naming.BusinessLocalBeanReference) Reference(javax.naming.Reference) BusinessLocalReference(org.apache.openejb.core.ivm.naming.BusinessLocalReference) BusinessLocalReference(org.apache.openejb.core.ivm.naming.BusinessLocalReference) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) BeanContext(org.apache.openejb.BeanContext) IntraVmJndiReference(org.apache.openejb.core.ivm.naming.IntraVmJndiReference) ObjectReference(org.apache.openejb.core.ivm.naming.ObjectReference) BusinessLocalBeanReference(org.apache.openejb.core.ivm.naming.BusinessLocalBeanReference) NamingException(javax.naming.NamingException) BusinessRemoteReference(org.apache.openejb.core.ivm.naming.BusinessRemoteReference)

Example 93 with Reference

use of javax.naming.Reference in project tomee by apache.

the class TomcatWebAppBuilder method startInternal.

/**
 * {@inheritDoc}
 */
// @Override
private void startInternal(final StandardContext standardContext) {
    if (isIgnored(standardContext)) {
        return;
    }
    if (shouldNotDeploy(standardContext)) {
        return;
    }
    final CoreContainerSystem cs = getContainerSystem();
    final Assembler a = getAssembler();
    if (a == null) {
        LOGGER.warning("OpenEJB has not been initialized so war will not be scanned for nested modules " + standardContext.getPath());
        return;
    }
    AppContext appContext = null;
    // Look for context info, maybe context is already scanned
    ContextInfo contextInfo = getContextInfo(standardContext);
    ClassLoader classLoader = standardContext.getLoader().getClassLoader();
    // bind jta before the app starts to ensure we have it in CDI
    final Thread thread = Thread.currentThread();
    final ClassLoader originalLoader = thread.getContextClassLoader();
    thread.setContextClassLoader(classLoader);
    final String listenerName = standardContext.getNamingContextListener().getName();
    ContextAccessController.setWritable(listenerName, standardContext.getNamingToken());
    try {
        final Context comp = Context.class.cast(ContextBindings.getClassLoader().lookup("comp"));
        // bind TransactionManager
        final TransactionManager transactionManager = SystemInstance.get().getComponent(TransactionManager.class);
        safeBind(comp, "TransactionManager", transactionManager);
        // bind TransactionSynchronizationRegistry
        final TransactionSynchronizationRegistry synchronizationRegistry = SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class);
        safeBind(comp, "TransactionSynchronizationRegistry", synchronizationRegistry);
    } catch (final NamingException e) {
    // no-op
    } finally {
        thread.setContextClassLoader(originalLoader);
        ContextAccessController.setReadOnly(listenerName);
    }
    if (contextInfo == null) {
        final AppModule appModule = loadApplication(standardContext);
        appModule.getProperties().put("loader.from", "tomcat");
        final boolean skipTomeeResourceWrapping = !"true".equalsIgnoreCase(SystemInstance.get().getProperty("tomee.tomcat.resource.wrap", "true"));
        if (!skipTomeeResourceWrapping && OpenEJBNamingResource.class.isInstance(standardContext.getNamingResources())) {
            // we can get the same resource twice as in tomcat
            final Collection<String> importedNames = new ArrayList<>();
            // add them to the app as resource
            final boolean forceDataSourceWrapping = "true".equalsIgnoreCase(SystemInstance.get().getProperty("tomee.tomcat.datasource.wrap", "false"));
            final OpenEJBNamingResource nr = (OpenEJBNamingResource) standardContext.getNamingResources();
            for (final ResourceBase resource : nr.getTomcatResources()) {
                final String name = resource.getName();
                // already init (org.apache.catalina.core.NamingContextListener.addResource())
                // skip wrapping to ensure resource consistency
                final boolean isDataSource = DataSource.class.getName().equals(resource.getType());
                final boolean isAlreadyCreated = ContextResource.class.isInstance(resource) && ContextResource.class.cast(resource).getSingleton() && isDataSource;
                if (!importedNames.contains(name)) {
                    importedNames.add(name);
                } else {
                    continue;
                }
                boolean found = false;
                for (final ResourceInfo r : SystemInstance.get().getComponent(OpenEjbConfiguration.class).facilities.resources) {
                    if (r.id.equals(name)) {
                        nr.removeResource(name);
                        found = true;
                        LOGGER.warning(name + " resource was defined in both tomcat and tomee so removing tomcat one");
                        break;
                    }
                }
                if (!found) {
                    final Resource newResource;
                    if (forceDataSourceWrapping || (!isAlreadyCreated && isDataSource)) {
                        // we forward it to TomEE datasources
                        newResource = new Resource(name, resource.getType());
                        boolean jta = false;
                        final Properties properties = newResource.getProperties();
                        final Iterator<String> params = resource.listProperties();
                        while (params.hasNext()) {
                            final String paramName = params.next();
                            final String paramValue = (String) resource.getProperty(paramName);
                            // handling some param name conversion to OpenEJB style
                            if ("driverClassName".equals(paramName)) {
                                properties.setProperty("JdbcDriver", paramValue);
                            } else if ("url".equals(paramName)) {
                                properties.setProperty("JdbcUrl", paramValue);
                            } else {
                                properties.setProperty(paramName, paramValue);
                            }
                            if ("JtaManaged".equalsIgnoreCase(paramName)) {
                                jta = Boolean.parseBoolean(paramValue);
                            }
                        }
                        if (!jta) {
                            properties.setProperty("JtaManaged", "false");
                        }
                    } else {
                        // custom type, let it be created
                        newResource = new Resource(name, resource.getType(), "org.apache.tomee:ProvidedByTomcat");
                        final Properties properties = newResource.getProperties();
                        properties.setProperty("jndiName", newResource.getId());
                        properties.setProperty("appName", getId(standardContext));
                        properties.setProperty("factory", (String) resource.getProperty("factory"));
                        final Reference reference = createReference(resource);
                        if (reference != null) {
                            properties.put("reference", reference);
                        }
                    }
                    appModule.getResources().add(newResource);
                }
            }
        }
        if (appModule != null) {
            try {
                contextInfo = addContextInfo(Contexts.getHostname(standardContext), standardContext);
                // ensure to do it before an exception can be thrown
                contextInfo.standardContext = standardContext;
                contextInfo.appInfo = configurationFactory.configureApplication(appModule);
                final Boolean autoDeploy = DeployerEjb.AUTO_DEPLOY.get();
                contextInfo.appInfo.autoDeploy = autoDeploy == null || autoDeploy;
                DeployerEjb.AUTO_DEPLOY.remove();
                if (!appModule.isWebapp()) {
                    classLoader = appModule.getClassLoader();
                } else {
                    final ClassLoader loader = standardContext.getLoader().getClassLoader();
                    if (loader instanceof TomEEWebappClassLoader) {
                        final TomEEWebappClassLoader tomEEWebappClassLoader = (TomEEWebappClassLoader) loader;
                        for (final URL url : appModule.getWebModules().iterator().next().getAddedUrls()) {
                            tomEEWebappClassLoader.addURL(url);
                        }
                    }
                }
                setFinderOnContextConfig(standardContext, appModule);
                servletContextHandler.getContexts().put(classLoader, standardContext.getServletContext());
                try {
                    appContext = a.createApplication(contextInfo.appInfo, classLoader);
                } finally {
                    servletContextHandler.getContexts().remove(classLoader);
                }
                // todo add watched resources to context
                eagerInitOfLocalBeanProxies(appContext.getBeanContexts(), classLoader);
            } catch (final Exception e) {
                LOGGER.error("Unable to deploy collapsed ear in war " + standardContext, e);
                undeploy(standardContext, contextInfo);
                // just to force tomee to start without EE part
                if (System.getProperty(TomEESystemConfig.TOMEE_EAT_EXCEPTION_PROP) == null) {
                    final TomEERuntimeException tre = new TomEERuntimeException(e);
                    final DeploymentExceptionManager dem = SystemInstance.get().getComponent(DeploymentExceptionManager.class);
                    dem.saveDeploymentException(contextInfo.appInfo, tre);
                    throw tre;
                }
                return;
            }
        }
    } else {
        contextInfo.standardContext = standardContext;
        if (contextInfo.module != null && contextInfo.module.getFinder() != null) {
            // TODO: make it more explicit or less hacky not using properties
            final OpenEJBContextConfig openEJBContextConfig = findOpenEJBContextConfig(standardContext);
            if (openEJBContextConfig != null) {
                openEJBContextConfig.finder(contextInfo.module.getFinder(), contextInfo.module.getClassLoader());
            }
        }
    }
    final String id = getId(standardContext);
    WebAppInfo webAppInfo = null;
    // appInfo is null when deployment fails
    if (contextInfo.appInfo != null) {
        for (final WebAppInfo w : contextInfo.appInfo.webApps) {
            if (id.equals(getId(w.host, w.contextRoot, contextInfo.version)) || id.equals(getId(w.host, w.moduleId, contextInfo.version))) {
                if (webAppInfo == null) {
                    webAppInfo = w;
                } else if (w.host != null && w.host.equals(Contexts.getHostname(standardContext))) {
                    webAppInfo = w;
                }
                break;
            }
        }
        if (appContext == null) {
            appContext = cs.getAppContext(contextInfo.appInfo.appId);
        }
    }
    if (webAppInfo != null) {
        if (appContext == null) {
            appContext = getContainerSystem().getAppContext(contextInfo.appInfo.appId);
        }
        // ensure matching (see getId() usage)
        webAppInfo.host = Contexts.getHostname(standardContext);
        webAppInfo.contextRoot = standardContext.getPath();
        // save jsf stuff
        final Map<String, Set<String>> scannedJsfClasses = new HashMap<>();
        for (final ClassListInfo info : webAppInfo.jsfAnnotatedClasses) {
            scannedJsfClasses.put(info.name, info.list);
        }
        jsfClasses.put(classLoader, scannedJsfClasses);
        try {
            // determine the injections
            final Set<Injection> injections = new HashSet<>();
            injections.addAll(appContext.getInjections());
            if (!contextInfo.appInfo.webAppAlone) {
                updateInjections(injections, classLoader, false);
                for (final BeanContext bean : appContext.getBeanContexts()) {
                    // TODO: how if the same class in multiple webapps?
                    updateInjections(bean.getInjections(), classLoader, true);
                }
            }
            injections.addAll(new InjectionBuilder(classLoader).buildInjections(webAppInfo.jndiEnc));
            // merge OpenEJB jndi into Tomcat jndi
            final TomcatJndiBuilder jndiBuilder = new TomcatJndiBuilder(standardContext, webAppInfo, injections);
            NamingUtil.setCurrentContext(standardContext);
            try {
                jndiBuilder.mergeJndi();
            } finally {
                NamingUtil.setCurrentContext(null);
            }
            // create EMF included in this webapp when nested in an ear
            for (final PersistenceUnitInfo unitInfo : contextInfo.appInfo.persistenceUnits) {
                if (unitInfo.webappName != null && unitInfo.webappName.equals(webAppInfo.moduleId)) {
                    try {
                        final ReloadableEntityManagerFactory remf = (ReloadableEntityManagerFactory) SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext().lookup(Assembler.PERSISTENCE_UNIT_NAMING_CONTEXT + unitInfo.id);
                        remf.overrideClassLoader(classLoader);
                        remf.createDelegate();
                    } catch (final NameNotFoundException nnfe) {
                        LOGGER.warning("Can't find " + unitInfo.id + " persistence unit");
                    }
                }
            }
            // add WebDeploymentInfo to ContainerSystem
            final WebContext webContext = new WebContext(appContext);
            webContext.setServletContext(standardContext.getServletContext());
            webContext.setJndiEnc(new InitialContext());
            webContext.setClassLoader(classLoader);
            webContext.setId(webAppInfo.moduleId);
            webContext.setContextRoot(webAppInfo.contextRoot);
            webContext.setHost(webAppInfo.host);
            webContext.setBindings(new HashMap<String, Object>());
            webContext.getInjections().addAll(injections);
            appContext.getWebContexts().add(webContext);
            cs.addWebContext(webContext);
            standardContext.getServletContext().setAttribute("openejb.web.context", webContext);
            if (!contextInfo.appInfo.webAppAlone) {
                final List<BeanContext> beanContexts = assembler.initEjbs(classLoader, contextInfo.appInfo, appContext, injections, new ArrayList<BeanContext>(), webAppInfo.moduleId);
                OpenEJBLifecycle.CURRENT_APP_INFO.set(contextInfo.appInfo);
                servletContextHandler.getContexts().put(classLoader, standardContext.getServletContext());
                try {
                    new CdiBuilder().build(contextInfo.appInfo, appContext, beanContexts, webContext);
                } catch (final Exception e) {
                    final DeploymentExceptionManager dem = SystemInstance.get().getComponent(DeploymentExceptionManager.class);
                    if (dem != null) {
                        dem.saveDeploymentException(contextInfo.appInfo, e);
                    }
                    throw e;
                } finally {
                    servletContextHandler.getContexts().remove(classLoader);
                    OpenEJBLifecycle.CURRENT_APP_INFO.remove();
                }
                assembler.startEjbs(true, beanContexts);
                assembler.bindGlobals(appContext.getBindings());
                eagerInitOfLocalBeanProxies(beanContexts, standardContext.getLoader().getClassLoader());
                deployWebServicesIfEjbCreatedHere(contextInfo.appInfo, beanContexts);
            }
            // jndi bindings
            webContext.getBindings().putAll(appContext.getBindings());
            webContext.getBindings().putAll(getJndiBuilder(classLoader, webAppInfo, injections, appContext.getProperties()).buildBindings(JndiEncBuilder.JndiScope.comp));
            final JavaeeInstanceManager instanceManager = new JavaeeInstanceManager(standardContext, webContext);
            standardContext.setInstanceManager(instanceManager);
            instanceManagers.put(classLoader, instanceManager);
            standardContext.getServletContext().setAttribute(InstanceManager.class.getName(), standardContext.getInstanceManager());
        } catch (final Exception e) {
            LOGGER.error("Error merging Java EE JNDI entries in to war " + standardContext.getPath() + ": Exception: " + e.getMessage(), e);
            if (System.getProperty(TomEESystemConfig.TOMEE_EAT_EXCEPTION_PROP) == null) {
                final DeploymentExceptionManager dem = SystemInstance.get().getComponent(DeploymentExceptionManager.class);
                if (dem != null && dem.getDeploymentException(contextInfo.appInfo) != null) {
                    if (RuntimeException.class.isInstance(e)) {
                        throw RuntimeException.class.cast(e);
                    }
                    throw new TomEERuntimeException(e);
                }
            }
        }
        final WebBeansContext webBeansContext = appContext.getWebBeansContext();
        if (webBeansContext != null && webBeansContext.getBeanManagerImpl().isInUse()) {
            OpenEJBLifecycle.initializeServletContext(standardContext.getServletContext(), webBeansContext);
        }
    }
    // router
    final URL routerConfig = RouterValve.configurationURL(standardContext.getServletContext());
    if (routerConfig != null) {
        final RouterValve filter = new RouterValve();
        filter.setPrefix(standardContext.getName());
        filter.setConfigurationPath(routerConfig);
        standardContext.getPipeline().addValve(filter);
    }
    // register realm to have it in TomcatSecurityService
    final Realm realm = standardContext.getRealm();
    realms.put(standardContext.getName(), realm);
}
Also used : CoreContainerSystem(org.apache.openejb.core.CoreContainerSystem) ContainerSystem(org.apache.openejb.spi.ContainerSystem) AppModule(org.apache.openejb.config.AppModule) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) InstanceManager(org.apache.tomcat.InstanceManager) ArrayList(java.util.ArrayList) RouterValve(org.apache.tomee.catalina.routing.RouterValve) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) NamingException(javax.naming.NamingException) DeploymentExceptionManager(org.apache.openejb.assembler.classic.DeploymentExceptionManager) HashSet(java.util.HashSet) InjectionBuilder(org.apache.openejb.assembler.classic.InjectionBuilder) ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) ContextResource(org.apache.tomcat.util.descriptor.web.ContextResource) WebResource(org.apache.catalina.WebResource) Resource(org.apache.openejb.config.sys.Resource) OpenEJBContextConfig(org.apache.catalina.startup.OpenEJBContextConfig) CoreContainerSystem(org.apache.openejb.core.CoreContainerSystem) Injection(org.apache.openejb.Injection) DataSource(javax.sql.DataSource) ContextResource(org.apache.tomcat.util.descriptor.web.ContextResource) BeanContext(org.apache.openejb.BeanContext) TransactionManager(javax.transaction.TransactionManager) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) CdiBuilder(org.apache.openejb.cdi.CdiBuilder) Assembler(org.apache.openejb.assembler.classic.Assembler) DirResourceSet(org.apache.catalina.webresources.DirResourceSet) Set(java.util.Set) WebResourceSet(org.apache.catalina.WebResourceSet) HashSet(java.util.HashSet) WebContext(org.apache.openejb.core.WebContext) ResourceBase(org.apache.tomcat.util.descriptor.web.ResourceBase) Properties(java.util.Properties) URL(java.net.URL) ClassListInfo(org.apache.openejb.assembler.classic.ClassListInfo) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) WebBeansContext(org.apache.webbeans.config.WebBeansContext) Realm(org.apache.catalina.Realm) WebContext(org.apache.openejb.core.WebContext) InitialContext(javax.naming.InitialContext) WebBeansContext(org.apache.webbeans.config.WebBeansContext) BeanContext(org.apache.openejb.BeanContext) Context(javax.naming.Context) ServletContext(javax.servlet.ServletContext) PolicyContext(org.apache.openejb.assembler.classic.PolicyContext) AppContext(org.apache.openejb.AppContext) StandardContext(org.apache.catalina.core.StandardContext) NameNotFoundException(javax.naming.NameNotFoundException) SystemComponentReference(org.apache.openejb.core.ivm.naming.SystemComponentReference) Reference(javax.naming.Reference) AtomicReference(java.util.concurrent.atomic.AtomicReference) AppContext(org.apache.openejb.AppContext) PersistenceUnitInfo(org.apache.openejb.assembler.classic.PersistenceUnitInfo) LifecycleException(org.apache.catalina.LifecycleException) NameNotFoundException(javax.naming.NameNotFoundException) IOException(java.io.IOException) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) InitialContext(javax.naming.InitialContext) ReloadableEntityManagerFactory(org.apache.openejb.assembler.classic.ReloadableEntityManagerFactory)

Example 94 with Reference

use of javax.naming.Reference in project tomee by apache.

the class TomcatWebAppBuilder method createReference.

private static Reference createReference(final ResourceBase resource) {
    final Reference ref;
    if (resource instanceof ContextResource) {
        final ContextResource cr = (ContextResource) resource;
        ref = new ResourceRef(resource.getType(), resource.getDescription(), cr.getScope(), cr.getAuth(), cr.getSingleton());
    } else {
        ref = new ResourceEnvRef(resource.getType());
    }
    final Iterator<String> params = resource.listProperties();
    while (params.hasNext()) {
        final String paramName = params.next();
        final String paramValue = (String) resource.getProperty(paramName);
        final StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
        ref.add(refAddr);
    }
    return ref;
}
Also used : StringRefAddr(javax.naming.StringRefAddr) SystemComponentReference(org.apache.openejb.core.ivm.naming.SystemComponentReference) Reference(javax.naming.Reference) AtomicReference(java.util.concurrent.atomic.AtomicReference) ResourceRef(org.apache.naming.ResourceRef) ResourceEnvRef(org.apache.naming.ResourceEnvRef) ContextResource(org.apache.tomcat.util.descriptor.web.ContextResource)

Example 95 with Reference

use of javax.naming.Reference in project tomee by apache.

the class SystemComponentFactory method getObjectInstance.

@Override
public Object getObjectInstance(final Object object, final Name name, final Context context, final Hashtable environment) throws Exception {
    final Reference ref = (Reference) object;
    // load the component type class
    final String className = getProperty(ref, COMPONENT_TYPE);
    final Class<?> clazz = loadClass(className);
    if (clazz == null) {
        return null;
    }
    // lookup the value
    final Object value = SystemInstance.get().getComponent(clazz);
    return value;
}
Also used : Reference(javax.naming.Reference)

Aggregations

Reference (javax.naming.Reference)226 NamingException (javax.naming.NamingException)79 RefAddr (javax.naming.RefAddr)59 StringRefAddr (javax.naming.StringRefAddr)54 Context (javax.naming.Context)41 NameNotFoundException (javax.naming.NameNotFoundException)40 InitialContext (javax.naming.InitialContext)37 Test (org.junit.Test)33 Name (javax.naming.Name)30 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)28 Properties (java.util.Properties)26 OperationNotSupportedException (javax.naming.OperationNotSupportedException)25 NotContextException (javax.naming.NotContextException)24 ObjectFactory (javax.naming.spi.ObjectFactory)23 CompositeName (javax.naming.CompositeName)21 Referenceable (javax.naming.Referenceable)18 Binding (javax.naming.Binding)17 CompoundName (javax.naming.CompoundName)16 LinkRef (javax.naming.LinkRef)15 Hashtable (java.util.Hashtable)12