Search in sources :

Example 11 with ContextResourceEnvRef

use of org.apache.tomcat.util.descriptor.web.ContextResourceEnvRef in project tomcat by apache.

the class NamingContextListener method createNamingContext.

/**
     * Create and initialize the JNDI naming context.
     */
private void createNamingContext() throws NamingException {
    // Creating the comp subcontext
    if (container instanceof Server) {
        compCtx = namingContext;
        envCtx = namingContext;
    } else {
        compCtx = namingContext.createSubcontext("comp");
        envCtx = compCtx.createSubcontext("env");
    }
    int i;
    if (log.isDebugEnabled())
        log.debug("Creating JNDI naming context");
    if (namingResources == null) {
        namingResources = new NamingResourcesImpl();
        namingResources.setContainer(container);
    }
    // Resource links
    ContextResourceLink[] resourceLinks = namingResources.findResourceLinks();
    for (i = 0; i < resourceLinks.length; i++) {
        addResourceLink(resourceLinks[i]);
    }
    // Resources
    ContextResource[] resources = namingResources.findResources();
    for (i = 0; i < resources.length; i++) {
        addResource(resources[i]);
    }
    // Resources Env
    ContextResourceEnvRef[] resourceEnvRefs = namingResources.findResourceEnvRefs();
    for (i = 0; i < resourceEnvRefs.length; i++) {
        addResourceEnvRef(resourceEnvRefs[i]);
    }
    // Environment entries
    ContextEnvironment[] contextEnvironments = namingResources.findEnvironments();
    for (i = 0; i < contextEnvironments.length; i++) {
        addEnvironment(contextEnvironments[i]);
    }
    // EJB references
    ContextEjb[] ejbs = namingResources.findEjbs();
    for (i = 0; i < ejbs.length; i++) {
        addEjb(ejbs[i]);
    }
    // WebServices references
    ContextService[] services = namingResources.findServices();
    for (i = 0; i < services.length; i++) {
        addService(services[i]);
    }
    // Binding a User Transaction reference
    if (container instanceof Context) {
        try {
            Reference ref = new TransactionRef();
            compCtx.bind("UserTransaction", ref);
            ContextTransaction transaction = namingResources.getTransaction();
            if (transaction != null) {
                Iterator<String> params = transaction.listProperties();
                while (params.hasNext()) {
                    String paramName = params.next();
                    String paramValue = (String) transaction.getProperty(paramName);
                    StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
                    ref.add(refAddr);
                }
            }
        } catch (NameAlreadyBoundException e) {
        // Ignore because UserTransaction was obviously
        // added via ResourceLink
        } catch (NamingException e) {
            log.error(sm.getString("naming.bindFailed", e));
        }
    }
    // Binding the resources directory context
    if (container instanceof Context) {
        try {
            compCtx.bind("Resources", ((Context) container).getResources());
        } catch (NamingException e) {
            log.error(sm.getString("naming.bindFailed", e));
        }
    }
}
Also used : ContextEnvironment(org.apache.tomcat.util.descriptor.web.ContextEnvironment) NamingContext(org.apache.naming.NamingContext) Context(org.apache.catalina.Context) ContextService(org.apache.tomcat.util.descriptor.web.ContextService) Server(org.apache.catalina.Server) ContextResourceLink(org.apache.tomcat.util.descriptor.web.ContextResourceLink) Reference(javax.naming.Reference) ContextTransaction(org.apache.tomcat.util.descriptor.web.ContextTransaction) ContextEjb(org.apache.tomcat.util.descriptor.web.ContextEjb) ContextResource(org.apache.tomcat.util.descriptor.web.ContextResource) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) StringRefAddr(javax.naming.StringRefAddr) TransactionRef(org.apache.naming.TransactionRef) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) NamingException(javax.naming.NamingException) ContextResourceEnvRef(org.apache.tomcat.util.descriptor.web.ContextResourceEnvRef)

Aggregations

ContextResourceEnvRef (org.apache.tomcat.util.descriptor.web.ContextResourceEnvRef)11 ContextEnvironment (org.apache.tomcat.util.descriptor.web.ContextEnvironment)7 ContextResource (org.apache.tomcat.util.descriptor.web.ContextResource)6 ContextEjb (org.apache.tomcat.util.descriptor.web.ContextEjb)5 ContextResourceLink (org.apache.tomcat.util.descriptor.web.ContextResourceLink)4 ContextService (org.apache.tomcat.util.descriptor.web.ContextService)4 ContextLocalEjb (org.apache.tomcat.util.descriptor.web.ContextLocalEjb)3 NamingException (javax.naming.NamingException)2 Reference (javax.naming.Reference)2 StringRefAddr (javax.naming.StringRefAddr)2 NamingResourcesImpl (org.apache.catalina.deploy.NamingResourcesImpl)2 MessageDestinationRef (org.apache.tomcat.util.descriptor.web.MessageDestinationRef)2 ResourceFactory (org.apache.tomee.common.ResourceFactory)2 HandleDelegate (javax.ejb.spi.HandleDelegate)1 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)1 MultipartConfigElement (javax.servlet.MultipartConfigElement)1 SessionCookieConfig (javax.servlet.SessionCookieConfig)1 TransactionSynchronizationRegistry (javax.transaction.TransactionSynchronizationRegistry)1 UserTransaction (javax.transaction.UserTransaction)1 Context (org.apache.catalina.Context)1