use of org.jboss.as.server.deployment.DeploymentUnit in project wildfly by wildfly.
the class WebComponentProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
return;
}
final Map<String, ComponentDescription> componentByClass = new HashMap<String, ComponentDescription>();
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final EEApplicationClasses applicationClassesDescription = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
final CompositeIndex compositeIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
if (moduleDescription == null) {
//not an EE deployment
return;
}
for (ComponentDescription component : moduleDescription.getComponentDescriptions()) {
componentByClass.put(component.getComponentClassName(), component);
}
final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
final TldsMetaData tldsMetaData = deploymentUnit.getAttachment(TldsMetaData.ATTACHMENT_KEY);
final Set<String> classes = getAllComponentClasses(deploymentUnit, compositeIndex, warMetaData, tldsMetaData);
for (String clazz : classes) {
if (clazz == null || clazz.trim().isEmpty()) {
continue;
}
ComponentDescription description = componentByClass.get(clazz);
if (description != null) {
//TODO: make sure the component is a managed bean
if (!(description.getViews().size() == 1)) {
throw UndertowLogger.ROOT_LOGGER.wrongComponentType(clazz);
}
} else {
//we do not make the standard tags into components, as there is no need
if (compositeIndex.getClassByName(DotName.createSimple(clazz)) == null) {
boolean found = false;
for (String pack : BUILTIN_TAGLIBS) {
if (clazz.startsWith(pack)) {
found = true;
break;
}
}
if (found) {
continue;
}
}
description = new WebComponentDescription(clazz, clazz, moduleDescription, deploymentUnit.getServiceName(), applicationClassesDescription);
moduleDescription.addComponent(description);
deploymentUnit.addToAttachmentList(WebComponentDescription.WEB_COMPONENTS, description.getStartServiceName());
}
}
}
use of org.jboss.as.server.deployment.DeploymentUnit 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.DeploymentUnit in project wildfly by wildfly.
the class UndertowHandlersDeploymentProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
if (module == null) {
return;
}
handleInfoFile(deploymentUnit, module);
handleJbossWebXml(deploymentUnit, module);
}
use of org.jboss.as.server.deployment.DeploymentUnit in project wildfly by wildfly.
the class UndertowJSRWebSocketDeploymentProcessor method installWebsockets.
private void installWebsockets(final DeploymentPhaseContext phaseContext, final WebSocketDeploymentInfo webSocketDeploymentInfo) {
DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
deploymentUnit.putAttachment(UndertowAttachments.WEB_SOCKET_DEPLOYMENT_INFO, webSocketDeploymentInfo);
}
use of org.jboss.as.server.deployment.DeploymentUnit in project wildfly by wildfly.
the class UndertowJSRWebSocketDeploymentProcessor method deploy.
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
if (module == null) {
return;
}
ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(module.getClassLoader());
WarMetaData metaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
if (metaData == null || metaData.getMergedJBossWebMetaData() == null) {
return;
}
if (!metaData.getMergedJBossWebMetaData().isEnableWebSockets()) {
return;
}
final Set<Class<?>> annotatedEndpoints = new HashSet<>();
final Set<Class<? extends Endpoint>> endpoints = new HashSet<>();
final Set<Class<? extends ServerApplicationConfig>> config = new HashSet<>();
final CompositeIndex index = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
final List<AnnotationInstance> serverEndpoints = index.getAnnotations(SERVER_ENDPOINT);
if (serverEndpoints != null) {
for (AnnotationInstance endpoint : serverEndpoints) {
if (endpoint.target() instanceof ClassInfo) {
ClassInfo clazz = (ClassInfo) endpoint.target();
try {
Class<?> moduleClass = ClassLoadingUtils.loadClass(clazz.name().toString(), module);
if (!Modifier.isAbstract(moduleClass.getModifiers())) {
annotatedEndpoints.add(moduleClass);
}
} catch (ClassNotFoundException e) {
UndertowLogger.ROOT_LOGGER.couldNotLoadWebSocketEndpoint(clazz.name().toString(), e);
}
}
}
}
final List<AnnotationInstance> clientEndpoints = index.getAnnotations(CLIENT_ENDPOINT);
if (clientEndpoints != null) {
for (AnnotationInstance endpoint : clientEndpoints) {
if (endpoint.target() instanceof ClassInfo) {
ClassInfo clazz = (ClassInfo) endpoint.target();
try {
Class<?> moduleClass = ClassLoadingUtils.loadClass(clazz.name().toString(), module);
if (!Modifier.isAbstract(moduleClass.getModifiers())) {
annotatedEndpoints.add(moduleClass);
}
} catch (ClassNotFoundException e) {
UndertowLogger.ROOT_LOGGER.couldNotLoadWebSocketEndpoint(clazz.name().toString(), e);
}
}
}
}
final Set<ClassInfo> subclasses = index.getAllKnownImplementors(SERVER_APPLICATION_CONFIG);
if (subclasses != null) {
for (final ClassInfo clazz : subclasses) {
try {
Class<?> moduleClass = ClassLoadingUtils.loadClass(clazz.name().toString(), module);
if (!Modifier.isAbstract(moduleClass.getModifiers())) {
config.add((Class) moduleClass);
}
} catch (ClassNotFoundException e) {
UndertowLogger.ROOT_LOGGER.couldNotLoadWebSocketConfig(clazz.name().toString(), e);
}
}
}
final Set<ClassInfo> epClasses = index.getAllKnownSubclasses(ENDPOINT);
if (epClasses != null) {
for (final ClassInfo clazz : epClasses) {
try {
Class<?> moduleClass = ClassLoadingUtils.loadClass(clazz.name().toString(), module);
if (!Modifier.isAbstract(moduleClass.getModifiers())) {
endpoints.add((Class) moduleClass);
}
} catch (ClassNotFoundException e) {
UndertowLogger.ROOT_LOGGER.couldNotLoadWebSocketConfig(clazz.name().toString(), e);
}
}
}
WebSocketDeploymentInfo webSocketDeploymentInfo = new WebSocketDeploymentInfo();
doDeployment(deploymentUnit, webSocketDeploymentInfo, annotatedEndpoints, config, endpoints);
installWebsockets(phaseContext, webSocketDeploymentInfo);
} finally {
Thread.currentThread().setContextClassLoader(oldCl);
}
}
Aggregations