Search in sources :

Example 11 with ContextResource

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

the class NamingResourcesMBean method removeResource.

/**
 * Remove any resource reference with the specified name.
 *
 * @param resourceName Name of the resource reference to remove
 */
public void removeResource(String resourceName) {
    resourceName = ObjectName.unquote(resourceName);
    NamingResources nresources = (NamingResources) this.resource;
    if (nresources == null) {
        return;
    }
    ContextResource resource = nresources.findResource(resourceName);
    if (resource == null) {
        throw new IllegalArgumentException("Invalid resource name '" + resourceName + "'");
    }
    nresources.removeResource(resourceName);
}
Also used : NamingResources(org.apache.catalina.deploy.NamingResources) ContextResource(org.apache.catalina.deploy.ContextResource)

Example 12 with ContextResource

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

the class NamingResourcesMBean method getResources.

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

Example 13 with ContextResource

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

the class StandardContext method removeResource.

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

Example 14 with ContextResource

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

the class WebModuleContextConfig method configureResource.

protected synchronized void configureResource() throws LifecycleException {
    List<ApplicationParameter> appParams = context.findApplicationParameters();
    ContextParameter contextParam;
    synchronized (appParams) {
        Iterator<ApplicationParameter> i = appParams.iterator();
        while (i.hasNext()) {
            ApplicationParameter appParam = i.next();
            contextParam = new EnvironmentProperty(appParam.getName(), appParam.getValue(), appParam.getDescription());
            webBundleDescriptor.addContextParameter(contextParam);
        }
    }
    ContextEnvironment[] envs = context.findEnvironments();
    EnvironmentProperty envEntry;
    for (int i = 0; i < envs.length; i++) {
        envEntry = new EnvironmentProperty(envs[i].getName(), envs[i].getValue(), envs[i].getDescription(), envs[i].getType());
        if (envs[i].getValue() != null) {
            envEntry.setValue(envs[i].getValue());
        }
        webBundleDescriptor.addEnvironmentProperty(envEntry);
        envProps.add(envEntry);
    }
    ContextResource[] resources = context.findResources();
    ResourceReferenceDescriptor resourceReference;
    Set<ResourceReferenceDescriptor> rrs = webBundleDescriptor.getResourceReferenceDescriptors();
    ResourcePrincipal rp;
    for (int i = 0; i < resources.length; i++) {
        resourceReference = new ResourceReferenceDescriptor(resources[i].getName(), resources[i].getDescription(), resources[i].getType());
        resourceReference.setJndiName(resources[i].getName());
        for (ResourceReferenceDescriptor rr : rrs) {
            if (resources[i].getName().equals(rr.getName())) {
                resourceReference.setJndiName(rr.getJndiName());
                rp = rr.getResourcePrincipal();
                if (rp != null) {
                    resourceReference.setResourcePrincipal(new ResourcePrincipal(rp.getName(), rp.getPassword()));
                }
            }
        }
        resourceReference.setAuthorization(resources[i].getAuth());
        webBundleDescriptor.addResourceReferenceDescriptor(resourceReference);
        resRefs.add(resourceReference);
    }
}
Also used : ContextEnvironment(org.apache.catalina.deploy.ContextEnvironment) ApplicationParameter(org.apache.catalina.deploy.ApplicationParameter) ContextParameter(com.sun.enterprise.deployment.web.ContextParameter) ContextResource(org.apache.catalina.deploy.ContextResource)

Aggregations

ContextResource (org.apache.catalina.deploy.ContextResource)14 NamingResources (org.apache.catalina.deploy.NamingResources)6 ObjectName (javax.management.ObjectName)3 StandardContext (org.apache.catalina.core.StandardContext)3 ContextEnvironment (org.apache.catalina.deploy.ContextEnvironment)3 Tomcat (org.apache.catalina.startup.Tomcat)3 ByteChunk (org.apache.tomcat.util.buf.ByteChunk)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 ContextResourceEnvRef (org.apache.catalina.deploy.ContextResourceEnvRef)2 ContextService (org.apache.catalina.deploy.ContextService)2 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)2 Test (org.junit.Test)2 ContextParameter (com.sun.enterprise.deployment.web.ContextParameter)1 AttributeNotFoundException (javax.management.AttributeNotFoundException)1 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)1