Search in sources :

Example 11 with JBossWebMetaData

use of org.jboss.metadata.web.jboss.JBossWebMetaData in project wildfly by wildfly.

the class WebMetaDataModifier method modify.

/**
     * Modifies web meta data to configure webservice stack transport and properties.
     *
     * @param dep webservice deployment
     */
void modify(final Deployment dep) {
    final JBossWebMetaData jbossWebMD = WSHelper.getOptionalAttachment(dep, JBossWebMetaData.class);
    if (jbossWebMD != null) {
        this.configureEndpoints(dep, jbossWebMD);
        this.modifyContextRoot(dep, jbossWebMD);
    }
}
Also used : JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData)

Example 12 with JBossWebMetaData

use of org.jboss.metadata.web.jboss.JBossWebMetaData in project wildfly by wildfly.

the class WebIntegrationProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EEModuleDescription module = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
    if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
        // Skip non web deployments
        return;
    }
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        WeldLogger.DEPLOYMENT_LOGGER.debug("Not installing Weld web tier integration as no war metadata found");
        return;
    }
    JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
    if (webMetaData == null) {
        WeldLogger.DEPLOYMENT_LOGGER.debug("Not installing Weld web tier integration as no merged web metadata found");
        return;
    }
    if (!WeldDeploymentMarker.isWeldDeployment(deploymentUnit)) {
        if (WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
            createDependency(deploymentUnit, warMetaData);
        }
        return;
    }
    createDependency(deploymentUnit, warMetaData);
    List<ListenerMetaData> listeners = webMetaData.getListeners();
    if (listeners == null) {
        listeners = new ArrayList<ListenerMetaData>();
        webMetaData.setListeners(listeners);
    } else {
        //if the weld servlet listener is present remove it
        //this should allow wars to be portable between AS7 and servlet containers
        final ListIterator<ListenerMetaData> iterator = listeners.listIterator();
        while (iterator.hasNext()) {
            final ListenerMetaData listener = iterator.next();
            if (listener.getListenerClass().trim().equals(WELD_SERVLET_LISTENER)) {
                WeldLogger.DEPLOYMENT_LOGGER.debugf("Removing weld servlet listener %s from web config, as it is not needed in EE6 environments", WELD_SERVLET_LISTENER);
                iterator.remove();
                break;
            }
        }
    }
    listeners.add(0, INITIAL_LISTENER_METADATA);
    listeners.add(TERMINAL_LISTENER_MEDATADA);
    //These listeners use resource injection, so they need to be components
    registerAsComponent(WELD_INITIAL_LISTENER, deploymentUnit);
    registerAsComponent(WELD_TERMINAL_LISTENER, deploymentUnit);
    deploymentUnit.addToAttachmentList(ExpressionFactoryWrapper.ATTACHMENT_KEY, WeldJspExpressionFactoryWrapper.INSTANCE);
    if (webMetaData.getContextParams() == null) {
        webMetaData.setContextParams(new ArrayList<ParamValueMetaData>());
    }
    final List<ParamValueMetaData> contextParams = webMetaData.getContextParams();
    setupWeldContextIgnores(contextParams, InitParameters.CONTEXT_IGNORE_FORWARD);
    setupWeldContextIgnores(contextParams, InitParameters.CONTEXT_IGNORE_INCLUDE);
    if (webMetaData.getFilterMappings() != null) {
        // register ConversationFilter
        boolean filterMappingFound = false;
        for (FilterMappingMetaData mapping : webMetaData.getFilterMappings()) {
            if (CONVERSATION_FILTER_NAME.equals(mapping.getFilterName())) {
                filterMappingFound = true;
                break;
            }
        }
        if (filterMappingFound) {
            // otherwise WeldListener will take care of conversation context activation
            boolean filterFound = false;
            // register ConversationFilter
            if (webMetaData.getFilters() == null) {
                webMetaData.setFilters(new FiltersMetaData());
            }
            for (FilterMetaData filter : webMetaData.getFilters()) {
                if (CONVERSATION_FILTER_CLASS.equals(filter.getFilterClass())) {
                    filterFound = true;
                    break;
                }
            }
            if (!filterFound) {
                webMetaData.getFilters().add(conversationFilterMetadata);
                registerAsComponent(CONVERSATION_FILTER_CLASS, deploymentUnit);
                webMetaData.getContextParams().add(CONVERSATION_FILTER_INITIALIZED);
            }
        }
    }
}
Also used : ParamValueMetaData(org.jboss.metadata.javaee.spec.ParamValueMetaData) JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData) FilterMetaData(org.jboss.metadata.web.spec.FilterMetaData) WarMetaData(org.jboss.as.web.common.WarMetaData) FiltersMetaData(org.jboss.metadata.web.spec.FiltersMetaData) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) ListenerMetaData(org.jboss.metadata.web.spec.ListenerMetaData) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) FilterMappingMetaData(org.jboss.metadata.web.spec.FilterMappingMetaData)

Example 13 with JBossWebMetaData

use of org.jboss.metadata.web.jboss.JBossWebMetaData in project wildfly by wildfly.

the class DevelopmentModeProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    if (!WeldDeploymentMarker.isWeldDeployment(deploymentUnit)) {
        // skip non weld deployments
        return;
    }
    // probe module is available
    if (!Reflections.isAccessible(PROBE_FILTER_CLASS_NAME, module.getClassLoader())) {
        return;
    }
    final WeldConfiguration configuration = Utils.getRootDeploymentUnit(deploymentUnit).getAttachment(WeldConfiguration.ATTACHMENT_KEY);
    // if development mode disabled then check war CONTEXT_PARAM_DEV_MODE and if available then register ProbeFilter and ProbeExtension
    if (!configuration.isDevelopmentMode()) {
        if (deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY) == null) {
            return;
        }
        if (DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
            final JBossWebMetaData webMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY).getMergedJBossWebMetaData();
            if (webMetaData == null) {
                return;
            }
            if (webMetaData.getContextParams() == null) {
                return;
            }
            final boolean devModeContextParam = webMetaData.getContextParams().stream().anyMatch(param -> CONTEXT_PARAM_DEV_MODE.equals(param.getParamName()) && Boolean.valueOf(param.getParamValue()));
            if (!devModeContextParam) {
                return;
            }
            registerProbeFilter(deploymentUnit, webMetaData);
            WeldPortableExtensions.getPortableExtensions(deploymentUnit).tryRegisterExtension(loadClass(PROBE_EXTENSION_CLASS_NAME, module.getClassLoader()), deploymentUnit);
        }
    // if development mode enabled then for WAR register ProbeFilter and register ProbeExtension for every deployment
    } else {
        if (DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
            if (deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY) == null) {
                return;
            }
            final JBossWebMetaData webMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY).getMergedJBossWebMetaData();
            if (webMetaData == null) {
                return;
            }
            registerProbeFilter(deploymentUnit, webMetaData);
        }
        WeldPortableExtensions.getPortableExtensions(deploymentUnit).tryRegisterExtension(loadClass(PROBE_EXTENSION_CLASS_NAME, module.getClassLoader()), deploymentUnit);
    }
}
Also used : JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 14 with JBossWebMetaData

use of org.jboss.metadata.web.jboss.JBossWebMetaData 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 15 with JBossWebMetaData

use of org.jboss.metadata.web.jboss.JBossWebMetaData 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 {
        module.getClassLoader().loadClass(CDI_INJECTOR_FACTORY_CLASS);
        // don't set this param if CDI is not in classpath
        if (WeldDeploymentMarker.isWeldDeployment(deploymentUnit)) {
            JAXRS_LOGGER.debug("Found CDI, 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) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Aggregations

JBossWebMetaData (org.jboss.metadata.web.jboss.JBossWebMetaData)25 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)14 WarMetaData (org.jboss.as.web.common.WarMetaData)14 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)7 ParamValueMetaData (org.jboss.metadata.javaee.spec.ParamValueMetaData)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)5 JBossServletMetaData (org.jboss.metadata.web.jboss.JBossServletMetaData)5 VirtualFile (org.jboss.vfs.VirtualFile)4 JBossWebservicesMetaData (org.jboss.wsf.spi.metadata.webservices.JBossWebservicesMetaData)4 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)3 EJBEndpoint (org.jboss.as.webservices.metadata.model.EJBEndpoint)3 POJOEndpoint (org.jboss.as.webservices.metadata.model.POJOEndpoint)3 ListenerMetaData (org.jboss.metadata.web.spec.ListenerMetaData)3 Module (org.jboss.modules.Module)3 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 WebService (javax.jws.WebService)2