Search in sources :

Example 1 with EJBClientDescriptorMetaData

use of org.jboss.as.ee.metadata.EJBClientDescriptorMetaData in project wildfly by wildfly.

the class EJBClientDescriptorParsingProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final XMLMapper mapper = createMapper(deploymentUnit);
    final ResourceRoot resourceRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
    final ServiceModuleLoader moduleLoader = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.SERVICE_MODULE_LOADER);
    VirtualFile descriptorFile = null;
    for (final String loc : EJB_CLIENT_DESCRIPTOR_LOCATIONS) {
        final VirtualFile file = resourceRoot.getRoot().getChild(loc);
        if (file.exists()) {
            descriptorFile = file;
            break;
        }
    }
    if (descriptorFile == null) {
        return;
    }
    if (deploymentUnit.getParent() != null) {
        EeLogger.ROOT_LOGGER.subdeploymentIgnored(descriptorFile.getPathName());
        return;
    }
    final File ejbClientDeploymentDescriptorFile;
    try {
        ejbClientDeploymentDescriptorFile = descriptorFile.getPhysicalFile();
    } catch (IOException e) {
        throw EeLogger.ROOT_LOGGER.failedToProcessEJBClientDescriptor(e);
    }
    final EJBClientDescriptorMetaData ejbClientDescriptorMetaData = parse(ejbClientDeploymentDescriptorFile, mapper);
    EeLogger.ROOT_LOGGER.debugf("Successfully parsed jboss-ejb-client.xml for deployment unit %s", deploymentUnit);
    // attach the metadata
    deploymentUnit.putAttachment(Attachments.EJB_CLIENT_METADATA, ejbClientDescriptorMetaData);
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) XMLMapper(org.jboss.staxmapper.XMLMapper) EJBClientDescriptorMetaData(org.jboss.as.ee.metadata.EJBClientDescriptorMetaData) ServiceModuleLoader(org.jboss.as.server.moduleservice.ServiceModuleLoader) IOException(java.io.IOException) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) File(java.io.File) VirtualFile(org.jboss.vfs.VirtualFile)

Example 2 with EJBClientDescriptorMetaData

use of org.jboss.as.ee.metadata.EJBClientDescriptorMetaData in project wildfly by wildfly.

the class EJBClientDescriptorMetaDataProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    // we only process top level deployment units
    if (deploymentUnit.getParent() != null) {
        return;
    }
    final EJBClientDescriptorMetaData ejbClientDescriptorMetaData = deploymentUnit.getAttachment(Attachments.EJB_CLIENT_METADATA);
    // no explicit EJB client configuration in this deployment, so nothing to do
    if (ejbClientDescriptorMetaData == null) {
        return;
    }
    // profile and remoting-ejb-receivers cannot be used together
    checkDescriptorConfiguration(ejbClientDescriptorMetaData);
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    if (module == null) {
        return;
    }
    // install the descriptor based EJB client context service
    final ServiceName ejbClientContextServiceName = EJBClientContextService.DEPLOYMENT_BASE_SERVICE_NAME.append(deploymentUnit.getName());
    final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
    // create the service
    final EJBClientContextService service = new EJBClientContextService();
    // add the service
    final ServiceBuilder<EJBClientContextService> serviceBuilder = serviceTarget.addService(ejbClientContextServiceName, service);
    if (appclient) {
        serviceBuilder.addDependency(EJBClientContextService.APP_CLIENT_URI_SERVICE_NAME, URI.class, service.getAppClientUri());
    }
    serviceBuilder.addDependency(EJBClientConfiguratorService.SERVICE_NAME, EJBClientConfiguratorService.class, service.getConfiguratorServiceInjector());
    final Injector<RemotingProfileService> profileServiceInjector = new Injector<RemotingProfileService>() {

        final Injector<EJBTransportProvider> injector = service.getLocalProviderInjector();

        boolean injected = false;

        public void inject(final RemotingProfileService value) throws InjectionException {
            final EJBTransportProvider provider = value.getLocalTransportProviderInjector().getOptionalValue();
            if (provider != null) {
                injected = true;
                injector.inject(provider);
            }
        }

        public void uninject() {
            if (injected) {
                injected = false;
                injector.uninject();
            }
        }
    };
    final String profile = ejbClientDescriptorMetaData.getProfile();
    final ServiceName profileServiceName;
    if (profile != null) {
        profileServiceName = RemotingProfileService.BASE_SERVICE_NAME.append(profile);
        serviceBuilder.addDependency(profileServiceName, RemotingProfileService.class, profileServiceInjector);
        serviceBuilder.addDependency(profileServiceName, RemotingProfileService.class, service.getProfileServiceInjector());
    } else {
        // if descriptor defines list of ejb-receivers instead of profile then we create internal ProfileService for this
        // application which contains defined receivers
        profileServiceName = ejbClientContextServiceName.append(INTERNAL_REMOTING_PROFILE);
        final Map<String, RemotingProfileService.ConnectionSpec> map = new HashMap<>();
        final RemotingProfileService profileService = new RemotingProfileService(Collections.emptyList(), map);
        final ServiceBuilder<RemotingProfileService> profileServiceBuilder = serviceTarget.addService(profileServiceName, profileService);
        if (ejbClientDescriptorMetaData.isLocalReceiverExcluded() != Boolean.TRUE) {
            final Boolean passByValue = ejbClientDescriptorMetaData.isLocalReceiverPassByValue();
            profileServiceBuilder.addDependency(passByValue == Boolean.TRUE ? LocalTransportProvider.BY_VALUE_SERVICE_NAME : LocalTransportProvider.BY_REFERENCE_SERVICE_NAME, EJBTransportProvider.class, profileService.getLocalTransportProviderInjector());
        }
        final Collection<EJBClientDescriptorMetaData.RemotingReceiverConfiguration> receiverConfigurations = ejbClientDescriptorMetaData.getRemotingReceiverConfigurations();
        for (EJBClientDescriptorMetaData.RemotingReceiverConfiguration receiverConfiguration : receiverConfigurations) {
            final String connectionRef = receiverConfiguration.getOutboundConnectionRef();
            final long connectTimeout = receiverConfiguration.getConnectionTimeout();
            final Properties channelCreationOptions = receiverConfiguration.getChannelCreationOptions();
            final OptionMap optionMap = getOptionMapFromProperties(channelCreationOptions, EJBClientDescriptorMetaDataProcessor.class.getClassLoader());
            final InjectedValue<AbstractOutboundConnectionService> injector = new InjectedValue<>();
            profileServiceBuilder.addDependency(AbstractOutboundConnectionService.OUTBOUND_CONNECTION_BASE_SERVICE_NAME.append(connectionRef), AbstractOutboundConnectionService.class, injector);
            final RemotingProfileService.ConnectionSpec connectionSpec = new RemotingProfileService.ConnectionSpec(connectionRef, injector, optionMap, connectTimeout);
            map.put(connectionRef, connectionSpec);
        }
        profileServiceBuilder.install();
        serviceBuilder.addDependency(profileServiceName, RemotingProfileService.class, profileServiceInjector);
        serviceBuilder.addDependency(profileServiceName, RemotingProfileService.class, service.getProfileServiceInjector());
    }
    // these items are the same no matter how we were configured
    final String deploymentNodeSelectorClassName = ejbClientDescriptorMetaData.getDeploymentNodeSelector();
    if (deploymentNodeSelectorClassName != null) {
        final DeploymentNodeSelector deploymentNodeSelector;
        try {
            deploymentNodeSelector = module.getClassLoader().loadClass(deploymentNodeSelectorClassName).asSubclass(DeploymentNodeSelector.class).getConstructor().newInstance();
        } catch (Exception e) {
            throw EjbLogger.ROOT_LOGGER.failedToCreateDeploymentNodeSelector(e, deploymentNodeSelectorClassName);
        }
        service.setDeploymentNodeSelector(deploymentNodeSelector);
    }
    final long invocationTimeout = ejbClientDescriptorMetaData.getInvocationTimeout();
    service.setInvocationTimeout(invocationTimeout);
    // clusters
    final Collection<EJBClientDescriptorMetaData.ClusterConfig> clusterConfigs = ejbClientDescriptorMetaData.getClusterConfigs();
    if (!clusterConfigs.isEmpty()) {
        final List<EJBClientCluster> clientClusters = new ArrayList<>(clusterConfigs.size());
        AuthenticationContext clustersAuthenticationContext = AuthenticationContext.empty();
        for (EJBClientDescriptorMetaData.ClusterConfig clusterConfig : clusterConfigs) {
            MatchRule defaultRule = MatchRule.ALL.matchAbstractType("ejb", "jboss");
            AuthenticationConfiguration defaultAuthenticationConfiguration = AuthenticationConfiguration.EMPTY;
            final EJBClientCluster.Builder clientClusterBuilder = new EJBClientCluster.Builder();
            final String clusterName = clusterConfig.getClusterName();
            clientClusterBuilder.setName(clusterName);
            defaultRule = defaultRule.matchProtocol("cluster");
            defaultRule = defaultRule.matchUrnName(clusterName);
            final long maxAllowedConnectedNodes = clusterConfig.getMaxAllowedConnectedNodes();
            clientClusterBuilder.setMaximumConnectedNodes(maxAllowedConnectedNodes);
            final String clusterNodeSelectorClassName = clusterConfig.getNodeSelector();
            if (clusterNodeSelectorClassName != null) {
                final ClusterNodeSelector clusterNodeSelector;
                try {
                    clusterNodeSelector = module.getClassLoader().loadClass(clusterNodeSelectorClassName).asSubclass(ClusterNodeSelector.class).getConstructor().newInstance();
                } catch (Exception e) {
                    throw EjbLogger.ROOT_LOGGER.failureDuringLoadOfClusterNodeSelector(clusterNodeSelectorClassName, clusterName, e);
                }
                clientClusterBuilder.setClusterNodeSelector(clusterNodeSelector);
            }
            final Properties clusterChannelCreationOptions = clusterConfig.getChannelCreationOptions();
            final OptionMap clusterChannelCreationOptionMap = getOptionMapFromProperties(clusterChannelCreationOptions, EJBClientDescriptorMetaDataProcessor.class.getClassLoader());
            final Properties clusterConnectionOptions = clusterConfig.getConnectionOptions();
            final OptionMap clusterConnectionOptionMap = getOptionMapFromProperties(clusterConnectionOptions, EJBClientDescriptorMetaDataProcessor.class.getClassLoader());
            final long clusterConnectTimeout = clusterConfig.getConnectTimeout();
            clientClusterBuilder.setConnectTimeoutMilliseconds(clusterConnectTimeout);
            final String clusterSecurityRealm = clusterConfig.getSecurityRealm();
            final String clusterUserName = clusterConfig.getUserName();
            CallbackHandler callbackHandler = getCallbackHandler(phaseContext.getServiceRegistry(), clusterUserName, clusterSecurityRealm);
            if (callbackHandler != null) {
                defaultAuthenticationConfiguration = defaultAuthenticationConfiguration.useCallbackHandler(callbackHandler);
            }
            if (clusterConnectionOptionMap != null) {
                RemotingOptions.mergeOptionsIntoAuthenticationConfiguration(clusterConnectionOptionMap, defaultAuthenticationConfiguration);
            }
            clustersAuthenticationContext = clustersAuthenticationContext.with(defaultRule, defaultAuthenticationConfiguration);
            final Collection<EJBClientDescriptorMetaData.ClusterNodeConfig> clusterNodeConfigs = clusterConfig.getClusterNodeConfigs();
            for (EJBClientDescriptorMetaData.ClusterNodeConfig clusterNodeConfig : clusterNodeConfigs) {
                MatchRule nodeRule = MatchRule.ALL.matchAbstractType("ejb", "jboss");
                AuthenticationConfiguration nodeAuthenticationConfiguration = AuthenticationConfiguration.EMPTY;
                final String nodeName = clusterNodeConfig.getNodeName();
                nodeRule = nodeRule.matchProtocol("node");
                nodeRule = nodeRule.matchUrnName(nodeName);
                final Properties channelCreationOptions = clusterNodeConfig.getChannelCreationOptions();
                final Properties connectionOptions = clusterNodeConfig.getConnectionOptions();
                final OptionMap connectionOptionMap = getOptionMapFromProperties(connectionOptions, EJBClientDescriptorMetaDataProcessor.class.getClassLoader());
                final long connectTimeout = clusterNodeConfig.getConnectTimeout();
                final String securityRealm = clusterNodeConfig.getSecurityRealm();
                final String userName = clusterNodeConfig.getUserName();
                CallbackHandler nodeCallbackHandler = getCallbackHandler(phaseContext.getServiceRegistry(), userName, securityRealm);
                if (nodeCallbackHandler != null) {
                    nodeAuthenticationConfiguration = nodeAuthenticationConfiguration.useCallbackHandler(nodeCallbackHandler);
                }
                if (connectionOptionMap != null) {
                    RemotingOptions.mergeOptionsIntoAuthenticationConfiguration(connectionOptionMap, nodeAuthenticationConfiguration);
                }
                clustersAuthenticationContext = clustersAuthenticationContext.with(0, nodeRule, nodeAuthenticationConfiguration);
            }
            final EJBClientCluster clientCluster = clientClusterBuilder.build();
            clientClusters.add(clientCluster);
        }
        service.setClientClusters(clientClusters);
        service.setClustersAuthenticationContext(clustersAuthenticationContext);
    }
    // install the service
    serviceBuilder.install();
    EjbLogger.DEPLOYMENT_LOGGER.debugf("Deployment unit %s will use %s as the EJB client context service", deploymentUnit, ejbClientContextServiceName);
    // attach the service name of this EJB client context to the deployment unit
    phaseContext.addDeploymentDependency(ejbClientContextServiceName, EjbDeploymentAttachmentKeys.EJB_CLIENT_CONTEXT_SERVICE);
    deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.EJB_CLIENT_CONTEXT_SERVICE_NAME, ejbClientContextServiceName);
    deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.EJB_REMOTING_PROFILE_SERVICE_NAME, profileServiceName);
}
Also used : AbstractOutboundConnectionService(org.jboss.as.remoting.AbstractOutboundConnectionService) InjectedValue(org.jboss.msc.value.InjectedValue) CallbackHandler(javax.security.auth.callback.CallbackHandler) AuthenticationContext(org.wildfly.security.auth.client.AuthenticationContext) HashMap(java.util.HashMap) EJBClientContextService(org.jboss.as.ejb3.remote.EJBClientContextService) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ArrayList(java.util.ArrayList) MatchRule(org.wildfly.security.auth.client.MatchRule) Properties(java.util.Properties) DeploymentNodeSelector(org.jboss.ejb.client.DeploymentNodeSelector) ClusterNodeSelector(org.jboss.ejb.client.ClusterNodeSelector) EJBClientDescriptorMetaData(org.jboss.as.ee.metadata.EJBClientDescriptorMetaData) Injector(org.jboss.msc.inject.Injector) RemotingProfileService(org.jboss.as.ejb3.remote.RemotingProfileService) EJBClientCluster(org.jboss.ejb.client.EJBClientCluster) AuthenticationConfiguration(org.wildfly.security.auth.client.AuthenticationConfiguration) ServiceTarget(org.jboss.msc.service.ServiceTarget) InjectionException(org.jboss.msc.inject.InjectionException) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) EJBTransportProvider(org.jboss.ejb.client.EJBTransportProvider) ServiceName(org.jboss.msc.service.ServiceName) OptionMap(org.xnio.OptionMap) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 3 with EJBClientDescriptorMetaData

use of org.jboss.as.ee.metadata.EJBClientDescriptorMetaData in project wildfly by wildfly.

the class DiscoveryRegistrationProcessor method deploy.

public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    // we only process top level deployment units
    if (deploymentUnit.getParent() != null) {
        return;
    }
    final ServiceName clientContextName = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_CLIENT_CONTEXT_SERVICE_NAME);
    final ServiceName profileServiceName = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_REMOTING_PROFILE_SERVICE_NAME);
    final DiscoveryService discoveryService = new DiscoveryService();
    final ServiceName discoveryServiceName = DiscoveryService.BASE_NAME.append(deploymentUnit.getName());
    final ServiceBuilder<Discovery> builder = phaseContext.getServiceTarget().addService(discoveryServiceName, discoveryService);
    Injector<DiscoveryProvider> providerInjector = discoveryService.getDiscoveryProviderInjector();
    new RemoteEJBDiscoveryConfigurator().configure(providerInjector::inject, registryProvider -> {
    });
    if (profileServiceName != null)
        builder.addDependency(profileServiceName, RemotingProfileService.class, new Injector<RemotingProfileService>() {

            Injector<DiscoveryProvider> providerInjector = discoveryService.getDiscoveryProviderInjector();

            public void inject(final RemotingProfileService value) throws InjectionException {
                providerInjector.inject(new StaticDiscoveryProvider(value.getServiceUrls()));
            }

            public void uninject() {
                providerInjector.uninject();
            }
        });
    // only add association service dependency if the context is configured to use the local EJB receiver & we are not app client
    final EJBClientDescriptorMetaData ejbClientDescriptorMetaData = deploymentUnit.getAttachment(Attachments.EJB_CLIENT_METADATA);
    final boolean useLocalReceiver = ejbClientDescriptorMetaData == null || ejbClientDescriptorMetaData.isLocalReceiverExcluded() != Boolean.TRUE;
    if (useLocalReceiver && !appClient) {
        builder.addDependency(AssociationService.SERVICE_NAME, AssociationService.class, new Injector<AssociationService>() {

            Injector<DiscoveryProvider> providerInjector = discoveryService.getDiscoveryProviderInjector();

            public void inject(final AssociationService value) throws InjectionException {
                providerInjector.inject(value.getLocalDiscoveryProvider());
            }

            public void uninject() {
                providerInjector.uninject();
            }
        });
    }
    builder.install();
}
Also used : RemoteEJBDiscoveryConfigurator(org.jboss.ejb.protocol.remote.RemoteEJBDiscoveryConfigurator) DiscoveryProvider(org.wildfly.discovery.spi.DiscoveryProvider) StaticDiscoveryProvider(org.wildfly.discovery.impl.StaticDiscoveryProvider) Discovery(org.wildfly.discovery.Discovery) AssociationService(org.jboss.as.ejb3.remote.AssociationService) InjectionException(org.jboss.msc.inject.InjectionException) ServiceName(org.jboss.msc.service.ServiceName) Injector(org.jboss.msc.inject.Injector) EJBClientDescriptorMetaData(org.jboss.as.ee.metadata.EJBClientDescriptorMetaData) StaticDiscoveryProvider(org.wildfly.discovery.impl.StaticDiscoveryProvider) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) RemotingProfileService(org.jboss.as.ejb3.remote.RemotingProfileService)

Example 4 with EJBClientDescriptorMetaData

use of org.jboss.as.ee.metadata.EJBClientDescriptorMetaData in project wildfly by wildfly.

the class EJBClientDescriptorParsingProcessor method parse.

private EJBClientDescriptorMetaData parse(final InputStream source, final File file, final XMLMapper mapper) throws DeploymentUnitProcessingException {
    try {
        final XMLInputFactory inputFactory = INPUT_FACTORY;
        setIfSupported(inputFactory, XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
        setIfSupported(inputFactory, XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
        final XMLStreamReader streamReader = inputFactory.createXMLStreamReader(source);
        try {
            final EJBClientDescriptorMetaData result = new EJBClientDescriptorMetaData();
            mapper.parseDocument(result, streamReader);
            return result;
        } finally {
            safeClose(streamReader);
        }
    } catch (XMLStreamException e) {
        throw EeLogger.ROOT_LOGGER.xmlErrorParsingEJBClientDescriptor(e, file.getAbsolutePath());
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) EJBClientDescriptorMetaData(org.jboss.as.ee.metadata.EJBClientDescriptorMetaData) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Aggregations

EJBClientDescriptorMetaData (org.jboss.as.ee.metadata.EJBClientDescriptorMetaData)4 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 RemotingProfileService (org.jboss.as.ejb3.remote.RemotingProfileService)2 InjectionException (org.jboss.msc.inject.InjectionException)2 Injector (org.jboss.msc.inject.Injector)2 ServiceName (org.jboss.msc.service.ServiceName)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 CallbackHandler (javax.security.auth.callback.CallbackHandler)1 XMLInputFactory (javax.xml.stream.XMLInputFactory)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 AssociationService (org.jboss.as.ejb3.remote.AssociationService)1 EJBClientContextService (org.jboss.as.ejb3.remote.EJBClientContextService)1 AbstractOutboundConnectionService (org.jboss.as.remoting.AbstractOutboundConnectionService)1 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)1 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)1