API Exception after deploying new Legacy UI module

Hey Developers :smiley:

As a part of GSoC 2015, I have been working on moving the Legacy UI to a new module.

Things Done:

  1. I moved the components from openmrs-core that are included in the admin ( from openmrs-core\webapp\src\main\webapp\WEB-INF\view\admin - including concepts, users, index.jsp etc ) to the location here in the new module: openmrs-module-legacyui\api\src\main\java\org\openmrs\module\legacyui\admin
  2. I can perfectly build the module
  3. I can perfectly build the core without the admin folder in the above mention location.
  4. However, there is an API exception that occurs when I deploy the module and click on Admin UI.
An error has occurred!!
The following error has occurred somewhere on this page
org.openmrs.api.Context.APIException: A user context must first be passed to setUserContext()...use Context.openSession() and (closeSession() to prevent memory leaks!) before using the API."

Unable to understand what I have missed on, maybe the controller functionality which needs to be included. But I was trying as a initial step to at least get the UI part if not for working.

This is the tomcat log: http://www.pastebin.ca/3010648

@dkayiwa, @wyclif @raff @darius: Please correct me on any possible mistake that I might have done or guide me on how to proceed :slight_smile:

Open to all suggestions from every developer out here :smiley:

Thank you, Tharunya Pati

Looking at the logs the root cause is because you have no controller and jsp mapped to /openmrs/module/legacyui/index, you might not need the controller but the index.jsp file should be present in your module.


Hey Wyclif,

Yes, I have included the index.jsp already here openmrs-module-legacyui\api\src\main\java\org\openmrs\module\legacyui\admin\index.jsp

I have tried placing it in openmrs-module-legacyui\api\src\main\java\org\openmrs\module\legacyui\index.jsp as well

Will try again and keep you posted :thumbsup: Thank you :slight_smile:

Hi Tharunya,

JSP pages should go under omod/src/main/webapp/… (and not under api/src/main/java)

(a) it’s webapp view code, not java code (b) it’s not part of the underlying API, but the web layer of the module

Here’s an arbitrary example:


Hi Darius,

Oh, yes! Perfect. My bad, I messed that. Sure, will get it right and update my progress! :smile:

Thank you :smiley:

Hey Wyclif and Darius,

Thank you so much :blush: It works perfect now :smiley:

1 Like

Hey all! :smile: @wyclif @dkayiwa @raff @darius CC: @burke

Note: As the post seems too long - The information in {} can be seen only for reference, but has been repeated quite some times so maybe ignored if known already. Included for clear description

Project code I am referring to for openmrs-module-legacyui

In brief, this is all that i have done and also have reported to you before:

1 . Moved the admin folder { from openmrs-webapp/src/main/webapp/WEB-INF/view/admin (Removed all folders and index.jsp existing in admin folder in core except for modules folder) to legacyui-omod/src/main/webapp/admin (You can see all the subfolders of admin such as: concepts,users,hl7 etc) }

2 . In index.jsp, changed the location of the included files { from users/* to admin/users/* Because, I moved index to the webapp instead of keeping it in webapp/admin. }

I am trying for admin/users as for now and hence: recent change + In localheader.jsp for users, changed the context path from /admin/users/ to /module/legacyui/admin/users/

3 . Moved the controllers: { from: openmrs-web/src/main/java/org/openmrs/web/controller/user to: legacyui-omod/src/main/java/org/openmrs/web/controller/user/

RoleListController has a problem: Question posted on OpenMRS ask here }

4 . webModuleApplicationContext.xml {

  • Added beans for RoleFormController as it doesn’t have @RequestMapping
  • Added prop keys for the respective jsp’s }

5 . **pom.*recent change Added scope for api as “provided”

I get an API Exception like before: Error LOG is here

The jsps and the controllers are in place I suppose. However, should I place the controllers right here in this way??

As there are packages like org.openmrs.module.legacyui.web.controller but I placed under org.openmrs.web.controller

The error message says no mapping found for ‘/openmrs/module/legacyui/admin/users/users.l ist’, are you sure you registered a url mapping for it? Because looking at your webApplicationContext.xml file i don’t see its mapping

Oops, Sorry.

There is no mapping required for UserListController since there is a requestmapping on the controller, I didnt quite understand where to include the module path for this controller as @darius suggested changing the RequestMapping isnt a good idea.

Do you suggest that I should look into any other way to map the users.jsp form to the UserListController? However, in core it works fine without the mapping, with just the @RequestMapping and the return value.

Coming to the other view: UserFormController gives the exact same error like above after giving a return value like here : https://github.com/Tharunya/openmrs-module-legacyui/blob/contextpath/omod/src/main/java/org/openmrs/web/controller/user/UserFormController.java#L120

Then the URL you are entering in the browser is incorrrect, you need to enter /openmrs/admin/users/users.list for it to work because that is what is defined in the UserListController

1 Like