Search in sources :

Example 6 with ContextEjb

use of org.apache.tomcat.util.descriptor.web.ContextEjb 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)

Example 7 with ContextEjb

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

the class NamingResourcesImpl method removeEjb.

/**
     * Remove any EJB resource reference with the specified name.
     *
     * @param name Name of the EJB resource reference to remove
     */
public void removeEjb(String name) {
    entries.remove(name);
    ContextEjb ejb = null;
    synchronized (ejbs) {
        ejb = ejbs.remove(name);
    }
    if (ejb != null) {
        support.firePropertyChange("ejb", ejb, null);
        ejb.setNamingResources(null);
    }
}
Also used : ContextEjb(org.apache.tomcat.util.descriptor.web.ContextEjb)

Example 8 with ContextEjb

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

the class TomcatJndiBuilder method mergeRef.

public void mergeRef(final NamingResourcesImpl naming, final EjbReferenceInfo ref) {
    if (isLookupRef(naming, ref)) {
        return;
    }
    ContextEjb ejb = naming.findEjb(ref.referenceName.replaceAll("^comp/env/", ""));
    boolean addEntry = false;
    if (ejb == null) {
        ejb = new ContextEjb();
        ejb.setName(ref.referenceName.replaceAll("^comp/env/", ""));
        addEntry = true;
    }
    ejb.setProperty(Constants.FACTORY, EjbFactory.class.getName());
    ejb.setProperty(NamingUtil.NAME, ref.referenceName.replaceAll("^comp/env/", ""));
    ejb.setHome(ref.homeClassName);
    ejb.setRemote(ref.interfaceClassName);
    ejb.setLink(null);
    ejb.setType(ref.interfaceClassName);
    if (useCrossClassLoaderRef) {
        ejb.setProperty(NamingUtil.EXTERNAL, Boolean.toString(ref.externalReference));
    }
    if (ref.ejbDeploymentId != null) {
        ejb.setProperty(NamingUtil.DEPLOYMENT_ID, ref.ejbDeploymentId);
    }
    if (ref.location != null) {
        ejb.setProperty(NamingUtil.JNDI_NAME, ref.location.jndiName);
        ejb.setProperty(NamingUtil.JNDI_PROVIDER_ID, ref.location.jndiProviderId);
    }
    if (addEntry) {
        naming.addEjb(ejb);
    }
    if (replaceEntry) {
        ContextAccessController.setWritable(namingContextListener.getName(), standardContext.getNamingToken());
        if (!addEntry) {
            namingContextListener.removeEjb(ejb.getName());
        }
        namingContextListener.addEjb(ejb);
        ContextAccessController.setReadOnly(namingContextListener.getName());
    }
}
Also used : EjbFactory(org.apache.tomee.common.EjbFactory) ContextEjb(org.apache.tomcat.util.descriptor.web.ContextEjb)

Aggregations

ContextEjb (org.apache.tomcat.util.descriptor.web.ContextEjb)8 ContextEnvironment (org.apache.tomcat.util.descriptor.web.ContextEnvironment)5 ContextResource (org.apache.tomcat.util.descriptor.web.ContextResource)5 ContextResourceEnvRef (org.apache.tomcat.util.descriptor.web.ContextResourceEnvRef)5 ContextResourceLink (org.apache.tomcat.util.descriptor.web.ContextResourceLink)4 ContextLocalEjb (org.apache.tomcat.util.descriptor.web.ContextLocalEjb)3 ContextService (org.apache.tomcat.util.descriptor.web.ContextService)3 NamingResourcesImpl (org.apache.catalina.deploy.NamingResourcesImpl)2 EjbFactory (org.apache.tomee.common.EjbFactory)2 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)1 NamingException (javax.naming.NamingException)1 Reference (javax.naming.Reference)1 StringRefAddr (javax.naming.StringRefAddr)1 MultipartConfigElement (javax.servlet.MultipartConfigElement)1 SessionCookieConfig (javax.servlet.SessionCookieConfig)1 Context (org.apache.catalina.Context)1 Server (org.apache.catalina.Server)1 Wrapper (org.apache.catalina.Wrapper)1 NamingContext (org.apache.naming.NamingContext)1 TransactionRef (org.apache.naming.TransactionRef)1