views:

179

answers:

1

I need to register a custom ELResolver for a Google App Engine project.

Since it must be registered before any request is received, as specified by the Javadoc:

It is illegal to register an ELResolver after the application has received any request from the client. If an attempt is made to register an ELResolver after that time, an IllegalStateException is thrown.

I'm using a ServletContextListener:

public class RegisterCustomELResolver implements ServletContextListener { 

    @Override 
    public void contextInitialized(ServletContextEvent sce) { 
        ServletContext context = sce.getServletContext(); 
        JspApplicationContext jspContext = 
            JspFactory.getDefaultFactory().getJspApplicationContext(context); 
        jspContext.addELResolver(new MyELResolver()); 
    } 

    ... 
}

The problem is that JspFactory.getDefaultFactory() returns always null. I've alreay filled a bug report. Any idea for a workaround?

+1  A: 

I am not sure which servletcontainer GAE uses "under the hoods" (Jetty? Tomcat?), but this is recognizeable as a bug in Tomcat 6.x. A workaround is to force the loading of JspRuntimeContext yourself before getting the factory:

Class.forName("org.apache.jasper.compiler.JspRuntimeContext");

See if this or similar hack helps.

BalusC
good! Now I'm getting a `java.lang.AbstractMethodError: javax.servlet.jsp.JspFactory.getJspApplicationContext(Ljavax/servlet/ServletContext;)Ljavax/servlet/jsp/JspApplicationContext;` exception. The JSP version is 2.0 wherese `getApplicationContext()` is defined for JSP 2.1. I'm definitively out of luck
dfa
`ELResolver` is JSP 2.1 as well. Is GAE really JSP 2.0? I'd expect it to be JSP 2.1. Is your `web.xml` declared as Servlet 2.5? Example here: http://snipplr.com/view/3775/minimal-webxml-webapp-descriptor-version-25/
BalusC
2.5, of course :)
dfa
I googled a bit and it seems that GAE comes with Servlet 2.5/JSP 2.1 API, but with Servlet2.4/JSP 2.0 impl. http://code.google.com/p/googleappengine/issues/detail?id=1506 Weird :) Hope they get it fixed soon.
BalusC
GAE is really JSP 2.0: http://code.google.com/p/googleappengine/issues/detail?id=1506
dfa
Yes, JSP 2.0 impl.. I said that and I even posted the same link :)
BalusC