use of org.jboss.as.naming.NamingContext in project wildfly by wildfly.
the class EEJndiViewExtension method execute.
public void execute(final JndiViewExtensionContext context) throws OperationFailedException {
final ModelNode applicationsNode = context.getResult().get("applications");
final ServiceRegistry serviceRegistry = context.getOperationContext().getServiceRegistry(false);
final Set<Resource.ResourceEntry> deploymentResource = context.getOperationContext().readResourceFromRoot(PathAddress.EMPTY_ADDRESS, false).getChildren(DEPLOYMENT);
for (final Resource.ResourceEntry entry : deploymentResource) {
final ServiceController<?> deploymentUnitServiceController = serviceRegistry.getService(ServiceName.JBOSS.append("deployment", "unit", entry.getName()));
if (deploymentUnitServiceController != null) {
final ModelNode deploymentNode = applicationsNode.get(entry.getName());
final DeploymentUnit deploymentUnit = DeploymentUnit.class.cast(deploymentUnitServiceController.getValue());
final String appName = cleanName(deploymentUnit.getName());
final ServiceName appContextName = ContextNames.contextServiceNameOfApplication(appName);
final ServiceController<?> appContextController = serviceRegistry.getService(appContextName);
if (appContextController != null) {
final NamingStore appStore = NamingStore.class.cast(appContextController.getValue());
try {
context.addEntries(deploymentNode.get("java:app"), new NamingContext(appStore, null));
} catch (NamingException e) {
throw new OperationFailedException(e, new ModelNode().set(EeLogger.ROOT_LOGGER.failedToRead("java:app", appName)));
}
}
if (DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
final List<ResourceRoot> roots = deploymentUnit.getAttachmentList(org.jboss.as.server.deployment.Attachments.RESOURCE_ROOTS);
if (roots != null)
for (ResourceRoot root : roots) {
if (SubDeploymentMarker.isSubDeployment(root)) {
final ResourceRoot parentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
final String relativePath = root.getRoot().getPathNameRelativeTo(parentRoot.getRoot());
final ServiceName subDeploymentServiceName = Services.deploymentUnitName(deploymentUnit.getName(), relativePath);
final ServiceController<?> subDeploymentController = serviceRegistry.getService(subDeploymentServiceName);
if (subDeploymentController != null) {
final DeploymentUnit subDeploymentUnit = DeploymentUnit.class.cast(subDeploymentController.getValue());
handleModule(context, subDeploymentUnit, deploymentNode.get("modules"), serviceRegistry);
}
}
}
} else {
handleModule(context, deploymentUnit, deploymentNode.get("modules"), serviceRegistry);
}
}
}
}
use of org.jboss.as.naming.NamingContext in project wildfly by wildfly.
the class HttpRemoteNamingServerService method start.
@Override
public void start(StartContext startContext) throws StartException {
final Context namingContext = new NamingContext(namingStore.getValue(), new Hashtable<String, Object>());
HttpRemoteNamingService service = new HttpRemoteNamingService(namingContext);
pathHandlerInjectedValue.getValue().addPrefixPath(NAMING, service.createHandler());
}
use of org.jboss.as.naming.NamingContext in project wildfly by wildfly.
the class EEJndiViewExtension method handleModule.
private void handleModule(final JndiViewExtensionContext context, final DeploymentUnit deploymentUnit, final ModelNode modulesNode, final ServiceRegistry serviceRegistry) throws OperationFailedException {
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
// If it isn't an EE module, just return
if (moduleDescription == null) {
return;
}
final String appName = moduleDescription.getApplicationName();
final String moduleName = moduleDescription.getModuleName();
final ModelNode moduleNode = modulesNode.get(moduleDescription.getModuleName());
final ServiceName moduleContextName = ContextNames.contextServiceNameOfModule(appName, moduleName);
final ServiceController<?> moduleContextController = serviceRegistry.getService(moduleContextName);
if (moduleContextController != null) {
final NamingStore moduleStore = NamingStore.class.cast(moduleContextController.getValue());
try {
context.addEntries(moduleNode.get("java:module"), new NamingContext(moduleStore, null));
} catch (NamingException e) {
throw new OperationFailedException(e, new ModelNode().set(EeLogger.ROOT_LOGGER.failedToRead("java:module", appName, moduleName)));
}
final Collection<ComponentDescription> componentDescriptions = moduleDescription.getComponentDescriptions();
for (ComponentDescription componentDescription : componentDescriptions) {
final String componentName = componentDescription.getComponentName();
final ServiceName compContextServiceName = ContextNames.contextServiceNameOfComponent(appName, moduleName, componentName);
final ServiceController<?> compContextController = serviceRegistry.getService(compContextServiceName);
if (compContextController != null) {
final ModelNode componentNode = moduleNode.get("components").get(componentName);
final NamingStore compStore = NamingStore.class.cast(compContextController.getValue());
try {
context.addEntries(componentNode.get("java:comp"), new NamingContext(compStore, null));
} catch (NamingException e) {
throw new OperationFailedException(e, new ModelNode().set(EeLogger.ROOT_LOGGER.failedToRead("java:comp", appName, moduleName, componentName)));
}
}
}
}
}
use of org.jboss.as.naming.NamingContext in project wildfly by wildfly.
the class JndiViewOperation method addEntries.
private void addEntries(final ModelNode current, final Context context) throws NamingException {
final NamingEnumeration<NameClassPair> entries = context.list("");
while (entries.hasMore()) {
final NameClassPair pair = entries.next();
final ModelNode node = current.get(pair.getName());
node.get("class-name").set(pair.getClassName());
try {
final Object value;
if (context instanceof NamingContext) {
value = ((NamingContext) context).lookup(pair.getName(), false);
} else {
value = context.lookup(pair.getName());
}
if (value instanceof Context) {
addEntries(node.get("children"), Context.class.cast(value));
} else if (value instanceof Reference) {
//node.get("value").set(value.toString());
} else {
String jndiViewValue = JndiViewManagedReferenceFactory.DEFAULT_JNDI_VIEW_INSTANCE_VALUE;
if (value instanceof JndiViewManagedReferenceFactory) {
try {
jndiViewValue = JndiViewManagedReferenceFactory.class.cast(value).getJndiViewInstanceValue();
} catch (Throwable e) {
// just log, don't stop the operation
NamingLogger.ROOT_LOGGER.failedToLookupJndiViewValue(pair.getName(), e);
}
} else if (!(value instanceof ManagedReferenceFactory)) {
jndiViewValue = String.valueOf(value);
}
node.get("value").set(jndiViewValue);
}
} catch (NamingException e) {
// just log, don't stop the operation
NamingLogger.ROOT_LOGGER.failedToLookupJndiViewValue(pair.getName(), e);
}
}
}
use of org.jboss.as.naming.NamingContext in project wildfly by wildfly.
the class RemoteNamingServerService method start.
public synchronized void start(StartContext context) throws StartException {
try {
final Context namingContext = new NamingContext(namingStore.getValue(), new Hashtable<String, Object>());
remoteNamingService = new RemoteNamingService(namingContext);
remoteNamingService.start(endpoint.getValue());
} catch (Exception e) {
throw new StartException("Failed to start remote naming service", e);
}
}
Aggregations