use of org.jboss.ejb.client.EJBClientInterceptor 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 Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
if (module == null) {
return;
}
// support for using capabilities to resolve service names
CapabilityServiceSupport capabilityServiceSupport = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.CAPABILITY_SERVICE_SUPPORT);
// check for EJB client interceptor configuration
final List<EJBClientInterceptor> deploymentEjbClientInterceptors = getClassPathInterceptors(module.getClassLoader());
List<EJBClientInterceptor> staticEjbClientInterceptors = deploymentUnit.getAttachment(org.jboss.as.ejb3.subsystem.Attachments.STATIC_EJB_CLIENT_INTERCEPTORS);
List<EJBClientInterceptor> ejbClientInterceptors = new ArrayList<>();
if (deploymentEjbClientInterceptors != null) {
ejbClientInterceptors.addAll(deploymentEjbClientInterceptors);
}
if (staticEjbClientInterceptors != null) {
ejbClientInterceptors.addAll(staticEjbClientInterceptors);
}
final boolean interceptorsDefined = ejbClientInterceptors != null && !ejbClientInterceptors.isEmpty();
final EJBClientDescriptorMetaData ejbClientDescriptorMetaData = deploymentUnit.getAttachment(Attachments.EJB_CLIENT_METADATA);
// no explicit EJB client configuration in this deployment, so nothing to do
if (ejbClientDescriptorMetaData == null && !interceptorsDefined) {
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(EJBClientContextService.APP_CLIENT_EJB_PROPERTIES_SERVICE_NAME, String.class, service.getAppClientEjbProperties());
}
// default transport providers: remote from config, local from service, in "else" below.
serviceBuilder.addDependency(EJBClientConfiguratorService.SERVICE_NAME, EJBClientConfiguratorService.class, service.getConfiguratorServiceInjector());
if (ejbClientDescriptorMetaData != null) {
// profile and remoting-ejb-receivers cannot be used together
checkDescriptorConfiguration(ejbClientDescriptorMetaData);
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) {
// set up a service for the named remoting profile
profileServiceName = capabilityServiceSupport.getCapabilityServiceName(REMOTING_PROFILE_CAPABILITY_NAME, profile);
// why below?
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.RemotingConnectionSpec> remotingConnectionMap = new HashMap<>();
final List<RemotingProfileService.HttpConnectionSpec> httpConnections = new ArrayList<>();
final RemotingProfileService profileService = new RemotingProfileService(Collections.emptyList(), remotingConnectionMap, httpConnections);
final ServiceBuilder<RemotingProfileService> profileServiceBuilder = serviceTarget.addService(profileServiceName, profileService);
if (ejbClientDescriptorMetaData.isLocalReceiverExcluded() != Boolean.TRUE) {
final Boolean passByValue = ejbClientDescriptorMetaData.isLocalReceiverPassByValue();
profileServiceBuilder.addDependency(passByValue == Boolean.FALSE ? LocalTransportProvider.BY_REFERENCE_SERVICE_NAME : LocalTransportProvider.BY_VALUE_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<OutboundConnection> injector = new InjectedValue<>();
final ServiceName internalServiceName = capabilityServiceSupport.getCapabilityServiceName(OUTBOUND_CONNECTION_CAPABILITY_NAME, connectionRef);
profileServiceBuilder.addDependency(internalServiceName, OutboundConnection.class, injector);
final RemotingProfileService.RemotingConnectionSpec connectionSpec = new RemotingProfileService.RemotingConnectionSpec(connectionRef, injector, optionMap, connectTimeout);
remotingConnectionMap.put(connectionRef, connectionSpec);
}
for (EJBClientDescriptorMetaData.HttpConnectionConfiguration httpConfigurations : ejbClientDescriptorMetaData.getHttpConnectionConfigurations()) {
final String uri = httpConfigurations.getUri();
RemotingProfileService.HttpConnectionSpec httpConnectionSpec = new RemotingProfileService.HttpConnectionSpec(uri);
httpConnections.add(httpConnectionSpec);
}
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);
final int defaultCompression = ejbClientDescriptorMetaData.getDefaultCompression();
service.setDefaultCompression(defaultCompression);
// 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);
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();
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);
}
deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.EJB_REMOTING_PROFILE_SERVICE_NAME, profileServiceName);
} else {
if (!appclient) {
serviceBuilder.addDependency(LocalTransportProvider.DEFAULT_LOCAL_TRANSPORT_PROVIDER_SERVICE_NAME, EJBTransportProvider.class, service.getLocalProviderInjector());
}
}
if (interceptorsDefined) {
service.setClientInterceptors(ejbClientInterceptors);
}
// 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);
}
use of org.jboss.ejb.client.EJBClientInterceptor in project wildfly by wildfly.
the class EJBClientDescriptorMetaDataProcessor method getClassPathInterceptors.
private List<EJBClientInterceptor> getClassPathInterceptors(final ClassLoader classLoader) throws DeploymentUnitProcessingException {
try {
final Enumeration<URL> resources = classLoader.getResources("META-INF/services/org.jboss.ejb.client.EJBClientInterceptor");
final ArrayList<EJBClientInterceptor> interceptors = new ArrayList<>();
if (resources.hasMoreElements()) {
do {
final URL url = resources.nextElement();
try (InputStream st = url.openStream();
InputStreamReader isr = new InputStreamReader(st, StandardCharsets.UTF_8);
BufferedReader r = new BufferedReader(isr)) {
String line;
while ((line = r.readLine()) != null) {
line = line.trim();
if (line.isEmpty() || line.charAt(0) == '#') {
continue;
}
try {
final EJBClientInterceptor interceptor = Class.forName(line, true, classLoader).asSubclass(EJBClientInterceptor.class).getConstructor().newInstance();
interceptors.add(interceptor);
} catch (Exception e) {
throw EjbLogger.ROOT_LOGGER.failedToCreateEJBClientInterceptor(e, line);
}
}
}
} while (resources.hasMoreElements());
}
return interceptors;
} catch (IOException e) {
return Collections.emptyList();
}
}
use of org.jboss.ejb.client.EJBClientInterceptor in project wildfly by wildfly.
the class ClientInterceptorsBindingsProcessor method deploy.
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
try {
final List<EJBClientInterceptor> clientInterceptors = new ArrayList<>();
for (final Class<? extends EJBClientInterceptor> interceptorClass : clientInterceptorCache.getClientInterceptors()) {
clientInterceptors.add(interceptorClass.newInstance());
}
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
deploymentUnit.putAttachment(org.jboss.as.ejb3.subsystem.Attachments.STATIC_EJB_CLIENT_INTERCEPTORS, clientInterceptors);
} catch (InstantiationException | IllegalAccessException e) {
throw new DeploymentUnitProcessingException(e);
}
}
use of org.jboss.ejb.client.EJBClientInterceptor in project wildfly by wildfly.
the class EJBClientContextService method start.
public void start(final StartContext context) throws StartException {
final EJBClientContext.Builder builder = new EJBClientContext.Builder();
// apply subsystem-level configuration that applies to all Jakarta Enterprise Beans client contexts
configuratorServiceInjector.getValue().accept(builder);
builder.setInvocationTimeout(invocationTimeout);
builder.setDefaultCompression(defaultCompression);
final EJBTransportProvider localTransport = localProviderInjector.getOptionalValue();
if (localTransport != null) {
builder.addTransportProvider(localTransport);
}
final RemotingProfileService profileService = profileServiceInjector.getOptionalValue();
if (profileService != null) {
for (RemotingProfileService.RemotingConnectionSpec spec : profileService.getConnectionSpecs()) {
final EJBClientConnection.Builder connBuilder = new EJBClientConnection.Builder();
connBuilder.setDestination(spec.getInjector().getValue().getDestinationUri());
// connBuilder.setConnectionTimeout(timeout);
builder.addClientConnection(connBuilder.build());
}
for (RemotingProfileService.HttpConnectionSpec spec : profileService.getHttpConnectionSpecs()) {
final EJBClientConnection.Builder connBuilder = new EJBClientConnection.Builder();
connBuilder.setDestination(spec.getUri());
builder.addClientConnection(connBuilder.build());
}
}
if (appClientUri.getOptionalValue() != null) {
final EJBClientConnection.Builder connBuilder = new EJBClientConnection.Builder();
connBuilder.setDestination(appClientUri.getOptionalValue());
builder.addClientConnection(connBuilder.build());
}
if (clientClusters != null) {
boolean firstSelector = true;
for (EJBClientCluster clientCluster : clientClusters) {
builder.addClientCluster(clientCluster);
ClusterNodeSelector selector = clientCluster.getClusterNodeSelector();
// Currently only one selector is supported per client context
if (firstSelector) {
if (selector != null) {
builder.setClusterNodeSelector(selector);
}
// TODO: There's a type missmatch in the 'jboss-ejb-client' component.
// The EJBClientContext class and his Builder uses 'int' whereas the
// EJBClientCluster class and his Builder uses 'long'
int maximumConnectedClusterNodes = (int) clientCluster.getMaximumConnectedNodes();
builder.setMaximumConnectedClusterNodes(maximumConnectedClusterNodes);
firstSelector = false;
}
}
}
if (deploymentNodeSelector != null) {
builder.setDeploymentNodeSelector(deploymentNodeSelector);
}
if (appClientEjbProperties.getOptionalValue() != null) {
setupEjbClientProps(appClientEjbProperties.getOptionalValue());
LegacyPropertiesConfiguration.configure(builder);
}
if (clientInterceptors != null) {
for (EJBClientInterceptor clientInterceptor : clientInterceptors) {
builder.addInterceptor(clientInterceptor);
}
}
clientContext = builder.build();
if (makeGlobal) {
doPrivileged((PrivilegedAction<Void>) () -> {
EJBClientContext.getContextManager().setGlobalDefault(clientContext);
return null;
});
}
}
use of org.jboss.ejb.client.EJBClientInterceptor in project wildfly by wildfly.
the class ClientInterceptorCache method loadClientInterceptors.
private void loadClientInterceptors() {
clientInterceptors = new ArrayList<>();
for (final ServerInterceptorMetaData si : serverInterceptorMetaData) {
final Class<? extends EJBClientInterceptor> interceptorClass;
final ModuleIdentifier moduleId = ModuleIdentifier.create(si.getModule());
try {
final Module module = Module.getCallerModuleLoader().loadModule(moduleId);
clientInterceptors.add(ClassLoadingUtils.loadClass(si.getClazz(), module).asSubclass(EJBClientInterceptor.class));
} catch (ModuleLoadException e) {
throw EjbLogger.ROOT_LOGGER.cannotLoadServerInterceptorModule(moduleId, e);
} catch (ClassNotFoundException e) {
throw EeLogger.ROOT_LOGGER.cannotLoadInterceptor(e, si.getClazz());
}
}
}
Aggregations