use of org.apache.catalina.deploy.NamingResourcesImpl in project tomcat by apache.
the class StandardServerSF method storeChildren.
/**
* Store the specified server element children.
*
* @param aWriter Current output writer
* @param indent Indentation level
* @param aObject Server to store
* @param parentDesc The element description
* @throws Exception Configuration storing error
*/
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aObject, StoreDescription parentDesc) throws Exception {
if (aObject instanceof StandardServer) {
StandardServer server = (StandardServer) aObject;
// Store nested <Listener> elements
LifecycleListener[] listeners = server.findLifecycleListeners();
storeElementArray(aWriter, indent, listeners);
/*LifecycleListener listener = null;
for (int i = 0; listener == null && i < listeners.length; i++)
if (listeners[i] instanceof ServerLifecycleListener)
listener = listeners[i];
if (listener != null) {
StoreDescription elementDesc = getRegistry()
.findDescription(
StandardServer.class.getName()
+ ".[ServerLifecycleListener]");
if (elementDesc != null) {
elementDesc.getStoreFactory().store(aWriter, indent,
listener);
}
}*/
// Store nested <GlobalNamingResources> element
NamingResourcesImpl globalNamingResources = server.getGlobalNamingResources();
StoreDescription elementDesc = getRegistry().findDescription(NamingResourcesImpl.class.getName() + ".[GlobalNamingResources]");
if (elementDesc != null) {
elementDesc.getStoreFactory().store(aWriter, indent, globalNamingResources);
}
// Store nested <Service> elements
Service[] services = server.findServices();
storeElementArray(aWriter, indent, services);
}
}
use of org.apache.catalina.deploy.NamingResourcesImpl in project tomcat by apache.
the class StandardContext method setNamingResources.
/**
* Set the naming resources for this web application.
*
* @param namingResources The new naming resources
*/
@Override
public void setNamingResources(NamingResourcesImpl namingResources) {
// Process the property setting change
NamingResourcesImpl oldNamingResources = this.namingResources;
this.namingResources = namingResources;
if (namingResources != null) {
namingResources.setContainer(this);
}
support.firePropertyChange("namingResources", oldNamingResources, this.namingResources);
if (getState() == LifecycleState.NEW || getState() == LifecycleState.INITIALIZING || getState() == LifecycleState.INITIALIZED) {
// when it starts
return;
}
if (oldNamingResources != null) {
try {
oldNamingResources.stop();
oldNamingResources.destroy();
} catch (LifecycleException e) {
log.error(sm.getString("standardContext.namingResource.destroy.fail"), e);
}
}
if (namingResources != null) {
try {
namingResources.init();
namingResources.start();
} catch (LifecycleException e) {
log.error(sm.getString("standardContext.namingResource.init.fail"), e);
}
}
}
use of org.apache.catalina.deploy.NamingResourcesImpl in project tomee by apache.
the class TomcatWebAppBuilder method start.
@Override
public void start(final StandardServer server) {
if (SystemInstance.get().isDefaultProfile()) {
// add user tomee is no user are specified
try {
final NamingResourcesImpl resources = server.getGlobalNamingResources();
final ContextResource userDataBaseResource = resources.findResource("UserDatabase");
final UserDatabase db = (UserDatabase) server.getGlobalNamingContext().lookup(userDataBaseResource.getName());
if (!db.getUsers().hasNext() && db instanceof MemoryUserDatabase) {
final MemoryUserDatabase mudb = (MemoryUserDatabase) db;
final boolean oldRo = mudb.getReadonly();
try {
((MemoryUserDatabase) db).setReadonly(false);
db.createRole("tomee-admin", "tomee admin role");
db.createUser("tomee", "tomee", "TomEE");
db.findUser("tomee").addRole(db.findRole("tomee-admin"));
} finally {
mudb.setReadonly(oldRo);
}
}
} catch (final Throwable t) {
// no-op
}
}
}
use of org.apache.catalina.deploy.NamingResourcesImpl in project tomee by apache.
the class OpenEJBContextConfig method adjustDataSourceNameIfNecessary.
private void adjustDataSourceNameIfNecessary() {
if (context == null || "false".equalsIgnoreCase(ADJUST_DATASOURCE_JNDI_NAMES)) {
return;
}
final NamingResourcesImpl resources = context.getNamingResources();
if (resources == null) {
return;
}
final ContextResource[] foundResources = resources.findResources();
String[] ids = null;
if (foundResources != null) {
for (final ContextResource resource : foundResources) {
if ("javax.sql.DataSource".equals(resource.getType()) && !ResourceFactory.class.getName().equals(resource.getProperty(Constants.FACTORY))) {
String jndiName = (String) resource.getProperty("mappedName");
if (jndiName == null) {
jndiName = resource.getName();
}
if (jndiName == null) {
continue;
}
if (ids == null) {
final Properties props = new Properties();
final OpenEjbConfiguration runningConfig = SystemInstance.get().getComponent(OpenEjbConfiguration.class);
final List<String> resourceIds = new ArrayList<>();
if (runningConfig != null) {
for (final ResourceInfo resourceInfo : runningConfig.facilities.resources) {
if (ConfigurationFactory.isResourceType(resourceInfo.service, resourceInfo.types, "javax.sql.DataSource") && ServiceUtils.implies(props, resourceInfo.properties)) {
resourceIds.add(resourceInfo.id);
}
}
}
ids = resourceIds.toArray(new String[resourceIds.size()]);
}
String mostMatchingId = null;
for (final String id : ids) {
if (id.equals(jndiName)) {
mostMatchingId = jndiName;
break;
} else if (jndiName.endsWith("/" + id) && mostMatchingId == null) {
mostMatchingId = id;
} else if (id.endsWith("/" + jndiName) && mostMatchingId == null) {
mostMatchingId = "openejb/Resource/" + id;
}
}
if (mostMatchingId != null) {
resource.setProperty("mappedName", "java:" + mostMatchingId);
resource.setProperty(NamingUtil.RESOURCE_ID, "java:" + mostMatchingId);
resource.setProperty(Constants.FACTORY, ResourceFactory.class.getName());
}
}
}
}
}
use of org.apache.catalina.deploy.NamingResourcesImpl in project tomee by apache.
the class TomEEDefaultIdentityStore method init.
@PostConstruct
private void init() throws Exception {
definition = definitionSupplier.get();
final StandardServer server = TomcatHelper.getServer();
final NamingResourcesImpl resources = server.getGlobalNamingResources();
final ContextResource userDataBaseResource = resources.findResource(definition.resource());
userDatabase = (UserDatabase) server.getGlobalNamingContext().lookup(userDataBaseResource.getName());
}
Aggregations