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);
}
}
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();
}
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));
}
}
}
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);
}
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()]);
}
Aggregations