Apache Tomcat/7.0.26 fails to run OpenMRS Platform 2.0 with the legacyui module

When you run OpenMRS platform 2.0 on apache tomcat 7.0.26 with the legacyui module installed, OpenMRS fails to run, with the error message below:

org.openmrs.api.APIException: A user context must first be passed to setUserContext()…use Context.openSession() (and closeSession() to prevent memory leaks!) before using the API org.openmrs.api.context.Context.getUserContext(Context.java:236) org.openmrs.api.context.Context.getAuthenticatedUser(Context.java:595) org.openmrs.api.context.Context.isAuthenticated(Context.java:605) org.openmrs.module.web.filter.ForcePasswordChangeFilter.doFilter(ForcePasswordChangeFilter.java:55) note The full stack trace of the root cause is available in the Apache Tomcat/7.0.26 logs.

This is caused by tomcat calling the dynamically registered ForcePasswordChangeFilter before the OpenmrsFilter which is supposed to set the user context.

It took me a while to figure this out because it was not happening locally, and i believe this is a bug in this version of tomcat. The solution was to upgrade to a newer version of tomcat. Am sharing here for the sake of those who may encounter this while trying out platform 2.0

@dkayiwa, for completeness, what version of tomcat did you upgrade to in order to get it working?

-Darius (by phone)

I upgraded to version 7.0.52 Version 7.0.50 which is used in the openmrs standalone also works well.

FWIW, i got that problem on the ubuntu server which runs mdsbuilder. So i confirmed the problem by locally changing this dependency of the OpenMRS standalone https://github.com/openmrs/openmrs-standalone/blob/master/pom.xml#L15 to version 7.0.26 to reproduce the exact problem.