• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openmrs / openmrs-module-webservices.rest / 15888493103

25 Jun 2025 10:27PM UTC coverage: 69.92% (+21.6%) from 48.289%
15888493103

push

github

web-flow
RESTWS-983: Build module against openmrs-core 2.4.x and make it the lowest supported version (#662)

* RESTWS-983 Build module against openmrs-core 2.4.x and make it the lowest supported version

* RESTWS-983 Move omod-2.3 and lower classes to omod-2.4

* RESTWS-983 Fixing tests

16 of 27 new or added lines in 13 files covered. (59.26%)

9 existing lines in 3 files now uncovered.

9835 of 14066 relevant lines covered (69.92%)

0.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.97
/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/DynamicBeanConfiguration.java
1
/**
2
 * This Source Code Form is subject to the terms of the Mozilla Public License,
3
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
4
 * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5
 * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6
 *
7
 * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8
 * graphic logo is a trademark of OpenMRS Inc.
9
 */
10
package org.openmrs.module.webservices.rest.web;
11

12
import java.lang.reflect.Method;
13
import java.util.Arrays;
14
import java.util.List;
15

16
import org.openmrs.api.APIException;
17
import org.openmrs.api.context.Context;
18
import org.openmrs.api.context.ServiceContext;
19
import org.springframework.context.annotation.Bean;
20
import org.springframework.context.annotation.Configuration;
21
import org.springframework.http.converter.HttpMessageConverter;
22
import org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver;
23
import org.springframework.web.servlet.handler.AbstractHandlerMapping;
24

25
/**
26
 * For configuration of beans whose classes are determined at runtime depending on the OpenMRS core
27
 * platform version.
28
 */
29
@Configuration("webservices.rest.dynamicBeanConfiguration")
30
public class DynamicBeanConfiguration {
1✔
31
        
32
        /**
33
         * In spring 3.1.2 MappingJacksonHttpMessageConverter was replaced with
34
         * MappingJackson2HttpMessageConverter and eventually removed in version 4.1.0. This bean
35
         * configuration method allows the module to run on both pre and post 4.1.0 versions of Spring
36
         * by loading the new class if it's available in the spring version that OpenMRS is running on
37
         * otherwise it falls back to the old one.
38
         */
39
        @Bean(name = "jsonHttpMessageConverter")
40
        public HttpMessageConverter<?> getMappingJacksonHttpMessageConverter() throws Exception {
41
                
42
                Class<?> clazz;
43
                try {
44
                        clazz = Context.loadClass("org.springframework.http.converter.json.MappingJackson2HttpMessageConverter");
1✔
45
                }
46
                catch (ClassNotFoundException e) {
×
47
                        clazz = Context.loadClass("org.springframework.http.converter.json.MappingJacksonHttpMessageConverter");
×
48
                }
1✔
49
                
50
                return (HttpMessageConverter<?>) clazz.newInstance();
1✔
51
        }
52
        
53
        /**
54
         * The AnnotationMethodHandlerExceptionResolver class was deprecated and eventually removed in
55
         * Spring 5 The recommended replacement class ExceptionHandlerExceptionResolver was introduced
56
         * in Spring 3.1.0 which is not available on OpenMRS platform versions 1.9.x and 1.10.x which
57
         * run Spring 3.0.5 That's why we can't just statically replace this class in the
58
         * webModuleApplicationContext.xml file.
59
         */
60
        @Bean
61
        public AbstractHandlerExceptionResolver getHandlerExceptionResolver() throws Exception {
62
                
63
                AbstractHandlerExceptionResolver bean = null;
1✔
64
                
65
                HttpMessageConverter<?> stringHttpMessageConverter = Context.getRegisteredComponent(
1✔
66
                            "stringHttpMessageConverter", HttpMessageConverter.class);
67
                
68
                HttpMessageConverter<?> jsonHttpMessageConverter = Context.getRegisteredComponent("jsonHttpMessageConverter",
1✔
69
                            HttpMessageConverter.class);
70
                
71
                HttpMessageConverter<?> xmlMarshallingHttpMessageConverter = Context.getRegisteredComponent(
1✔
72
                            "xmlMarshallingHttpMessageConverter", HttpMessageConverter.class);
73
                
74
                try {
75
                        Class<?> clazz = Context
1✔
UNCOV
76
                                .loadClass("org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver");
×
77
                        
UNCOV
78
                        bean = (AbstractHandlerExceptionResolver) clazz.newInstance();
×
79
                        
UNCOV
80
                        Method method = bean.getClass().getMethod("setMessageConverters", HttpMessageConverter[].class);
×
UNCOV
81
                        method.invoke(bean, new Object[] { new HttpMessageConverter[] { stringHttpMessageConverter,
×
82
                                jsonHttpMessageConverter, xmlMarshallingHttpMessageConverter } });
83
                }
84
                catch (ClassNotFoundException e) {
1✔
85
                        Class<?> clazz = Context
1✔
86
                                .loadClass("org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver");
1✔
87
                        
88
                        bean = (AbstractHandlerExceptionResolver) clazz.newInstance();
1✔
89
                        
90
                        Method method = bean.getClass().getMethod("setMessageConverters", List.class);
1✔
91
                        method.invoke(bean, Arrays.asList(stringHttpMessageConverter,
1✔
92
                                jsonHttpMessageConverter, xmlMarshallingHttpMessageConverter));
UNCOV
93
                }
×
94
                
95
                bean.setOrder(1);
1✔
96
                
97
                return bean;
1✔
98
        }
99
        
100
        /**
101
         * The DefaultAnnotationHandlerMapping class was deprecated and eventually removed in Spring 5
102
         * The recommended replacement class RequestMappingHandlerMapping was introduced in Spring 3.1.0
103
         * which is not available on OpenMRS platform versions 1.9.x and 1.10.x which run Spring 3.0.5
104
         * That's why we can't just statically replace this class in the webModuleApplicationContext.xml
105
         * file.
106
         */
107
        @Bean
108
        public AbstractHandlerMapping getHandlerMapping() throws Exception {
109
                
110
                Class<?> clazz;
111
                try {
112
                        clazz = Context.loadClass("org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping");
1✔
113
                }
114
                catch (ClassNotFoundException e) {
×
115
                        clazz = Context.loadClass("org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping");
×
116
                }
1✔
117
                
118
                return (AbstractHandlerMapping) clazz.newInstance();
1✔
119
        }
120
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc