Search in sources :

Example 1 with ContextEjb

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

the class OpenEJBNamingContextListener method processInitialNamingResources.

private void processInitialNamingResources() {
    // Resource links
    final ContextResourceLink[] resourceLinks = namingResources.findResourceLinks();
    for (final ContextResourceLink resourceLink : resourceLinks) {
        addResourceLink(resourceLink);
    }
    // Resources
    final ContextResource[] resources = namingResources.findResources();
    for (final ContextResource resource : resources) {
        addResource(resource);
    }
    // Resources Env
    final ContextResourceEnvRef[] resourceEnvRefs = namingResources.findResourceEnvRefs();
    for (final ContextResourceEnvRef resourceEnvRef : resourceEnvRefs) {
        addResourceEnvRef(resourceEnvRef);
    }
    // Environment entries
    final ContextEnvironment[] contextEnvironments = namingResources.findEnvironments();
    for (final ContextEnvironment contextEnvironment : contextEnvironments) {
        addEnvironment(contextEnvironment);
    }
    // EJB references
    final ContextEjb[] ejbs = namingResources.findEjbs();
    for (final ContextEjb ejb : ejbs) {
        addEjb(ejb);
    }
}
Also used : ContextEnvironment(org.apache.tomcat.util.descriptor.web.ContextEnvironment) ContextResourceLink(org.apache.tomcat.util.descriptor.web.ContextResourceLink) ContextResourceEnvRef(org.apache.tomcat.util.descriptor.web.ContextResourceEnvRef) ContextEjb(org.apache.tomcat.util.descriptor.web.ContextEjb) ContextResource(org.apache.tomcat.util.descriptor.web.ContextResource)

Example 2 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 EjbLocalReferenceInfo ref) {
    if (isLookupRef(naming, ref)) {
        return;
    }
    // NamingContextListener.addLocalEjb is empty so we'll just use an ejb ref
    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(null);
    ejb.setProperty(ref.localbean ? NamingUtil.LOCALBEAN : NamingUtil.LOCAL, ref.interfaceClassName);
    ejb.setLink(null);
    ejb.setType(ref.interfaceClassName);
    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)

Example 3 with ContextEjb

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

the class ContextConfig method configureContext.

private void configureContext(WebXml webxml) {
    // As far as possible, process in alphabetical order so it is easy to
    // check everything is present
    // Some validation depends on correct public ID
    context.setPublicId(webxml.getPublicId());
    // Everything else in order
    context.setEffectiveMajorVersion(webxml.getMajorVersion());
    context.setEffectiveMinorVersion(webxml.getMinorVersion());
    for (Entry<String, String> entry : webxml.getContextParams().entrySet()) {
        context.addParameter(entry.getKey(), entry.getValue());
    }
    context.setDenyUncoveredHttpMethods(webxml.getDenyUncoveredHttpMethods());
    context.setDisplayName(webxml.getDisplayName());
    context.setDistributable(webxml.isDistributable());
    for (ContextLocalEjb ejbLocalRef : webxml.getEjbLocalRefs().values()) {
        context.getNamingResources().addLocalEjb(ejbLocalRef);
    }
    for (ContextEjb ejbRef : webxml.getEjbRefs().values()) {
        context.getNamingResources().addEjb(ejbRef);
    }
    for (ContextEnvironment environment : webxml.getEnvEntries().values()) {
        context.getNamingResources().addEnvironment(environment);
    }
    for (ErrorPage errorPage : webxml.getErrorPages().values()) {
        context.addErrorPage(errorPage);
    }
    for (FilterDef filter : webxml.getFilters().values()) {
        if (filter.getAsyncSupported() == null) {
            filter.setAsyncSupported("false");
        }
        context.addFilterDef(filter);
    }
    for (FilterMap filterMap : webxml.getFilterMappings()) {
        context.addFilterMap(filterMap);
    }
    context.setJspConfigDescriptor(webxml.getJspConfigDescriptor());
    for (String listener : webxml.getListeners()) {
        context.addApplicationListener(listener);
    }
    for (Entry<String, String> entry : webxml.getLocaleEncodingMappings().entrySet()) {
        context.addLocaleEncodingMappingParameter(entry.getKey(), entry.getValue());
    }
    // Prevents IAE
    if (webxml.getLoginConfig() != null) {
        context.setLoginConfig(webxml.getLoginConfig());
    }
    for (MessageDestinationRef mdr : webxml.getMessageDestinationRefs().values()) {
        context.getNamingResources().addMessageDestinationRef(mdr);
    }
    // messageDestinations were ignored in Tomcat 6, so ignore here
    context.setIgnoreAnnotations(webxml.isMetadataComplete());
    for (Entry<String, String> entry : webxml.getMimeMappings().entrySet()) {
        context.addMimeMapping(entry.getKey(), entry.getValue());
    }
    context.setRequestCharacterEncoding(webxml.getRequestCharacterEncoding());
    // Name is just used for ordering
    for (ContextResourceEnvRef resource : webxml.getResourceEnvRefs().values()) {
        context.getNamingResources().addResourceEnvRef(resource);
    }
    for (ContextResource resource : webxml.getResourceRefs().values()) {
        context.getNamingResources().addResource(resource);
    }
    context.setResponseCharacterEncoding(webxml.getResponseCharacterEncoding());
    boolean allAuthenticatedUsersIsAppRole = webxml.getSecurityRoles().contains(SecurityConstraint.ROLE_ALL_AUTHENTICATED_USERS);
    for (SecurityConstraint constraint : webxml.getSecurityConstraints()) {
        if (allAuthenticatedUsersIsAppRole) {
            constraint.treatAllAuthenticatedUsersAsApplicationRole();
        }
        context.addConstraint(constraint);
    }
    for (String role : webxml.getSecurityRoles()) {
        context.addSecurityRole(role);
    }
    for (ContextService service : webxml.getServiceRefs().values()) {
        context.getNamingResources().addService(service);
    }
    for (ServletDef servlet : webxml.getServlets().values()) {
        Wrapper wrapper = context.createWrapper();
        if (servlet.getLoadOnStartup() != null) {
            wrapper.setLoadOnStartup(servlet.getLoadOnStartup().intValue());
        }
        if (servlet.getEnabled() != null) {
            wrapper.setEnabled(servlet.getEnabled().booleanValue());
        }
        wrapper.setName(servlet.getServletName());
        Map<String, String> params = servlet.getParameterMap();
        for (Entry<String, String> entry : params.entrySet()) {
            wrapper.addInitParameter(entry.getKey(), entry.getValue());
        }
        wrapper.setRunAs(servlet.getRunAs());
        Set<SecurityRoleRef> roleRefs = servlet.getSecurityRoleRefs();
        for (SecurityRoleRef roleRef : roleRefs) {
            wrapper.addSecurityReference(roleRef.getName(), roleRef.getLink());
        }
        wrapper.setServletClass(servlet.getServletClass());
        MultipartDef multipartdef = servlet.getMultipartDef();
        if (multipartdef != null) {
            long maxFileSize = -1;
            long maxRequestSize = -1;
            int fileSizeThreshold = 0;
            if (null != multipartdef.getMaxFileSize()) {
                maxFileSize = Long.parseLong(multipartdef.getMaxFileSize());
            }
            if (null != multipartdef.getMaxRequestSize()) {
                maxRequestSize = Long.parseLong(multipartdef.getMaxRequestSize());
            }
            if (null != multipartdef.getFileSizeThreshold()) {
                fileSizeThreshold = Integer.parseInt(multipartdef.getFileSizeThreshold());
            }
            wrapper.setMultipartConfigElement(new MultipartConfigElement(multipartdef.getLocation(), maxFileSize, maxRequestSize, fileSizeThreshold));
        }
        if (servlet.getAsyncSupported() != null) {
            wrapper.setAsyncSupported(servlet.getAsyncSupported().booleanValue());
        }
        wrapper.setOverridable(servlet.isOverridable());
        context.addChild(wrapper);
    }
    for (Entry<String, String> entry : webxml.getServletMappings().entrySet()) {
        context.addServletMappingDecoded(entry.getKey(), entry.getValue());
    }
    SessionConfig sessionConfig = webxml.getSessionConfig();
    if (sessionConfig != null) {
        if (sessionConfig.getSessionTimeout() != null) {
            context.setSessionTimeout(sessionConfig.getSessionTimeout().intValue());
        }
        SessionCookieConfig scc = context.getServletContext().getSessionCookieConfig();
        scc.setName(sessionConfig.getCookieName());
        Map<String, String> attributes = sessionConfig.getCookieAttributes();
        for (Map.Entry<String, String> attribute : attributes.entrySet()) {
            scc.setAttribute(attribute.getKey(), attribute.getValue());
        }
        if (sessionConfig.getSessionTrackingModes().size() > 0) {
            context.getServletContext().setSessionTrackingModes(sessionConfig.getSessionTrackingModes());
        }
    }
    for (String welcomeFile : webxml.getWelcomeFiles()) {
        /*
             * The following will result in a welcome file of "" so don't add
             * that to the context
             * <welcome-file-list>
             *   <welcome-file/>
             * </welcome-file-list>
             */
        if (welcomeFile != null && welcomeFile.length() > 0) {
            context.addWelcomeFile(welcomeFile);
        }
    }
    // Do this last as it depends on servlets
    for (JspPropertyGroup jspPropertyGroup : webxml.getJspPropertyGroups()) {
        String jspServletName = context.findServletMapping("*.jsp");
        if (jspServletName == null) {
            jspServletName = "jsp";
        }
        if (context.findChild(jspServletName) != null) {
            for (String urlPattern : jspPropertyGroup.getUrlPatterns()) {
                context.addServletMappingDecoded(urlPattern, jspServletName, true);
            }
        } else {
            if (log.isDebugEnabled()) {
                for (String urlPattern : jspPropertyGroup.getUrlPatterns()) {
                    log.debug("Skipping " + urlPattern + " , no servlet " + jspServletName);
                }
            }
        }
    }
    for (Entry<String, String> entry : webxml.getPostConstructMethods().entrySet()) {
        context.addPostConstructMethod(entry.getKey(), entry.getValue());
    }
    for (Entry<String, String> entry : webxml.getPreDestroyMethods().entrySet()) {
        context.addPreDestroyMethod(entry.getKey(), entry.getValue());
    }
}
Also used : ContextService(org.apache.tomcat.util.descriptor.web.ContextService) ErrorPage(org.apache.tomcat.util.descriptor.web.ErrorPage) SessionConfig(org.apache.tomcat.util.descriptor.web.SessionConfig) SecurityRoleRef(org.apache.tomcat.util.descriptor.web.SecurityRoleRef) FilterMap(org.apache.tomcat.util.descriptor.web.FilterMap) SecurityConstraint(org.apache.tomcat.util.descriptor.web.SecurityConstraint) JspPropertyGroup(org.apache.tomcat.util.descriptor.web.JspPropertyGroup) MessageDestinationRef(org.apache.tomcat.util.descriptor.web.MessageDestinationRef) ContextLocalEjb(org.apache.tomcat.util.descriptor.web.ContextLocalEjb) MultipartDef(org.apache.tomcat.util.descriptor.web.MultipartDef) SessionCookieConfig(jakarta.servlet.SessionCookieConfig) ContextEnvironment(org.apache.tomcat.util.descriptor.web.ContextEnvironment) Wrapper(org.apache.catalina.Wrapper) FilterDef(org.apache.tomcat.util.descriptor.web.FilterDef) ServletDef(org.apache.tomcat.util.descriptor.web.ServletDef) ContextEjb(org.apache.tomcat.util.descriptor.web.ContextEjb) SecurityConstraint(org.apache.tomcat.util.descriptor.web.SecurityConstraint) ContextResource(org.apache.tomcat.util.descriptor.web.ContextResource) MultipartConfigElement(jakarta.servlet.MultipartConfigElement) ContextResourceEnvRef(org.apache.tomcat.util.descriptor.web.ContextResourceEnvRef) FilterMap(org.apache.tomcat.util.descriptor.web.FilterMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with ContextEjb

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

the class NamingResourcesSF method storeChildren.

/**
 * Store the specified NamingResources properties.
 *
 * @param aWriter
 *            PrintWriter to which we are storing
 * @param indent
 *            Number of spaces to indent this element
 * @param aElement
 *            Object whose properties are being stored
 * @param elementDesc
 *            element descriptor
 *
 * @exception Exception
 *                if an exception occurs while storing
 *
 * @see org.apache.catalina.storeconfig.StoreFactoryBase#storeChildren(java.io.PrintWriter,
 *      int, java.lang.Object, StoreDescription)
 */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aElement, StoreDescription elementDesc) throws Exception {
    if (aElement instanceof NamingResourcesImpl) {
        NamingResourcesImpl resources = (NamingResourcesImpl) aElement;
        // Store nested <Ejb> elements
        ContextEjb[] ejbs = resources.findEjbs();
        storeElementArray(aWriter, indent, ejbs);
        // Store nested <Environment> elements
        ContextEnvironment[] envs = resources.findEnvironments();
        storeElementArray(aWriter, indent, envs);
        // Store nested <LocalEjb> elements
        ContextLocalEjb[] lejbs = resources.findLocalEjbs();
        storeElementArray(aWriter, indent, lejbs);
        // Store nested <Resource> elements
        ContextResource[] dresources = resources.findResources();
        storeElementArray(aWriter, indent, dresources);
        // Store nested <ResourceEnvRef> elements
        ContextResourceEnvRef[] resEnv = resources.findResourceEnvRefs();
        storeElementArray(aWriter, indent, resEnv);
        // Store nested <ResourceLink> elements
        ContextResourceLink[] resourceLinks = resources.findResourceLinks();
        storeElementArray(aWriter, indent, resourceLinks);
    }
}
Also used : ContextEnvironment(org.apache.tomcat.util.descriptor.web.ContextEnvironment) ContextResourceLink(org.apache.tomcat.util.descriptor.web.ContextResourceLink) ContextEjb(org.apache.tomcat.util.descriptor.web.ContextEjb) ContextResource(org.apache.tomcat.util.descriptor.web.ContextResource) ContextLocalEjb(org.apache.tomcat.util.descriptor.web.ContextLocalEjb) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) ContextResourceEnvRef(org.apache.tomcat.util.descriptor.web.ContextResourceEnvRef)

Example 5 with ContextEjb

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

the class NamingContextListener method containerEvent.

// ---------------------------------------------- ContainerListener Methods
/**
     * Acknowledge the occurrence of the specified event.
     * Note: Will never be called when the listener is associated to a Server,
     * since it is not a Container.
     *
     * @param event ContainerEvent that has occurred
     */
@Override
public void containerEvent(ContainerEvent event) {
    if (!initialized)
        return;
    // Setting the context in read/write mode
    ContextAccessController.setWritable(getName(), token);
    String type = event.getType();
    if (type.equals("addEjb")) {
        String ejbName = (String) event.getData();
        if (ejbName != null) {
            ContextEjb ejb = namingResources.findEjb(ejbName);
            addEjb(ejb);
        }
    } else if (type.equals("addEnvironment")) {
        String environmentName = (String) event.getData();
        if (environmentName != null) {
            ContextEnvironment env = namingResources.findEnvironment(environmentName);
            addEnvironment(env);
        }
    } else if (type.equals("addLocalEjb")) {
        String localEjbName = (String) event.getData();
        if (localEjbName != null) {
            ContextLocalEjb localEjb = namingResources.findLocalEjb(localEjbName);
            addLocalEjb(localEjb);
        }
    } else if (type.equals("addResource")) {
        String resourceName = (String) event.getData();
        if (resourceName != null) {
            ContextResource resource = namingResources.findResource(resourceName);
            addResource(resource);
        }
    } else if (type.equals("addResourceLink")) {
        String resourceLinkName = (String) event.getData();
        if (resourceLinkName != null) {
            ContextResourceLink resourceLink = namingResources.findResourceLink(resourceLinkName);
            addResourceLink(resourceLink);
        }
    } else if (type.equals("addResourceEnvRef")) {
        String resourceEnvRefName = (String) event.getData();
        if (resourceEnvRefName != null) {
            ContextResourceEnvRef resourceEnvRef = namingResources.findResourceEnvRef(resourceEnvRefName);
            addResourceEnvRef(resourceEnvRef);
        }
    } else if (type.equals("addService")) {
        String serviceName = (String) event.getData();
        if (serviceName != null) {
            ContextService service = namingResources.findService(serviceName);
            addService(service);
        }
    } else if (type.equals("removeEjb")) {
        String ejbName = (String) event.getData();
        if (ejbName != null) {
            removeEjb(ejbName);
        }
    } else if (type.equals("removeEnvironment")) {
        String environmentName = (String) event.getData();
        if (environmentName != null) {
            removeEnvironment(environmentName);
        }
    } else if (type.equals("removeLocalEjb")) {
        String localEjbName = (String) event.getData();
        if (localEjbName != null) {
            removeLocalEjb(localEjbName);
        }
    } else if (type.equals("removeResource")) {
        String resourceName = (String) event.getData();
        if (resourceName != null) {
            removeResource(resourceName);
        }
    } else if (type.equals("removeResourceLink")) {
        String resourceLinkName = (String) event.getData();
        if (resourceLinkName != null) {
            removeResourceLink(resourceLinkName);
        }
    } else if (type.equals("removeResourceEnvRef")) {
        String resourceEnvRefName = (String) event.getData();
        if (resourceEnvRefName != null) {
            removeResourceEnvRef(resourceEnvRefName);
        }
    } else if (type.equals("removeService")) {
        String serviceName = (String) event.getData();
        if (serviceName != null) {
            removeService(serviceName);
        }
    }
    // Setting the context in read only mode
    ContextAccessController.setReadOnly(getName());
}
Also used : ContextEnvironment(org.apache.tomcat.util.descriptor.web.ContextEnvironment) ContextService(org.apache.tomcat.util.descriptor.web.ContextService) ContextLocalEjb(org.apache.tomcat.util.descriptor.web.ContextLocalEjb) ContextResourceLink(org.apache.tomcat.util.descriptor.web.ContextResourceLink) ContextResourceEnvRef(org.apache.tomcat.util.descriptor.web.ContextResourceEnvRef) ContextEjb(org.apache.tomcat.util.descriptor.web.ContextEjb) ContextResource(org.apache.tomcat.util.descriptor.web.ContextResource)

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 MessageDestinationRef (org.apache.tomcat.util.descriptor.web.MessageDestinationRef)2 EjbFactory (org.apache.tomee.common.EjbFactory)2 MultipartConfigElement (jakarta.servlet.MultipartConfigElement)1 SessionCookieConfig (jakarta.servlet.SessionCookieConfig)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)1 NamingException (javax.naming.NamingException)1 Reference (javax.naming.Reference)1 StringRefAddr (javax.naming.StringRefAddr)1