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

openmrs / openmrs-core / 43293528472

12 Nov 2026 05:19PM UTC coverage: 66.969% (+0.2%) from 66.721%
43293528472

push

github

ibacher
Validate module ids and contain module paths (#6813)

38 of 42 new or added lines in 4 files covered. (90.48%)

391 existing lines in 8 files now uncovered.

26387 of 39402 relevant lines covered (66.97%)

0.67 hits per line

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

45.9
/web/src/main/java/org/openmrs/module/web/WebModuleUtil.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.web;
11

12
import javax.servlet.Filter;
13
import javax.servlet.ServletConfig;
14
import javax.servlet.ServletContext;
15
import javax.servlet.ServletException;
16
import javax.servlet.ServletRequest;
17
import javax.servlet.http.HttpServlet;
18
import javax.servlet.http.HttpServletRequest;
19
import javax.xml.parsers.DocumentBuilder;
20
import javax.xml.parsers.DocumentBuilderFactory;
21
import javax.xml.parsers.ParserConfigurationException;
22
import javax.xml.transform.Transformer;
23
import javax.xml.transform.TransformerException;
24
import javax.xml.transform.TransformerFactory;
25
import javax.xml.transform.dom.DOMSource;
26
import javax.xml.transform.stream.StreamResult;
27
import java.io.File;
28
import java.io.FileInputStream;
29
import java.io.FileNotFoundException;
30
import java.io.FileOutputStream;
31
import java.io.IOException;
32
import java.io.InputStream;
33
import java.io.OutputStream;
34
import java.io.StringReader;
35
import java.util.ArrayDeque;
36
import java.util.ArrayList;
37
import java.util.Collection;
38
import java.util.Deque;
39
import java.util.Enumeration;
40
import java.util.HashMap;
41
import java.util.Iterator;
42
import java.util.LinkedHashMap;
43
import java.util.List;
44
import java.util.Map;
45
import java.util.Properties;
46
import java.util.concurrent.locks.Lock;
47
import java.util.concurrent.locks.ReentrantLock;
48
import java.util.jar.JarEntry;
49
import java.util.jar.JarFile;
50
import java.util.regex.Pattern;
51

52
import org.openmrs.api.APIException;
53
import org.openmrs.api.context.Context;
54
import org.openmrs.module.Module;
55
import org.openmrs.module.ModuleException;
56
import org.openmrs.module.ModuleFactory;
57
import org.openmrs.module.ModuleUtil;
58
import org.openmrs.module.web.filter.ModuleFilterConfig;
59
import org.openmrs.module.web.filter.ModuleFilterDefinition;
60
import org.openmrs.module.web.filter.ModuleFilterMapping;
61
import org.openmrs.scheduler.SchedulerException;
62
import org.openmrs.scheduler.SchedulerService;
63
import org.openmrs.scheduler.TaskDefinition;
64
import org.openmrs.util.OpenmrsUtil;
65
import org.openmrs.util.PrivilegeConstants;
66
import org.openmrs.web.DispatcherServlet;
67
import org.openmrs.web.StaticDispatcherServlet;
68
import org.slf4j.Logger;
69
import org.slf4j.LoggerFactory;
70
import org.springframework.web.context.support.WebApplicationContextUtils;
71
import org.springframework.web.context.support.XmlWebApplicationContext;
72
import org.w3c.dom.Document;
73
import org.w3c.dom.Element;
74
import org.w3c.dom.NamedNodeMap;
75
import org.w3c.dom.Node;
76
import org.w3c.dom.NodeList;
77
import org.xml.sax.InputSource;
78

79
import static org.openmrs.util.XmlUtils.createDocumentBuilder;
80

81
public class WebModuleUtil {
82

83
        private WebModuleUtil() {
84
        }
85
        
86
        private static final Logger log = LoggerFactory.getLogger(WebModuleUtil.class);
1 ✔
87
        
88
        private static final Lock SERVLET_LOCK = new ReentrantLock();
1 ✔
89
        
90
        private static final Lock FILTERS_LOCK = new ReentrantLock();
1 ✔
91
        
92
        // caches all modules' mapped servlets
93
        private static final Map<String, HttpServlet> MODULE_SERVLETS = new HashMap<>();
1 ✔
94
        
95
        // caches all modules filters and filter-mappings
96
        private static final Map<Module, Collection<Filter>> MODULE_FILTERS = new HashMap<>();
1 ✔
97
        
98
        private static final Map<String, Filter> MODULE_FILTERS_BY_NAME = new HashMap<>();
1 ✔
99
        
100
        private static final Deque<ModuleFilterMapping> MODULE_FILTER_MAPPINGS = new ArrayDeque<>();
1 ✔
101
        
102
        private static DispatcherServlet dispatcherServlet = null;
1 ✔
103
        
104
        private static StaticDispatcherServlet staticDispatcherServlet = null;
1 ✔
105
        
106
        /**
107
         * Performs the webapp specific startup needs for modules Normal startup is done in
108
         * {@link ModuleFactory#startModule(Module)} If delayContextRefresh is true, the spring context
109
         * is not rerun. This will save a lot of time, but it also means that the calling method is
110
         * responsible for restarting the context if necessary (the calling method will also have to
111
         * call {@link #loadServlets(Module, ServletContext)} and
112
         * {@link #loadFilters(Module, ServletContext)}).<br>
113
         * <br>
114
         * If delayContextRefresh is true and this module should have caused a context refresh, a true
115
         * value is returned. Otherwise, false is returned
116
         *
117
         * @param mod Module to start
118
         * @param servletContext the current ServletContext
119
         * @param delayContextRefresh true/false whether or not to do the context refresh
120
         * @return boolean whether or not the spring context need to be refreshed
121
         */
122
        public static boolean startModule(Module mod, ServletContext servletContext, boolean delayContextRefresh) {
123
                
124
                log.debug("Trying to start module {}", mod);
1 ✔
125
                
126
                // only try and start this module if the api started it without a
127
                // problem.
128
                if (ModuleFactory.isModuleStarted(mod) && !mod.hasStartupError()) {
1 ✔
129
                        
130
                        String realPath = getRealPath(servletContext);
1 ✔
131
                        
132
                        if (realPath == null) {
1 ✔
133
                                realPath = System.getProperty("user.dir");
1 ✔
134
                        }
135
                        
136
                        File webInf = new File(realPath + "/WEB-INF".replace("/", File.separator));
1 ✔
137
                        if (!webInf.exists()) {
1 ✔
138
                                webInf.mkdir();
1 ✔
139
                        }
140
                        
141
                        // flag to tell whether we added any xml/dwr/etc changes that necessitate a refresh
142
                        // of the web application context
143
                        boolean moduleNeedsContextRefresh = false;
1 ✔
144
                        
145
                        // copy the html files into the webapp (from /web/module/ in the module)
146
                        // also looks for a spring context file. If found, schedules spring to be restarted
147
                        JarFile jarFile = null;
1 ✔
148
                        OutputStream outStream = null;
1 ✔
149
                        InputStream inStream = null;
1 ✔
150
                        try {
151
                                File modFile = mod.getFile();
1 ✔
152
                                jarFile = new JarFile(modFile);
1 ✔
153
                                Enumeration<JarEntry> entries = jarFile.entries();
1 ✔
154
                                
155
                                while (entries.hasMoreElements()) {
1 ✔
156
                                        JarEntry entry = entries.nextElement();
1 ✔
157
                                        String name = entry.getName();
1 ✔
158
                                        log.debug("Entry name: {}", name);
1 ✔
159
                                        if (name.startsWith("web/module/")) {
1 ✔
160
                                                // trim out the starting path of "web/module/"
161
                                                String filepath = name.substring(11);
1 ✔
162

163
                                                File baseDir;
164

165
                                                // If this is within the tag file directory, copy it into /WEB-INF/tags/module/moduleId/...
166
                                                if (filepath.startsWith("tags/")) {
1 ✔
UNCOV
167
                                                        filepath = filepath.substring(5);
×
NEW
168
                                                        baseDir = new File(webInf, "tags/module".replace("/", File.separator));
×
169
                                                }
170
                                                // Otherwise, copy it into /WEB-INF/view/module/moduleId/...
171
                                                else {
172
                                                        baseDir = new File(webInf, "view/module".replace("/", File.separator));
1 ✔
173
                                                }
174
                                                
175
                                                // if a module id has a . in it, we should treat that as a /, i.e. files in the module
176
                                                // ui.springmvc should go in folder names like .../ui/springmvc/...
177
                                                File moduleDir = ModuleUtil.resolveWithinDirectory(baseDir,
1 ✔
178
                                                    mod.getModuleIdAsPath().replace("/", File.separator));
1 ✔
179
                                                log.debug("Moving file from: {} to {}/{}", name, moduleDir, filepath);
1 ✔
180

181
                                                // get the output file
182
                                                File outFile = filepath.isEmpty() ? moduleDir
1 ✔
183
                                                        : ModuleUtil.resolveWithinDirectory(moduleDir, filepath.replace("/", File.separator));
1 ✔
184
                                                if (entry.isDirectory()) {
1 ✔
185
                                                        if (!outFile.exists()) {
1 ✔
186
                                                                outFile.mkdirs();
1 ✔
187
                                                        }
188
                                                } else {
189
                                                        // make the parent directories in case it doesn't exist
190
                                                        File parentDir = outFile.getParentFile();
×
UNCOV
191
                                                        if (!parentDir.exists()) {
×
UNCOV
192
                                                                parentDir.mkdirs();
×
193
                                                        }
194
                                                        
195
                                                        // copy the contents over to the webapp for non directories
196
                                                        outStream = new FileOutputStream(outFile, false);
×
UNCOV
197
                                                        inStream = jarFile.getInputStream(entry);
×
198
                                                        OpenmrsUtil.copyFile(inStream, outStream);
×
199
                                                }
200
                                        } else if ("moduleApplicationContext.xml".equals(name) || "webModuleApplicationContext.xml".equals(name)) {
1 ✔
201
                                                moduleNeedsContextRefresh = true;
×
UNCOV
202
                                        } else if (name.equals(mod.getModuleId() + "Context.xml")) {
×
203
                                                String msg = "DEPRECATED: '" + name
×
204
                                                        + "' should be named 'moduleApplicationContext.xml' now. Please update/upgrade. ";
205
                                                throw new ModuleException(msg, mod.getModuleId());
×
206
                                        }
207
                                }
1 ✔
208
                        }
209
                        catch (IOException io) {
1 ✔
210
                                log.warn("Unable to copy files from module " + mod.getModuleId() + " to the web layer", io);
1 ✔
211
                        }
212
                        finally {
213
                                if (jarFile != null) {
1 ✔
214
                                        try {
215
                                                jarFile.close();
1 ✔
216
                                        }
217
                                        catch (IOException io) {
×
UNCOV
218
                                                log.warn("Couldn't close jar file: " + jarFile.getName(), io);
×
219
                                        }
1 ✔
220
                                }
221
                                if (inStream != null) {
1 ✔
222
                                        try {
223
                                                inStream.close();
×
224
                                        }
225
                                        catch (IOException io) {
×
UNCOV
226
                                                log.warn("Couldn't close InputStream: " + io);
×
UNCOV
227
                                        }
×
228
                                }
229
                                if (outStream != null) {
1 ✔
230
                                        try {
231
                                                outStream.close();
×
232
                                        }
233
                                        catch (IOException io) {
×
UNCOV
234
                                                log.warn("Couldn't close OutputStream: " + io);
×
UNCOV
235
                                        }
×
236
                                }
237
                        }
238
                        
239
                        // find and add the dwr code to the dwr-modules.xml file (if defined)
240
                        InputStream inputStream = null;
1 ✔
241
                        try {
242
                                Document config = mod.getConfig();
1 ✔
243
                                Element root = config.getDocumentElement();
1 ✔
244
                                if (root.getElementsByTagName("dwr").getLength() > 0) {
1 ✔
245
                                        
246
                                        // get the dwr-module.xml file that we're appending our code to
247
                                        File f = new File(realPath + "/WEB-INF/dwr-modules.xml".replace("/", File.separator));
1 ✔
248
                                        
249
                                        // testing if file exists
250
                                        if (!f.exists()) {
1 ✔
251
                                                // if it does not -> needs to be created
252
                                                createDwrModulesXml(realPath);
1 ✔
253
                                        }
254
                                        
255
                                        inputStream = new FileInputStream(f);
1 ✔
256
                                        Document dwrmodulexml = getDWRModuleXML(inputStream, realPath);
1 ✔
257
                                        Element outputRoot = dwrmodulexml.getDocumentElement();
1 ✔
258
                                        
259
                                        // loop over all of the children of the "dwr" tag
260
                                        Node node = root.getElementsByTagName("dwr").item(0);
1 ✔
261
                                        Node current = node.getFirstChild();
1 ✔
262
                                        
263
                                        while (current != null) {
1 ✔
264
                                                if ("allow".equals(current.getNodeName()) || "signatures".equals(current.getNodeName())
1 ✔
265
                                                        || "init".equals(current.getNodeName())) {
1 ✔
266
                                                        ((Element) current).setAttribute("moduleId", mod.getModuleId());
1 ✔
267
                                                        outputRoot.appendChild(dwrmodulexml.importNode(current, true));
1 ✔
268
                                                }
269
                                                
270
                                                current = current.getNextSibling();
1 ✔
271
                                        }
272
                                        
273
                                        moduleNeedsContextRefresh = true;
1 ✔
274
                                        
275
                                        // save the dwr-modules.xml file.
276
                                        OpenmrsUtil.saveDocument(dwrmodulexml, f);
1 ✔
277
                                }
278
                        }
UNCOV
279
                        catch (FileNotFoundException e) {
×
UNCOV
280
                                throw new ModuleException(realPath + "/WEB-INF/dwr-modules.xml file doesn't exist.", e);
×
281
                        }
282
                        finally {
283
                                if (inputStream != null) {
1 ✔
284
                                        try {
285
                                                inputStream.close();
1 ✔
286
                                        }
UNCOV
287
                                        catch (IOException io) {
×
UNCOV
288
                                                log.error("Error while closing input stream", io);
×
289
                                        }
1 ✔
290
                                }
291
                        }
292
                        
293
                        // mark to delete the entire module web directory on exit
294
                        // this will usually only be used when an improper shutdown has occurred.
295
                        File outFile = getModuleWebFolder(realPath, mod.getModuleIdAsPath());
1 ✔
296
                        outFile.deleteOnExit();
1 ✔
297
                        
298
                        // additional checks on module needing a context refresh
299
                        if (!moduleNeedsContextRefresh && mod.getAdvicePoints() != null && !mod.getAdvicePoints().isEmpty()) {
1 ✔
300
                                
301
                                // AOP advice points are only loaded during the context refresh now.
302
                                // if the context hasn't been marked to be refreshed yet, mark it
303
                                // now if this module defines some advice
UNCOV
304
                                moduleNeedsContextRefresh = true;
×
305
                                
306
                        }
307
                        
308
                        // refresh the spring web context to get the just-created xml
309
                        // files into it (if we copied an xml file)
310
                        if (moduleNeedsContextRefresh && !delayContextRefresh) {
1 ✔
UNCOV
311
                                log.debug("Refreshing context for module {}", mod.getModuleId());
×
312
                                
313
                                try {
UNCOV
314
                                        refreshWAC(servletContext, false, mod);
×
315
                                        log.debug("Done refreshing context for module {}", mod.getModuleId());
×
316
                                }
317
                                catch (Exception e) {
×
UNCOV
318
                                        String msg = "Unable to refresh the WebApplicationContext";
×
319
                                        mod.setStartupErrorMessage(msg, e);
×
320
                                        
UNCOV
321
                                        if (log.isWarnEnabled()) {
×
UNCOV
322
                                                log.warn(msg + " for module: " + mod.getModuleId(), e);
×
323
                                        }
324
                                        
325
                                        try {
UNCOV
326
                                                stopModule(mod, servletContext, true);
×
327
                                                ModuleFactory.stopModule(mod, true, true); //remove jar from classloader play
×
328
                                        }
329
                                        catch (Exception e2) {
×
330
                                                // exception expected with most modules here
UNCOV
331
                                                if (log.isWarnEnabled()) {
×
332
                                                        log.warn("Error while stopping a module that had an error on refreshWAC", e2);
×
333
                                                }
UNCOV
334
                                        }
×
335
                                        
336
                                        // try starting the application context again
337
                                        log.debug("Refreshing context for module {} (re-trying)", mod.getModuleId());
×
UNCOV
338
                                        refreshWAC(servletContext, false, mod);
×
339
                                        log.debug("Done refreshing context for module {} (re-trying)", mod.getModuleId());
×
340
                                        
UNCOV
341
                                        notifySuperUsersAboutModuleFailure(mod);
×
UNCOV
342
                                }
×
343
                                
344
                        }
345
                        
346
                        if (!delayContextRefresh && ModuleFactory.isModuleStarted(mod)) {
1 ✔
347
                                // only loading the servlets/filters if spring is refreshed because one
348
                                // might depend on files being available in spring
349
                                // if the caller wanted to delay the refresh then they are responsible for
350
                                // calling these two methods on the module
351
                                
352
                                // find and cache the module's servlets
353
                                //(only if the module started successfully previously)
354
                                log.debug("Loading servlets and filters for module {}", mod);
×
355
                                servletContext.setAttribute(OpenmrsJspServlet.OPENMRS_TLD_SCAN_NEEDED, true);
×
UNCOV
356
                                loadServlets(mod, servletContext);
×
UNCOV
357
                                loadFilters(mod, servletContext);
×
358
                        }
359
                        
360
                        // return true if the module needs a context refresh and we didn't do it here
361
                        return (moduleNeedsContextRefresh && delayContextRefresh);
1 ✔
362
                        
363
                }
364
                
365
                // we aren't processing this module, so a context refresh is not necessary
UNCOV
366
                return false;
×
367
        }
368
        
369
        /** Stops all tasks started by given module
370
         * @param mod
371
         */
372
        private static void stopTasks(Module mod) {
373
                SchedulerService schedulerService;
374
                try {
375
                        schedulerService = Context.getSchedulerService();
1 ✔
376
                } catch (NullPointerException | APIException e) {
×
377
                        // if we got here, the scheduler has already been shut down, so there's no work to do
UNCOV
378
                        return;
×
379
                }
1 ✔
380
                
381
                String modulePackageName = mod.getPackageName();
1 ✔
382
                for (TaskDefinition task : schedulerService.getRegisteredTasks()) {
1 ✔
383
                        
UNCOV
384
                        String taskClass = task.getTaskClass();
×
385
                        if (isModulePackageNameInTaskClass(modulePackageName, taskClass)) {
×
386
                                try {
387
                                        schedulerService.shutdownTask(task);
×
388
                                }
389
                                catch (SchedulerException e) {
×
UNCOV
390
                                        log.error("Couldn't stop task:" + task + " for module: " + mod);
×
391
                                }
×
392
                        }
UNCOV
393
                }
×
394
        }
1 ✔
395
        
396
        /**
397
         * Checks if module package name is in task class name
398
         * @param modulePackageName the package name of module
399
         * @param taskClass the class of given task
400
         * @return true if task and module are in the same package
401
         * <strong>Should</strong> return false for different package names
402
         * <strong>Should</strong> return false if module has longer package name
403
         * <strong>Should</strong> properly match subpackages
404
         * <strong>Should</strong> return false for empty package names
405
         */
406
        public static boolean isModulePackageNameInTaskClass(String modulePackageName, String taskClass) {
407
                return modulePackageName.length() <= taskClass.length()
1 ✔
408
                        && taskClass.matches(Pattern.quote(modulePackageName) + "(\\..*)+");
1 ✔
409
        }
410
        
411
        /**
412
         * Send an Alert to all super users that the given module did not start successfully.
413
         *
414
         * @param mod The Module that failed
415
         */
416
        private static void notifySuperUsersAboutModuleFailure(Module mod) {
417
                try {
418
                        // Add the privileges necessary for notifySuperUsers
UNCOV
419
                        Context.addProxyPrivilege(PrivilegeConstants.MANAGE_ALERTS);
×
UNCOV
420
                        Context.addProxyPrivilege(PrivilegeConstants.GET_USERS);
×
421
                        
422
                        // Send an alert to all administrators
UNCOV
423
                        Context.getAlertService().notifySuperUsers("Module.startupError.notification.message", null, mod.getName());
×
424
                }
425
                finally {
426
                        // Remove added privileges
UNCOV
427
                        Context.removeProxyPrivilege(PrivilegeConstants.GET_USERS);
×
428
                        Context.removeProxyPrivilege(PrivilegeConstants.MANAGE_ALERTS);
×
429
                }
UNCOV
430
        }
×
431
        
432
        /**
433
         * This method will find and cache this module's servlets (so that it doesn't have to look them
434
         * up every time)
435
         *
436
         * @param mod
437
         * @param servletContext the servlet context
438
         */
439
        public static void loadServlets(Module mod, ServletContext servletContext) {
440
                Element rootNode = mod.getConfig().getDocumentElement();
1 ✔
441
                NodeList servletTags = rootNode.getElementsByTagName("servlet");
1 ✔
442
                
443
                for (int i = 0; i < servletTags.getLength(); i++) {
1 ✔
444
                        Node node = servletTags.item(i);
1 ✔
445
                        NodeList childNodes = node.getChildNodes();
1 ✔
446
                        String name = "", className = "";
1 ✔
447

448
                        Map<String, String> initParams = new HashMap<>();
1 ✔
449
                        for (int j = 0; j < childNodes.getLength(); j++) {
1 ✔
450
                                Node childNode = childNodes.item(j);
1 ✔
451
                                if ("servlet-name".equals(childNode.getNodeName())) {
1 ✔
452
                                        if (childNode.getTextContent() != null) {
1 ✔
453
                                                name = childNode.getTextContent().trim();
1 ✔
454
                                        }
455
                                } else if ("servlet-class".equals(childNode.getNodeName()) && childNode.getTextContent() != null) {
1 ✔
456
                                        className = childNode.getTextContent().trim();
1 ✔
457
                                } else if ("init-param".equals(childNode.getNodeName())) {
1 ✔
458
                                        NodeList initParamChildren = childNode.getChildNodes();
1 ✔
459
                                        String paramName = null, paramValue = null;
1 ✔
460
                                        for (int k = 0; k < initParamChildren.getLength(); k++) {
1 ✔
461
                                                Node initParamChild = initParamChildren.item(k);
1 ✔
462
                                                if ("param-name".equals(initParamChild.getNodeName()) && initParamChild.getTextContent() != null) {
1 ✔
463
                                                        paramName = initParamChild.getTextContent().trim();
1 ✔
464
                                                } else if ("param-value".equals(initParamChild.getNodeName()) && initParamChild.getTextContent() != null) {
1 ✔
465
                                                        paramValue = initParamChild.getTextContent().trim();
1 ✔
466
                                                }
467
                                        }
468

469
                                        if (paramName != null && paramValue != null) {
1 ✔
470
                                                initParams.put(paramName, paramValue);
1 ✔
471
                                        }
472
                                }
473
                        }
474
                        if (name.length() == 0 || className.length() == 0) {
1 ✔
475
                                log.warn("both 'servlet-name' and 'servlet-class' are required for the 'servlet' tag. Given '" + name
×
UNCOV
476
                                        + "' and '" + className + "' for module " + mod.getName());
×
UNCOV
477
                                continue;
×
478
                        }
479
                        
480
                        HttpServlet httpServlet;
481
                        try {
482
                                httpServlet = (HttpServlet) ModuleFactory.getModuleClassLoader(mod).loadClass(className).newInstance();
1 ✔
483
                        }
484
                        catch (ClassCastException e) {
×
UNCOV
485
                                log.warn("Class {} from module {} is not a valid HttpServlet", className, mod, e);
×
486
                                continue;
×
487
                        }
488
                        catch (ClassNotFoundException e) {
×
UNCOV
489
                                log.warn("Class {} not found for servlet {} from module {}", className, name, mod, e);
×
490
                                continue;
×
491
                        }
492
                        catch (IllegalAccessException e) {
×
UNCOV
493
                                log.warn("Class {} cannot be accessed for servlet {} from module {}", className, name, mod, e);
×
494
                                continue;
×
495
                        }
496
                        catch (InstantiationException e) {
×
UNCOV
497
                                log.warn("Class {} cannot be instantiated for servlet {} from module {}", className, name, mod, e);
×
UNCOV
498
                                continue;
×
499
                        }
1 ✔
500
                        
501
                        try {
502
                                log.debug("Initializing {} servlet. - {}.", name, httpServlet);
1 ✔
503
                                ServletConfig servletConfig = new ModuleServlet.SimpleServletConfig(name, servletContext, initParams);
1 ✔
504
                                httpServlet.init(servletConfig);
1 ✔
505
                        }
506
                        catch (Exception e) {
×
UNCOV
507
                                log.warn("Unable to initialize servlet {}", name, e);
×
UNCOV
508
                                throw new ModuleException("Unable to initialize servlet " + name, mod.getModuleId(), e);
×
509
                        }
1 ✔
510
                        
511
                        // don't allow modules to overwrite servlets of other modules.
512
                        HttpServlet otherServletUsingSameName = MODULE_SERVLETS.get(name);
1 ✔
513
                        if (otherServletUsingSameName != null) {
1 ✔
UNCOV
514
                                String otherServletName = otherServletUsingSameName.getClass().getName();
×
UNCOV
515
                                throw new ModuleException("A servlet mapping with name " + name + " is already in use and pointing at: "
×
516
                                        + otherServletName + " from another installed module and this module is trying"
517
                                        + " to use that same name.  Either the module attempting to be installed (" + mod
518
                                        + ") will not work or the other one will not.  Please consult the developers of these two"
519
                                        + " modules to sort this out.");
520
                        }
521
                        
522
                        log.debug("Caching the {} servlet.", name);
1 ✔
523
                        
524
                        SERVLET_LOCK.lock();
1 ✔
525
                        try {
526
                                MODULE_SERVLETS.put(name, httpServlet);
1 ✔
527
                        } finally {
528
                                SERVLET_LOCK.unlock();
1 ✔
529
                        }
530
                }
531
        }
1 ✔
532
        
533
        /**
534
         * Remove the servlets defined for this module
535
         *
536
         * @param mod the module that is being stopped that needs its servlets removed
537
         */
538
        public static void unloadServlets(Module mod) {
539
                Element rootNode = mod.getConfig().getDocumentElement();
1 ✔
540
                NodeList servletTags = rootNode.getElementsByTagName("servlet");
1 ✔
541
                
542
                for (int i = 0; i < servletTags.getLength(); i++) {
1 ✔
543
                        Node node = servletTags.item(i);
1 ✔
544
                        NodeList childNodes = node.getChildNodes();
1 ✔
545
                        String name;
546
                        for (int j = 0; j < childNodes.getLength(); j++) {
1 ✔
547
                                Node childNode = childNodes.item(j);
1 ✔
548
                                if ("servlet-name".equals(childNode.getNodeName()) && childNode.getTextContent() != null) {
1 ✔
549
                                        name = childNode.getTextContent().trim();
1 ✔
550
                                        
551
                                        HttpServlet servlet;
552
                                        SERVLET_LOCK.lock();
1 ✔
553
                                        try {
554
                                                servlet = MODULE_SERVLETS.get(name);
1 ✔
555
                                        } finally {
556
                                                SERVLET_LOCK.unlock();
1 ✔
557
                                        }
558
                                        
559
                                        if (servlet != null) {
1 ✔
560
                                                // shut down the servlet
561
                                                servlet.destroy();
1 ✔
562
                                        }
563
                                        
564
                                        SERVLET_LOCK.lock();
1 ✔
565
                                        try {
566
                                                MODULE_SERVLETS.remove(name);
1 ✔
567
                                        } finally {
568
                                                SERVLET_LOCK.unlock();
1 ✔
569
                                        }
570
                                }
571
                        }
572
                }
573
        }
1 ✔
574
        
575
        /**
576
         * This method will initialize and store this module's filters
577
         *
578
         * @param module - The Module to load and register Filters
579
         * @param servletContext - The servletContext within which this method is called
580
         */
581
        public static void loadFilters(Module module, ServletContext servletContext) {
582
                
583
                // Load Filters
UNCOV
584
                Map<String, Filter> filters = new LinkedHashMap<>();
×
585
                
586
                Map<String, Filter> existingFilters;
587
                FILTERS_LOCK.lock();
×
588
                try {
589
                        existingFilters = new HashMap<>(MODULE_FILTERS_BY_NAME);
×
590
                } finally {
UNCOV
591
                        FILTERS_LOCK.unlock();
×
592
                }
593
                
594
                for (ModuleFilterDefinition def : ModuleFilterDefinition.retrieveFilterDefinitions(module)) {
×
UNCOV
595
                        String name = def.getFilterName();
×
596
                        String className = def.getFilterClass();
×
597
                        
598
                        if (existingFilters.containsKey(name)) {
×
UNCOV
599
                                throw new ModuleException("A filter with the name " + name + " is already in use and pointing at: "
×
UNCOV
600
                                        + existingFilters.get(name).getClass().getName()
×
601
                                        + " from another installed module and this module is trying"
602
                                        + " to use that same name.  Either the module attempting to be installed (" + module
603
                                        + ") will not work or the other one will not.  Please consult the developers of these two"
604
                                        + " modules to sort this out.");
605
                        }
606
                        
UNCOV
607
                        ModuleFilterConfig config = ModuleFilterConfig.getInstance(def, servletContext);
×
608
                        
609
                        Filter filter;
610
                        try {
611
                                filter = (Filter) ModuleFactory.getModuleClassLoader(module).loadClass(className).newInstance();
×
612
                        }
613
                        catch (ClassCastException e) {
×
UNCOV
614
                                log.warn("Class {} from module {} is not a valid Filter", className, module, e);
×
615
                                continue;
×
616
                        }
617
                        catch (ClassNotFoundException e) {
×
UNCOV
618
                                log.warn("Class {} not found for servlet {} from module {}", className, name, module, e);
×
619
                                continue;
×
620
                        }
621
                        catch (IllegalAccessException e) {
×
UNCOV
622
                                log.warn("Class {} cannot be accessed for servlet {} from module {}", className, name, module, e);
×
623
                                continue;
×
624
                        }
625
                        catch (InstantiationException e) {
×
626
                                log.warn("Class {} cannot be instantiated for servlet {} from module {}", className, name, module, e);
×
UNCOV
627
                                continue;
×
UNCOV
628
                        }
×
629
                        
630
                        try {
UNCOV
631
                                log.debug("Initializing {} filter. - {}.", name, filter);
×
632
                                filter.init(config);
×
633
                        }
634
                        catch (Exception e) {
×
635
                                log.warn("Unable to initialize servlet {}", name, e);
×
UNCOV
636
                                throw new ModuleException("Unable to initialize servlet " + name, module.getModuleId(), e);
×
637
                        }
×
638
                        
UNCOV
639
                        filters.put(name, filter);
×
640
                }
×
641

642
                FILTERS_LOCK.lock();
×
643
                try {
644
                        MODULE_FILTERS.put(module, filters.values());
×
UNCOV
645
                        MODULE_FILTERS_BY_NAME.putAll(filters);
×
UNCOV
646
                        log.debug("Module {} successfully loaded {} filters.", module, filters.size());
×
647
                        
648
                        // Load Filter Mappings
UNCOV
649
                        Deque<ModuleFilterMapping> modMappings = ModuleFilterMapping.retrieveFilterMappings(module);
×
650
                        
651
                        // IMPORTANT: Filter load order
652
                        // retrieveFilterMappings will return the list of filters in the order they occur in the config.xml file
653
                        // here we add them to the *front* of the filter mappings
654
                        modMappings.descendingIterator().forEachRemaining(MODULE_FILTER_MAPPINGS::addFirst);
×
655
                        
656
                        log.debug("Module {} successfully loaded {} filter mappings.", module, modMappings.size());
×
657
                } finally {
658
                        FILTERS_LOCK.unlock();
×
659
                }
UNCOV
660
        }
×
661
        
662
        /**
663
         * This method will destroy and remove all filters that were registered by the passed
664
         * {@link Module}
665
         *
666
         * @param module - The Module for which you want to remove and destroy filters.
667
         */
668
        public static void unloadFilters(Module module) {
669
                
670
                // Unload Filter Mappings
671
                for (Iterator<ModuleFilterMapping> mapIter = MODULE_FILTER_MAPPINGS.iterator(); mapIter.hasNext();) {
1 ✔
672
                        ModuleFilterMapping mapping = mapIter.next();
×
673
                        if (module.equals(mapping.getModule())) {
×
UNCOV
674
                                mapIter.remove();
×
675
                                log.debug("Removed ModuleFilterMapping: " + mapping);
×
676
                        }
UNCOV
677
                }
×
678
                
679
                // unload Filters
680
                Collection<Filter> filters = MODULE_FILTERS.get(module);
1 ✔
681
                if (filters != null) {
1 ✔
682
                        try {
683
                                for (Filter f : filters) {
×
UNCOV
684
                                        f.destroy();
×
685
                                }
×
686
                        }
687
                        catch (Exception e) {
×
UNCOV
688
                                log.warn("An error occurred while trying to destroy and remove module Filter.", e);
×
689
                        }
×
690
                        
UNCOV
691
                        log.debug("Module: " + module.getModuleId() + " successfully unloaded " + filters.size() + " filters.");
×
692
                        MODULE_FILTERS.remove(module);
×
693

694
                        MODULE_FILTERS_BY_NAME.values().removeIf(filters::contains);
×
695
                }
696
        }
1 ✔
697
        
698
        /**
699
         * This method will return all Filters that have been registered a module
700
         *
701
         * @return A Collection of {@link Filter}s that have been registered by a module
702
         */
703
        public static Collection<Filter> getFilters() {
UNCOV
704
                return MODULE_FILTERS_BY_NAME.values();
×
705
        }
706
        
707
        /**
708
         * This method will return all Filter Mappings that have been registered by a module
709
         *
710
         * @return A Collection of all {@link ModuleFilterMapping}s that have been registered by a
711
         *         Module
712
         */
713
        public static Collection<ModuleFilterMapping> getFilterMappings() {
UNCOV
714
                return new ArrayList<>(MODULE_FILTER_MAPPINGS);
×
715
        }
716
        
717
        /**
718
         * Return List of Filters that have been loaded through Modules that have mappings that pass for
719
         * the passed request
720
         *
721
         * @param request - The request to check for matching {@link Filter}s
722
         * @return List of all {@link Filter}s that have filter mappings that match the passed request
723
         */
724
        public static List<Filter> getFiltersForRequest(ServletRequest request) {
725
                
726
                List<Filter> filters = new ArrayList<>();
×
727
                if (request != null) {
×
UNCOV
728
                        HttpServletRequest httpRequest = (HttpServletRequest) request;
×
729
                        String requestPath = httpRequest.getRequestURI();
×
730
                        
731
                        if (requestPath != null) {
×
UNCOV
732
                                if (requestPath.startsWith(httpRequest.getContextPath())) {
×
733
                                        requestPath = requestPath.substring(httpRequest.getContextPath().length());
×
734
                                }
735
                                for (ModuleFilterMapping filterMapping : WebModuleUtil.getFilterMappings()) {
×
736
                                        if (ModuleFilterMapping.filterMappingPasses(filterMapping, requestPath)) {
×
737
                                                Filter passedFilter = MODULE_FILTERS_BY_NAME.get(filterMapping.getFilterName());
×
UNCOV
738
                                                if (passedFilter != null) {
×
739
                                                        filters.add(passedFilter);
×
740
                                                } else {
UNCOV
741
                                                        log.warn("Unable to retrieve filter that has a name of " + filterMapping.getFilterName()
×
742
                                                                + " in filter mapping.");
743
                                                }
744
                                        }
UNCOV
745
                                }
×
746
                        }
747
                }
UNCOV
748
                return filters;
×
749
        }
750
        
751
        /**
752
         * @param inputStream
753
         * @param realPath
754
         * @return
755
         */
756
        private static Document getDWRModuleXML(InputStream inputStream, String realPath) {
757
                Document dwrmodulexml;
758
                try {
759
                        DocumentBuilder db = createDocumentBuilder();
1 ✔
760
                        dwrmodulexml = db.parse(inputStream);
1 ✔
761
                }
UNCOV
762
                catch (Exception e) {
×
UNCOV
763
                        throw new ModuleException("Error parsing dwr-modules.xml file", e);
×
764
                }
1 ✔
765
                
766
                return dwrmodulexml;
1 ✔
767
        }
768
        
769
        /**
770
         * Reverses all activities done by startModule(org.openmrs.module.Module) Normal stop/shutdown
771
         * is done by ModuleFactory
772
         */
773
        public static void shutdownModules(ServletContext servletContext) {
774
                
UNCOV
775
                String realPath = getRealPath(servletContext);
×
776
                
777
                // clear the module messages
778
                String messagesPath = realPath + "/WEB-INF/";
×
UNCOV
779
                File folder = new File(messagesPath.replace("/", File.separator));
×
780
                
781
                File[] files = folder.listFiles();
×
782
                if (folder.exists() && files != null) {
×
UNCOV
783
                        Properties emptyProperties = new Properties();
×
784
                        for (File f : files) {
×
785
                                if (f.getName().startsWith("module_messages")) {
×
786
                                        OpenmrsUtil.storeProperties(emptyProperties, f, "");
×
787
                                }
788
                        }
789
                }
790
                
791
                // call web shutdown for each module
UNCOV
792
                for (Module mod : ModuleFactory.getLoadedModules()) {
×
UNCOV
793
                        stopModule(mod, servletContext, true);
×
UNCOV
794
                }
×
795
                
796
        }
×
797
        
798
        /**
799
         * Reverses all visible activities done by startModule(org.openmrs.module.Module)
800
         *
801
         * @param mod
802
         * @param servletContext
803
         */
804
        public static void stopModule(Module mod, ServletContext servletContext) {
UNCOV
805
                stopModule(mod, servletContext, false);
×
UNCOV
806
        }
×
807
        
808
        /**
809
         * Reverses all visible activities done by startModule(org.openmrs.module.Module)
810
         *
811
         * @param mod
812
         * @param servletContext
813
         * @param skipRefresh
814
         */
815
        public static void stopModule(Module mod, ServletContext servletContext, boolean skipRefresh) {
816
                
817
                String moduleId = mod.getModuleId();
1 ✔
818
                String modulePackage = mod.getPackageName();
1 ✔
819
                
820
                // stop all dependent modules
821
                for (Module dependentModule : ModuleFactory.getStartedModules()) {
1 ✔
UNCOV
822
                        if (!dependentModule.equals(mod) && dependentModule.getRequiredModules().contains(modulePackage)) {
×
UNCOV
823
                                stopModule(dependentModule, servletContext, skipRefresh);
×
824
                        }
825
                }
×
826
                
827
                String realPath = getRealPath(servletContext);
1 ✔
828

829
                // (not) deleting module message properties
830
                
831
                // remove the module's servlets
832
                unloadServlets(mod);
1 ✔
833
                
834
                // remove the module's filters and filter mappings
835
                unloadFilters(mod);
1 ✔
836
                
837
                // stop all tasks associated with mod
838
                stopTasks(mod);
1 ✔
839
                
840
                // remove this module's entries in the dwr xml file
841
                InputStream inputStream = null;
1 ✔
842
                try {
843
                        Document config = mod.getConfig();
1 ✔
844
                        Element root = config.getDocumentElement();
1 ✔
845
                        // if they defined any xml element
846
                        if (root.getElementsByTagName("dwr").getLength() > 0) {
1 ✔
847
                                
848
                                // get the dwr-module.xml file that we're appending our code to
849
                                File f = new File(realPath + "/WEB-INF/dwr-modules.xml".replace("/", File.separator));
×
850
                                
851
                                // testing if file exists
852
                                if (!f.exists()) {
×
853
                                        // if it does not -> needs to be created
UNCOV
854
                                        createDwrModulesXml(realPath);
×
855
                                }
856
                                
857
                                inputStream = new FileInputStream(f);
×
UNCOV
858
                                Document dwrmodulexml = getDWRModuleXML(inputStream, realPath);
×
UNCOV
859
                                Element outputRoot = dwrmodulexml.getDocumentElement();
×
860
                                
861
                                // loop over all of the children of the "dwr" tag
862
                                // and remove all "allow" and "signature" tags that have the
863
                                // same moduleId attr as the module being stopped
UNCOV
864
                                NodeList nodeList = outputRoot.getChildNodes();
×
UNCOV
865
                                int i = 0;
×
UNCOV
866
                                while (i < nodeList.getLength()) {
×
867
                                        Node current = nodeList.item(i);
×
868
                                        if ("allow".equals(current.getNodeName()) || "signatures".equals(current.getNodeName())) {
×
869
                                                NamedNodeMap attrs = current.getAttributes();
×
870
                                                Node attr = attrs.getNamedItem("moduleId");
×
871
                                                if (attr != null && moduleId.equals(attr.getNodeValue())) {
×
872
                                                        outputRoot.removeChild(current);
×
873
                                                } else {
874
                                                        i++;
×
875
                                                }
UNCOV
876
                                        } else {
×
877
                                                i++;
×
878
                                        }
879
                                }
×
880
                                
881
                                // save the dwr-modules.xml file.
882
                                OpenmrsUtil.saveDocument(dwrmodulexml, f);
×
883
                        }
884
                }
885
                catch (FileNotFoundException e) {
×
UNCOV
886
                        throw new ModuleException(realPath + "/WEB-INF/dwr-modules.xml file doesn't exist.", e);
×
887
                }
888
                finally {
889
                        if (inputStream != null) {
1 ✔
890
                                try {
UNCOV
891
                                        inputStream.close();
×
892
                                }
UNCOV
893
                                catch (IOException io) {
×
894
                                        log.error("Error while closing input stream", io);
×
UNCOV
895
                                }
×
896
                        }
897
                }
898

899
                // delete the web files from the webapp
900
                File moduleWebFolder = getModuleWebFolder(realPath, moduleId);
1 ✔
901
                if (moduleWebFolder.exists()) {
1 ✔
902
                        try {
903
                                OpenmrsUtil.deleteDirectory(moduleWebFolder);
1 ✔
NEW
904
                        } catch (IOException io) {
×
NEW
905
                                log.warn("Couldn't delete: " + moduleWebFolder.getAbsolutePath(), io);
×
906
                        }
1 ✔
907
                }
908

909
                if (!skipRefresh) {
1 ✔
UNCOV
910
                        refreshWAC(servletContext, false, null);
×
911
                }
912
                
913
        }
1 ✔
914
        
915
        /**
916
         * Stops, closes, and refreshes the Spring context for the given <code>servletContext</code>
917
         *
918
         * @param servletContext
919
         * @param isOpenmrsStartup if this refresh is being done at application startup
920
         * @param startedModule the module that was just started and waiting on the context refresh
921
         * @return The newly refreshed webApplicationContext
922
         */
923
        public static XmlWebApplicationContext refreshWAC(ServletContext servletContext, boolean isOpenmrsStartup,
924
                Module startedModule) {
UNCOV
925
                XmlWebApplicationContext wac = (XmlWebApplicationContext) WebApplicationContextUtils
×
UNCOV
926
                        .getWebApplicationContext(servletContext);
×
UNCOV
927
                log.debug("Refreshing Web Application Context of class: {}", wac.getClass().getName());
×
928
                
929
                if (dispatcherServlet != null) {
×
930
                        dispatcherServlet.stopAndCloseApplicationContext();
×
931
                }
932
                
933
                if (staticDispatcherServlet != null) {
×
UNCOV
934
                        staticDispatcherServlet.stopAndCloseApplicationContext();
×
935
                }
936
                
937
                XmlWebApplicationContext newAppContext = (XmlWebApplicationContext) ModuleUtil.refreshApplicationContext(wac,
×
938
                    isOpenmrsStartup, startedModule);
939
                
940
                try {
941
                        // must "refresh" the spring dispatcherservlet as well to add in
942
                        //the new handlerMappings
UNCOV
943
                        if (dispatcherServlet != null) {
×
UNCOV
944
                                dispatcherServlet.reInitFrameworkServlet();
×
945
                        }
946
                        
947
                        if (staticDispatcherServlet != null) {
×
UNCOV
948
                                staticDispatcherServlet.refreshApplicationContext();
×
949
                        }
950
                }
951
                catch (ServletException se) {
×
UNCOV
952
                        log.warn("Caught a servlet exception while refreshing the dispatcher servlet", se);
×
UNCOV
953
                }
×
954
                
955
                return newAppContext;
×
956
        }
957
        
958
        /**
959
         * Save the dispatcher servlet for use later (reinitializing things)
960
         *
961
         * @param ds
962
         */
963
        public static void setDispatcherServlet(DispatcherServlet ds) {
964
                log.debug("Setting dispatcher servlet: " + ds);
1 ✔
965
                dispatcherServlet = ds;
1 ✔
966
        }
1 ✔
967
        
968
        /**
969
         * Save the static content dispatcher servlet for use later when refreshing spring
970
         *
971
         * @param ds
972
         */
973
        public static void setStaticDispatcherServlet(StaticDispatcherServlet ds) {
UNCOV
974
                log.debug("Setting dispatcher servlet for static content: " + ds);
×
UNCOV
975
                staticDispatcherServlet = ds;
×
UNCOV
976
        }
×
977
        
978
        /**
979
         * Finds the servlet defined by the servlet name
980
         *
981
         * @param servletName the name of the servlet out of the path
982
         * @return the current servlet or null if none defined
983
         */
984
        public static HttpServlet getServlet(String servletName) {
985
                return MODULE_SERVLETS.get(servletName);
1 ✔
986
        }
987
        
988
        /**
989
         * Retrieves a path to a folder that stores web files of a module. <br>
990
         * (path-to-openmrs/WEB-INF/view/module/moduleid)
991
         *
992
         * @param moduleId module id (e.g., "basicmodule")
993
         * @return a path to a folder that stores web files or null if not in a web environment
994
         * <strong>Should</strong> return the correct module folder
995
         * <strong>Should</strong> return null if the dispatcher servlet is not yet set
996
         * <strong>Should</strong> return the correct module folder if real path has a trailing slash
997
         */
998
        public static String getModuleWebFolder(String moduleId) {
999
                if (dispatcherServlet == null) {
1 ✔
1000
                        throw new ModuleException("Dispatcher servlet must be present in the web environment");
1 ✔
1001
                }
1002
                
1003
                String moduleFolder = "WEB-INF/view/module/";
1 ✔
1004
                String realPath = dispatcherServlet.getServletContext().getRealPath("");
1 ✔
1005
                String moduleWebFolder;
1006
                
1007
                //RealPath may contain '/' on Windows when running tests with the mocked servlet context
1008
                if (realPath.endsWith(File.separator) || realPath.endsWith("/")) {
1 ✔
1009
                        moduleWebFolder = realPath + moduleFolder;
1 ✔
1010
                } else {
1011
                        moduleWebFolder = realPath + "/" + moduleFolder;
1 ✔
1012
                }
1013
                
1014
                moduleWebFolder += moduleId;
1 ✔
1015
                
1016
                return moduleWebFolder.replace("/", File.separator);
1 ✔
1017
        }
1018
        
1019
        public static void createDwrModulesXml(String realPath) {
1020
                try {
1021
                        DocumentBuilder docBuilder = createDocumentBuilder();
1 ✔
1022
                        
1023
                        // root elements
1024
                        Document doc = docBuilder.newDocument();
1 ✔
1025
                        Element rootElement = doc.createElement("dwr");
1 ✔
1026
                        doc.appendChild(rootElement);
1 ✔
1027
                        
1028
                        // write the content into xml file
1029
                        TransformerFactory transformerFactory = TransformerFactory.newInstance();
1 ✔
1030
                        Transformer transformer = transformerFactory.newTransformer();
1 ✔
1031
                        DOMSource source = new DOMSource(doc);
1 ✔
1032
                        StreamResult result = new StreamResult(new File(realPath
1 ✔
1033
                                + "/WEB-INF/dwr-modules.xml".replace("/", File.separator)));
1 ✔
1034
                        
1035
                        transformer.transform(source, result);
1 ✔
1036
                        
1037
                }
UNCOV
1038
                catch (APIException pce) {
×
UNCOV
1039
                        log.error("Failed to parse document", pce);
×
1040
                }
UNCOV
1041
                catch (TransformerException tfe) {
×
UNCOV
1042
                        log.error("Failed to transorm xml source", tfe);
×
1043
                }
1 ✔
1044
        }
1 ✔
1045

1046
        public static String getRealPath(ServletContext servletContext) {
1047
                return servletContext.getRealPath("");
1 ✔
1048
        }
1049

1050
        /**
1051
         * Resolves the web folder of a module (path-to-openmrs/WEB-INF/view/module/moduleIdAsPath) and
1052
         * verifies that it stays inside the module web folder.
1053
         *
1054
         * @param realPath the real path of the web application
1055
         * @param moduleIdAsPath the module id, or the module id with dots replaced by slashes
1056
         * @return the module's web folder
1057
         * @throws ModuleException if the module id escapes the module web folder
1058
         */
1059
        private static File getModuleWebFolder(String realPath, String moduleIdAsPath) {
1060
                File moduleFolder = new File(realPath, "WEB-INF/view/module".replace("/", File.separator));
1 ✔
1061
                return ModuleUtil.resolveWithinDirectory(moduleFolder, moduleIdAsPath.replace("/", File.separator));
1 ✔
1062
        }
1063

1064
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc