Search in sources :

Example 1 with NamingContext

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);
            }
        }
    }
}
Also used : NamingStore(org.jboss.as.naming.NamingStore) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) NamingContext(org.jboss.as.naming.NamingContext) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) ServiceName(org.jboss.msc.service.ServiceName) NamingException(javax.naming.NamingException) ServiceController(org.jboss.msc.service.ServiceController) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 2 with NamingContext

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());
}
Also used : NamingContext(org.jboss.as.naming.NamingContext) StopContext(org.jboss.msc.service.StopContext) StartContext(org.jboss.msc.service.StartContext) Context(javax.naming.Context) NamingContext(org.jboss.as.naming.NamingContext) HttpRemoteNamingService(org.wildfly.httpclient.naming.HttpRemoteNamingService)

Example 3 with NamingContext

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)));
                }
            }
        }
    }
}
Also used : NamingStore(org.jboss.as.naming.NamingStore) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ServiceName(org.jboss.msc.service.ServiceName) OperationFailedException(org.jboss.as.controller.OperationFailedException) NamingException(javax.naming.NamingException) ModelNode(org.jboss.dmr.ModelNode) NamingContext(org.jboss.as.naming.NamingContext)

Example 4 with NamingContext

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);
        }
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) NamingContext(org.jboss.as.naming.NamingContext) Context(javax.naming.Context) NameClassPair(javax.naming.NameClassPair) Reference(javax.naming.Reference) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) JndiViewManagedReferenceFactory(org.jboss.as.naming.JndiViewManagedReferenceFactory) NamingException(javax.naming.NamingException) ModelNode(org.jboss.dmr.ModelNode) NamingContext(org.jboss.as.naming.NamingContext) JndiViewManagedReferenceFactory(org.jboss.as.naming.JndiViewManagedReferenceFactory)

Example 5 with NamingContext

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);
    }
}
Also used : StopContext(org.jboss.msc.service.StopContext) StartContext(org.jboss.msc.service.StartContext) NamingContext(org.jboss.as.naming.NamingContext) Context(javax.naming.Context) StartException(org.jboss.msc.service.StartException) NamingContext(org.jboss.as.naming.NamingContext) RemoteNamingService(org.wildfly.naming.client.remote.RemoteNamingService) IOException(java.io.IOException) StartException(org.jboss.msc.service.StartException)

Aggregations

NamingContext (org.jboss.as.naming.NamingContext)5 Context (javax.naming.Context)3 NamingException (javax.naming.NamingException)3 ModelNode (org.jboss.dmr.ModelNode)3 OperationFailedException (org.jboss.as.controller.OperationFailedException)2 NamingStore (org.jboss.as.naming.NamingStore)2 ServiceName (org.jboss.msc.service.ServiceName)2 StartContext (org.jboss.msc.service.StartContext)2 StopContext (org.jboss.msc.service.StopContext)2 IOException (java.io.IOException)1 NameClassPair (javax.naming.NameClassPair)1 Reference (javax.naming.Reference)1 OperationContext (org.jboss.as.controller.OperationContext)1 Resource (org.jboss.as.controller.registry.Resource)1 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)1 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)1 JndiViewManagedReferenceFactory (org.jboss.as.naming.JndiViewManagedReferenceFactory)1 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)1 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)1 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)1