use of org.apache.tomcat.util.descriptor.web.ContextResource in project tomee by apache.
the class TomcatWebAppBuilder method createReference.
private static Reference createReference(final ResourceBase resource) {
final Reference ref;
if (resource instanceof ContextResource) {
final ContextResource cr = (ContextResource) resource;
ref = new ResourceRef(resource.getType(), resource.getDescription(), cr.getScope(), cr.getAuth(), cr.getSingleton());
} else {
ref = new ResourceEnvRef(resource.getType());
}
final Iterator<String> params = resource.listProperties();
while (params.hasNext()) {
final String paramName = params.next();
final String paramValue = (String) resource.getProperty(paramName);
final StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
ref.add(refAddr);
}
return ref;
}
use of org.apache.tomcat.util.descriptor.web.ContextResource in project tomee by apache.
the class TomcatWebAppBuilder method loadWebModule.
/**
* Creates a new {@link WebModule} instance from given
* tomcat context instance.
*
* @param standardContext tomcat context instance
*/
private void loadWebModule(final AppModule appModule, final StandardContext standardContext) {
final List<WebModule> webModules = appModule.getWebModules();
if (webModules.isEmpty()) {
final File file = appModule.getFile();
LOGGER.error("Failed to find a single module in: " + file);
return;
}
final WebModule webModule = webModules.get(0);
final WebApp webApp = webModule.getWebApp();
// create the web module
final String path = standardContext.getPath();
LOGGER.debug("context path = " + path);
webModule.setHost(Contexts.getHostname(standardContext));
// Add all Tomcat env entries to context so they can be overriden by the env.properties file
final NamingResourcesImpl naming = standardContext.getNamingResources();
for (final ContextEnvironment environment : naming.findEnvironments()) {
EnvEntry envEntry = webApp.getEnvEntryMap().get(environment.getName());
if (envEntry == null) {
envEntry = new EnvEntry();
envEntry.setName(environment.getName());
webApp.getEnvEntry().add(envEntry);
}
envEntry.setEnvEntryValue(environment.getValue());
envEntry.setEnvEntryType(environment.getType());
}
// remove all jndi entries where there is a configured Tomcat resource or resource-link
for (final ContextResource resource : naming.findResources()) {
final String name = resource.getName();
removeRef(webApp, name);
}
for (final ContextResourceLink resourceLink : naming.findResourceLinks()) {
final String name = resourceLink.getName();
removeRef(webApp, name);
}
// remove all env entries from the web xml that are not overridable
for (final ContextEnvironment environment : naming.findEnvironments()) {
if (!environment.getOverride()) {
// overrides are not allowed
webApp.getEnvEntryMap().remove(environment.getName());
}
}
}
use of org.apache.tomcat.util.descriptor.web.ContextResource in project tomee by apache.
the class OpenEJBNamingContextListener method processInitialNamingResources.
private void processInitialNamingResources() {
// Resource links
final ContextResourceLink[] resourceLinks = namingResources.findResourceLinks();
for (final ContextResourceLink resourceLink : resourceLinks) {
addResourceLink(resourceLink);
}
// Resources
final ContextResource[] resources = namingResources.findResources();
for (final ContextResource resource : resources) {
addResource(resource);
}
// Resources Env
final ContextResourceEnvRef[] resourceEnvRefs = namingResources.findResourceEnvRefs();
for (final ContextResourceEnvRef resourceEnvRef : resourceEnvRefs) {
addResourceEnvRef(resourceEnvRef);
}
// Environment entries
final ContextEnvironment[] contextEnvironments = namingResources.findEnvironments();
for (final ContextEnvironment contextEnvironment : contextEnvironments) {
addEnvironment(contextEnvironment);
}
// EJB references
final ContextEjb[] ejbs = namingResources.findEjbs();
for (final ContextEjb ejb : ejbs) {
addEjb(ejb);
}
}
use of org.apache.tomcat.util.descriptor.web.ContextResource in project tomee by apache.
the class TomcatJndiBuilder method importOpenEJBResourcesInTomcat.
public static void importOpenEJBResourcesInTomcat(final Collection<ResourceInfo> resources, final StandardServer server) {
final NamingResourcesImpl naming = server.getGlobalNamingResources();
for (final ResourceInfo info : resources) {
final String name = info.id;
// if invalid or existing or lazy just skip it cause doesnt work during startup
if (name == null || naming.findResource(name) != null || info.properties.containsKey("UseAppClassLoader")) {
continue;
}
final ContextResource resource = new ContextResource();
resource.setName(name);
resource.setProperty(Constants.FACTORY, ResourceFactory.class.getName());
resource.setProperty(NamingUtil.NAME, name);
resource.setType(info.className);
resource.setAuth("Container");
naming.addResource(resource);
}
}
use of org.apache.tomcat.util.descriptor.web.ContextResource in project tomee by apache.
the class TomcatJndiBuilder method mergeRef.
public void mergeRef(final NamingResourcesImpl naming, final ResourceReferenceInfo ref) {
if (isLookupRef(naming, ref)) {
return;
}
final String name = ref.referenceName.replaceAll("^comp/env/", "");
if (isOpenEjb(naming, name)) {
return;
}
ContextResource resource = naming.findResource(name);
boolean addEntry = false;
if (resource == null) {
resource = new ContextResource();
resource.setName(name);
addEntry = true;
}
resource.setProperty(Constants.FACTORY, ResourceFactory.class.getName());
resource.setProperty(NamingUtil.NAME, name);
resource.setType(ref.referenceType);
resource.setAuth(ref.referenceAuth);
if (ref.resourceID != null) {
resource.setProperty(NamingUtil.RESOURCE_ID, ref.resourceID);
}
if (ref.location != null) {
resource.setProperty(NamingUtil.JNDI_NAME, ref.location.jndiName);
resource.setProperty(NamingUtil.JNDI_PROVIDER_ID, ref.location.jndiProviderId);
}
if (addEntry) {
naming.addResource(resource);
}
if (replaceEntry) {
ContextAccessController.setWritable(namingContextListener.getName(), standardContext.getNamingToken());
if (!addEntry) {
namingContextListener.removeResource(resource.getName());
}
namingContextListener.addResource(resource);
ContextAccessController.setReadOnly(namingContextListener.getName());
}
}
Aggregations