use of org.jboss.as.server.deployment.module.ResourceRoot in project wildfly by wildfly.
the class WarStructureDeploymentProcessor method createResourceRoots.
/**
* Create the resource roots for a .war deployment
*
*
* @param deploymentRoot the deployment root
* @return the resource roots
* @throws java.io.IOException for any error
*/
private List<ResourceRoot> createResourceRoots(final VirtualFile deploymentRoot, final DeploymentUnit deploymentUnit) throws IOException, DeploymentUnitProcessingException {
final List<ResourceRoot> entries = new ArrayList<ResourceRoot>();
// WEB-INF classes
final VirtualFile webinfClasses = deploymentRoot.getChild(WEB_INF_CLASSES);
if (webinfClasses.exists()) {
final ResourceRoot webInfClassesRoot = new ResourceRoot(webinfClasses.getName(), webinfClasses, null);
ModuleRootMarker.mark(webInfClassesRoot);
entries.add(webInfClassesRoot);
}
// WEB-INF lib
Map<String, MountedDeploymentOverlay> overlays = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_OVERLAY_LOCATIONS);
final VirtualFile webinfLib = deploymentRoot.getChild(WEB_INF_LIB);
if (webinfLib.exists()) {
final List<VirtualFile> archives = webinfLib.getChildren(DEFAULT_WEB_INF_LIB_FILTER);
for (final VirtualFile archive : archives) {
try {
String relativeName = archive.getPathNameRelativeTo(deploymentRoot);
MountedDeploymentOverlay overlay = overlays.get(relativeName);
Closeable closable = null;
if (overlay != null) {
overlay.remountAsZip(false);
} else if (archive.isFile()) {
closable = VFS.mountZip(archive, archive, TempFileProviderService.provider());
} else {
closable = null;
}
final ResourceRoot webInfArchiveRoot = new ResourceRoot(archive.getName(), archive, new MountHandle(closable));
ModuleRootMarker.mark(webInfArchiveRoot);
entries.add(webInfArchiveRoot);
} catch (IOException e) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToProcessWebInfLib(archive), e);
}
}
}
return entries;
}
use of org.jboss.as.server.deployment.module.ResourceRoot in project wildfly by wildfly.
the class WebParsingDeploymentProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
ClassLoader old = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
try {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(WebParsingDeploymentProcessor.class);
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
// Skip non web deployments
return;
}
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
final VirtualFile alternateDescriptor = deploymentRoot.getAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_WEB_DEPLOYMENT_DESCRIPTOR);
// Locate the descriptor
final VirtualFile webXml;
if (alternateDescriptor != null) {
webXml = alternateDescriptor;
} else {
webXml = deploymentRoot.getRoot().getChild(WEB_XML);
}
final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
assert warMetaData != null;
if (webXml.exists()) {
InputStream is = null;
try {
is = webXml.openStream();
final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
MetaDataElementParser.DTDInfo dtdInfo = new MetaDataElementParser.DTDInfo();
inputFactory.setXMLResolver(dtdInfo);
final XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is);
WebMetaData webMetaData = WebMetaDataParser.parse(xmlReader, dtdInfo, SpecDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
if (schemaValidation && webMetaData.getSchemaLocation() != null) {
XMLSchemaValidator validator = new XMLSchemaValidator(new XMLResourceResolver());
InputStream xmlInput = webXml.openStream();
try {
if (webMetaData.is23())
validator.validate("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN", xmlInput);
else if (webMetaData.is24())
validator.validate("http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd", xmlInput);
else if (webMetaData.is25())
validator.validate("http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd", xmlInput);
else if (webMetaData.is30())
validator.validate("http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd", xmlInput);
else if (webMetaData.is31())
validator.validate("http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd", xmlInput);
else
validator.validate("-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN", xmlInput);
} catch (SAXException e) {
throw new DeploymentUnitProcessingException("Failed to validate " + webXml, e);
} finally {
xmlInput.close();
}
}
warMetaData.setWebMetaData(webMetaData);
} catch (XMLStreamException e) {
Integer lineNumber = null;
Integer columnNumber = null;
if (e.getLocation() != null) {
lineNumber = e.getLocation().getLineNumber();
columnNumber = e.getLocation().getColumnNumber();
}
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToParseXMLDescriptor(webXml.toString(), lineNumber, columnNumber), e);
} catch (IOException e) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToParseXMLDescriptor(webXml.toString()), e);
} finally {
try {
if (is != null) {
is.close();
}
} catch (IOException e) {
// Ignore
}
}
}
} finally {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(old);
}
}
use of org.jboss.as.server.deployment.module.ResourceRoot in project wildfly by wildfly.
the class WarAnnotationDeploymentProcessor method deploy.
/**
* Process web annotations.
*/
public void deploy(final 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;
Map<String, WebMetaData> annotationsMetaData = warMetaData.getAnnotationsMetaData();
if (annotationsMetaData == null) {
annotationsMetaData = new HashMap<String, WebMetaData>();
warMetaData.setAnnotationsMetaData(annotationsMetaData);
}
Map<ResourceRoot, Index> indexes = AnnotationIndexUtils.getAnnotationIndexes(deploymentUnit);
// Process lib/*.jar
for (final Entry<ResourceRoot, Index> entry : indexes.entrySet()) {
final Index jarIndex = entry.getValue();
annotationsMetaData.put(entry.getKey().getRootName(), processAnnotations(jarIndex));
}
Map<ModuleIdentifier, CompositeIndex> additionalModelAnnotations = deploymentUnit.getAttachment(Attachments.ADDITIONAL_ANNOTATION_INDEXES_BY_MODULE);
if (additionalModelAnnotations != null) {
final List<WebMetaData> additional = new ArrayList<WebMetaData>();
for (Entry<ModuleIdentifier, CompositeIndex> entry : additionalModelAnnotations.entrySet()) {
for (Index index : entry.getValue().getIndexes()) {
additional.add(processAnnotations(index));
}
}
warMetaData.setAdditionalModuleAnnotationsMetadata(additional);
}
}
use of org.jboss.as.server.deployment.module.ResourceRoot in project wildfly by wildfly.
the class JBossWebservicesDescriptorDeploymentProcessor method deploy.
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit unit = phaseContext.getDeploymentUnit();
final ResourceRoot deploymentRoot = unit.getAttachment(Attachments.DEPLOYMENT_ROOT);
final URL jbossWebservicesDescriptorURL = getJBossWebServicesDescriptorURL(deploymentRoot);
if (jbossWebservicesDescriptorURL != null) {
final JBossWebservicesPropertyReplaceFactory webservicesFactory = new JBossWebservicesPropertyReplaceFactory(jbossWebservicesDescriptorURL, JBossDescriptorPropertyReplacement.propertyReplacer(unit));
final JBossWebservicesMetaData jbossWebservicesMD = webservicesFactory.load(jbossWebservicesDescriptorURL);
unit.putAttachment(WSAttachmentKeys.JBOSS_WEBSERVICES_METADATA_KEY, jbossWebservicesMD);
}
}
use of org.jboss.as.server.deployment.module.ResourceRoot in project wildfly by wildfly.
the class WSLibraryFilterProcessor method deploy.
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit unit = phaseContext.getDeploymentUnit();
if (DeploymentTypeMarker.isType(DeploymentType.EAR, unit)) {
return;
}
final CompositeIndex index = unit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
if (index != null) {
//perform checks on included libraries only if there're actually WS endpoints in the deployment
if (hasWSEndpoints(index)) {
AttachmentList<ResourceRoot> resourceRoots = unit.getAttachment(RESOURCE_ROOTS);
if (resourceRoots != null) {
for (ResourceRoot root : resourceRoots) {
if (hasClassesFromPackage(root.getAttachment(ANNOTATION_INDEX), "org.apache.cxf")) {
throw WSLogger.ROOT_LOGGER.invalidLibraryInDeployment("Apache CXF", root.getRootName());
}
}
}
}
} else {
WSLogger.ROOT_LOGGER.tracef("Skipping WS annotation processing since no composite annotation index found in unit: %s", unit.getName());
}
}
Aggregations