Search in sources :

Example 1 with NamingResourcesImpl

use of org.apache.catalina.deploy.NamingResourcesImpl in project tomee by apache.

the class TomcatWebAppBuilder method loadWebModule.

/**
 * Creates a new {@link WebModule} instance from given
 * tomcat context instance.
 *
 * @param standardContext tomcat context instance
 */
private void loadWebModule(final AppModule appModule, final StandardContext standardContext) {
    final List<WebModule> webModules = appModule.getWebModules();
    if (webModules.isEmpty()) {
        final File file = appModule.getFile();
        LOGGER.error("Failed to find a single module in: " + file);
        return;
    }
    final WebModule webModule = webModules.get(0);
    final WebApp webApp = webModule.getWebApp();
    // create the web module
    final String path = standardContext.getPath();
    LOGGER.debug("context path = " + path);
    webModule.setHost(Contexts.getHostname(standardContext));
    // Add all Tomcat env entries to context so they can be overriden by the env.properties file
    final NamingResourcesImpl naming = standardContext.getNamingResources();
    for (final ContextEnvironment environment : naming.findEnvironments()) {
        EnvEntry envEntry = webApp.getEnvEntryMap().get(environment.getName());
        if (envEntry == null) {
            envEntry = new EnvEntry();
            envEntry.setName(environment.getName());
            webApp.getEnvEntry().add(envEntry);
        }
        envEntry.setEnvEntryValue(environment.getValue());
        envEntry.setEnvEntryType(environment.getType());
    }
    // remove all jndi entries where there is a configured Tomcat resource or resource-link
    for (final ContextResource resource : naming.findResources()) {
        final String name = resource.getName();
        removeRef(webApp, name);
    }
    for (final ContextResourceLink resourceLink : naming.findResourceLinks()) {
        final String name = resourceLink.getName();
        removeRef(webApp, name);
    }
    // remove all env entries from the web xml that are not overridable
    for (final ContextEnvironment environment : naming.findEnvironments()) {
        if (!environment.getOverride()) {
            // overrides are not allowed
            webApp.getEnvEntryMap().remove(environment.getName());
        }
    }
}
Also used : ContextEnvironment(org.apache.tomcat.util.descriptor.web.ContextEnvironment) ContextResourceLink(org.apache.tomcat.util.descriptor.web.ContextResourceLink) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) WebModule(org.apache.openejb.config.WebModule) File(java.io.File) JarFile(java.util.jar.JarFile) WebApp(org.apache.openejb.jee.WebApp) EnvEntry(org.apache.openejb.jee.EnvEntry) ContextResource(org.apache.tomcat.util.descriptor.web.ContextResource)

Example 2 with NamingResourcesImpl

use of org.apache.catalina.deploy.NamingResourcesImpl in project tomee by apache.

the class TomcatJndiBuilder method importOpenEJBResourcesInTomcat.

public static void importOpenEJBResourcesInTomcat(final Collection<ResourceInfo> resources, final StandardServer server) {
    final NamingResourcesImpl naming = server.getGlobalNamingResources();
    for (final ResourceInfo info : resources) {
        final String name = info.id;
        // if invalid or existing or lazy just skip it cause doesnt work during startup
        if (name == null || naming.findResource(name) != null || info.properties.containsKey("UseAppClassLoader")) {
            continue;
        }
        final ContextResource resource = new ContextResource();
        resource.setName(name);
        resource.setProperty(Constants.FACTORY, ResourceFactory.class.getName());
        resource.setProperty(NamingUtil.NAME, name);
        resource.setType(info.className);
        resource.setAuth("Container");
        naming.addResource(resource);
    }
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) ResourceFactory(org.apache.tomee.common.ResourceFactory) ContextResource(org.apache.tomcat.util.descriptor.web.ContextResource)

Example 3 with NamingResourcesImpl

use of org.apache.catalina.deploy.NamingResourcesImpl in project tomee by apache.

the class TomcatJndiBuilder method mergeJndi.

public void mergeJndi() throws OpenEJBException {
    final NamingResourcesImpl naming = standardContext.getNamingResources();
    final URI moduleUri = URLs.uri(webAppInfo.moduleId);
    for (final EnvEntryInfo ref : webAppInfo.jndiEnc.envEntries) {
        mergeRef(naming, ref);
    }
    for (final EjbReferenceInfo ref : webAppInfo.jndiEnc.ejbReferences) {
        mergeRef(naming, ref);
    }
    for (final EjbLocalReferenceInfo ref : webAppInfo.jndiEnc.ejbLocalReferences) {
        mergeRef(naming, ref);
    }
    for (final PersistenceContextReferenceInfo ref : webAppInfo.jndiEnc.persistenceContextRefs) {
        mergeRef(naming, ref, moduleUri);
    }
    for (final PersistenceUnitReferenceInfo ref : webAppInfo.jndiEnc.persistenceUnitRefs) {
        mergeRef(naming, ref, moduleUri);
    }
    for (final ResourceReferenceInfo ref : webAppInfo.jndiEnc.resourceRefs) {
        mergeRef(naming, ref);
    }
    for (final ResourceEnvReferenceInfo ref : webAppInfo.jndiEnc.resourceEnvRefs) {
        mergeRef(naming, ref);
    }
    for (final ServiceReferenceInfo ref : webAppInfo.jndiEnc.serviceRefs) {
        mergeRef(naming, ref);
    }
    final ContextTransaction contextTransaction = new ContextTransaction();
    contextTransaction.setProperty(Constants.FACTORY, UserTransactionFactory.class.getName());
    naming.setTransaction(contextTransaction);
}
Also used : ResourceReferenceInfo(org.apache.openejb.assembler.classic.ResourceReferenceInfo) PersistenceContextReferenceInfo(org.apache.openejb.assembler.classic.PersistenceContextReferenceInfo) EjbReferenceInfo(org.apache.openejb.assembler.classic.EjbReferenceInfo) UserTransactionFactory(org.apache.tomee.common.UserTransactionFactory) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) EnvEntryInfo(org.apache.openejb.assembler.classic.EnvEntryInfo) EjbLocalReferenceInfo(org.apache.openejb.assembler.classic.EjbLocalReferenceInfo) ResourceEnvReferenceInfo(org.apache.openejb.assembler.classic.ResourceEnvReferenceInfo) ContextTransaction(org.apache.tomcat.util.descriptor.web.ContextTransaction) URI(java.net.URI) ServiceReferenceInfo(org.apache.openejb.assembler.classic.ServiceReferenceInfo) PersistenceUnitReferenceInfo(org.apache.openejb.assembler.classic.PersistenceUnitReferenceInfo)

Example 4 with NamingResourcesImpl

use of org.apache.catalina.deploy.NamingResourcesImpl in project tomee by apache.

the class OpenEJBContextConfig method contextConfig.

@Override
protected void contextConfig(final Digester digester) {
    final NamingResourcesImpl resources;
    if (context != null) {
        resources = context.getNamingResources();
    } else {
        resources = null;
    }
    if (resources instanceof OpenEJBNamingResource) {
        ((OpenEJBNamingResource) resources).setTomcatResource(true);
    }
    super.contextConfig(digester);
    if (resources instanceof OpenEJBNamingResource) {
        ((OpenEJBNamingResource) resources).setTomcatResource(false);
    }
    if (context instanceof StandardContext) {
        final StandardContext standardContext = (StandardContext) context;
        final NamingContextListener namingContextListener = standardContext.getNamingContextListener();
        if (null != namingContextListener) {
            namingContextListener.setExceptionOnFailedWrite(standardContext.getJndiExceptionOnFailedWrite());
        }
    }
}
Also used : IgnoredStandardContext(org.apache.tomee.catalina.IgnoredStandardContext) StandardContext(org.apache.catalina.core.StandardContext) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) NamingContextListener(org.apache.catalina.core.NamingContextListener) OpenEJBNamingResource(org.apache.tomee.catalina.OpenEJBNamingResource)

Example 5 with NamingResourcesImpl

use of org.apache.catalina.deploy.NamingResourcesImpl in project tomcat by apache.

the class GlobalNamingResourcesSF method store.

/*
     * Store with NamingResource Factory
     *
     * @see org.apache.catalina.storeconfig.IStoreFactory#store(java.io.PrintWriter,
     *      int, java.lang.Object)
     */
@Override
public void store(PrintWriter aWriter, int indent, Object aElement) throws Exception {
    if (aElement instanceof NamingResourcesImpl) {
        StoreDescription elementDesc = getRegistry().findDescription(NamingResourcesImpl.class.getName() + ".[GlobalNamingResources]");
        if (elementDesc != null) {
            getStoreAppender().printIndent(aWriter, indent + 2);
            getStoreAppender().printOpenTag(aWriter, indent + 2, aElement, elementDesc);
            NamingResourcesImpl resources = (NamingResourcesImpl) aElement;
            StoreDescription resourcesdesc = getRegistry().findDescription(NamingResourcesImpl.class.getName());
            if (resourcesdesc != null) {
                resourcesdesc.getStoreFactory().store(aWriter, indent + 2, resources);
            } else {
                log.warn(sm.getString("globalNamingResourcesSF.noFactory"));
            }
            getStoreAppender().printIndent(aWriter, indent + 2);
            getStoreAppender().printCloseTag(aWriter, elementDesc);
        } else {
            log.warn(sm.getString("storeFactory.noDescriptor", aElement.getClass(), "GlobalNamingResources"));
        }
    } else {
        log.warn(sm.getString("globalNamingResourcesSF.wrongElement", aElement.getClass()));
    }
}
Also used : NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl)

Aggregations

NamingResourcesImpl (org.apache.catalina.deploy.NamingResourcesImpl)24 ContextResource (org.apache.tomcat.util.descriptor.web.ContextResource)10 ObjectName (javax.management.ObjectName)6 ContextEnvironment (org.apache.tomcat.util.descriptor.web.ContextEnvironment)6 ContextResourceLink (org.apache.tomcat.util.descriptor.web.ContextResourceLink)6 ArrayList (java.util.ArrayList)5 MalformedObjectNameException (javax.management.MalformedObjectNameException)3 ManagedBean (org.apache.tomcat.util.modeler.ManagedBean)3 Context (org.apache.catalina.Context)2 LifecycleListener (org.apache.catalina.LifecycleListener)2 StandardContext (org.apache.catalina.core.StandardContext)2 StandardServer (org.apache.catalina.core.StandardServer)2 ResourceInfo (org.apache.openejb.assembler.classic.ResourceInfo)2 ContextEjb (org.apache.tomcat.util.descriptor.web.ContextEjb)2 ContextResourceEnvRef (org.apache.tomcat.util.descriptor.web.ContextResourceEnvRef)2 ContextTransaction (org.apache.tomcat.util.descriptor.web.ContextTransaction)2 File (java.io.File)1 URI (java.net.URI)1 Properties (java.util.Properties)1 JarFile (java.util.jar.JarFile)1