Search in sources :

Example 6 with WarMetaData

use of org.jboss.as.web.common.WarMetaData in project wildfly by wildfly.

the class JSFDependencyProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final DeploymentUnit tl = deploymentUnit.getParent() == null ? deploymentUnit : deploymentUnit.getParent();
    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    // Set default when no default version has been set on the war file
    String jsfVersion = JsfVersionMarker.getVersion(tl).equals(JsfVersionMarker.NONE) ? JSFModuleIdFactory.getInstance().getDefaultSlot() : JsfVersionMarker.getVersion(tl);
    String defaultJsfVersion = JSFModuleIdFactory.getInstance().getDefaultSlot();
    if (JsfVersionMarker.isJsfDisabled(deploymentUnit)) {
        if (jsfVersion.equals(defaultJsfVersion) && !moduleIdFactory.isValidJSFSlot(jsfVersion)) {
            throw JSFLogger.ROOT_LOGGER.invalidDefaultJSFImpl(defaultJsfVersion);
        }
        addJSFAPI(JsfVersionMarker.JSF_2_0, moduleSpecification, moduleLoader);
        return;
    }
    if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit) && !DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
        return;
    }
    if (jsfVersion.equals(JsfVersionMarker.WAR_BUNDLES_JSF_IMPL)) {
        // if Jakarta Server Faces is provided by the application we leave it alone
        return;
    }
    if (!moduleIdFactory.isValidJSFSlot(jsfVersion)) {
        JSFLogger.ROOT_LOGGER.unknownJSFVersion(jsfVersion, defaultJsfVersion);
        jsfVersion = defaultJsfVersion;
    }
    if (jsfVersion.equals(defaultJsfVersion) && !moduleIdFactory.isValidJSFSlot(jsfVersion)) {
        throw JSFLogger.ROOT_LOGGER.invalidDefaultJSFImpl(defaultJsfVersion);
    }
    addJSFAPI(jsfVersion, moduleSpecification, moduleLoader);
    addJSFImpl(jsfVersion, moduleSpecification, moduleLoader);
    moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, JSF_SUBSYSTEM, false, false, true, false));
    addJSFInjection(jsfVersion, moduleSpecification, moduleLoader);
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData != null) {
        addCDIFlag(warMetaData, deploymentUnit);
    }
}
Also used : ModuleLoader(org.jboss.modules.ModuleLoader) ModuleDependency(org.jboss.as.server.deployment.module.ModuleDependency) ModuleSpecification(org.jboss.as.server.deployment.module.ModuleSpecification) WarMetaData(org.jboss.as.web.common.WarMetaData) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 7 with WarMetaData

use of org.jboss.as.web.common.WarMetaData in project wildfly by wildfly.

the class JaxrsCdiIntegrationProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    if (!JaxrsDeploymentMarker.isJaxrsDeployment(deploymentUnit)) {
        return;
    }
    if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
        return;
    }
    final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    final JBossWebMetaData webdata = warMetaData.getMergedJBossWebMetaData();
    try {
        final CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
        if (support.hasCapability(WELD_CAPABILITY_NAME)) {
            final WeldCapability api = support.getOptionalCapabilityRuntimeAPI(WELD_CAPABILITY_NAME, WeldCapability.class).get();
            if (api.isWeldDeployment(deploymentUnit)) {
                // don't set this param if Jakarta Contexts and Dependency Injection is not in classpath
                module.getClassLoader().loadClass(CDI_INJECTOR_FACTORY_CLASS);
                JAXRS_LOGGER.debug("Found Jakarta Contexts and Dependency Injection, adding injector factory class");
                setContextParameter(webdata, "resteasy.injector.factory", CDI_INJECTOR_FACTORY_CLASS);
            }
        }
    } catch (ClassNotFoundException ignored) {
    }
}
Also used : JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData) WarMetaData(org.jboss.as.web.common.WarMetaData) WeldCapability(org.jboss.as.weld.WeldCapability) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport)

Example 8 with WarMetaData

use of org.jboss.as.web.common.WarMetaData in project wildfly by wildfly.

the class JaxrsScanningProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!JaxrsDeploymentMarker.isJaxrsDeployment(deploymentUnit)) {
        return;
    }
    final DeploymentUnit parent = deploymentUnit.getParent() == null ? deploymentUnit : deploymentUnit.getParent();
    final Map<ModuleIdentifier, ResteasyDeploymentData> deploymentData;
    if (deploymentUnit.getParent() == null) {
        deploymentData = Collections.synchronizedMap(new HashMap<ModuleIdentifier, ResteasyDeploymentData>());
        deploymentUnit.putAttachment(JaxrsAttachments.ADDITIONAL_RESTEASY_DEPLOYMENT_DATA, deploymentData);
    } else {
        deploymentData = parent.getAttachment(JaxrsAttachments.ADDITIONAL_RESTEASY_DEPLOYMENT_DATA);
    }
    final ModuleIdentifier moduleIdentifier = deploymentUnit.getAttachment(Attachments.MODULE_IDENTIFIER);
    ResteasyDeploymentData resteasyDeploymentData = new ResteasyDeploymentData();
    final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    try {
        if (warMetaData == null) {
            resteasyDeploymentData.setScanAll(true);
            scan(deploymentUnit, module.getClassLoader(), resteasyDeploymentData);
            deploymentData.put(moduleIdentifier, resteasyDeploymentData);
        } else {
            scanWebDeployment(deploymentUnit, warMetaData.getMergedJBossWebMetaData(), module.getClassLoader(), resteasyDeploymentData);
            scan(deploymentUnit, module.getClassLoader(), resteasyDeploymentData);
            // must check context param for Application subclass declaration
            if (resteasyDeploymentData.getScannedResourceClasses().isEmpty() && !resteasyDeploymentData.isDispatcherCreated() && hasBootClasses(warMetaData.getMergedJBossWebMetaData())) {
                checkOtherParams(deploymentUnit, warMetaData.getMergedJBossWebMetaData(), module.getClassLoader(), resteasyDeploymentData);
            }
        }
        deploymentUnit.putAttachment(JaxrsAttachments.RESTEASY_DEPLOYMENT_DATA, resteasyDeploymentData);
    } catch (ModuleLoadException e) {
        throw new DeploymentUnitProcessingException(e);
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) HashMap(java.util.HashMap) WarMetaData(org.jboss.as.web.common.WarMetaData) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 9 with WarMetaData

use of org.jboss.as.web.common.WarMetaData in project wildfly by wildfly.

the class JaxrsSpringProcessor method deploy.

public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (deploymentUnit.getParent() != null) {
        return;
    }
    final List<DeploymentUnit> deploymentUnits = new ArrayList<DeploymentUnit>();
    deploymentUnits.add(deploymentUnit);
    deploymentUnits.addAll(deploymentUnit.getAttachmentList(Attachments.SUB_DEPLOYMENTS));
    boolean found = false;
    for (DeploymentUnit unit : deploymentUnits) {
        WarMetaData warMetaData = unit.getAttachment(WarMetaData.ATTACHMENT_KEY);
        if (warMetaData == null) {
            continue;
        }
        JBossWebMetaData md = warMetaData.getMergedJBossWebMetaData();
        if (md == null) {
            continue;
        }
        if (md.getContextParams() != null) {
            boolean skip = false;
            for (ParamValueMetaData prop : md.getContextParams()) {
                if (prop.getParamName().equals(ENABLE_PROPERTY)) {
                    boolean explicitEnable = Boolean.parseBoolean(prop.getParamValue());
                    if (explicitEnable) {
                        found = true;
                    } else {
                        skip = true;
                    }
                    break;
                } else if (prop.getParamName().equals(DISABLE_PROPERTY) && "true".equals(prop.getParamValue())) {
                    skip = true;
                    JaxrsLogger.JAXRS_LOGGER.disablePropertyDeprecated();
                    break;
                }
            }
            if (skip) {
                continue;
            }
        }
        if (md.getListeners() != null) {
            for (ListenerMetaData listener : md.getListeners()) {
                if (SPRING_LISTENER.equals(listener.getListenerClass())) {
                    found = true;
                    break;
                }
            }
        }
        if (md.getServlets() != null) {
            for (JBossServletMetaData servlet : md.getServlets()) {
                if (SPRING_SERVLET.equals(servlet.getServletClass())) {
                    found = true;
                    break;
                }
            }
        }
        if (found) {
            try {
                // actual close is done by the MSC service above
                MountHandle mh = new MountHandle(null);
                ResourceRoot resourceRoot = new ResourceRoot(getResteasySpringVirtualFile(), mh);
                ModuleRootMarker.mark(resourceRoot);
                deploymentUnit.addToAttachmentList(Attachments.RESOURCE_ROOTS, resourceRoot);
            } catch (Exception e) {
                throw new DeploymentUnitProcessingException(e);
            }
            return;
        }
    }
}
Also used : ParamValueMetaData(org.jboss.metadata.javaee.spec.ParamValueMetaData) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData) MountHandle(org.jboss.as.server.deployment.module.MountHandle) JBossServletMetaData(org.jboss.metadata.web.jboss.JBossServletMetaData) ArrayList(java.util.ArrayList) WarMetaData(org.jboss.as.web.common.WarMetaData) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) StartException(org.jboss.msc.service.StartException) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) ListenerMetaData(org.jboss.metadata.web.spec.ListenerMetaData) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 10 with WarMetaData

use of org.jboss.as.web.common.WarMetaData in project wildfly by wildfly.

the class JwtActivationProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        return;
    }
    JBossWebMetaData mergedMetaData = warMetaData.getMergedJBossWebMetaData();
    LoginConfigMetaData loginConfig = mergedMetaData != null ? mergedMetaData.getLoginConfig() : null;
    if (loginConfig != null && !JWT_AUTH_METHOD.equals(loginConfig.getAuthMethod())) {
        // An auth-method has been defined, this is not MP-JWT
        return;
    }
    if (loginConfig == null) {
        final CompositeIndex index = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
        List<AnnotationInstance> annotations = index.getAnnotations(LOGIN_CONFIG_DOT_NAME);
        for (AnnotationInstance annotation : annotations) {
            // First we must be sure the annotation is on an Application class.
            AnnotationTarget target = annotation.target();
            if (target.kind() == Kind.CLASS && extendsApplication(target.asClass(), index)) {
                loginConfig = new LoginConfigMetaData();
                AnnotationValue authMethodValue = annotation.value(AUTH_METHOD);
                if (authMethodValue == null) {
                    throw ROOT_LOGGER.noAuthMethodSpecified();
                }
                loginConfig.setAuthMethod(authMethodValue.asString());
                AnnotationValue realmNameValue = annotation.value(REALM_NAME);
                if (realmNameValue != null) {
                    loginConfig.setRealmName(realmNameValue.asString());
                }
                mergedMetaData.setLoginConfig(loginConfig);
                break;
            }
            ROOT_LOGGER.loginConfigInvalidTarget(target.toString());
        }
    }
    if (loginConfig != null && JWT_AUTH_METHOD.equals(loginConfig.getAuthMethod())) {
        ROOT_LOGGER.tracef("Activating JWT for deployment %s.", deploymentUnit.getName());
        JwtDeploymentMarker.mark(deploymentUnit);
        VirtualDomainMarkerUtility.virtualDomainRequired(deploymentUnit);
    }
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData) LoginConfigMetaData(org.jboss.metadata.web.spec.LoginConfigMetaData) WarMetaData(org.jboss.as.web.common.WarMetaData) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) AnnotationValue(org.jboss.jandex.AnnotationValue) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) AnnotationInstance(org.jboss.jandex.AnnotationInstance)

Aggregations

WarMetaData (org.jboss.as.web.common.WarMetaData)38 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)31 JBossWebMetaData (org.jboss.metadata.web.jboss.JBossWebMetaData)20 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)14 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)12 VirtualFile (org.jboss.vfs.VirtualFile)11 HashSet (java.util.HashSet)9 Module (org.jboss.modules.Module)9 ArrayList (java.util.ArrayList)8 ParamValueMetaData (org.jboss.metadata.javaee.spec.ParamValueMetaData)8 HashMap (java.util.HashMap)7 JBossServletMetaData (org.jboss.metadata.web.jboss.JBossServletMetaData)6 ListenerMetaData (org.jboss.metadata.web.spec.ListenerMetaData)6 IOException (java.io.IOException)5 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)5 CompositeIndex (org.jboss.as.server.deployment.annotation.CompositeIndex)5 WebMetaData (org.jboss.metadata.web.spec.WebMetaData)5 ServiceName (org.jboss.msc.service.ServiceName)5 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)4 ModuleSpecification (org.jboss.as.server.deployment.module.ModuleSpecification)4