use of org.jboss.as.server.deployment.DeploymentUnitProcessingException in project wildfly by wildfly.
the class WeldComponentIntegrationProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!WeldDeploymentMarker.isWeldDeployment(deploymentUnit)) {
return;
}
final DeploymentUnit topLevelDeployment = getRootDeploymentUnit(deploymentUnit);
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
final ServiceName weldBootstrapService = topLevelDeployment.getServiceName().append(WeldBootstrapService.SERVICE_NAME);
final ServiceName weldStartService = topLevelDeployment.getServiceName().append(WeldStartService.SERVICE_NAME);
final ServiceName beanManagerService = ServiceNames.beanManagerServiceName(deploymentUnit);
final Iterable<ComponentIntegrator> componentIntegrators = ServiceLoader.load(ComponentIntegrator.class, WildFlySecurityManager.getClassLoaderPrivileged(WeldComponentIntegrationProcessor.class));
final ComponentInterceptorSupport componentInterceptorSupport = ServiceLoaders.loadSingle(ComponentInterceptorSupport.class, WeldComponentIntegrationProcessor.class).orElse(null);
WeldClassIntrospector.install(deploymentUnit, phaseContext.getServiceTarget());
eeModuleDescription.setDefaultClassIntrospectorServiceName(WeldClassIntrospector.serviceName(deploymentUnit));
for (ComponentDescription component : eeModuleDescription.getComponentDescriptions()) {
final String beanName;
if (isBeanNameRequired(component, componentIntegrators)) {
beanName = component.getComponentName();
} else {
beanName = null;
}
component.getConfigurators().add((context, description, configuration) -> {
//add interceptor to activate the request scope if required
final EjbRequestScopeActivationInterceptor.Factory requestFactory = new EjbRequestScopeActivationInterceptor.Factory(beanManagerService);
for (ViewConfiguration view : configuration.getViews()) {
view.addViewInterceptor(requestFactory, InterceptorOrder.View.CDI_REQUEST_SCOPE);
}
configuration.addTimeoutViewInterceptor(requestFactory, InterceptorOrder.View.CDI_REQUEST_SCOPE);
});
component.getConfigurators().addFirst(new ComponentConfigurator() {
@Override
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
final Class<?> componentClass = configuration.getComponentClass();
final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
final ModuleClassLoader classLoader = module.getClassLoader();
//get the interceptors so they can be injected as well
final Set<Class<?>> interceptorClasses = new HashSet<Class<?>>();
for (InterceptorDescription interceptorDescription : description.getAllInterceptors()) {
try {
interceptorClasses.add(ClassLoadingUtils.loadClass(interceptorDescription.getInterceptorClassName(), module));
} catch (ClassNotFoundException e) {
throw WeldLogger.ROOT_LOGGER.couldNotLoadInterceptorClass(interceptorDescription.getInterceptorClassName(), e);
}
}
addWeldIntegration(componentIntegrators, componentInterceptorSupport, context.getServiceTarget(), configuration, description, componentClass, beanName, weldBootstrapService, weldStartService, beanManagerService, interceptorClasses, classLoader, description.getBeanDeploymentArchiveId());
}
});
}
}
use of org.jboss.as.server.deployment.DeploymentUnitProcessingException in project wildfly by wildfly.
the class ExternalBeanArchiveProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
return;
}
if (deploymentUnit.getParent() != null) {
return;
}
final Set<String> componentClassNames = new HashSet<>();
final ServiceLoader<ComponentSupport> supportServices = ServiceLoader.load(ComponentSupport.class, WildFlySecurityManager.getClassLoaderPrivileged(ExternalBeanArchiveProcessor.class));
final String beanArchiveIdPrefix = deploymentUnit.getName() + ".external.";
final List<DeploymentUnit> deploymentUnits = new ArrayList<DeploymentUnit>();
deploymentUnits.add(deploymentUnit);
deploymentUnits.addAll(deploymentUnit.getAttachmentList(Attachments.SUB_DEPLOYMENTS));
PropertyReplacingBeansXmlParser parser = new PropertyReplacingBeansXmlParser(deploymentUnit);
final HashSet<URL> existing = new HashSet<URL>();
for (DeploymentUnit deployment : deploymentUnits) {
try {
final ExplicitBeanArchiveMetadataContainer weldDeploymentMetadata = deployment.getAttachment(ExplicitBeanArchiveMetadataContainer.ATTACHMENT_KEY);
if (weldDeploymentMetadata != null) {
for (ExplicitBeanArchiveMetadata md : weldDeploymentMetadata.getBeanArchiveMetadata().values()) {
existing.add(md.getBeansXmlFile().toURL());
if (md.getAdditionalBeansXmlFile() != null) {
existing.add(md.getAdditionalBeansXmlFile().toURL());
}
}
}
} catch (MalformedURLException e) {
throw new DeploymentUnitProcessingException(e);
}
EEModuleDescription moduleDesc = deployment.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
if (moduleDesc != null) {
for (ComponentDescription component : moduleDesc.getComponentDescriptions()) {
for (ComponentSupport support : supportServices) {
if (!support.isDiscoveredExternalType(component)) {
componentClassNames.add(component.getComponentClassName());
break;
}
}
}
}
}
final ServiceLoader<ModuleServicesProvider> moduleServicesProviders = ServiceLoader.load(ModuleServicesProvider.class, WildFlySecurityManager.getClassLoaderPrivileged(WeldDeploymentProcessor.class));
for (DeploymentUnit deployment : deploymentUnits) {
final Module module = deployment.getAttachment(Attachments.MODULE);
if (module == null) {
return;
}
for (DependencySpec dep : module.getDependencies()) {
final Module dependency = loadModuleDependency(dep);
if (dependency == null) {
continue;
}
Set<URL> urls = findExportedLocalBeansXml(dependency);
if (urls != null) {
List<BeanDeploymentArchiveImpl> moduleBdas = new ArrayList<>();
for (URL url : urls) {
if (existing.contains(url)) {
continue;
}
/*
* Workaround for http://java.net/jira/browse/JAVASERVERFACES-2837
*/
if (url.toString().contains("jsf-impl-2.2")) {
continue;
}
/*
* Workaround for resteasy-cdi bundling beans.xml
*/
if (url.toString().contains("resteasy-cdi")) {
continue;
}
WeldLogger.DEPLOYMENT_LOGGER.debugf("Found external beans.xml: %s", url.toString());
final BeansXml beansXml = parseBeansXml(url, parser, deploymentUnit);
final UrlScanner urlScanner = new UrlScanner();
final List<String> discoveredClasses = new ArrayList<String>();
if (!urlScanner.handleBeansXml(url, discoveredClasses)) {
continue;
}
discoveredClasses.removeAll(componentClassNames);
final BeanDeploymentArchiveImpl bda = new BeanDeploymentArchiveImpl(new HashSet<String>(discoveredClasses), beansXml, dependency, beanArchiveIdPrefix + url.toExternalForm(), BeanArchiveType.EXTERNAL);
WeldLogger.DEPLOYMENT_LOGGER.beanArchiveDiscovered(bda);
// Add module services to external bean deployment archive
for (Entry<Class<? extends Service>, Service> entry : ServiceLoaders.loadModuleServices(moduleServicesProviders, deploymentUnit, deployment, module, null).entrySet()) {
bda.getServices().add(entry.getKey(), Reflections.cast(entry.getValue()));
}
deploymentUnit.addToAttachmentList(WeldAttachments.ADDITIONAL_BEAN_DEPLOYMENT_MODULES, bda);
moduleBdas.add(bda);
// make sure that if this beans.xml is seen by some other module, it is not processed twice
existing.add(url);
}
//BDA's from inside the same module have visibility on each other
for (BeanDeploymentArchiveImpl i : moduleBdas) {
for (BeanDeploymentArchiveImpl j : moduleBdas) {
if (i != j) {
i.addBeanDeploymentArchive(j);
}
}
}
}
}
}
}
use of org.jboss.as.server.deployment.DeploymentUnitProcessingException in project wildfly by wildfly.
the class WeldPortableExtensionProcessor method loadAttachments.
private void loadAttachments(Module module, DeploymentUnit deploymentUnit, WeldPortableExtensions extensions) throws DeploymentUnitProcessingException {
// now load extensions
try {
Enumeration<URL> resources = module.getClassLoader().getResources("META-INF/services/" + Extension.class.getName());
final List<String> services = new ArrayList<>();
while (resources.hasMoreElements()) {
URL resource = resources.nextElement();
final InputStream stream = resource.openStream();
try {
final BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8));
String line;
while ((line = reader.readLine()) != null) {
final int commentIdx = line.indexOf('#');
final String className;
if (commentIdx == -1) {
className = line.trim();
} else {
className = line.substring(0, commentIdx).trim();
}
if (className.length() == 0) {
continue;
}
services.add(className);
}
} finally {
VFSUtils.safeClose(stream);
}
}
for (String service : services) {
final Class<Extension> extensionClass = loadExtension(service, module.getClassLoader());
if (extensionClass == null) {
continue;
}
extensions.tryRegisterExtension(extensionClass, deploymentUnit);
}
} catch (IOException e) {
throw new DeploymentUnitProcessingException(e);
}
}
use of org.jboss.as.server.deployment.DeploymentUnitProcessingException in project wildfly by wildfly.
the class IronJacamarDeploymentParsingProcessor method process.
public static IronJacamarXmlDescriptor process(VirtualFile deploymentRoot, boolean resolveProperties) throws DeploymentUnitProcessingException {
IronJacamarXmlDescriptor xmlDescriptor = null;
if (deploymentRoot == null || !deploymentRoot.exists())
return null;
final String deploymentRootName = deploymentRoot.getName().toLowerCase(Locale.ENGLISH);
VirtualFile serviceXmlFile = null;
if (deploymentRootName.endsWith(".rar")) {
serviceXmlFile = deploymentRoot.getChild("/META-INF/ironjacamar.xml");
}
if (serviceXmlFile == null || !serviceXmlFile.exists())
return null;
InputStream xmlStream = null;
Activation result = null;
try {
xmlStream = serviceXmlFile.openStream();
IronJacamarParser ironJacamarParser = new IronJacamarParser();
ironJacamarParser.setSystemPropertiesResolved(resolveProperties);
result = ironJacamarParser.parse(xmlStream);
if (result != null) {
xmlDescriptor = new IronJacamarXmlDescriptor(result);
} else
throw ConnectorLogger.ROOT_LOGGER.failedToParseServiceXml(serviceXmlFile);
} catch (Exception e) {
throw ConnectorLogger.ROOT_LOGGER.failedToParseServiceXml(e, serviceXmlFile);
} finally {
VFSUtils.safeClose(xmlStream);
}
return xmlDescriptor;
}
use of org.jboss.as.server.deployment.DeploymentUnitProcessingException in project wildfly by wildfly.
the class ParsedRaDeploymentProcessor method process.
public static ServiceBuilder<ResourceAdapterDeployment> process(final ConnectorXmlDescriptor connectorXmlDescriptor, final IronJacamarXmlDescriptor ironJacamarXmlDescriptor, final ClassLoader classLoader, final ServiceTarget serviceTarget, final Map<ResourceRoot, Index> annotationIndexes, final ServiceName duServiceName, final ManagementResourceRegistration registration, Resource deploymentResource) throws DeploymentUnitProcessingException {
Connector cmd = connectorXmlDescriptor != null ? connectorXmlDescriptor.getConnector() : null;
final Activation activation = ironJacamarXmlDescriptor != null ? ironJacamarXmlDescriptor.getIronJacamar() : null;
try {
// Annotation merging
Annotations annotator = new Annotations();
if (annotationIndexes != null && annotationIndexes.size() > 0) {
DEPLOYMENT_CONNECTOR_LOGGER.debugf("ParsedRaDeploymentProcessor: Found %d annotationIndexes", annotationIndexes.size());
for (Index index : annotationIndexes.values()) {
// Don't apply any empty indexes, as IronJacamar doesn't like that atm.
if (index.getKnownClasses() != null && index.getKnownClasses().size() > 0) {
AnnotationRepository repository = new JandexAnnotationRepositoryImpl(index, classLoader);
cmd = annotator.merge(cmd, repository, classLoader);
DEPLOYMENT_CONNECTOR_LOGGER.debugf("ParsedRaDeploymentProcessor: CMD=%s", cmd);
}
}
}
if (annotationIndexes == null || annotationIndexes.size() == 0)
DEPLOYMENT_CONNECTOR_LOGGER.debugf("ParsedRaDeploymentProcessor: Found 0 annotationIndexes");
// FIXME: when the connector is null the Iron Jacamar data is ignored
if (cmd != null) {
// Validate metadata
cmd.validate();
// Merge metadata
cmd = (new Merger()).mergeConnectorWithCommonIronJacamar(activation, cmd);
}
TransactionSupportEnum transactionSupport = TransactionSupportEnum.NoTransaction;
if (cmd != null && cmd.getResourceadapter() != null && cmd.getResourceadapter().getOutboundResourceadapter() != null) {
transactionSupport = cmd.getResourceadapter().getOutboundResourceadapter().getTransactionSupport();
}
if (activation != null && activation.getTransactionSupport() != null) {
transactionSupport = activation.getTransactionSupport();
}
final ServiceName deployerServiceName = ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(connectorXmlDescriptor.getDeploymentName());
final ResourceAdapterDeploymentService raDeploymentService = new ResourceAdapterDeploymentService(connectorXmlDescriptor, cmd, activation, classLoader, deployerServiceName, duServiceName, registration, deploymentResource);
// Create the service
ServiceBuilder<ResourceAdapterDeployment> builder = Services.addServerExecutorDependency(serviceTarget.addService(deployerServiceName, raDeploymentService), raDeploymentService.getExecutorServiceInjector(), false).addDependency(ConnectorServices.IRONJACAMAR_MDR, AS7MetadataRepository.class, raDeploymentService.getMdrInjector()).addDependency(ConnectorServices.RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, raDeploymentService.getRaRepositoryInjector()).addDependency(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE, ManagementRepository.class, raDeploymentService.getManagementRepositoryInjector()).addDependency(ConnectorServices.RESOURCE_ADAPTER_REGISTRY_SERVICE, ResourceAdapterDeploymentRegistry.class, raDeploymentService.getRegistryInjector()).addDependency(ConnectorServices.TRANSACTION_INTEGRATION_SERVICE, TransactionIntegration.class, raDeploymentService.getTxIntegrationInjector()).addDependency(ConnectorServices.CONNECTOR_CONFIG_SERVICE, JcaSubsystemConfiguration.class, raDeploymentService.getConfigInjector()).addDependency(ConnectorServices.IDLE_REMOVER_SERVICE).addDependency(ConnectorServices.CONNECTION_VALIDATOR_SERVICE).addDependency(NamingService.SERVICE_NAME);
if (transactionSupport == null || transactionSupport.equals(TransactionSupportEnum.NoTransaction)) {
builder.addDependency(ConnectorServices.NON_TX_CCM_SERVICE, CachedConnectionManager.class, raDeploymentService.getCcmInjector());
} else {
builder.addDependency(ConnectorServices.CCM_SERVICE, CachedConnectionManager.class, raDeploymentService.getCcmInjector());
}
if (activation != null && ActivationSecurityUtil.isLegacySecurityRequired(activation)) {
builder.addDependency(SubjectFactoryService.SERVICE_NAME, SubjectFactory.class, raDeploymentService.getSubjectFactoryInjector()).addDependency(SimpleSecurityManagerService.SERVICE_NAME, ServerSecurityManager.class, raDeploymentService.getServerSecurityManager());
}
return builder;
} catch (Throwable t) {
throw new DeploymentUnitProcessingException(t);
}
}
Aggregations