k.joseph
(Kaweesi Joseph)
March 29, 2016, 10:03pm
1
Investigated this well but not yet sure why openmrs is failing to set my module’s service: Error message:
http://pastebin.com/HCLUBb2Q
Source-code: https://github.com/rwanda-rbc-emr/openmrs-module-quarterlyreporting
The moduleApplicationContext.xml file here contains this failing bean;
<bean parent="serviceContext">
<property name="moduleService">
<list>
<value>org.openmrs.module.quarterlyreporting.service.QuarterlyReportingService
</value>
<bean
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<bean
class="org.openmrs.module.quarterlyreporting.serviceimpl.QuarterlyReportingServiceImpl">
<property name="quarterlyreportingDAO">
<bean
class="org.openmrs.module.quarterlyreporting.db.daoimpl.QuarterlyReportingDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
</property>
</bean>
</property>
<property name="preInterceptors">
<list>
<ref bean="authorizationInterceptor" />
</list>
</property>
<property name="transactionAttributeSource">
<bean
class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource" />
</property>
</bean>
</list>
</property>
</bean>
k.joseph
(Kaweesi Joseph)
March 29, 2016, 10:06pm
2
This is slightly related to but different from:
Hi,
I’m creating a new module for CSV imports and trying to test it on a static main() method. I’m stuck with an exception. I get org.openmrs.api.APIException: Service not found exception whenever I try Context.getService(CsvImporterService.class);
My moduleApplication-context.xml has this bean, but I still get the following:
log4j:WARN No appenders could be found for logger (org.openmrs.util.OpenmrsUtil).
log4j:WARN Please initialize the log4j system properly.
INFO 4/25/15 1:05 PM:liquibase:…
Seems to result from ClassNotFoundException being caught at:
//pay attention that here, cls = Class.forName(classString), the system class loader and
//cls2 is the openmrs class loader, like above.
log.debug("cls==cls2: "
+ String.valueOf(cls == OpenmrsClassLoader.getInstance().loadClass(classString)));
}
}
catch (Exception e) { /*pass*/}
}
}
catch (ClassNotFoundException e) {
throw new APIException("Unable to set module service: " + classString, e);
}
// add this module service to the normal list of services
setService(cls, classInstance);
//Run onStartup for all services implementing the OpenmrsService interface.
if (OpenmrsService.class.isAssignableFrom(classInstance.getClass())) {
moduleOpenmrsServices.put(classString, (OpenmrsService) classInstance);
runOpenmrsServiceOnStartup((OpenmrsService) classInstance, classString);
}
Doing further investigation
k.joseph
(Kaweesi Joseph)
March 29, 2016, 10:57pm
3
So, after debugging openmrs-core api, i could understand where the issue was, the service set under values tag above contained empty spaces/tabs at its end which caused
throw new APIException("Unable to find classString or classInstance in params");
}
Class cls = null;
// load the given 'classString' class from either the openmrs class
// loader or the system class loader depending on if we're in a testing
// environment or not (system == testing, openmrs == normal)
try {
if (useSystemClassLoader == false) {
cls = OpenmrsClassLoader.getInstance().loadClass(classString);
if (cls != null && log.isDebugEnabled()) {
try {
log.debug("cls classloader: " + cls.getClass().getClassLoader() + " uid: "
+ cls.getClass().getClassLoader().hashCode());
}
catch (Exception e) { /*pass*/}
}
} else if (useSystemClassLoader == true) {
try {
to fail as a class not found issue.
A quick fix in my module is removing all spaces under values tag which means changing.
<value>org.openmrs.module.quarterlyreporting.service.QuarterlyReportingService
</value>
to
<value>org.openmrs.module.quarterlyreporting.service.QuarterlyReportingService</value>
I suggest that openmrs-core fixes this by invoking trim() onto the Service classString at:
if (classString == null || classInstance == null) {
throw new APIException("service.unable.find", (Object[]) null);
}
Class cls = null;
// load the given 'classString' class from either the openmrs class
// loader or the system class loader depending on if we're in a testing
// environment or not (system == testing, openmrs == normal)
try {
if (!useSystemClassLoader) {
cls = OpenmrsClassLoader.getInstance().loadClass(classString);
if (cls != null && log.isDebugEnabled()) {
try {
log.debug("cls classloader: " + cls.getClass().getClassLoader() + " uid: "
+ cls.getClass().getClassLoader().hashCode());
}
catch (Exception e) { /*pass*/}
}
} else if (useSystemClassLoader) {
We can ticket this as an intro task to quickly be worked upon since any mis-added space(s) as in my case currently may help the dev to spend more time investigating such as simple issue
1 Like
k.joseph
(Kaweesi Joseph)
March 31, 2016, 10:01am
4
i leave this for the newbies to file a ticket and work on it
darius
(Darius Jazayeri)
March 31, 2016, 12:51pm
5
I disagree about creating a ticket for this.
There are hundreds or thousands of places in our spring xml files where we specify a <value>
and we don’t trim any of these. Why would we have API support for trimming just one of them?
3 Likes
teleivo
(Ivo Ulrich)
April 19, 2016, 2:09pm
6
thanks @k_joseph you saved me from debugging duty! my hero of the day
I think the formatter should just not format the xml in this way.
2 Likes