use of org.jboss.as.ee.component.DeploymentDescriptorEnvironment in project wildfly by wildfly.
the class PersistenceRefProcessor method getPersistenceContextRefs.
/**
* Resolves persistence-unit-ref
*
* @param environment The environment to resolve the elements for
* @param classLoader The deployment class loader
* @param deploymentReflectionIndex The reflection index
* @return The bindings for the environment entries
*/
private List<BindingConfiguration> getPersistenceContextRefs(DeploymentUnit deploymentUnit, DeploymentDescriptorEnvironment environment, ClassLoader classLoader, DeploymentReflectionIndex deploymentReflectionIndex, ResourceInjectionTarget resourceInjectionTarget) throws DeploymentUnitProcessingException {
List<BindingConfiguration> bindingConfigurations = new ArrayList<BindingConfiguration>();
final RemoteEnvironment remoteEnvironment = environment.getEnvironment();
if (remoteEnvironment == null) {
return bindingConfigurations;
}
if (remoteEnvironment instanceof Environment) {
PersistenceContextReferencesMetaData persistenceUnitRefs = ((Environment) remoteEnvironment).getPersistenceContextRefs();
if (persistenceUnitRefs != null) {
for (PersistenceContextReferenceMetaData puRef : persistenceUnitRefs) {
String name = puRef.getName();
String persistenceUnitName = puRef.getPersistenceUnitName();
String lookup = puRef.getLookupName();
if (!isEmpty(lookup) && !isEmpty(persistenceUnitName)) {
throw JpaLogger.ROOT_LOGGER.cannotSpecifyBoth("<lookup-name>", lookup, "persistence-unit-name", persistenceUnitName, "<persistence-context-ref/>", resourceInjectionTarget);
}
if (!name.startsWith("java:")) {
name = environment.getDefaultContext() + name;
}
// our injection (source) comes from the local (ENC) lookup, no matter what.
LookupInjectionSource injectionSource = new LookupInjectionSource(name);
//add any injection targets
processInjectionTargets(resourceInjectionTarget, injectionSource, classLoader, deploymentReflectionIndex, puRef, EntityManager.class);
BindingConfiguration bindingConfiguration = null;
if (!isEmpty(lookup)) {
bindingConfiguration = new BindingConfiguration(name, new LookupInjectionSource(lookup));
} else {
PropertiesMetaData properties = puRef.getProperties();
Map<String, String> map = new HashMap<>();
if (properties != null) {
for (PropertyMetaData prop : properties) {
map.put(prop.getKey(), prop.getValue());
}
}
PersistenceContextType type = (puRef.getPersistenceContextType() == null || puRef.getPersistenceContextType() == PersistenceContextTypeDescription.TRANSACTION) ? PersistenceContextType.TRANSACTION : PersistenceContextType.EXTENDED;
SynchronizationType synchronizationType = (puRef.getPersistenceContextSynchronization() == null || PersistenceContextSynchronizationType.Synchronized.equals(puRef.getPersistenceContextSynchronization())) ? SynchronizationType.SYNCHRONIZED : SynchronizationType.UNSYNCHRONIZED;
InjectionSource pcBindingSource = this.getPersistenceContextBindingSource(deploymentUnit, persistenceUnitName, type, synchronizationType, map);
bindingConfiguration = new BindingConfiguration(name, pcBindingSource);
}
bindingConfigurations.add(bindingConfiguration);
}
}
}
return bindingConfigurations;
}
use of org.jboss.as.ee.component.DeploymentDescriptorEnvironment in project wildfly by wildfly.
the class WarMetaDataProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
// Skip non web deployments
return;
}
WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
assert warMetaData != null;
boolean isComplete = false;
WebMetaData specMetaData = warMetaData.getWebMetaData();
if (specMetaData != null) {
if (specMetaData instanceof Web25MetaData) {
isComplete |= ((Web25MetaData) specMetaData).isMetadataComplete();
} else if (specMetaData instanceof Web30MetaData) {
isComplete |= ((Web30MetaData) specMetaData).isMetadataComplete();
} else {
// As per Servlet 3.0 spec, metadata is not completed unless it's set to true in web.xml.
// Hence, any web.xml 2.4 or earlier deployment is not metadata completed.
isComplete = false;
}
}
// Find all fragments that have been processed by deployers, and place
// them in a map keyed by location
LinkedList<String> order = new LinkedList<String>();
List<WebOrdering> orderings = new ArrayList<WebOrdering>();
HashSet<String> jarsSet = new HashSet<String>();
Set<VirtualFile> overlays = new HashSet<VirtualFile>();
Map<String, VirtualFile> scis = new HashMap<String, VirtualFile>();
boolean fragmentFound = false;
Map<String, WebFragmentMetaData> webFragments = warMetaData.getWebFragmentsMetaData();
List<ResourceRoot> resourceRoots = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
for (ResourceRoot resourceRoot : resourceRoots) {
if (resourceRoot.getRoot().getName().toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
jarsSet.add(resourceRoot.getRootName());
// Find overlays
VirtualFile overlay = resourceRoot.getRoot().getChild("META-INF/resources");
if (overlay.exists()) {
overlays.add(overlay);
}
// Find ServletContainerInitializer services
VirtualFile sci = resourceRoot.getRoot().getChild("META-INF/services/javax.servlet.ServletContainerInitializer");
if (sci.exists()) {
scis.put(resourceRoot.getRootName(), sci);
}
}
}
if (!isComplete) {
HashSet<String> jarsWithoutFragmentsSet = new HashSet<String>();
jarsWithoutFragmentsSet.addAll(jarsSet);
for (String jarName : webFragments.keySet()) {
fragmentFound = true;
WebFragmentMetaData fragmentMetaData = webFragments.get(jarName);
webFragments.put(jarName, fragmentMetaData);
WebOrdering webOrdering = new WebOrdering();
webOrdering.setName(fragmentMetaData.getName());
webOrdering.setJar(jarName);
jarsWithoutFragmentsSet.remove(jarName);
if (fragmentMetaData.getOrdering() != null) {
if (fragmentMetaData.getOrdering().getAfter() != null) {
for (OrderingElementMetaData orderingElementMetaData : fragmentMetaData.getOrdering().getAfter().getOrdering()) {
if (orderingElementMetaData.isOthers()) {
webOrdering.setAfterOthers(true);
} else {
webOrdering.addAfter(orderingElementMetaData.getName());
}
}
}
if (fragmentMetaData.getOrdering().getBefore() != null) {
for (OrderingElementMetaData orderingElementMetaData : fragmentMetaData.getOrdering().getBefore().getOrdering()) {
if (orderingElementMetaData.isOthers()) {
webOrdering.setBeforeOthers(true);
} else {
webOrdering.addBefore(orderingElementMetaData.getName());
}
}
}
}
orderings.add(webOrdering);
}
// fragment specifying no name and no order
for (String jarName : jarsWithoutFragmentsSet) {
WebOrdering ordering = new WebOrdering();
ordering.setJar(jarName);
orderings.add(ordering);
}
}
if (!fragmentFound) {
// Drop the order as there is no fragment in the webapp
orderings.clear();
}
// Generate web fragments parsing order
AbsoluteOrderingMetaData absoluteOrderingMetaData = null;
if (!isComplete && specMetaData instanceof Web30MetaData) {
absoluteOrderingMetaData = ((Web30MetaData) specMetaData).getAbsoluteOrdering();
}
if (absoluteOrderingMetaData != null) {
// Absolute ordering from web.xml, any relative fragment ordering is ignored
int otherPos = -1;
int i = 0;
for (OrderingElementMetaData orderingElementMetaData : absoluteOrderingMetaData.getOrdering()) {
if (orderingElementMetaData.isOthers()) {
if (otherPos >= 0) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidMultipleOthers());
}
otherPos = i;
} else {
boolean found = false;
for (WebOrdering ordering : orderings) {
if (orderingElementMetaData.getName().equals(ordering.getName())) {
order.add(ordering.getJar());
jarsSet.remove(ordering.getJar());
found = true;
break;
}
}
if (!found) {
UndertowLogger.ROOT_LOGGER.invalidAbsoluteOrdering(orderingElementMetaData.getName());
} else {
i++;
}
}
}
if (otherPos >= 0) {
order.addAll(otherPos, jarsSet);
jarsSet.clear();
}
} else if (orderings.size() > 0) {
// Resolve relative ordering
try {
resolveOrder(orderings, order);
} catch (IllegalStateException e) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidRelativeOrdering(), e);
}
jarsSet.clear();
} else {
// No order specified
order.addAll(jarsSet);
jarsSet.clear();
warMetaData.setNoOrder(true);
}
if (UndertowLogger.ROOT_LOGGER.isDebugEnabled()) {
StringBuilder builder = new StringBuilder();
builder.append("Resolved order: [ ");
for (String jar : order) {
builder.append(jar).append(' ');
}
builder.append(']');
UndertowLogger.ROOT_LOGGER.debug(builder.toString());
}
warMetaData.setOrder(order);
warMetaData.setOverlays(overlays);
warMetaData.setScis(scis);
Map<String, WebMetaData> annotationsMetaData = warMetaData.getAnnotationsMetaData();
// The fragments and corresponding annotations will need to be merged in order
// For each JAR in the order:
// - Merge the annotation metadata into the fragment meta data (unless the fragment exists and is meta data complete)
// - Merge the fragment metadata into merged fragment meta data
WebCommonMetaData mergedFragmentMetaData = new WebCommonMetaData();
if (specMetaData == null) {
// If there is no web.xml, it has to be considered to be the latest version
specMetaData = new Web31MetaData();
specMetaData.setVersion("3.1");
}
// Augment with meta data from annotations in /WEB-INF/classes
WebMetaData annotatedMetaData = annotationsMetaData.get("classes");
if (annotatedMetaData == null && deploymentUnit.hasAttachment(Attachments.OSGI_MANIFEST)) {
annotatedMetaData = annotationsMetaData.get(deploymentUnit.getName());
}
if (annotatedMetaData != null) {
if (isComplete) {
// Discard @WebFilter, @WebListener and @WebServlet
annotatedMetaData.setFilters(null);
annotatedMetaData.setFilterMappings(null);
annotatedMetaData.setListeners(null);
annotatedMetaData.setServlets(null);
annotatedMetaData.setServletMappings(null);
}
WebCommonMetaDataMerger.augment(specMetaData, annotatedMetaData, null, true);
}
// Augment with meta data from fragments and annotations from the corresponding JAR
for (String jar : order) {
WebFragmentMetaData webFragmentMetaData = webFragments.get(jar);
if (webFragmentMetaData == null || isComplete) {
webFragmentMetaData = new WebFragmentMetaData();
// Add non overriding default distributable flag
webFragmentMetaData.setDistributable(new EmptyMetaData());
}
WebMetaData jarAnnotatedMetaData = annotationsMetaData.get(jar);
if ((isComplete || webFragmentMetaData.isMetadataComplete()) && jarAnnotatedMetaData != null) {
// Discard @WebFilter, @WebListener and @WebServlet
jarAnnotatedMetaData.setFilters(null);
jarAnnotatedMetaData.setFilterMappings(null);
jarAnnotatedMetaData.setListeners(null);
jarAnnotatedMetaData.setServlets(null);
jarAnnotatedMetaData.setServletMappings(null);
}
if (jarAnnotatedMetaData != null) {
// Merge annotations corresponding to the JAR
WebCommonMetaDataMerger.augment(webFragmentMetaData, jarAnnotatedMetaData, null, true);
}
// Merge fragment meta data according to the conflict rules
try {
WebCommonMetaDataMerger.augment(mergedFragmentMetaData, webFragmentMetaData, specMetaData, false);
} catch (Exception e) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidWebFragment(jar), e);
}
}
// Augment with meta data from annotations from JARs excluded from the order
for (String jar : jarsSet) {
WebFragmentMetaData webFragmentMetaData = new WebFragmentMetaData();
// Add non overriding default distributable flag
webFragmentMetaData.setDistributable(new EmptyMetaData());
WebMetaData jarAnnotatedMetaData = annotationsMetaData.get(jar);
if (jarAnnotatedMetaData != null) {
// Discard @WebFilter, @WebListener and @WebServlet
jarAnnotatedMetaData.setFilters(null);
jarAnnotatedMetaData.setFilterMappings(null);
jarAnnotatedMetaData.setListeners(null);
jarAnnotatedMetaData.setServlets(null);
jarAnnotatedMetaData.setServletMappings(null);
}
if (jarAnnotatedMetaData != null) {
// Merge annotations corresponding to the JAR
WebCommonMetaDataMerger.augment(webFragmentMetaData, jarAnnotatedMetaData, null, true);
}
// Merge fragment meta data according to the conflict rules
try {
WebCommonMetaDataMerger.augment(mergedFragmentMetaData, webFragmentMetaData, specMetaData, false);
} catch (Exception e) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidWebFragment(jar), e);
}
}
WebCommonMetaDataMerger.augment(specMetaData, mergedFragmentMetaData, null, true);
List<WebMetaData> additional = warMetaData.getAdditionalModuleAnnotationsMetadata();
if (additional != null && !isComplete) {
//augument with annotations from additional modules
for (WebMetaData annotations : additional) {
// Merge annotations corresponding to the JAR
WebCommonMetaDataMerger.augment(specMetaData, annotations, null, true);
}
}
// Override with meta data (JBossWebMetaData) Create a merged view
JBossWebMetaData mergedMetaData = new JBossWebMetaData();
JBossWebMetaData metaData = warMetaData.getJBossWebMetaData();
JBossWebMetaDataMerger.merge(mergedMetaData, metaData, specMetaData);
// FIXME: Incorporate any ear level overrides
// Use the OSGi Web-ContextPath if not given otherwise
String contextRoot = mergedMetaData.getContextRoot();
Manifest manifest = deploymentUnit.getAttachment(Attachments.OSGI_MANIFEST);
if (contextRoot == null && manifest != null) {
contextRoot = manifest.getMainAttributes().getValue("Web-ContextPath");
mergedMetaData.setContextRoot(contextRoot);
}
warMetaData.setMergedJBossWebMetaData(mergedMetaData);
if (mergedMetaData.isMetadataComplete()) {
MetadataCompleteMarker.setMetadataComplete(deploymentUnit, true);
}
//now attach any JNDI binding related information to the deployment
if (mergedMetaData.getJndiEnvironmentRefsGroup() != null) {
final DeploymentDescriptorEnvironment bindings = new DeploymentDescriptorEnvironment("java:module/env/", mergedMetaData.getJndiEnvironmentRefsGroup());
deploymentUnit.putAttachment(org.jboss.as.ee.component.Attachments.MODULE_DEPLOYMENT_DESCRIPTOR_ENVIRONMENT, bindings);
}
//override module name if applicable
if (mergedMetaData.getModuleName() != null && !mergedMetaData.getModuleName().isEmpty()) {
final EEModuleDescription description = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
description.setModuleName(mergedMetaData.getModuleName());
}
//WFLY-3102 EJB in WAR should inherit WAR's security domain
if (mergedMetaData.getSecurityDomain() != null) {
final EEModuleDescription description = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
description.setDefaultSecurityDomain(mergedMetaData.getSecurityDomain());
}
//merge security roles from the ear
DeploymentUnit parent = deploymentUnit.getParent();
if (parent != null) {
final EarMetaData earMetaData = parent.getAttachment(org.jboss.as.ee.structure.Attachments.EAR_METADATA);
if (earMetaData != null) {
SecurityRolesMetaData earSecurityRolesMetaData = earMetaData.getSecurityRoles();
if (earSecurityRolesMetaData != null) {
if (mergedMetaData.getSecurityRoles() == null) {
mergedMetaData.setSecurityRoles(new SecurityRolesMetaData());
}
SecurityRolesMetaDataMerger.merge(mergedMetaData.getSecurityRoles(), mergedMetaData.getSecurityRoles(), earSecurityRolesMetaData);
}
}
}
}
use of org.jboss.as.ee.component.DeploymentDescriptorEnvironment in project wildfly by wildfly.
the class WSIntegrationProcessorJAXWS_HANDLER method propagateNamingContext.
private static void propagateNamingContext(final ComponentDescription jaxwsHandlerDescription, final EJBEndpoint ejbEndpoint) {
final ServiceName ejbContextServiceName = ejbEndpoint.getContextServiceName();
final DeploymentDescriptorEnvironment ejbEnv = ejbEndpoint.getDeploymentDescriptorEnvironment();
// configure JAXWS EJB3 handler to be able to see EJB3 environment
jaxwsHandlerDescription.setContextServiceName(ejbContextServiceName);
jaxwsHandlerDescription.setDeploymentDescriptorEnvironment(ejbEnv);
jaxwsHandlerDescription.addDependency(ejbContextServiceName, ServiceBuilder.DependencyType.REQUIRED);
}
use of org.jboss.as.ee.component.DeploymentDescriptorEnvironment in project wildfly by wildfly.
the class ApplicationClientParsingDeploymentProcessor method deploy.
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!DeploymentTypeMarker.isType(DeploymentType.APPLICATION_CLIENT, deploymentUnit)) {
return;
}
final ApplicationClientMetaData appClientMD = parseAppClient(deploymentUnit, SpecDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
final JBossClientMetaData jbossClientMD = parseJBossClient(deploymentUnit, JBossDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
final JBossClientMetaData merged;
if (appClientMD == null && jbossClientMD == null) {
return;
} else if (appClientMD == null) {
merged = jbossClientMD;
} else {
merged = new JBossClientMetaData();
merged.setEnvironmentRefsGroupMetaData(new AppClientEnvironmentRefsGroupMetaData());
merged.merge(jbossClientMD, appClientMD);
}
if (merged.isMetadataComplete()) {
MetadataCompleteMarker.setMetadataComplete(deploymentUnit, true);
}
deploymentUnit.putAttachment(AppClientAttachments.APPLICATION_CLIENT_META_DATA, merged);
final DeploymentDescriptorEnvironment environment = new DeploymentDescriptorEnvironment("java:module/env/", merged.getEnvironmentRefsGroupMetaData());
deploymentUnit.putAttachment(org.jboss.as.ee.component.Attachments.MODULE_DEPLOYMENT_DESCRIPTOR_ENVIRONMENT, environment);
//override module name if applicable
if (merged.getModuleName() != null && !merged.getModuleName().isEmpty()) {
final EEModuleDescription description = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
description.setModuleName(merged.getModuleName());
}
}
use of org.jboss.as.ee.component.DeploymentDescriptorEnvironment in project wildfly by wildfly.
the class ApplicationClientManifestProcessor method deploy.
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!DeploymentTypeMarker.isType(DeploymentType.APPLICATION_CLIENT, deploymentUnit)) {
return;
}
final ResourceRoot root = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
final Manifest manifest = root.getAttachment(Attachments.MANIFEST);
if (manifest != null) {
Attributes main = manifest.getMainAttributes();
if (main != null) {
String mainClass = main.getValue("Main-Class");
if (mainClass != null && !mainClass.isEmpty()) {
try {
final Class<?> clazz = module.getClassLoader().loadClass(mainClass);
deploymentUnit.putAttachment(AppClientAttachments.MAIN_CLASS, clazz);
final ApplicationClientComponentDescription description = new ApplicationClientComponentDescription(clazz.getName(), moduleDescription, deploymentUnit.getServiceName(), applicationClasses);
moduleDescription.addComponent(description);
deploymentUnit.putAttachment(AppClientAttachments.APPLICATION_CLIENT_COMPONENT, description);
final DeploymentDescriptorEnvironment environment = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.MODULE_DEPLOYMENT_DESCRIPTOR_ENVIRONMENT);
if (environment != null) {
DescriptorEnvironmentLifecycleMethodProcessor.handleMethods(environment, moduleDescription, mainClass);
}
} catch (ClassNotFoundException e) {
throw AppClientLogger.ROOT_LOGGER.cannotLoadAppClientMainClass(e);
}
}
}
}
}
Aggregations