use of org.jboss.as.web.common.WarMetaData 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);
}
}
use of org.jboss.as.web.common.WarMetaData in project wildfly by wildfly.
the class SecurityDomainResolvingProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
if (warMetaData == null) {
return;
}
final SecurityMetaData securityMetaData = deploymentUnit.getAttachment(ATTACHMENT_KEY);
if (securityMetaData != null && securityMetaData.getSecurityDomain() != null) {
// The SecurityDomain is already defined.
return;
}
final JBossWebMetaData metaData = warMetaData.getMergedJBossWebMetaData();
String securityDomain = metaData.getSecurityDomain();
if (securityDomain == null) {
securityDomain = getJBossAppSecurityDomain(deploymentUnit);
}
securityDomain = securityDomain == null ? defaultSecurityDomain : unprefixSecurityDomain(securityDomain);
if (securityDomain != null) {
if (mappedSecurityDomain.test(securityDomain)) {
ServiceName securityDomainName = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT).getCapabilityServiceName(Capabilities.CAPABILITY_APPLICATION_SECURITY_DOMAIN, securityDomain).append(Constants.SECURITY_DOMAIN);
if (securityMetaData != null) {
securityMetaData.setSecurityDomain(securityDomainName);
}
deploymentUnit.putAttachment(RESOLVED_SECURITY_DOMAIN, securityDomain);
} else if (legacySecurityInstalled(deploymentUnit)) {
deploymentUnit.putAttachment(RESOLVED_SECURITY_DOMAIN, securityDomain);
}
}
}
use of org.jboss.as.web.common.WarMetaData in project wildfly by wildfly.
the class SharedSessionManagerDeploymentProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
SharedSessionManagerConfig sharedConfig = deploymentUnit.getAttachment(SharedSessionManagerConfig.ATTACHMENT_KEY);
if (sharedConfig == null)
return;
String deploymentName = (deploymentUnit.getParent() == null) ? deploymentUnit.getName() : String.join(".", deploymentUnit.getParent().getName(), deploymentUnit.getName());
WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
String serverName = Optional.ofNullable(warMetaData).map(metaData -> metaData.getMergedJBossWebMetaData().getServerInstanceName()).orElse(Optional.ofNullable(DefaultDeploymentMappingProvider.instance().getMapping(deploymentName)).map(Map.Entry::getKey).orElse(this.defaultServerName));
SessionConfigMetaData sessionConfig = sharedConfig.getSessionConfig();
ServletContainerService servletContainer = deploymentUnit.getAttachment(UndertowAttachments.SERVLET_CONTAINER_SERVICE);
Integer defaultSessionTimeout = ((sessionConfig != null) && sessionConfig.getSessionTimeoutSet()) ? sessionConfig.getSessionTimeout() : (servletContainer != null) ? servletContainer.getDefaultSessionTimeout() : Integer.valueOf(30);
CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
Module module = deploymentUnit.getAttachment(Attachments.MODULE);
ServiceTarget target = phaseContext.getServiceTarget();
ServiceName deploymentServiceName = deploymentUnit.getServiceName();
ServiceName managerServiceName = deploymentServiceName.append(SharedSessionManagerConfig.SHARED_SESSION_MANAGER_SERVICE_NAME);
ServiceName codecServiceName = deploymentServiceName.append(SharedSessionManagerConfig.SHARED_SESSION_IDENTIFIER_CODEC_SERVICE_NAME);
SessionManagementProvider provider = this.getDistributableWebDeploymentProvider(deploymentUnit, sharedConfig);
SessionManagerFactoryConfiguration configuration = new SessionManagerFactoryConfiguration() {
@Override
public String getServerName() {
return serverName;
}
@Override
public String getDeploymentName() {
return deploymentName;
}
@Override
public Integer getMaxActiveSessions() {
return sharedConfig.getMaxActiveSessions();
}
@Override
public Module getModule() {
return module;
}
@Override
public Duration getDefaultSessionTimeout() {
return Duration.ofMinutes(defaultSessionTimeout);
}
};
provider.getSessionManagerFactoryServiceConfigurator(managerServiceName, configuration).configure(support).build(target).install();
provider.getSessionIdentifierCodecServiceConfigurator(codecServiceName, configuration).configure(support).build(target).install();
}
use of org.jboss.as.web.common.WarMetaData in project wildfly by wildfly.
the class TldParsingDeploymentProcessor 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;
}
final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
if (warMetaData == null || warMetaData.getMergedJBossWebMetaData() == null) {
return;
}
TldsMetaData tldsMetaData = deploymentUnit.getAttachment(TldsMetaData.ATTACHMENT_KEY);
if (tldsMetaData == null) {
tldsMetaData = new TldsMetaData();
deploymentUnit.putAttachment(TldsMetaData.ATTACHMENT_KEY, tldsMetaData);
}
Map<String, TldMetaData> tlds = new HashMap<String, TldMetaData>();
tldsMetaData.setTlds(tlds);
final List<TldMetaData> uniqueTlds = new ArrayList<>();
final VirtualFile deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
final List<VirtualFile> testRoots = new ArrayList<VirtualFile>();
testRoots.add(deploymentRoot);
testRoots.add(deploymentRoot.getChild(WEB_INF));
testRoots.add(deploymentRoot.getChild(META_INF));
for (ResourceRoot root : deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS)) {
testRoots.add(root.getRoot());
testRoots.add(root.getRoot().getChild(META_INF));
testRoots.add(root.getRoot().getChild(META_INF).getChild(RESOURCES));
}
JspConfigMetaData merged = warMetaData.getMergedJBossWebMetaData().getJspConfig();
if (merged != null && merged.getTaglibs() != null) {
for (final TaglibMetaData tld : merged.getTaglibs()) {
boolean found = false;
for (final VirtualFile root : testRoots) {
VirtualFile child = root.getChild(tld.getTaglibLocation());
if (child.exists()) {
if (isTldFile(child)) {
TldMetaData value = processTld(deploymentRoot, child, tlds, uniqueTlds);
if (!tlds.containsKey(tld.getTaglibUri())) {
tlds.put(tld.getTaglibUri(), value);
}
}
found = true;
break;
}
}
if (!found) {
UndertowLogger.ROOT_LOGGER.tldNotFound(tld.getTaglibLocation());
}
}
}
// TLDs are located in WEB-INF or any subdir (except the top level "classes" and "lib")
// and in JARs from WEB-INF/lib, in META-INF or any subdir
List<ResourceRoot> resourceRoots = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
for (ResourceRoot resourceRoot : resourceRoots) {
if (resourceRoot.getRoot().getName().toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
VirtualFile webFragment = resourceRoot.getRoot().getChild(META_INF);
if (webFragment.exists() && webFragment.isDirectory()) {
processTlds(deploymentRoot, webFragment.getChildren(), tlds, uniqueTlds);
}
}
}
VirtualFile webInf = deploymentRoot.getChild(WEB_INF);
if (webInf.exists() && webInf.isDirectory()) {
for (VirtualFile file : webInf.getChildren()) {
if (isTldFile(file)) {
processTld(deploymentRoot, file, tlds, uniqueTlds);
} else if (file.isDirectory() && !CLASSES.equals(file.getName()) && !LIB.equals(file.getName())) {
processTlds(deploymentRoot, file.getChildren(), tlds, uniqueTlds);
}
}
}
JBossWebMetaData mergedMd = warMetaData.getMergedJBossWebMetaData();
if (mergedMd.getListeners() == null) {
mergedMd.setListeners(new ArrayList<ListenerMetaData>());
}
final ArrayList<TldMetaData> allTlds = new ArrayList<>(uniqueTlds);
allTlds.addAll(tldsMetaData.getSharedTlds(deploymentUnit));
for (final TldMetaData tld : allTlds) {
if (tld.getListeners() != null) {
for (ListenerMetaData l : tld.getListeners()) {
mergedMd.getListeners().add(l);
}
}
}
}
use of org.jboss.as.web.common.WarMetaData in project wildfly by wildfly.
the class ServletContainerInitializerDeploymentProcessor method deploy.
/**
* Process SCIs.
*/
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
final ServiceModuleLoader loader = deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER);
if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
// Skip non web deployments
return;
}
WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
assert warMetaData != null;
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
if (module == null) {
throw UndertowLogger.ROOT_LOGGER.failedToResolveModule(deploymentUnit);
}
final ClassLoader classLoader = module.getClassLoader();
ScisMetaData scisMetaData = deploymentUnit.getAttachment(ScisMetaData.ATTACHMENT_KEY);
if (scisMetaData == null) {
scisMetaData = new ScisMetaData();
deploymentUnit.putAttachment(ScisMetaData.ATTACHMENT_KEY, scisMetaData);
}
Set<ServletContainerInitializer> scis = scisMetaData.getScis();
Set<Class<? extends ServletContainerInitializer>> sciClasses = new HashSet<>();
if (scis == null) {
scis = new LinkedHashSet<>();
scisMetaData.setScis(scis);
}
Map<ServletContainerInitializer, Set<Class<?>>> handlesTypes = scisMetaData.getHandlesTypes();
if (handlesTypes == null) {
handlesTypes = new HashMap<ServletContainerInitializer, Set<Class<?>>>();
scisMetaData.setHandlesTypes(handlesTypes);
}
// Find the SCIs from shared modules
for (ModuleDependency dependency : moduleSpecification.getAllDependencies()) {
// Should not include SCI if services is not included
if (!dependency.isImportServices()) {
continue;
}
try {
Module depModule = loader.loadModule(dependency.getIdentifier());
ServiceLoader<ServletContainerInitializer> serviceLoader = depModule.loadService(ServletContainerInitializer.class);
for (ServletContainerInitializer service : serviceLoader) {
if (sciClasses.add(service.getClass())) {
scis.add(service);
}
}
} catch (ModuleLoadException e) {
if (!dependency.isOptional()) {
throw UndertowLogger.ROOT_LOGGER.errorLoadingSCIFromModule(dependency.getIdentifier().toString(), e);
}
}
}
// Find local ServletContainerInitializer services
List<String> order = warMetaData.getOrder();
Map<String, VirtualFile> localScis = warMetaData.getScis();
if (order != null && localScis != null) {
for (String jar : order) {
VirtualFile sci = localScis.get(jar);
if (sci != null) {
scis.addAll(loadSci(classLoader, sci, jar, true, sciClasses));
}
}
}
// SCI's deployed in the war itself
if (localScis != null) {
VirtualFile warDeployedScis = localScis.get("classes");
if (warDeployedScis != null) {
scis.addAll(loadSci(classLoader, warDeployedScis, deploymentUnit.getName(), true, sciClasses));
}
}
// Process HandlesTypes for ServletContainerInitializer
Map<Class<?>, Set<ServletContainerInitializer>> typesMap = new HashMap<Class<?>, Set<ServletContainerInitializer>>();
for (ServletContainerInitializer service : scis) {
try {
if (service.getClass().isAnnotationPresent(HandlesTypes.class)) {
HandlesTypes handlesTypesAnnotation = service.getClass().getAnnotation(HandlesTypes.class);
Class<?>[] typesArray = handlesTypesAnnotation.value();
if (typesArray != null) {
for (Class<?> type : typesArray) {
Set<ServletContainerInitializer> servicesSet = typesMap.get(type);
if (servicesSet == null) {
servicesSet = new HashSet<ServletContainerInitializer>();
typesMap.put(type, servicesSet);
}
servicesSet.add(service);
handlesTypes.put(service, new HashSet<Class<?>>());
}
}
}
} catch (ArrayStoreException e) {
// Class.findAnnotation() has a bug under JDK < 11 which throws ArrayStoreException
throw UndertowLogger.ROOT_LOGGER.missingClassInAnnotation(HandlesTypes.class.getSimpleName(), service.getClass().getName());
}
}
Class<?>[] typesArray = typesMap.keySet().toArray(new Class<?>[0]);
final CompositeIndex index = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
if (index == null) {
throw UndertowLogger.ROOT_LOGGER.unableToResolveAnnotationIndex(deploymentUnit);
}
final CompositeIndex parent;
if (deploymentUnit.getParent() != null) {
parent = deploymentUnit.getParent().getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
} else {
parent = null;
}
// WFLY-4205, look in the parent as well as the war
CompositeIndex parentIndex = deploymentUnit.getParent() == null ? null : deploymentUnit.getParent().getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
// Find classes which extend, implement, or are annotated by HandlesTypes
for (Class<?> type : typesArray) {
DotName className = DotName.createSimple(type.getName());
Set<ClassInfo> classInfos = new HashSet<>();
classInfos.addAll(processHandlesType(className, type, index, parent));
if (parentIndex != null) {
classInfos.addAll(processHandlesType(className, type, parentIndex, parent));
}
Set<Class<?>> classes = loadClassInfoSet(classInfos, classLoader);
Set<ServletContainerInitializer> sciSet = typesMap.get(type);
for (ServletContainerInitializer sci : sciSet) {
handlesTypes.get(sci).addAll(classes);
}
}
}
Aggregations