Search in sources :

Example 1 with AppListenerDescriptor

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

the class ListenerClass method check.

/**
 * Listener class must implement a no arg constructor.
 *
 * @param descriptor the Web deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(WebBundleDescriptor descriptor) {
    AppListenerDescriptor listener = null;
    Enumeration listenerEnum;
    Result result;
    boolean oneFailed = false;
    Class listenerClass = null;
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    listenerEnum = descriptor.getAppListenerDescriptors().elements();
    if (listenerEnum.hasMoreElements()) {
        result = loadWarFile(descriptor);
        while (listenerEnum.hasMoreElements()) {
            listener = (AppListenerDescriptor) listenerEnum.nextElement();
            if (listener.getListener().equals(smh.getLocalString("JAXRPCContextListener", "com.sun.xml.rpc.server.http.JAXRPCContextListener"))) {
                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.passed(smh.getLocalString(getClass().getName() + ".passed1", "Listener Class Name is [ {0} ], make sure it is available in classpath at runtime.", new Object[] { listener.getListener() }));
                continue;
            }
            if ("".equals(listener.getListener())) {
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.failed(smh.getLocalString(getClass().getName() + ".failed", "Empty or Null String specified for Listener Class Name in [ {0} ].", new Object[] { compName.toString() }));
                oneFailed = true;
                continue;
            }
            listenerClass = loadClass(result, listener.getListener());
            if (!runIndividualListenerTest(result, listenerClass))
                oneFailed = true;
        }
        if (oneFailed) {
            result.setStatus(Result.FAILED);
        } else {
            result.setStatus(Result.PASSED);
        }
    } else {
        result = getInitializedResult();
        result.setStatus(Result.NOT_APPLICABLE);
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.web.ListenerClass" + ".notApplicable", "There are no listener components within the web archive [ {0} ]", new Object[] { descriptor.getName() }));
    }
    return result;
}
Also used : Enumeration(java.util.Enumeration) AppListenerDescriptor(com.sun.enterprise.deployment.web.AppListenerDescriptor) Result(com.sun.enterprise.tools.verifier.Result)

Example 2 with AppListenerDescriptor

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

the class WebListenerHandler method processAnnotation.

private HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, WebBundleDescriptor webBundleDesc) throws AnnotationProcessorException {
    Class listenerClass = (Class) ainfo.getAnnotatedElement();
    if (!(ServletContextListener.class.isAssignableFrom(listenerClass) || ServletContextAttributeListener.class.isAssignableFrom(listenerClass) || ServletRequestListener.class.isAssignableFrom(listenerClass) || ServletRequestAttributeListener.class.isAssignableFrom(listenerClass) || HttpSessionListener.class.isAssignableFrom(listenerClass) || HttpSessionAttributeListener.class.isAssignableFrom(listenerClass) || HttpSessionIdListener.class.isAssignableFrom(listenerClass))) {
        log(Level.SEVERE, ainfo, localStrings.getLocalString("web.deployment.annotation.handlers.needtoimpllistenerinterface", "The Class {0} having annotation javax.servlet.annotation.WebListener need to implement one of the following interfaces: javax.servlet.ServletContextLisener, javax.servlet.ServletContextAttributeListener, javax.servlet.ServletRequestListener, javax.servletServletRequestAttributeListener, javax.servlet.http.HttpSessionListener, javax.servlet.http.HttpSessionAttributeListener, javax.servlet.http.HttpSessionIdListener.", listenerClass.getName()));
        return getDefaultFailedResult();
    }
    WebListener listenerAn = (WebListener) ainfo.getAnnotation();
    AppListenerDescriptor appListener = new AppListenerDescriptorImpl(listenerClass.getName());
    appListener.setDescription(listenerAn.value());
    webBundleDesc.addAppListenerDescriptor(appListener);
    return getDefaultProcessedResult();
}
Also used : HttpSessionListener(javax.servlet.http.HttpSessionListener) WebListener(javax.servlet.annotation.WebListener) ServletRequestListener(javax.servlet.ServletRequestListener) AppListenerDescriptorImpl(org.glassfish.web.deployment.descriptor.AppListenerDescriptorImpl) AppListenerDescriptor(com.sun.enterprise.deployment.web.AppListenerDescriptor) HttpSessionIdListener(javax.servlet.http.HttpSessionIdListener)

Example 3 with AppListenerDescriptor

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

the class WarScanner method scanXmlDefinedClassesIfNecessary.

// This is not mandated by the spec. It is for WSIT.
// We will also scan any servlets/filters/listeners classes specified
// in web.xml additionally if those classes are not resided in the wars.
private void scanXmlDefinedClassesIfNecessary(WebBundleDescriptor webBundleDesc) throws IOException {
    ClassLoader commonCL = clh.getCommonClassLoader();
    for (Iterator webComponents = webBundleDesc.getWebComponentDescriptors().iterator(); webComponents.hasNext(); ) {
        WebComponentDescriptor webCompDesc = (WebComponentDescriptor) webComponents.next();
        if (webCompDesc.isServlet()) {
            String servletName = webCompDesc.getWebComponentImplementation();
            if (isScan(servletName, commonCL)) {
                addScanClassName(servletName);
            }
        }
    }
    Vector servletFilters = webBundleDesc.getServletFilters();
    for (int i = 0; i < servletFilters.size(); i++) {
        ServletFilter filter = (ServletFilter) servletFilters.elementAt(i);
        String filterName = filter.getClassName();
        if (isScan(filterName, commonCL)) {
            addScanClassName(filter.getClassName());
        }
    }
    Vector listeners = webBundleDesc.getAppListenerDescriptors();
    for (int j = 0; j < listeners.size(); j++) {
        AppListenerDescriptor listenerDesc = (AppListenerDescriptor) listeners.elementAt(j);
        String listenerName = listenerDesc.getListener();
        if (isScan(listenerName, commonCL)) {
            addScanClassName(listenerDesc.getListener());
        }
    }
}
Also used : WebComponentDescriptor(com.sun.enterprise.deployment.WebComponentDescriptor) ServletFilter(com.sun.enterprise.deployment.web.ServletFilter) Iterator(java.util.Iterator) AppListenerDescriptor(com.sun.enterprise.deployment.web.AppListenerDescriptor) Vector(java.util.Vector)

Aggregations

AppListenerDescriptor (com.sun.enterprise.deployment.web.AppListenerDescriptor)3 WebComponentDescriptor (com.sun.enterprise.deployment.WebComponentDescriptor)1 ServletFilter (com.sun.enterprise.deployment.web.ServletFilter)1 Result (com.sun.enterprise.tools.verifier.Result)1 Enumeration (java.util.Enumeration)1 Iterator (java.util.Iterator)1 Vector (java.util.Vector)1 ServletRequestListener (javax.servlet.ServletRequestListener)1 WebListener (javax.servlet.annotation.WebListener)1 HttpSessionIdListener (javax.servlet.http.HttpSessionIdListener)1 HttpSessionListener (javax.servlet.http.HttpSessionListener)1 AppListenerDescriptorImpl (org.glassfish.web.deployment.descriptor.AppListenerDescriptorImpl)1