Search in sources :

Example 6 with FilterHolder

use of org.mortbay.jetty.servlet.FilterHolder in project gradle by gradle.

the class JettyConfiguration method parseAnnotations.

public void parseAnnotations() throws Exception {
    String v = System.getProperty("java.version");
    String[] version = v.split("\\.");
    if (version == null) {
        Log.info("Unable to determine jvm version, annotations will not be supported");
        return;
    }
    int major = Integer.parseInt(version[0]);
    int minor = Integer.parseInt(version[1]);
    if ((major >= 1) && (minor >= 5)) {
        //TODO it would be nice to be able to re-use the parseAnnotations() method on
        //the org.mortbay.jetty.annotations.Configuration class, but it's too difficult?
        //able to use annotations on jdk1.5 and above
        Class<?> annotationParserClass = Thread.currentThread().getContextClassLoader().loadClass("org.mortbay.jetty.annotations.AnnotationParser");
        Method parseAnnotationsMethod = annotationParserClass.getMethod("parseAnnotations", WebAppContext.class, Class.class, RunAsCollection.class, InjectionCollection.class, LifeCycleCallbackCollection.class);
        //look thru _servlets
        Iterator itor = LazyList.iterator(_servlets);
        while (itor.hasNext()) {
            ServletHolder holder = (ServletHolder) itor.next();
            //TODO: Some paths within Jetty can acquire persistent file locks on the jars containing these classes.
            Class servlet = getWebAppContext().loadClass(holder.getClassName());
            parseAnnotationsMethod.invoke(null, getWebAppContext(), servlet, _runAsCollection, _injections, _callbacks);
        }
        //look thru _filters
        itor = LazyList.iterator(_filters);
        while (itor.hasNext()) {
            FilterHolder holder = (FilterHolder) itor.next();
            Class filter = getWebAppContext().loadClass(holder.getClassName());
            parseAnnotationsMethod.invoke(null, getWebAppContext(), filter, null, _injections, _callbacks);
        }
        //look thru _listeners
        itor = LazyList.iterator(_listeners);
        while (itor.hasNext()) {
            Object listener = itor.next();
            parseAnnotationsMethod.invoke(null, getWebAppContext(), listener.getClass(), null, _injections, _callbacks);
        }
    } else {
        Log.info("Annotations are not supported on jvms prior to jdk1.5");
    }
}
Also used : FilterHolder(org.mortbay.jetty.servlet.FilterHolder) ServletHolder(org.mortbay.jetty.servlet.ServletHolder) Iterator(java.util.Iterator) Method(java.lang.reflect.Method)

Aggregations

FilterHolder (org.mortbay.jetty.servlet.FilterHolder)6 Server (org.mortbay.jetty.Server)4 ServletHolder (org.mortbay.jetty.servlet.ServletHolder)4 Context (org.mortbay.jetty.servlet.Context)3 ServletHandler (org.mortbay.jetty.servlet.ServletHandler)3 SelectChannelConnector (org.mortbay.jetty.nio.SelectChannelConnector)2 Method (java.lang.reflect.Method)1 Iterator (java.util.Iterator)1 WicketFilter (org.apache.wicket.protocol.http.WicketFilter)1 FilterMapping (org.mortbay.jetty.servlet.FilterMapping)1 ContextLoaderListener (org.springframework.web.context.ContextLoaderListener)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1 RequestContextListener (org.springframework.web.context.request.RequestContextListener)1 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)1