Search in sources :

Example 6 with ContextResourceLink

use of org.apache.catalina.deploy.ContextResourceLink in project Payara by payara.

the class StandardContext method removeResourceLink.

/**
 * Remove any resource link with the specified name.
 *
 * @param link Name of the resource link to remove
 */
@Override
public void removeResourceLink(String link) {
    String decoded = URLDecoder.decode(link);
    if (namingResources == null) {
        return;
    }
    ContextResourceLink resource = namingResources.findResourceLink(decoded);
    if (resource == null) {
        throw new IllegalArgumentException("Invalid resource name '" + decoded + "'");
    }
    namingResources.removeResourceLink(decoded);
    if (notifyContainerListeners) {
        fireContainerEvent("removeResourceLink", decoded);
    }
}
Also used : ContextResourceLink(org.apache.catalina.deploy.ContextResourceLink)

Example 7 with ContextResourceLink

use of org.apache.catalina.deploy.ContextResourceLink in project Payara by payara.

the class StandardContext method addResourceLink.

/**
 * Add a resource link for this web application.
 *
 * @param resourceLinkName New resource link name
 */
public String addResourceLink(String resourceLinkName, String global, String name, String type) throws MalformedObjectNameException {
    NamingResources nresources = getNamingResources();
    if (nresources == null) {
        return null;
    }
    ContextResourceLink resourceLink = nresources.findResourceLink(resourceLinkName);
    if (resourceLink != null) {
        throw new IllegalArgumentException("Invalid resource link name - already exists'" + resourceLinkName + "'");
    }
    resourceLink = new ContextResourceLink();
    resourceLink.setGlobal(global);
    resourceLink.setName(resourceLinkName);
    resourceLink.setType(type);
    nresources.addResourceLink(resourceLink);
    // Return the corresponding MBean name
    return createObjectName(resourceLink).toString();
}
Also used : ContextResourceLink(org.apache.catalina.deploy.ContextResourceLink) NamingResources(org.apache.catalina.deploy.NamingResources)

Example 8 with ContextResourceLink

use of org.apache.catalina.deploy.ContextResourceLink in project tomcat70 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 NamingResources();
        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) {
            logger.error(sm.getString("naming.bindFailed", e));
        }
    }
    // Binding the resources directory context
    if (container instanceof Context) {
        try {
            compCtx.bind("Resources", ((Container) container).getResources());
        } catch (NamingException e) {
            logger.error(sm.getString("naming.bindFailed", e));
        }
    }
}
Also used : ContextEnvironment(org.apache.catalina.deploy.ContextEnvironment) NamingContext(org.apache.naming.NamingContext) Context(org.apache.catalina.Context) ContextService(org.apache.catalina.deploy.ContextService) Server(org.apache.catalina.Server) ContextResourceLink(org.apache.catalina.deploy.ContextResourceLink) Reference(javax.naming.Reference) NamingResources(org.apache.catalina.deploy.NamingResources) ContextTransaction(org.apache.catalina.deploy.ContextTransaction) ContextEjb(org.apache.catalina.deploy.ContextEjb) ContextResource(org.apache.catalina.deploy.ContextResource) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) StringRefAddr(javax.naming.StringRefAddr) TransactionRef(org.apache.naming.TransactionRef) NamingException(javax.naming.NamingException) ContextResourceEnvRef(org.apache.catalina.deploy.ContextResourceEnvRef)

Example 9 with ContextResourceLink

use of org.apache.catalina.deploy.ContextResourceLink in project tomcat70 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);
    NamingResources nresources = (NamingResources) this.resource;
    if (nresources == null) {
        return;
    }
    ContextResourceLink resourceLink = nresources.findResourceLink(resourceLinkName);
    if (resourceLink == null) {
        throw new IllegalArgumentException("Invalid resource Link name '" + resourceLinkName + "'");
    }
    nresources.removeResourceLink(resourceLinkName);
}
Also used : ContextResourceLink(org.apache.catalina.deploy.ContextResourceLink) NamingResources(org.apache.catalina.deploy.NamingResources)

Example 10 with ContextResourceLink

use of org.apache.catalina.deploy.ContextResourceLink in project tomcat70 by apache.

the class NamingResourcesMBean method getResourceLinks.

/**
 * Return the MBean Names of all the defined resource link references for
 * this application.
 */
public String[] getResourceLinks() {
    ContextResourceLink[] resourceLinks = ((NamingResources) this.resource).findResourceLinks();
    ArrayList<String> results = new ArrayList<String>();
    for (int i = 0; i < resourceLinks.length; i++) {
        try {
            ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), resourceLinks[i]);
            results.add(oname.toString());
        } catch (MalformedObjectNameException e) {
            IllegalArgumentException iae = new IllegalArgumentException("Cannot create object name for resource " + resourceLinks[i]);
            iae.initCause(e);
            throw iae;
        }
    }
    return results.toArray(new String[results.size()]);
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) ContextResourceLink(org.apache.catalina.deploy.ContextResourceLink) NamingResources(org.apache.catalina.deploy.NamingResources) ArrayList(java.util.ArrayList) ObjectName(javax.management.ObjectName)

Aggregations

ContextResourceLink (org.apache.catalina.deploy.ContextResourceLink)12 NamingResources (org.apache.catalina.deploy.NamingResources)7 ObjectName (javax.management.ObjectName)3 ContextEnvironment (org.apache.catalina.deploy.ContextEnvironment)3 ArrayList (java.util.ArrayList)2 InstanceNotFoundException (javax.management.InstanceNotFoundException)2 MBeanException (javax.management.MBeanException)2 MalformedObjectNameException (javax.management.MalformedObjectNameException)2 RuntimeOperationsException (javax.management.RuntimeOperationsException)2 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)2 Context (org.apache.catalina.Context)2 Test (org.junit.Test)2 AttributeNotFoundException (javax.management.AttributeNotFoundException)1 Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)1 NamingException (javax.naming.NamingException)1 Reference (javax.naming.Reference)1 StringRefAddr (javax.naming.StringRefAddr)1 Server (org.apache.catalina.Server)1