Monday, March 3, 2008

Missing context.xml file

Problem
Tomcat application (with custom db realm authentication) starts up correctly, but fails to show pages. Error in logs says:

Mar 3, 2008 10:28:02 AM org.apache.catalina.authenticator.FormAuthenticator forwardToLoginPage
WARNING: Unexpected error forwarding to login page
org.apache.jasper.JasperException: java.lang.NullPointerException
at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:541)
...
org.apache.catalina.authenticator.FormAuthenticator.forwardToLoginPage(FormAuthenticator.java:316)
at org.apache.catalina.authenticator.FormAuthenticator.authenticate(FormAuthenticator.java:244)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:491)
at
...
Caused by: java.lang.NullPointerException
at org.apache.jsp.login_jsp._jspInit(login_jsp.java:22)
at org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:52)
at
...


Solution
Even though I at first thought this was a problem with conflicting jars, the error was caused by a missing context.xml file, in which a datasource was defined; this datasource was also used by the custom realm and apparently this caused the weird nullPointerException in login.jsp. Putting back our context.xml file solved the problem. An indication of this problem was the line

SEVERE: Null component Catalina:type=DataSource,path=/,host=localhost,class=javax. sql.DataSource,
within the server log; about which the following google search result put me on the right track:
http://www.theserverside.com/news/thread.tss?thread_id=33892

No comments: