Search in sources :

Example 1 with WebProperty

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

the class ASCacheHelperClass method check.

public Result check(WebBundleDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    boolean oneFailed = false;
    boolean notApp = false;
    boolean oneWarning = false;
    boolean presentHelper = false;
    try {
        Cache cache = ((SunWebAppImpl) descriptor.getSunDescriptor()).getCache();
        CacheHelper[] helperClasses = null;
        CacheHelper helperClass = null;
        WebProperty[] webProps;
        String name = null;
        String classname = null;
        String[] names = null;
        // to-do vkv# check for class-name attribute.
        if (cache != null)
            helperClasses = cache.getCacheHelper();
        if (cache != null && helperClasses != null && helperClasses.length > 0) {
            names = new String[helperClasses.length];
            for (int rep = 0; rep < helperClasses.length; rep++) {
                helperClass = helperClasses[rep];
                if (helperClass == null)
                    continue;
                int i = rep + 1;
                name = getXPathValue("sun-web-app/cache/cache-helper[" + i + "]/@name");
                classname = getXPathValue("sun-web-app/cache/cache-helper[" + i + "]/@class-name");
                Class hClass = null;
                names[rep] = name;
                if (name != null && name.length() != 0) {
                    // check if the name already exist
                    boolean isDuplicate = false;
                    for (int rep1 = 0; rep1 < rep; rep1++) {
                        if (name.equals(names[rep1])) {
                            isDuplicate = true;
                            break;
                        }
                    }
                    if (isDuplicate) {
                        oneFailed = true;
                        addErrorDetails(result, compName);
                        result.failed(smh.getLocalString(getClass().getName() + ".failed", "FAILED [AS-WEB cache-helper] name attribute [ {0} ], must be unique in the entire list of cache-helper.", new Object[] { name }));
                    } else {
                        if (classname != null && classname.length() != 0) {
                            hClass = loadClass(result, classname);
                        }
                        if (hClass != null)
                            presentHelper = true;
                        else
                            presentHelper = false;
                        if (!presentHelper) {
                            addWarningDetails(result, compName);
                            result.warning(smh.getLocalString(getClass().getName() + ".error", "WARNING [AS-WEB cache-helper] " + "name [ {0} ], class not present in the war file.", new Object[] { name }));
                            oneWarning = true;
                        } else {
                            addGoodDetails(result, compName);
                            result.passed(smh.getLocalString(getClass().getName() + ".passed", "PASSED [AS-WEB cache-helper] name  [ {0} ], helper class is valid.", new Object[] { name }));
                        }
                    }
                } else {
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString(getClass().getName() + ".failed1", "FAILED [AS-WEB cache-helper] name [ {0} ], either empty or null.", new Object[] { name }));
                    oneFailed = true;
                }
                webProps = helperClass.getWebProperty();
                if (ASWebProperty.checkWebProperties(webProps, result, descriptor, this)) {
                    oneFailed = true;
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString(getClass().getName() + ".failed2", "FAILED [AS-WEB cache-helper] Atleast one name/value pair is not valid in helper-class of [ {0} ].", new Object[] { descriptor.getName() }));
                }
            }
        // end of for
        } else {
            notApp = true;
            addNaDetails(result, compName);
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "NOT APPLICABLE [AS-WEB cache-helper] There is no cache-helper element for the web application", 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() + ".failed3", "FAILED [AS-WEB cache-helper] could not create the cache object"));
    }
    return result;
}
Also used : SunWebAppImpl(org.glassfish.web.deployment.runtime.SunWebAppImpl) CacheHelper(org.glassfish.web.deployment.runtime.CacheHelper) WebProperty(org.glassfish.web.deployment.runtime.WebProperty) Result(com.sun.enterprise.tools.verifier.Result) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Cache(org.glassfish.web.deployment.runtime.Cache)

Example 2 with WebProperty

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

the class SessionManagerConfigurationHelper method getPersistenceFrequency.

/**
 * Get the persistence frequency for this web module
 * (this is the value from sun-web.xml if defined
 * @param smBean the session manager config bean
 */
protected String getPersistenceFrequency(SessionManager smBean) {
    String persistenceFrequency = null;
    ManagerProperties mgrBean = smBean.getManagerProperties();
    if ((mgrBean != null) && (mgrBean.sizeWebProperty() > 0)) {
        WebProperty[] props = mgrBean.getWebProperty();
        for (int i = 0; i < props.length; i++) {
            String name = props[i].getAttributeValue(WebProperty.NAME);
            String value = props[i].getAttributeValue(WebProperty.VALUE);
            if (name.equalsIgnoreCase("persistenceFrequency")) {
                persistenceFrequency = value;
            }
        }
    }
    return persistenceFrequency;
}
Also used : ManagerProperties(org.glassfish.web.deployment.runtime.ManagerProperties) WebProperty(org.glassfish.web.deployment.runtime.WebProperty)

Example 3 with WebProperty

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

the class DynamicWebServletRegistrationImpl method configureSession.

/**
 * Configure the properties of the session, such as the timeout,
 * whether to force URL rewriting etc.
 * HERCULES:mod passing in new param wbd
 */
private void configureSession(SessionProperties spBean, WebBundleDescriptor wbd) {
    boolean timeoutConfigured = false;
    // tomcat default (see StandardContext)
    int timeoutSeconds = 1800;
    setCookies(webContainer.instanceEnableCookies);
    if ((spBean != null) && (spBean.sizeWebProperty() > 0)) {
        for (WebProperty prop : spBean.getWebProperty()) {
            String name = prop.getAttributeValue(WebProperty.NAME);
            String value = prop.getAttributeValue(WebProperty.VALUE);
            if (name == null || value == null) {
                throw new IllegalArgumentException(rb.getString(LogFacade.NULL_WEB_MODULE_PROPERTY));
            }
            if ("timeoutSeconds".equalsIgnoreCase(name)) {
                try {
                    timeoutSeconds = Integer.parseInt(value);
                    timeoutConfigured = true;
                } catch (NumberFormatException e) {
                // XXX need error message
                }
            } else if ("enableCookies".equalsIgnoreCase(name)) {
                setCookies(ConfigBeansUtilities.toBoolean(value));
            } else if ("enableURLRewriting".equalsIgnoreCase(name)) {
                setEnableURLRewriting(ConfigBeansUtilities.toBoolean(value));
            } else {
                if (logger.isLoggable(Level.INFO)) {
                    logger.log(Level.INFO, LogFacade.PROP_NOT_YET_SUPPORTED, name);
                }
            }
        }
    }
    int webXmlTimeoutSeconds = -1;
    if (wbd != null) {
        webXmlTimeoutSeconds = wbd.getSessionConfig().getSessionTimeout() * 60;
    }
    // ignore if the value is the 30 min default
    if (webXmlTimeoutSeconds != -1 && webXmlTimeoutSeconds != 1800) {
        getManager().setMaxInactiveIntervalSeconds(webXmlTimeoutSeconds);
    } else {
        /*
             * Do not override Tomcat default, unless 'timeoutSeconds' was
             * specified in sun-web.xml
             */
        if (timeoutConfigured) {
            getManager().setMaxInactiveIntervalSeconds(timeoutSeconds);
        }
    }
}
Also used : WebProperty(org.glassfish.web.deployment.runtime.WebProperty) UserDataConstraint(com.sun.enterprise.deployment.web.UserDataConstraint) SecurityConstraint(com.sun.enterprise.deployment.web.SecurityConstraint) WebServiceEndpoint(com.sun.enterprise.deployment.WebServiceEndpoint)

Example 4 with WebProperty

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

the class DynamicWebServletRegistrationImpl method configureCookieProperties.

/**
 * Configure the settings for the session cookie using the values
 * in sun-web.xml's cookie-property
 */
private void configureCookieProperties(CookieProperties bean) {
    if (bean != null) {
        WebProperty[] props = bean.getWebProperty();
        if (props != null) {
            SessionCookieConfig cookieConfig = new SessionCookieConfig();
            for (WebProperty prop : props) {
                String name = prop.getAttributeValue(WebProperty.NAME);
                String value = prop.getAttributeValue(WebProperty.VALUE);
                if (name == null || value == null) {
                    throw new IllegalArgumentException(rb.getString(LogFacade.NULL_WEB_MODULE_PROPERTY));
                }
                if ("cookieName".equalsIgnoreCase(name)) {
                    cookieConfig.setName(value);
                } else if ("cookiePath".equalsIgnoreCase(name)) {
                    cookieConfig.setPath(value);
                } else if ("cookieMaxAgeSeconds".equalsIgnoreCase(name)) {
                    try {
                        cookieConfig.setMaxAge(Integer.parseInt(value));
                    } catch (NumberFormatException e) {
                    // XXX need error message
                    }
                } else if ("cookieDomain".equalsIgnoreCase(name)) {
                    cookieConfig.setDomain(value);
                } else if ("cookieComment".equalsIgnoreCase(name)) {
                    cookieConfig.setComment(value);
                } else if ("cookieSecure".equalsIgnoreCase(name)) {
                    cookieConfig.setSecure(value);
                } else if ("cookieHttpOnly".equalsIgnoreCase(name)) {
                    cookieConfig.setHttpOnly(Boolean.valueOf(value));
                } else {
                    Object[] params = { name, value };
                    logger.log(Level.WARNING, LogFacade.INVALID_PROPERTY, params);
                }
            }
            if (props.length > 0) {
                if (logger.isLoggable(Level.FINE)) {
                    logger.log(Level.FINE, LogFacade.CONFIGURE_COOKIE_PROPERTIES, new Object[] { getPath(), cookieConfig });
                }
                setSessionCookieConfigFromSunWebXml(cookieConfig);
            }
        }
    }
}
Also used : WebProperty(org.glassfish.web.deployment.runtime.WebProperty) SessionCookieConfig(com.sun.enterprise.web.session.SessionCookieConfig)

Example 5 with WebProperty

use of org.glassfish.web.deployment.runtime.WebProperty 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 javax.faces.jar
    // from the system class path
    Boolean useMyFaces = (Boolean) servletContext.getAttribute("com.sun.faces.useMyFaces");
    if (useMyFaces != null && useMyFaces) {
        sysClassPath = sysClassPath.replace("javax.faces.jar", "$disabled$.raj");
        // jsf-connector.jar manifest has a Class-Path to javax.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)

Aggregations

WebProperty (org.glassfish.web.deployment.runtime.WebProperty)16 SunWebAppImpl (org.glassfish.web.deployment.runtime.SunWebAppImpl)4 XMLElement (com.sun.enterprise.deployment.node.XMLElement)3 Element (org.w3c.dom.Element)3 WebComponentDescriptor (com.sun.enterprise.deployment.WebComponentDescriptor)2 WebServiceEndpoint (com.sun.enterprise.deployment.WebServiceEndpoint)2 SecurityConstraint (com.sun.enterprise.deployment.web.SecurityConstraint)2 UserDataConstraint (com.sun.enterprise.deployment.web.UserDataConstraint)2 Cache (org.glassfish.web.deployment.runtime.Cache)2 JspConfig (org.glassfish.web.deployment.runtime.JspConfig)2 ManagerProperties (org.glassfish.web.deployment.runtime.ManagerProperties)2 JCDIService (com.sun.enterprise.container.common.spi.JCDIService)1 Application (com.sun.enterprise.deployment.Application)1 ServiceReferenceDescriptor (com.sun.enterprise.deployment.ServiceReferenceDescriptor)1 PrincipalNameDescriptor (com.sun.enterprise.deployment.runtime.common.PrincipalNameDescriptor)1 SecurityRoleMapping (com.sun.enterprise.deployment.runtime.common.SecurityRoleMapping)1 IdempotentUrlPattern (com.sun.enterprise.deployment.runtime.web.IdempotentUrlPattern)1 InitializationParameter (com.sun.enterprise.deployment.web.InitializationParameter)1 Result (com.sun.enterprise.tools.verifier.Result)1 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)1