Search in sources :

Example 16 with NamingResourcesImpl

use of org.apache.catalina.deploy.NamingResourcesImpl 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]);
    }
    // Message Destination References
    MessageDestinationRef[] mdrs = namingResources.findMessageDestinationRefs();
    for (i = 0; i < mdrs.length; i++) {
        addMessageDestinationRef(mdrs[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 : ContextService(org.apache.tomcat.util.descriptor.web.ContextService) Server(org.apache.catalina.Server) MessageDestinationRef(org.apache.tomcat.util.descriptor.web.MessageDestinationRef) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) NamingException(javax.naming.NamingException) ContextEnvironment(org.apache.tomcat.util.descriptor.web.ContextEnvironment) NamingContext(org.apache.naming.NamingContext) Context(org.apache.catalina.Context) 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) StringRefAddr(javax.naming.StringRefAddr) TransactionRef(org.apache.naming.TransactionRef) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) ContextResourceEnvRef(org.apache.tomcat.util.descriptor.web.ContextResourceEnvRef)

Example 17 with NamingResourcesImpl

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

the class SetNextNamingRule method end.

// --------------------------------------------------------- Public Methods
/**
 * Process the end of this element.
 *
 * @param namespace the namespace URI of the matching element, or an
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just
 *   the element name otherwise
 */
@Override
public void end(String namespace, String name) throws Exception {
    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.peek(1);
    boolean context = false;
    NamingResourcesImpl namingResources = null;
    if (parent instanceof Context) {
        namingResources = ((Context) parent).getNamingResources();
        context = true;
    } else {
        namingResources = (NamingResourcesImpl) parent;
    }
    // Call the specified method
    IntrospectionUtils.callMethod1(namingResources, methodName, child, paramType, digester.getClassLoader());
    StringBuilder code = digester.getGeneratedCode();
    if (code != null) {
        if (context) {
            code.append(digester.toVariableName(parent)).append(".getNamingResources()");
        } else {
            code.append(digester.toVariableName(namingResources));
        }
        code.append(".").append(methodName).append('(');
        code.append(digester.toVariableName(child)).append(");");
        code.append(System.lineSeparator());
    }
}
Also used : Context(org.apache.catalina.Context) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl)

Example 18 with NamingResourcesImpl

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

the class NamingResourcesMBean method addEnvironment.

// ------------------------------------------------------------- Operations
/**
 * Add an environment entry for this web application.
 *
 * @param envName New environment entry name
 * @param type The type of the new environment entry
 * @param value The value of the new environment entry
 * @return the object name of the new environment entry
 * @throws MalformedObjectNameException if the object name was invalid
 */
public String addEnvironment(String envName, String type, String value) throws MalformedObjectNameException {
    NamingResourcesImpl nresources = (NamingResourcesImpl) this.resource;
    if (nresources == null) {
        return null;
    }
    ContextEnvironment env = nresources.findEnvironment(envName);
    if (env != null) {
        throw new IllegalArgumentException(sm.getString("namingResourcesMBean.addAlreadyExists.environment", envName));
    }
    env = new ContextEnvironment();
    env.setName(envName);
    env.setType(type);
    env.setValue(value);
    nresources.addEnvironment(env);
    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("ContextEnvironment");
    ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), env);
    return oname.toString();
}
Also used : ContextEnvironment(org.apache.tomcat.util.descriptor.web.ContextEnvironment) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) ManagedBean(org.apache.tomcat.util.modeler.ManagedBean) ObjectName(javax.management.ObjectName)

Example 19 with NamingResourcesImpl

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

the class NamingResourcesMBean method removeResourceLink.

/**
 * Remove any resource link reference with the specified name.
 *
 * @param resourceLinkName Name of the resource link reference to remove
 */
public void removeResourceLink(String resourceLinkName) {
    resourceLinkName = ObjectName.unquote(resourceLinkName);
    NamingResourcesImpl nresources = (NamingResourcesImpl) this.resource;
    if (nresources == null) {
        return;
    }
    ContextResourceLink resourceLink = nresources.findResourceLink(resourceLinkName);
    if (resourceLink == null) {
        throw new IllegalArgumentException(sm.getString("namingResourcesMBean.removeNotFound.resourceLink", resourceLinkName));
    }
    nresources.removeResourceLink(resourceLinkName);
}
Also used : ContextResourceLink(org.apache.tomcat.util.descriptor.web.ContextResourceLink) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl)

Example 20 with NamingResourcesImpl

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

the class NamingResourcesMBean method getResourceLinks.

/**
 * Return the MBean Names of all the defined resource link references for
 * this application.
 * @return an array of object names as strings
 */
public String[] getResourceLinks() {
    ContextResourceLink[] resourceLinks = ((NamingResourcesImpl) this.resource).findResourceLinks();
    List<String> results = new ArrayList<>();
    for (ContextResourceLink resourceLink : resourceLinks) {
        try {
            ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), resourceLink);
            results.add(oname.toString());
        } catch (MalformedObjectNameException e) {
            throw new IllegalArgumentException(sm.getString("namingResourcesMBean.createObjectNameError.resourceLink", resourceLink), e);
        }
    }
    return results.toArray(new String[0]);
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) ContextResourceLink(org.apache.tomcat.util.descriptor.web.ContextResourceLink) ArrayList(java.util.ArrayList) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) ObjectName(javax.management.ObjectName)

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