Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: openmrs/openmrs-core
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 74a4cd0a2aa6
Choose a base ref
...
head repository: openmrs/openmrs-core
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: eb901429a01d
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Apr 24, 2013

  1. Fixing memory leaks that happen because of the JspServlet's objects that

    have references to the openmrs class loader: Investigate possible memory
    leak in 1.9.0 or one of its bundled modules. - TRUNK-3440
    dkayiwa committed Apr 24, 2013
    Copy the full SHA
    213a2f9 View commit details
  2. Merge pull request #290 from dkayiwa/TRUNK-3440

    Fixing memory leaks that happen because of the JspServlet's objects that have references to the openmrs class loader: Investigate possible memory leak in 1.9.0 or one of its bundled modules. - TRUNK-3440
    dkayiwa committed Apr 24, 2013
    Copy the full SHA
    eb90142 View commit details
6 changes: 6 additions & 0 deletions web/pom.xml
Original file line number Diff line number Diff line change
@@ -133,6 +133,12 @@
<artifactId>mysql-connector-mxj</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>jasper</artifactId>
<version>6.0.18</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
9 changes: 9 additions & 0 deletions web/src/main/java/org/openmrs/module/web/WebModuleUtil.java
Original file line number Diff line number Diff line change
@@ -58,6 +58,7 @@
import org.openmrs.util.OpenmrsUtil;
import org.openmrs.util.PrivilegeConstants;
import org.openmrs.web.DispatcherServlet;
import org.openmrs.web.OpenmrsJspServlet;
import org.openmrs.web.StaticDispatcherServlet;
import org.openmrs.web.dwr.OpenmrsDWRServlet;
import org.springframework.web.context.support.WebApplicationContextUtils;
@@ -854,9 +855,17 @@ public static XmlWebApplicationContext refreshWAC(ServletContext servletContext,
staticDispatcherServlet.stopAndCloseApplicationContext();
}

if (OpenmrsJspServlet.jspServlet != null) {
OpenmrsJspServlet.jspServlet.stop();
}

XmlWebApplicationContext newAppContext = (XmlWebApplicationContext) ModuleUtil.refreshApplicationContext(wac,
isOpenmrsStartup, startedModule);

if (OpenmrsJspServlet.jspServlet != null) {
OpenmrsJspServlet.jspServlet.refresh();
}

try {
// must "refresh" the spring dispatcherservlet as well to add in
//the new handlerMappings
67 changes: 67 additions & 0 deletions web/src/main/java/org/openmrs/web/OpenmrsJspServlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* The contents of this file are subject to the OpenMRS Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://license.openmrs.org
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
*/
package org.openmrs.web;

import java.lang.reflect.Field;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.jasper.servlet.JspServlet;

/**
* This class is only used to get access to the JspServlet. <br/>
* <br/>
* When Spring's root webApplicationContext is refreshed, this servlet needs to be refreshed too
* because it has references (via the objects it creates like JspRuntimeContext, etc) to the openmrs
* class loader that is being destroyed.
*/
public class OpenmrsJspServlet extends JspServlet {

private static final long serialVersionUID = 1L;

private Log log = LogFactory.getLog(this.getClass());

public static OpenmrsJspServlet jspServlet;

public void init(ServletConfig config) throws ServletException {
super.init(config);

jspServlet = this;
}

public void stop() {
try {
this.destroy();
}
catch (Throwable ex) {
log.error(ex);
}
}

public void refresh() {
try {
//Get a reference to the private ServletConfig config such that we
//can initialize the servlet again.
Field field = this.getClass().getSuperclass().getDeclaredField("config");
field.setAccessible(true);
init((ServletConfig) field.get(this));
}
catch (Throwable ex) {
log.error(ex);
}
}
}
2 changes: 1 addition & 1 deletion webapp/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -375,7 +375,7 @@

<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<servlet-class>org.openmrs.web.OpenmrsJspServlet</servlet-class>
</servlet>

<!-- Gives access to servlets within modules -->