use of org.apache.catalina.deploy.NamingResourcesImpl 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.catalina.deploy.NamingResourcesImpl 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.catalina.deploy.NamingResourcesImpl in project tomee by apache.
the class TomcatJndiBuilder method mergeJndi.
public void mergeJndi() throws OpenEJBException {
final NamingResourcesImpl naming = standardContext.getNamingResources();
final URI moduleUri = URLs.uri(webAppInfo.moduleId);
for (final EnvEntryInfo ref : webAppInfo.jndiEnc.envEntries) {
mergeRef(naming, ref);
}
for (final EjbReferenceInfo ref : webAppInfo.jndiEnc.ejbReferences) {
mergeRef(naming, ref);
}
for (final EjbLocalReferenceInfo ref : webAppInfo.jndiEnc.ejbLocalReferences) {
mergeRef(naming, ref);
}
for (final PersistenceContextReferenceInfo ref : webAppInfo.jndiEnc.persistenceContextRefs) {
mergeRef(naming, ref, moduleUri);
}
for (final PersistenceUnitReferenceInfo ref : webAppInfo.jndiEnc.persistenceUnitRefs) {
mergeRef(naming, ref, moduleUri);
}
for (final ResourceReferenceInfo ref : webAppInfo.jndiEnc.resourceRefs) {
mergeRef(naming, ref);
}
for (final ResourceEnvReferenceInfo ref : webAppInfo.jndiEnc.resourceEnvRefs) {
mergeRef(naming, ref);
}
for (final ServiceReferenceInfo ref : webAppInfo.jndiEnc.serviceRefs) {
mergeRef(naming, ref);
}
final ContextTransaction contextTransaction = new ContextTransaction();
contextTransaction.setProperty(Constants.FACTORY, UserTransactionFactory.class.getName());
naming.setTransaction(contextTransaction);
}
use of org.apache.catalina.deploy.NamingResourcesImpl in project tomee by apache.
the class OpenEJBContextConfig method contextConfig.
@Override
protected void contextConfig(final Digester digester) {
final NamingResourcesImpl resources;
if (context != null) {
resources = context.getNamingResources();
} else {
resources = null;
}
if (resources instanceof OpenEJBNamingResource) {
((OpenEJBNamingResource) resources).setTomcatResource(true);
}
super.contextConfig(digester);
if (resources instanceof OpenEJBNamingResource) {
((OpenEJBNamingResource) resources).setTomcatResource(false);
}
if (context instanceof StandardContext) {
final StandardContext standardContext = (StandardContext) context;
final NamingContextListener namingContextListener = standardContext.getNamingContextListener();
if (null != namingContextListener) {
namingContextListener.setExceptionOnFailedWrite(standardContext.getJndiExceptionOnFailedWrite());
}
}
}
use of org.apache.catalina.deploy.NamingResourcesImpl in project tomcat by apache.
the class GlobalNamingResourcesSF method store.
/*
* Store with NamingResource Factory
*
* @see org.apache.catalina.storeconfig.IStoreFactory#store(java.io.PrintWriter,
* int, java.lang.Object)
*/
@Override
public void store(PrintWriter aWriter, int indent, Object aElement) throws Exception {
if (aElement instanceof NamingResourcesImpl) {
StoreDescription elementDesc = getRegistry().findDescription(NamingResourcesImpl.class.getName() + ".[GlobalNamingResources]");
if (elementDesc != null) {
getStoreAppender().printIndent(aWriter, indent + 2);
getStoreAppender().printOpenTag(aWriter, indent + 2, aElement, elementDesc);
NamingResourcesImpl resources = (NamingResourcesImpl) aElement;
StoreDescription resourcesdesc = getRegistry().findDescription(NamingResourcesImpl.class.getName());
if (resourcesdesc != null) {
resourcesdesc.getStoreFactory().store(aWriter, indent + 2, resources);
} else {
log.warn(sm.getString("globalNamingResourcesSF.noFactory"));
}
getStoreAppender().printIndent(aWriter, indent + 2);
getStoreAppender().printCloseTag(aWriter, elementDesc);
} else {
log.warn(sm.getString("storeFactory.noDescriptor", aElement.getClass(), "GlobalNamingResources"));
}
} else {
log.warn(sm.getString("globalNamingResourcesSF.wrongElement", aElement.getClass()));
}
}
Aggregations