I am trying to access the service , I have added to the serviceContext but it keeps giving error unable to find service.Same code was working earlier suddenly stopped working.
Link to repo GitHub - vishi-chauhan/hims-loginaudit: Login trail of user in OPENMRS
Using it like this LoginAuditService service = Context.getService(LoginAuditService.class);
Found the issue, I was calling the REST service in which servicecontext was used just after starting the server, due to which I believe all dependencies were not not injected.
But, if I open the application in browser and login and move to the admin setting-manage module which will make application to load the module and all dependencies properly than it does not gives me error even once.
But it also requires me to open app and go to manage modules atleast once to make it work properly else will give internal server error no qualified bean found.
Once the dependency injected, everything works fine without any issue.
Build loginaudit module in local system
2.Inject the module dependency in webservice omod 1.9
3.In session controller Autowire the bean
4.Call the method in the get session method
5.Run the tomact
6.Call session service from POSTMAN
If I don’t Autowire the dependency, OPENMRS startup works but when I fetch the service from service context - LoginAuditService service = Context.getService(LoginAuditService.class);
I have to intercept session service call which is used for Authentication so that I can save the entry to the db.Any other way to do this, please suggest.
We are using React as front end which is hosted on different server from OPENMRS.
For user to login/logout, using rest service–> openmrs/ws/rest/v1/session.
We need to keep track of user login and logout in OPENMRS.
To do so created a module auditlogin in which defined service(LoginAuditService) with two methods savelogindetail and savelogoutdetail which are called in get session and delete session respectively.
To access LoginAuditService in webservices module, injected the same in servercontext.
1.Tried Autowire for LoginAuditService which stops OPENMRS from starting with error dependency not found.
2.Tried getting service from context OPENMRS starts up(as Loginservice is fetched inside a method not as class variable) but throws error when getting service is processed at method call.
But now we have another issue.
JSESSIONID does not work bcz browser does not allow to set cookie for other domain(OPENMRS instance is running on different server than front end).So we need to pass user and password with each rest call and it creates login/logout entry for each rest call.
The rest call from your front end to the OpenMRS instance domain will result into a JSESSIONID cookie which you can pass in subsequent rest calls from the front end to the OpenMRS instance domain.