Search in sources :

Example 6 with SunWebAppImpl

use of org.glassfish.web.deployment.runtime.SunWebAppImpl in project Payara by payara.

the class WebModuleListener method configureJsp.

// ------------------------------------------------------- Private Methods
/**
 * Configure all JSP related aspects of the web module, including
 * any relevant TLDs as well as the jsp config settings of the
 * JspServlet (using the values from sun-web.xml's jsp-config).
 */
private void configureJsp(WebModule webModule) {
    ServletContext servletContext = webModule.getServletContext();
    servletContext.setAttribute("org.glassfish.jsp.isStandaloneWebapp", Boolean.valueOf(webModule.isStandalone()));
    // Find tld URI and set it to ServletContext attribute
    List<URI> appLibUris = webModule.getDeployAppLibs();
    Map<URI, List<String>> appLibTldMap = new HashMap<URI, List<String>>();
    if (appLibUris != null && appLibUris.size() > 0) {
        Pattern pattern = Pattern.compile("META-INF/.*\\.tld");
        for (URI uri : appLibUris) {
            List<String> entries = JarURIPattern.getJarEntries(uri, pattern);
            if (entries != null && entries.size() > 0) {
                appLibTldMap.put(uri, entries);
            }
        }
    }
    Collection<TldProvider> tldProviders = webContainer.getTldProviders();
    Map<URI, List<String>> tldMap = new HashMap<URI, List<String>>();
    for (TldProvider tldProvider : tldProviders) {
        // Skip any JSF related TLDs for non-JSF apps
        if ("jsfTld".equals(tldProvider.getName()) && !webModule.isJsfApplication()) {
            continue;
        }
        Map<URI, List<String>> tmap = tldProvider.getTldMap();
        if (tmap != null) {
            tldMap.putAll(tmap);
        }
    }
    tldMap.putAll(appLibTldMap);
    servletContext.setAttribute("com.sun.appserv.tld.map", tldMap);
    /*
         * Discover all TLDs that are known to contain listener
         * declarations, and store the resulting map as a
         * ServletContext attribute
         */
    Map<URI, List<String>> tldListenerMap = new HashMap<URI, List<String>>();
    for (TldProvider tldProvider : tldProviders) {
        // Skip any JSF related TLDs for non-JSF apps
        if ("jsfTld".equals(tldProvider.getName()) && !webModule.isJsfApplication()) {
            continue;
        }
        Map<URI, List<String>> tmap = tldProvider.getTldListenerMap();
        if (tmap != null) {
            tldListenerMap.putAll(tmap);
        }
    }
    tldListenerMap.putAll(appLibTldMap);
    servletContext.setAttribute("com.sun.appserv.tldlistener.map", tldListenerMap);
    ServiceLocator defaultServices = webContainer.getServerContext().getDefaultServices();
    // set services for jsf injection
    servletContext.setAttribute(Constants.HABITAT_ATTRIBUTE, defaultServices);
    SunWebAppImpl bean = webModule.getIasWebAppConfigBean();
    // Find the default jsp servlet
    Wrapper wrapper = (Wrapper) webModule.findChild(org.apache.catalina.core.Constants.JSP_SERVLET_NAME);
    if (wrapper == null) {
        return;
    }
    if (webModule.getTldValidation()) {
        wrapper.addInitParameter("enableTldValidation", "true");
    }
    if (bean != null && bean.getJspConfig() != null) {
        WebProperty[] props = bean.getJspConfig().getWebProperty();
        for (int i = 0; i < props.length; i++) {
            String pname = props[i].getAttributeValue("name");
            String pvalue = props[i].getAttributeValue("value");
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, LogFacade.JSP_CONFIG_PROPERTY, "[" + webModule.getID() + "] is [" + pname + "] = [" + pvalue + "]");
            }
            wrapper.addInitParameter(pname, pvalue);
        }
    }
    // Override any log setting with the container wide logging level
    wrapper.addInitParameter("logVerbosityLevel", getJasperLogLevel());
    ResourceInjectorImpl resourceInjector = new ResourceInjectorImpl(webModule);
    servletContext.setAttribute("com.sun.appserv.jsp.resource.injector", resourceInjector);
    // START SJSAS 6311155
    String sysClassPath = ASClassLoaderUtil.getModuleClassPath((ServiceLocator) defaultServices, webModule.getID(), null);
    // If the configuration flag usMyFaces is set, remove jakarta.faces.jar
    // from the system class path
    Boolean useMyFaces = (Boolean) servletContext.getAttribute("com.sun.faces.useMyFaces");
    if (useMyFaces != null && useMyFaces) {
        sysClassPath = sysClassPath.replace("jakarta.faces.jar", "$disabled$.raj");
        // jsf-connector.jar manifest has a Class-Path to jakarta.faces.jar
        sysClassPath = sysClassPath.replace("jsf-connector.jar", "$disabled$.raj");
    }
    // servletContext.getAttribute(("org.apache.catalina.jsp_classpath")
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, LogFacade.SYS_CLASSPATH, webModule.getID() + " is " + sysClassPath);
    }
    if (sysClassPath.equals("")) {
        // In embedded mode, services returns SingleModulesRegistry and
        // it has no modules.
        // Try "java.class.path" system property instead.
        sysClassPath = System.getProperty("java.class.path");
    }
    sysClassPath = trimSysClassPath(sysClassPath);
    wrapper.addInitParameter("com.sun.appserv.jsp.classpath", sysClassPath);
    // END SJSAS 6311155
    // Configure JSP monitoring
    servletContext.setAttribute("org.glassfish.jsp.monitor.probeEmitter", new JspProbeEmitterImpl(webModule));
    // Pass BeanManager's ELResolver as ServletContext attribute
    // (see IT 11168)
    InvocationManager invocationMgr = webContainer.getInvocationManager();
    WebComponentInvocation inv = new WebComponentInvocation(webModule);
    try {
        invocationMgr.preInvoke(inv);
        JCDIService jcdiService = defaultServices.getService(JCDIService.class);
        // JCDIService can be absent if weld integration is missing in the runtime, so check for null is needed.
        if (jcdiService != null && jcdiService.isCurrentModuleJCDIEnabled()) {
            jcdiService.setELResolver(servletContext);
        }
    } catch (NamingException e) {
    // Ignore
    } finally {
        invocationMgr.postInvoke(inv);
    }
}
Also used : SunWebAppImpl(org.glassfish.web.deployment.runtime.SunWebAppImpl) JarURIPattern(com.sun.enterprise.util.net.JarURIPattern) Pattern(java.util.regex.Pattern) JspProbeEmitterImpl(com.sun.enterprise.web.jsp.JspProbeEmitterImpl) WebProperty(org.glassfish.web.deployment.runtime.WebProperty) JCDIService(com.sun.enterprise.container.common.spi.JCDIService) HashMap(java.util.HashMap) ResourceInjectorImpl(com.sun.enterprise.web.jsp.ResourceInjectorImpl) InvocationManager(org.glassfish.api.invocation.InvocationManager) URI(java.net.URI) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ServletContext(javax.servlet.ServletContext) ArrayList(java.util.ArrayList) List(java.util.List) NamingException(javax.naming.NamingException) TldProvider(org.glassfish.api.web.TldProvider)

Example 7 with SunWebAppImpl

use of org.glassfish.web.deployment.runtime.SunWebAppImpl in project Payara by payara.

the class ASCacheMapping method check.

public Result check(WebBundleDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    boolean notApp = false;
    // Cache cache = getCache(descriptor);
    try {
        Cache cache = ((SunWebAppImpl) descriptor.getSunDescriptor()).getCache();
        CacheMapping[] cacheMapp = null;
        String servletName = null;
        String urlPattern = null;
        String timeout = null;
        String[] httpMethods;
        // boolean[] keyFields;
        String cacheHelperRef;
        if (cache != null) {
            cacheMapp = cache.getCacheMapping();
        }
        if (cache != null && cacheMapp != null && cacheMapp.length != 0) {
            for (int rep = 0; rep < cacheMapp.length; rep++) {
                servletName = cacheMapp[rep].getServletName();
                urlPattern = cacheMapp[rep].getURLPattern();
                timeout = cacheMapp[rep].getTimeout();
                httpMethods = cacheMapp[rep].getHttpMethod();
                cacheHelperRef = cacheMapp[rep].getCacheHelperRef();
                if (servletName != null) {
                    if (validServletName(servletName, descriptor)) {
                        addGoodDetails(result, compName);
                        result.passed(smh.getLocalString(getClass().getName() + ".passed", "PASSED [AS-WEB cache-mapping] servlet-name  [ {0} ] properly defined.", new Object[] { servletName }));
                    } else {
                        addErrorDetails(result, compName);
                        result.failed(smh.getLocalString(getClass().getName() + ".failed", "FAILED [AS-WEB cache-mapping] servlet-name [ {0} ], does not exist in the web application.", new Object[] { servletName }));
                        oneFailed = true;
                    }
                } else if (urlPattern != null) {
                    if (validURL(urlPattern)) {
                        addGoodDetails(result, compName);
                        result.passed(smh.getLocalString(getClass().getName() + ".passed1", "PASSED [AS-WEB cache-mapping] url-pattern [ {0} ] properly defined.", new Object[] { urlPattern }));
                    } else {
                        addErrorDetails(result, compName);
                        result.failed(smh.getLocalString(getClass().getName() + ".failed1", "FAILED [AS-WEB cache-mapping] url-pattern [ {0} ], does not exist in  the web application.", new Object[] { urlPattern }));
                        oneFailed = true;
                    }
                }
                if (cacheHelperRef != null) {
                    // test cache-helper-ref
                    if (validCacheHelperRef(cacheHelperRef, cache)) {
                        addGoodDetails(result, compName);
                        result.passed(smh.getLocalString(getClass().getName() + ".passed2", "PASSED [AS-WEB cache-mapping] cache-helper-ref element [ {0} ]  defined properly.", new Object[] { cacheHelperRef }));
                    } else {
                        oneFailed = true;
                        addErrorDetails(result, compName);
                        result.failed(smh.getLocalString(getClass().getName() + ".failed2", "FAILED [AS-WEB cache-mapping] cache-helper-ref [ {0} ] not valid, either empty or  cache-helper not defined for it.", new Object[] { cacheHelperRef }));
                    }
                } else {
                    if (timeout != null) {
                        int i = rep + 1;
                        String timeoutName = getXPathValue("sun-web-app/cache/cache-mapping[" + i + "]/timeout/@name");
                        if (validTimeout(timeout, timeoutName)) {
                            addGoodDetails(result, compName);
                            result.passed(smh.getLocalString(getClass().getName() + ".passed3", "PASSED [AS-WEB cache-mapping] timeout element [ {0} ] properly defined.", new Object[] { new Integer(timeout) }));
                        } else {
                            oneFailed = true;
                            addErrorDetails(result, compName);
                            result.failed(smh.getLocalString(getClass().getName() + ".failed3", "FAILED [AS-WEB cache-mapping] timeout element [{0}] must be a Long ( Not less than -1 and not more that MAX_LONG) and its name attribute [{1}] can not be empty/null.", new Object[] { timeout, timeoutName }));
                        }
                    }
                    // <addition author="irfan@sun.com" [bug/rfe]-id="4706026" >
                    int j = rep + 1;
                    int count = getCountNodeSet("sun-web-app/cache/cache-mapping[" + j + "]/refresh-field");
                    if (// refresh field element present
                    count > 0) {
                        String cacheMapName = null;
                        if (cacheMapp[rep].getServletName() != null)
                            cacheMapName = cacheMapp[rep].getServletName();
                        else
                            cacheMapName = cacheMapp[rep].getURLPattern();
                        String name = getXPathValue("sun-web-app/cache/cache-mapping[" + j + "]/refresh-field/@name");
                        if (name != null && name.length() != 0) {
                            addGoodDetails(result, compName);
                            result.passed(smh.getLocalString(getClass().getName() + ".passed3a", "PASSED [AS-WEB cache-mapping] for {0}, refresh-field name [{1}] has been furnished", new Object[] { cacheMapName, name }));
                        } else {
                            addErrorDetails(result, compName);
                            result.failed(smh.getLocalString(getClass().getName() + ".failed3a", "FAILED [AS-WEB cache-mapping] for {0}, refresh-field name [{1}] cannot be empty/null string", new Object[] { cacheMapName, name }));
                            oneFailed = true;
                        }
                    }
                    // </addition>
                    if (checkHTTPMethodList(httpMethods, result, compName, descriptor)) {
                    } else {
                        oneFailed = true;
                        addErrorDetails(result, compName);
                        result.failed(smh.getLocalString(getClass().getName() + ".failed4", "FAILED [AS-WEB cache-mapping] http-method - List of HTTP methods is not proper, " + " atleast one of the method name in the list is empty/null "));
                    }
                    // <addition author="irfan@sun.com" [bug/rfe]-id="4706026" >
                    if ((getCountNodeSet("sun-web-app/cache/cache-mapping[" + j + "]/key-field")) > 0)
                        testForKeyFields(cache, j, result, compName);
                // </addition>
                }
            }
        } else {
            notApp = true;
            addNaDetails(result, compName);
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "NOT APPLICABLE [AS-WEB cache-mapping] element not defined", new Object[] { descriptor.getName() }));
        }
        if (oneFailed) {
            result.setStatus(Result.FAILED);
        } else if (oneWarning) {
            result.setStatus(Result.WARNING);
        } else if (notApp) {
            result.setStatus(Result.NOT_APPLICABLE);
        } else {
            result.setStatus(Result.PASSED);
        }
    } catch (Exception ex) {
        oneFailed = true;
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failed7", "FAILED [AS-WEB cache-mapping] could not create the cache object"));
    }
    return result;
}
Also used : SunWebAppImpl(org.glassfish.web.deployment.runtime.SunWebAppImpl) Result(com.sun.enterprise.tools.verifier.Result) CacheMapping(org.glassfish.web.deployment.runtime.CacheMapping) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Cache(org.glassfish.web.deployment.runtime.Cache)

Example 8 with SunWebAppImpl

use of org.glassfish.web.deployment.runtime.SunWebAppImpl in project Payara by payara.

the class ASCacheMappingFieldConstraint method check.

public Result check(WebBundleDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    boolean oneFailed = false;
    boolean notApp = false;
    boolean doneAtleastOnce = false;
    try {
        Cache cache = ((SunWebAppImpl) descriptor.getSunDescriptor()).getCache();
        CacheMapping[] cacheMapp = null;
        String servletName;
        String urlPattern;
        ConstraintField[] fieldConstraints = null;
        String mappingFor = null;
        if (cache != null) {
            cacheMapp = cache.getCacheMapping();
        }
        if (cache != null && cacheMapp != null && cacheMapp.length != 0) {
            for (int rep = 0; rep < cacheMapp.length; rep++) {
                servletName = cacheMapp[rep].getServletName();
                urlPattern = cacheMapp[rep].getURLPattern();
                if (servletName != null)
                    mappingFor = servletName;
                else
                    mappingFor = urlPattern;
                fieldConstraints = cacheMapp[rep].getConstraintField();
                if (fieldConstraints != null && fieldConstraints.length != 0) {
                    for (int rep1 = 0; rep1 < fieldConstraints.length; rep1++) {
                        if (fieldConstraints[rep1] != null) {
                            doneAtleastOnce = true;
                            if (checkFieldConstraint(fieldConstraints[rep1], result, mappingFor, descriptor, compName)) {
                            // nothing more required
                            } else {
                                oneFailed = true;
                                addErrorDetails(result, compName);
                                result.failed(smh.getLocalString(getClass().getName() + ".failed", "FAILED [AS-WEB cache-mapping] List of field-constraint in cache-mapping for [ {0} ] is not proper,  within the web archive/(gf/)sun-web.xml of [ {1} ].", new Object[] { mappingFor, descriptor.getName() }));
                            }
                        }
                    }
                // end of for(int rep1=0;rep1 < fieldConstraints.length;rep1++)
                }
            }
        // end of for(int rep=0;rep < cacheMapp.length;rep++)
        } else {
            notApp = true;
        }
        if (oneFailed) {
            result.setStatus(Result.FAILED);
        } else if (notApp || !doneAtleastOnce) {
            result.setStatus(Result.NOT_APPLICABLE);
            addNaDetails(result, compName);
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "NOT APPLICABLE [AS-WEB cache-mapping ] constraint-field not defined in [ {0} ].", new Object[] { descriptor.getName() }));
        } else {
            result.setStatus(Result.PASSED);
        }
    } catch (Exception ex) {
        oneFailed = true;
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failed", "FAILED [AS-WEB cache-mapping] could not create the cache object"));
    }
    return result;
}
Also used : SunWebAppImpl(org.glassfish.web.deployment.runtime.SunWebAppImpl) ConstraintField(org.glassfish.web.deployment.runtime.ConstraintField) CacheMapping(org.glassfish.web.deployment.runtime.CacheMapping) Cache(org.glassfish.web.deployment.runtime.Cache)

Example 9 with SunWebAppImpl

use of org.glassfish.web.deployment.runtime.SunWebAppImpl in project Payara by payara.

the class DynamicWebServletRegistrationImpl method configureMiscSettings.

/**
 * Configure miscellaneous settings such as the pool size for
 * single threaded servlets, specifying a temporary directory other
 * than the default etc.
 *
 * Since the work directory is used when configuring the session manager
 * persistence settings, this method must be invoked prior to
 * <code>configureSessionSettings</code>.
 *
 * Properties are inherited from VirtualServer and may be overridden by configuration from sun-web.xml
 */
void configureMiscSettings(final VirtualServer vs, final String contextPath) {
    for (final Property prop : vs.getProperties()) {
        final String name = prop.getName();
        final String value = prop.getValue();
        configureProperty(vs, contextPath, name, value);
    }
    // sen-web.xml preserved for backward compatibility
    final SunWebAppImpl configBean = getIasWebAppConfigBean();
    if (configBean != null && configBean.sizeWebProperty() > 0) {
        for (final WebProperty webProperty : configBean.getWebProperty()) {
            final String name = webProperty.getAttributeValue("name");
            final String value = webProperty.getAttributeValue("value");
            configureProperty(vs, contextPath, name, value);
        }
    }
}
Also used : SunWebAppImpl(org.glassfish.web.deployment.runtime.SunWebAppImpl) WebProperty(org.glassfish.web.deployment.runtime.WebProperty) Property(org.jvnet.hk2.config.types.Property) WebProperty(org.glassfish.web.deployment.runtime.WebProperty)

Example 10 with SunWebAppImpl

use of org.glassfish.web.deployment.runtime.SunWebAppImpl in project Payara by payara.

the class WebApplication method stopCoherenceWeb.

private void stopCoherenceWeb() {
    if (wmInfo.getDescriptor() != null && wmInfo.getDescriptor().getSunDescriptor() != null) {
        SunWebAppImpl sunWebApp = (SunWebAppImpl) wmInfo.getDescriptor().getSunDescriptor();
        if (sunWebApp.getSessionConfig() != null && sunWebApp.getSessionConfig().getSessionManager() != null) {
            SessionManager sessionManager = sunWebApp.getSessionConfig().getSessionManager();
            String persistenceType = sessionManager.getAttributeValue(SessionManager.PERSISTENCE_TYPE);
            if (PersistenceType.COHERENCE_WEB.getType().equals(persistenceType)) {
                ClassLoader cloader = wmInfo.getAppClassLoader();
                try {
                    Class<?> cacheFactoryClass = cloader.loadClass("com.tangosol.net.CacheFactory");
                    if (cacheFactoryClass != null) {
                        Method shutdownMethod = cacheFactoryClass.getMethod("shutdown");
                        if (shutdownMethod != null) {
                            shutdownMethod.invoke(null);
                        }
                    }
                } catch (Exception ex) {
                    if (logger.isLoggable(Level.WARNING)) {
                        String msg = rb.getString(LogFacade.EXCEPTION_SHUTDOWN_COHERENCE_WEB);
                        msg = MessageFormat.format(msg, wmInfo.getDescriptor().getName());
                        logger.log(Level.WARNING, msg, ex);
                    }
                }
            }
        }
    }
}
Also used : SunWebAppImpl(org.glassfish.web.deployment.runtime.SunWebAppImpl) SessionManager(org.glassfish.web.deployment.runtime.SessionManager) Method(java.lang.reflect.Method)

Aggregations

SunWebAppImpl (org.glassfish.web.deployment.runtime.SunWebAppImpl)12 Cache (org.glassfish.web.deployment.runtime.Cache)5 WebProperty (org.glassfish.web.deployment.runtime.WebProperty)5 WebComponentDescriptor (com.sun.enterprise.deployment.WebComponentDescriptor)3 Application (com.sun.enterprise.deployment.Application)2 ServiceReferenceDescriptor (com.sun.enterprise.deployment.ServiceReferenceDescriptor)2 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)2 SecurityRoleMapping (com.sun.enterprise.deployment.runtime.common.SecurityRoleMapping)2 IdempotentUrlPattern (com.sun.enterprise.deployment.runtime.web.IdempotentUrlPattern)2 Result (com.sun.enterprise.tools.verifier.Result)2 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)2 CacheMapping (org.glassfish.web.deployment.runtime.CacheMapping)2 ClassLoader (org.glassfish.web.deployment.runtime.ClassLoader)2 JspConfig (org.glassfish.web.deployment.runtime.JspConfig)2 JCDIService (com.sun.enterprise.container.common.spi.JCDIService)1 ResourceEnvReferenceDescriptor (com.sun.enterprise.deployment.ResourceEnvReferenceDescriptor)1 ResourceReferenceDescriptor (com.sun.enterprise.deployment.ResourceReferenceDescriptor)1 XMLElement (com.sun.enterprise.deployment.node.XMLElement)1 EjbRefNode (com.sun.enterprise.deployment.node.runtime.EjbRefNode)1 MessageDestinationRefNode (com.sun.enterprise.deployment.node.runtime.MessageDestinationRefNode)1