Search in sources :

Example 21 with WebComponentDescriptor

use of com.sun.enterprise.deployment.WebComponentDescriptor in project Payara by payara.

the class WebContainer method loadWebModule.

/**
 * Creates and configures a web module and adds it to the specified
 * virtual server.
 */
private WebModule loadWebModule(VirtualServer vs, WebModuleConfig wmInfo, String j2eeApplication, Properties deploymentProperties) throws Exception {
    String wmName = wmInfo.getName();
    String wmContextPath = wmInfo.getContextPath();
    if (wmContextPath.indexOf('%') != -1) {
        try {
            RequestUtil.urlDecode(wmContextPath, "UTF-8");
        } catch (Exception e) {
            String msg = rb.getString(LogFacade.INVALID_ENCODED_CONTEXT_ROOT);
            msg = MessageFormat.format(msg, wmName, wmContextPath);
            throw new Exception(msg);
        }
    }
    if (wmContextPath.length() == 0 && vs.getDefaultWebModuleID() != null) {
        String msg = rb.getString(LogFacade.DEFAULT_WEB_MODULE_CONFLICT);
        msg = MessageFormat.format(msg, new Object[] { wmName, vs.getID() });
        throw new Exception(msg);
    }
    wmInfo.setWorkDirBase(_appsWorkRoot);
    // START S1AS 6178005
    wmInfo.setStubBaseDir(appsStubRoot);
    // END S1AS 6178005
    String displayContextPath = null;
    if (wmContextPath.length() == 0)
        displayContextPath = "/";
    else
        displayContextPath = wmContextPath;
    Map<String, AdHocServletInfo> adHocPaths = null;
    Map<String, AdHocServletInfo> adHocSubtrees = null;
    WebModule ctx = (WebModule) vs.findChild(wmContextPath);
    if (ctx != null) {
        if (ctx instanceof AdHocWebModule) {
            /*
                 * Found ad-hoc web module which has been created by web
                 * container in order to store mappings for ad-hoc paths
                 * and subtrees.
                 * All these mappings must be propagated to the context
                 * that is being deployed.
                 */
            if (ctx.hasAdHocPaths()) {
                adHocPaths = ctx.getAdHocPaths();
            }
            if (ctx.hasAdHocSubtrees()) {
                adHocSubtrees = ctx.getAdHocSubtrees();
            }
            vs.removeChild(ctx);
        } else if (Constants.DEFAULT_WEB_MODULE_NAME.equals(ctx.getModuleName())) {
            /*
                 * Dummy context that was created just off of a docroot,
                 * (see
                 * VirtualServer.createSystemDefaultWebModuleIfNecessary()).
                 * Unload it so it can be replaced with the web module to be
                 * loaded
                 */
            unloadWebModule(wmContextPath, ctx.getWebBundleDescriptor().getApplication().getRegistrationName(), vs.getName(), true, null);
        } else if (!ctx.getAvailable()) {
            /*
                 * Context has been marked unavailable by a previous
                 * call to disableWebModule. Mark the context as available and
                 * return
                 */
            ctx.setAvailable(true);
            return ctx;
        } else {
            String msg = rb.getString(LogFacade.DUPLICATE_CONTEXT_ROOT);
            throw new Exception(MessageFormat.format(msg, vs.getID(), ctx.getModuleName(), displayContextPath, wmName));
        }
    }
    if (logger.isLoggable(Level.FINEST)) {
        Object[] params = { wmName, vs.getID(), displayContextPath };
        logger.log(Level.FINEST, LogFacade.WEB_MODULE_LOADING, params);
    }
    File docBase = null;
    if (JWS_APPCLIENT_MODULE_NAME.equals(wmName)) {
        docBase = new File(System.getProperty("com.sun.aas.installRoot"));
    } else {
        docBase = wmInfo.getLocation();
    }
    ctx = (WebModule) _embedded.createContext(wmName, wmContextPath, docBase, vs.getDefaultContextXmlLocation(), vs.getDefaultWebXmlLocation(), useDOLforDeployment, wmInfo);
    // for now disable JNDI
    ctx.setUseNaming(false);
    // Set JSR 77 object name and attributes
    Engine engine = (Engine) vs.getParent();
    if (engine != null) {
        ctx.setEngineName(engine.getName());
        ctx.setJvmRoute(engine.getJvmRoute());
    }
    String j2eeServer = _serverContext.getInstanceName();
    String domain = _serverContext.getDefaultDomainName();
    // String[] javaVMs = J2EEModuleUtil.getjavaVMs();
    ctx.setDomain(domain);
    ctx.setJ2EEServer(j2eeServer);
    ctx.setJ2EEApplication(j2eeApplication);
    // turn on container internal cache by default as in v2
    // ctx.setCachingAllowed(false);
    ctx.setCacheControls(vs.getCacheControls());
    ctx.setBean(wmInfo.getBean());
    if (adHocPaths != null) {
        ctx.addAdHocPaths(adHocPaths);
    }
    if (adHocSubtrees != null) {
        ctx.addAdHocSubtrees(adHocSubtrees);
    }
    // Object containing web.xml information
    WebBundleDescriptor wbd = wmInfo.getDescriptor();
    // Set the context root
    if (wbd != null) {
        ctx.setContextRoot(wbd.getContextRoot());
    } else {
        // Should never happen.
        logger.log(Level.WARNING, LogFacade.UNABLE_TO_SET_CONTEXT_ROOT, wmInfo);
    }
    // 
    // Ensure that the generated directory for JSPs in the document root
    // (i.e. those that are serviced by a system default-web-module)
    // is different for each virtual server.
    String wmInfoWorkDir = wmInfo.getWorkDir();
    if (wmInfoWorkDir != null) {
        StringBuilder workDir = new StringBuilder(wmInfo.getWorkDir());
        if (wmName.equals(Constants.DEFAULT_WEB_MODULE_NAME)) {
            workDir.append("-");
            workDir.append(FileUtils.makeFriendlyFilename(vs.getID()));
        }
        ctx.setWorkDir(workDir.toString());
    }
    ClassLoader parentLoader = wmInfo.getParentLoader();
    if (parentLoader == null) {
        // Use the shared classloader as the parent for all
        // standalone web-modules
        parentLoader = _serverContext.getSharedClassLoader();
    }
    ctx.setParentClassLoader(parentLoader);
    if (wbd != null) {
        // Determine if an alternate DD is set for this web-module in
        // the application
        ctx.configureAlternateDD(wbd);
        ctx.configureWebServices(wbd);
    }
    // Object containing sun-web.xml information
    SunWebAppImpl iasBean = null;
    // The default context is the only case when wbd == null
    if (wbd != null) {
        iasBean = (SunWebAppImpl) wbd.getSunDescriptor();
    }
    // set the sun-web config bean
    ctx.setIasWebAppConfigBean(iasBean);
    // Configure SingleThreadedServletPools, work/tmp directory etc
    ctx.configureMiscSettings(iasBean, vs, displayContextPath);
    // Configure alternate docroots if dummy web module
    if (ctx.getID().startsWith(Constants.DEFAULT_WEB_MODULE_NAME)) {
        ctx.setAlternateDocBases(vs.getProperties());
    }
    // Configure the class loader delegation model, classpath etc
    Loader loader = ctx.configureLoader(iasBean);
    // Set the class loader on the DOL object
    if (wbd != null && wbd.hasWebServices()) {
        wbd.addExtraAttribute("WEBLOADER", loader);
    }
    for (LifecycleListener listener : ctx.findLifecycleListeners()) {
        if (listener instanceof ContextConfig) {
            ((ContextConfig) listener).setClassLoader(wmInfo.getAppClassLoader());
        }
    }
    // Configure the session manager and other related settings
    ctx.configureSessionSettings(wbd, wmInfo);
    // set i18n info from locale-charset-info tag in sun-web.xml
    ctx.setI18nInfo();
    if (wbd != null) {
        String resourceType = wmInfo.getObjectType();
        boolean isSystem = resourceType != null && resourceType.startsWith("system-");
        // security will generate policy for system default web module
        if (!wmName.startsWith(Constants.DEFAULT_WEB_MODULE_NAME)) {
            // TODO : v3 : dochez Need to remove dependency on security
            Realm realm = habitat.getService(Realm.class);
            if ("null".equals(j2eeApplication)) {
                /*
                     * Standalone webapps inherit the realm referenced by
                     * the virtual server on which they are being deployed,
                     * unless they specify their own
                     */
                if (realm != null && realm instanceof RealmInitializer) {
                    ((RealmInitializer) realm).initializeRealm(wbd, isSystem, vs.getAuthRealmName());
                    ctx.setRealm(realm);
                }
            } else {
                if (realm != null && realm instanceof RealmInitializer) {
                    ((RealmInitializer) realm).initializeRealm(wbd, isSystem, null);
                    ctx.setRealm(realm);
                }
            }
        }
        // post processing DOL object for standalone web module
        if (wbd.getApplication() != null && wbd.getApplication().isVirtual()) {
            wbd.visit(new WebValidatorWithoutCL());
        }
    }
    // Add virtual server mime mappings, if present
    addMimeMappings(ctx, vs.getMimeMap());
    String moduleName = Constants.DEFAULT_WEB_MODULE_NAME;
    String monitoringNodeName = moduleName;
    if (wbd != null && wbd.getApplication() != null) {
        // Not a dummy web module
        com.sun.enterprise.deployment.Application app = wbd.getApplication();
        ctx.setStandalone(app.isVirtual());
        // S1AS BEGIN WORKAROUND FOR 6174360
        if (app.isVirtual()) {
            // Standalone web module
            moduleName = app.getRegistrationName();
            monitoringNodeName = wbd.getModuleID();
        } else {
            // Nested (inside EAR) web module
            moduleName = wbd.getModuleDescriptor().getArchiveUri();
            StringBuilder sb = new StringBuilder();
            sb.append(app.getRegistrationName()).append(MONITORING_NODE_SEPARATOR).append(moduleName);
            monitoringNodeName = sb.toString().replaceAll("\\.", "\\\\.").replaceAll("_war", "\\\\.war");
        }
    // S1AS END WORKAROUND FOR 6174360
    }
    ctx.setModuleName(moduleName);
    ctx.setMonitoringNodeName(monitoringNodeName);
    List<String> servletNames = new ArrayList<String>();
    if (wbd != null) {
        for (WebComponentDescriptor webCompDesc : wbd.getWebComponentDescriptors()) {
            if (webCompDesc.isServlet()) {
                servletNames.add(webCompDesc.getCanonicalName());
            }
        }
    }
    webStatsProviderBootstrap.registerApplicationStatsProviders(monitoringNodeName, vs.getName(), servletNames);
    vs.addChild(ctx);
    ctx.loadSessions(deploymentProperties);
    return ctx;
}
Also used : SunWebAppImpl(org.glassfish.web.deployment.runtime.SunWebAppImpl) WebValidatorWithoutCL(org.glassfish.web.deployment.util.WebValidatorWithoutCL) RealmInitializer(com.sun.enterprise.security.integration.RealmInitializer) ArrayList(java.util.ArrayList) WebappClassLoader(org.glassfish.web.loader.WebappClassLoader) Loader(org.apache.catalina.Loader) LifecycleListener(org.apache.catalina.LifecycleListener) ContextConfig(org.apache.catalina.startup.ContextConfig) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) WebappClassLoader(org.glassfish.web.loader.WebappClassLoader) Realm(org.apache.catalina.Realm) StandardEngine(org.apache.catalina.core.StandardEngine) Engine(org.apache.catalina.Engine) LifecycleException(org.apache.catalina.LifecycleException) NamingException(javax.naming.NamingException) BindException(java.net.BindException) MalformedURLException(java.net.MalformedURLException) WebComponentDescriptor(com.sun.enterprise.deployment.WebComponentDescriptor) Application(com.sun.enterprise.deployment.Application) File(java.io.File)

Example 22 with WebComponentDescriptor

use of com.sun.enterprise.deployment.WebComponentDescriptor in project Payara by payara.

the class DynamicWebServletRegistrationImpl method addMapping.

@Override
public Set<String> addMapping(String... urlPatterns) {
    Set<String> conflicts = super.addMapping(urlPatterns);
    if (conflicts.isEmpty() && urlPatterns != null && urlPatterns.length > 0) {
        /*
             * Propagate the new mappings to the underlying 
             * WebBundleDescriptor provided by the deployment backend,
             * so that corresponding security constraints may be calculated
             * by the security subsystem, which uses the
             * WebBundleDescriptor as its input
             */
        WebBundleDescriptor wbd = ((WebModule) getContext()).getWebBundleDescriptor();
        if (wbd == null) {
            throw new IllegalStateException("Missing WebBundleDescriptor for " + getContext().getName());
        }
        WebComponentDescriptor wcd = wbd.getWebComponentByCanonicalName(getName());
        if (wcd == null) {
            throw new IllegalStateException("Missing WebComponentDescriptor for " + getName());
        }
        for (String urlPattern : urlPatterns) {
            wcd.addUrlPattern(urlPattern);
        }
    }
    return conflicts;
}
Also used : WebComponentDescriptor(com.sun.enterprise.deployment.WebComponentDescriptor) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) PwcWebModule(com.sun.enterprise.web.pwc.PwcWebModule)

Example 23 with WebComponentDescriptor

use of com.sun.enterprise.deployment.WebComponentDescriptor in project Payara by payara.

the class WebModuleListener method initIncludeJars.

private void initIncludeJars() {
    if (includeInitialized) {
        return;
    }
    String includeJarsString = null;
    ;
    for (WebComponentDescriptor wcd : wbd.getWebComponentDescriptors()) {
        if ("jsp".equals(wcd.getCanonicalName())) {
            InitializationParameter initp = wcd.getInitializationParameterByName("system-jar-includes");
            if (initp != null) {
                includeJarsString = initp.getValue();
                break;
            }
        }
    }
    includeInitialized = true;
    if (includeJarsString == null) {
        includeJars = null;
        return;
    }
    includeJars = new ArrayList<String>();
    StringTokenizer tokenizer = new StringTokenizer(includeJarsString);
    while (tokenizer.hasMoreElements()) {
        includeJars.add(tokenizer.nextToken());
    }
}
Also used : WebComponentDescriptor(com.sun.enterprise.deployment.WebComponentDescriptor) StringTokenizer(java.util.StringTokenizer) InitializationParameter(com.sun.enterprise.deployment.web.InitializationParameter)

Example 24 with WebComponentDescriptor

use of com.sun.enterprise.deployment.WebComponentDescriptor in project Payara by payara.

the class WebArchivist method postAnnotationProcess.

@Override
protected void postAnnotationProcess(WebBundleDescriptorImpl descriptor, ReadableArchive archive) throws IOException {
    super.postAnnotationProcess(descriptor, archive);
    // read web-fragment.xml
    List<WebFragmentDescriptor> wfList = readStandardFragments(descriptor, archive);
    // extension annotation processing will be done in top level
    if (isProcessAnnotation(descriptor)) {
        Map<ExtensionsArchivist, RootDeploymentDescriptor> localExtensions = new HashMap<>();
        for (WebFragmentDescriptor wfDesc : wfList) {
            // should be overridden and be true also
            if (descriptor.isFullAttribute()) {
                wfDesc.setFullAttribute(String.valueOf(descriptor.isFullAttribute()));
            }
            super.readAnnotations(archive, wfDesc, localExtensions);
        }
        // scan manifest classpath
        ModuleScanner scanner = getScanner();
        if (scanner instanceof WarScanner) {
            ((WarScanner) scanner).setScanOtherLibraries(true);
            readAnnotations(archive, descriptor, localExtensions, scanner);
        }
    }
    WebFragmentDescriptor mergedWebFragment = new WebFragmentDescriptor();
    mergedWebFragment.setExists(false);
    for (WebFragmentDescriptor wf : wfList) {
        // we have the first fragment that's contains the web-fragment.xml file
        if (!mergedWebFragment.isExists() && wf.isExists()) {
            mergedWebFragment.setExists(true);
            mergedWebFragment.setDistributable(wf.isDistributable());
        }
        mergedWebFragment.addWebBundleDescriptor(wf);
    }
    if (!wfList.isEmpty()) {
        descriptor.addWebBundleDescriptor(mergedWebFragment);
        // if there any mapping stubs left, there is something invalid referenced from web.xml
        for (WebComponentDescriptor desc : descriptor.getWebComponentDescriptors()) {
            if (desc instanceof WebComponentDescriptorStub) {
                throw new RuntimeException(String.format("There is no web component by the name of %s here.", desc.getName()));
            }
        }
    }
    // apply default from default-web.xml to web.xml
    WebBundleDescriptorImpl defaultWebBundleDescriptor = getPlainDefaultWebXmlBundleDescriptor();
    descriptor.addDefaultWebBundleDescriptor(defaultWebBundleDescriptor);
}
Also used : WebComponentDescriptor(com.sun.enterprise.deployment.WebComponentDescriptor) HashMap(java.util.HashMap) RootDeploymentDescriptor(org.glassfish.deployment.common.RootDeploymentDescriptor) ModuleScanner(com.sun.enterprise.deployment.annotation.impl.ModuleScanner) ExtensionsArchivist(com.sun.enterprise.deployment.archivist.ExtensionsArchivist) WarScanner(org.glassfish.web.deployment.annotation.impl.WarScanner)

Example 25 with WebComponentDescriptor

use of com.sun.enterprise.deployment.WebComponentDescriptor in project Payara by payara.

the class ListSubComponentsCommand method getModuleLevelComponents.

private Map<String, String> getModuleLevelComponents(BundleDescriptor bundle, String type, Map<String, String> subComponentsMap) {
    Map<String, String> moduleSubComponentMap = new LinkedHashMap<String, String>();
    if (bundle instanceof WebBundleDescriptor) {
        WebBundleDescriptor wbd = (WebBundleDescriptor) bundle;
        // look at ejb in war case
        Collection<EjbBundleDescriptor> ejbBundleDescs = wbd.getExtensionsDescriptors(EjbBundleDescriptor.class);
        if (ejbBundleDescs.size() > 0) {
            EjbBundleDescriptor ejbBundle = ejbBundleDescs.iterator().next();
            moduleSubComponentMap.putAll(getModuleLevelComponents(ejbBundle, type, subComponentsMap));
        }
        if (type != null && type.equals("ejbs")) {
            return moduleSubComponentMap;
        }
        for (WebComponentDescriptor wcd : wbd.getWebComponentDescriptors()) {
            StringBuffer sb = new StringBuffer();
            String canonicalName = wcd.getCanonicalName();
            sb.append("<");
            // The component type is limited to JSP or Servlet at this level. JAX-RS resources for example need to be obtained elsewhere.
            String wcdType = (wcd.isServlet() ? "Servlet" : "JSP");
            sb.append(wcdType);
            sb.append(">");
            moduleSubComponentMap.put(canonicalName, sb.toString());
            subComponentsMap.put(wcd.getCanonicalName(), wcdType);
        }
    } else if (bundle instanceof EjbBundleDescriptor) {
        if (type != null && type.equals("servlets")) {
            return moduleSubComponentMap;
        }
        EjbBundleDescriptor ebd = (EjbBundleDescriptor) bundle;
        for (EjbDescriptor ejbDesc : ebd.getEjbs()) {
            StringBuffer sb = new StringBuffer();
            String ejbName = ejbDesc.getName();
            sb.append("<");
            String ejbType = ejbDesc.getEjbTypeForDisplay();
            sb.append(ejbType);
            sb.append(">");
            moduleSubComponentMap.put(ejbName, sb.toString());
            subComponentsMap.put(ejbDesc.getName(), ejbType);
        }
    }
    return moduleSubComponentMap;
}
Also used : WebComponentDescriptor(com.sun.enterprise.deployment.WebComponentDescriptor) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

WebComponentDescriptor (com.sun.enterprise.deployment.WebComponentDescriptor)28 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)7 Iterator (java.util.Iterator)5 RunAsIdentityDescriptor (com.sun.enterprise.deployment.RunAsIdentityDescriptor)4 WebComponentContext (com.sun.enterprise.deployment.annotation.context.WebComponentContext)4 Role (org.glassfish.security.common.Role)4 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)3 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)3 WebServicesDescriptor (com.sun.enterprise.deployment.WebServicesDescriptor)3 Set (java.util.Set)3 SunWebAppImpl (org.glassfish.web.deployment.runtime.SunWebAppImpl)3 Application (com.sun.enterprise.deployment.Application)2 ServiceReferenceDescriptor (com.sun.enterprise.deployment.ServiceReferenceDescriptor)2 WebService (com.sun.enterprise.deployment.WebService)2 WebBundleContext (com.sun.enterprise.deployment.annotation.context.WebBundleContext)2 SecurityRoleMapping (com.sun.enterprise.deployment.runtime.common.SecurityRoleMapping)2 IdempotentUrlPattern (com.sun.enterprise.deployment.runtime.web.IdempotentUrlPattern)2 AnnotatedElement (java.lang.reflect.AnnotatedElement)2 WebServlet (javax.servlet.annotation.WebServlet)2 SecurityRoleMapper (org.glassfish.deployment.common.SecurityRoleMapper)2