Skip to content

Commit 98e81b6

Browse files
authored
TRUNK-6461: Migrate URL mappings to PathPattern-compatible syntax (#5445)
* TRUNK-6461: Migrate URL mappings to PathPattern-compatible syntax * TRUNK-6461: Remove `order` property from URL mapping configuration
1 parent ceed9a8 commit 98e81b6

File tree

2 files changed

+65
-6
lines changed

2 files changed

+65
-6
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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.web;
11+
12+
import jakarta.servlet.http.HttpServletRequest;
13+
import jakarta.servlet.http.HttpServletResponse;
14+
import org.springframework.web.servlet.ModelAndView;
15+
import org.springframework.web.servlet.mvc.Controller;
16+
17+
public class StaticResourceDispatcher implements Controller {
18+
19+
private Controller jstlContentController;
20+
21+
private Controller staticContentController;
22+
23+
@Override
24+
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
25+
26+
String fullPath = request.getRequestURI();
27+
28+
String ctx = request.getContextPath();
29+
if (ctx != null && !ctx.isEmpty() && fullPath.startsWith(ctx)) {
30+
fullPath = fullPath.substring(ctx.length());
31+
}
32+
33+
String lastSegment;
34+
int slash = fullPath.lastIndexOf('/');
35+
if (slash >= 0) {
36+
lastSegment = fullPath.substring(slash + 1);
37+
} else {
38+
lastSegment = fullPath;
39+
}
40+
41+
if ("openmrsmessages.js".equals(lastSegment) || "drugOrder.js".equals(lastSegment)) {
42+
return jstlContentController.handleRequest(request, response);
43+
}
44+
45+
return staticContentController.handleRequest(request, response);
46+
}
47+
48+
public void setJstlContentController(Controller jstlContentController) {
49+
this.jstlContentController = jstlContentController;
50+
}
51+
52+
public void setStaticContentController(Controller staticContentController) {
53+
this.staticContentController = staticContentController;
54+
}
55+
}

webapp/src/main/webapp/WEB-INF/openmrs_static_content-servlet.xml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,21 @@
2323
<property name="prefix" value="/WEB-INF/view/" />
2424
<property name="suffix" value=""/>
2525
</bean>
26-
26+
2727
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
2828
<property name="mappings">
2929
<props>
30-
<prop key="**/openmrsmessages.js">jstlContentController</prop>
31-
<prop key="**/drugOrder.js">jstlContentController</prop>
32-
<prop key="**/*.js">staticContentController</prop>
33-
<prop key="**/*">staticContentController</prop>
30+
<prop key="/**">staticResourceDispatcher</prop>
3431
</props>
3532
</property>
3633
</bean>
34+
35+
<bean id="staticResourceDispatcher" class="org.openmrs.web.StaticResourceDispatcher">
36+
<property name="staticContentController" ref="staticContentController"/>
37+
<property name="jstlContentController" ref="jstlContentController"/>
38+
</bean>
39+
40+
3741

3842
<util:map id="urlRewrites">
3943
<entry key="/scripts/jquery/jquery-1.3.2.min.js" value="/scripts/jquery/jquery.min.js"/>
@@ -52,4 +56,4 @@
5256
<property name="interpretJstl"><value>true</value></property>
5357
</bean>
5458

55-
</beans>
59+
</beans>

0 commit comments

Comments
 (0)