Search in sources :

Example 11 with ContextResourceLink

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

the class NamingResourcesImpl method removeResourceLink.

/**
 * Remove any resource link with the specified name.
 *
 * @param name Name of the resource link to remove
 */
@Override
public void removeResourceLink(String name) {
    entries.remove(name);
    ContextResourceLink resourceLink = null;
    synchronized (resourceLinks) {
        resourceLink = resourceLinks.remove(name);
    }
    if (resourceLink != null) {
        support.firePropertyChange("resourceLink", resourceLink, null);
        // De-register with JMX
        if (resourceRequireExplicitRegistration) {
            try {
                MBeanUtils.destroyMBean(resourceLink);
            } catch (Exception e) {
                log.warn(sm.getString("namingResources.mbeanDestroyFail", resourceLink.getName()), e);
            }
        }
        resourceLink.setNamingResources(null);
    }
}
Also used : ContextResourceLink(org.apache.tomcat.util.descriptor.web.ContextResourceLink) NamingException(javax.naming.NamingException) LifecycleException(org.apache.catalina.LifecycleException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 12 with ContextResourceLink

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

the class ContextResourceLinkMBean method getAttribute.

/**
 * Obtain and return the value of a specific attribute of this MBean.
 *
 * @param name Name of the requested attribute
 *
 * @exception AttributeNotFoundException if this attribute is not
 *  supported by this MBean
 * @exception MBeanException if the initializer of an object
 *  throws an exception
 * @exception ReflectionException if a Java reflection exception
 *  occurs when invoking the getter
 */
@Override
public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException, ReflectionException {
    // Validate the input parameters
    if (name == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException(sm.getString("mBean.nullName")), sm.getString("mBean.nullName"));
    }
    ContextResourceLink cl = doGetManagedResource();
    String value = null;
    if ("global".equals(name)) {
        return cl.getGlobal();
    } else if ("description".equals(name)) {
        return cl.getDescription();
    } else if ("name".equals(name)) {
        return cl.getName();
    } else if ("type".equals(name)) {
        return cl.getType();
    } else {
        value = (String) cl.getProperty(name);
        if (value == null) {
            throw new AttributeNotFoundException(sm.getString("mBean.attributeNotFound", name));
        }
    }
    return value;
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) ContextResourceLink(org.apache.tomcat.util.descriptor.web.ContextResourceLink) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 13 with ContextResourceLink

use of org.apache.tomcat.util.descriptor.web.ContextResourceLink 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 14 with ContextResourceLink

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

Example 15 with ContextResourceLink

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

the class NamingResourcesMBean method addResourceLink.

/**
 * Add a resource link reference for this web application.
 *
 * @param resourceLinkName New resource link reference name
 * @param type New resource link reference type
 * @return the object name of the new resource link
 * @throws MalformedObjectNameException if the object name was invalid
 */
public String addResourceLink(String resourceLinkName, String type) throws MalformedObjectNameException {
    NamingResourcesImpl nresources = (NamingResourcesImpl) this.resource;
    if (nresources == null) {
        return null;
    }
    ContextResourceLink resourceLink = nresources.findResourceLink(resourceLinkName);
    if (resourceLink != null) {
        throw new IllegalArgumentException(sm.getString("namingResourcesMBean.addAlreadyExists.resourceLink", resourceLinkName));
    }
    resourceLink = new ContextResourceLink();
    resourceLink.setName(resourceLinkName);
    resourceLink.setType(type);
    nresources.addResourceLink(resourceLink);
    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("ContextResourceLink");
    ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), resourceLink);
    return oname.toString();
}
Also used : ContextResourceLink(org.apache.tomcat.util.descriptor.web.ContextResourceLink) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) ManagedBean(org.apache.tomcat.util.modeler.ManagedBean) ObjectName(javax.management.ObjectName)

Aggregations

ContextResourceLink (org.apache.tomcat.util.descriptor.web.ContextResourceLink)16 ContextEnvironment (org.apache.tomcat.util.descriptor.web.ContextEnvironment)10 ContextResource (org.apache.tomcat.util.descriptor.web.ContextResource)7 NamingResourcesImpl (org.apache.catalina.deploy.NamingResourcesImpl)6 NamingException (javax.naming.NamingException)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 LifecycleException (org.apache.catalina.LifecycleException)4 ContextEjb (org.apache.tomcat.util.descriptor.web.ContextEjb)4 ContextResourceEnvRef (org.apache.tomcat.util.descriptor.web.ContextResourceEnvRef)4 ObjectName (javax.management.ObjectName)2 RuntimeOperationsException (javax.management.RuntimeOperationsException)2 Context (org.apache.catalina.Context)2 ContextLocalEjb (org.apache.tomcat.util.descriptor.web.ContextLocalEjb)2 ContextService (org.apache.tomcat.util.descriptor.web.ContextService)2 Test (org.junit.Test)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 JarFile (java.util.jar.JarFile)1 AttributeNotFoundException (javax.management.AttributeNotFoundException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1