Skip to content

Commit

Permalink
#2783 Fixed the application closing process:
Browse files Browse the repository at this point in the history
- fixed close log4j2: removed old version 2.15.0, added: log4j-web-2.16.0.jar, disabled auto initialized and manual initialize: Log4jServletContextListener, log4jServletFilter; (web.xml, lib)
- fixed close DataSource: volatile dataSourceFound (BasePooledAccess.java), moved mysql-connector-java-5.1.49.jar from WebContent\WEB_INF\lib to tomcat\lib and corrected dockerfile, changing the import of a particular implementation (com.mysql.jdbc.Statement) to an interface (java.sql.Statement) in classes: ScheduledExecuteInactiveEventDAOimpl.java, MailingListDAO.java, ReportDAO.java, ReportInstanceDAO.java, ReportInstanceDataDAO.java, ReportInstancePointDAO.java, DataPointDAO.java, DataSourceDAO.java, FlexProjectDAO.java, MaintenanceEventDAO.java, PointEventDetectorDAO.java, PointLinkDAO.java, PublisherDAO.java, ScheduledEventDAO.java, UserCommentDAO.java, OnlyMigrationDataPointDAO.java, OnlyMigrationDataSourceDAO.java, OnlyMigrationUserCommentDAO.java;
- fixed unregistered jdbc driver: added initialize DriverManager, added method: DatabaseAccessUtils.unregisterDriver, using in BasePooledAccess.terminate;
- fixed close Quartz Scheduler: added sleep 1000 [ms];
  • Loading branch information
Limraj committed Mar 4, 2024
1 parent 34177e5 commit 8248acf
Show file tree
Hide file tree
Showing 29 changed files with 71 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#Create an Scada-LTS.war file and deploy it into Docker Tomcat Image.
FROM tomcat:9.0.53
LABEL maintainer="[email protected]"
COPY WebContent/WEB-INF/lib/mysql-connector-java-5.1.49.jar /usr/local/tomcat/lib/mysql-connector-java-5.1.49.jar
COPY tomcat/lib/mysql-connector-java-5.1.49.jar /usr/local/tomcat/lib/mysql-connector-java-5.1.49.jar
COPY tomcat/lib/activation.jar /usr/local/tomcat/lib/activation.jar
COPY tomcat/lib/jaxb-api-2.4.0-b180830.0359.jar /usr/local/tomcat/lib/jaxb-api-2.4.0-b180830.0359.jar
COPY tomcat/lib/jaxb-core-3.0.2.jar /usr/local/tomcat/lib/jaxb-core-3.0.2.jar
Expand Down
Binary file removed WebContent/WEB-INF/lib/log4j-1.2-api-2.15.0.jar
Binary file not shown.
Binary file removed WebContent/WEB-INF/lib/log4j-api-2.15.0.jar
Binary file not shown.
Binary file removed WebContent/WEB-INF/lib/log4j-core-2.15.0.jar
Binary file not shown.
Binary file added WebContent/WEB-INF/lib/log4j-web-2.16.0.jar
Binary file not shown.
24 changes: 24 additions & 0 deletions WebContent/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,30 @@
<param-name>com.serotonin.web.taglib.ListSortTag.downImage.altKey</param-name>
<param-value>pagination.descending</param-value>
</context-param>

<!-- Log4j2 -->
<context-param>
<param-name>isLog4jAutoInitializationDisabled</param-name>
<param-value>true</param-value>
</context-param>
<listener>
<listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class>
</listener>
<filter>
<filter-name>log4jServletFilter</filter-name>
<filter-class>org.apache.logging.log4j.web.Log4jServletFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>log4jServletFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
<dispatcher>ASYNC</dispatcher>
</filter-mapping>
<!-- END Log4j2 -->

<!-- secure javamelody -->
<login-config>
<auth-method>DIGEST</auth-method>
Expand Down
10 changes: 7 additions & 3 deletions src/com/serotonin/mango/db/BasePooledAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -37,6 +38,7 @@
import com.serotonin.mango.Common;

import static com.serotonin.mango.db.DatabaseAccessUtils.closeDataSource;
import static com.serotonin.mango.db.DatabaseAccessUtils.unregisterDriver;

/**
* @author Matthew Lohbihler
Expand All @@ -45,7 +47,7 @@ abstract public class BasePooledAccess extends DatabaseAccess
{
private final static Log log = LogFactory.getLog(BasePooledAccess.class);
protected DataSource dataSource;
protected boolean dataSourceFound = false;
private volatile boolean dataSourceFound;


@SuppressWarnings("deprecation")
Expand All @@ -63,6 +65,7 @@ protected void initializeImpl(String propertyPrefix, String dataSourceName)
try (Connection conn = dataSource.getConnection()) {
log.info("DataSource meta: " + conn.getMetaData().getDatabaseProductName() + " " + conn.getMetaData().getDatabaseProductVersion());
dataSourceFound = true;
DriverManager.getDrivers();
}
}
catch(NamingException e)
Expand Down Expand Up @@ -165,11 +168,12 @@ public void terminate()
if(dataSourceFound) {
closeDataSource(dataSource);
}
unregisterDriver();
log.info("Stopped database");
}
catch(SQLException e)
catch(Throwable e)
{
log.warn(e.getMessage(), e);
log.error(e.getMessage(), e);
}
}

Expand Down
18 changes: 18 additions & 0 deletions src/com/serotonin/mango/db/DatabaseAccessUtils.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.serotonin.mango.db;

import java.sql.Driver;
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.sql.DataSource;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;

public class DatabaseAccessUtils {

Expand All @@ -20,4 +23,19 @@ public static void closeDataSource(DataSource dataSource) throws SQLException {
else
dataSource.getConnection().close();
}

public static void unregisterDriver() {
Enumeration<Driver> drivers = DriverManager.getDrivers();
while (drivers.hasMoreElements()) {
Driver driver = drivers.nextElement();
if(driver != null) {
try {
DriverManager.deregisterDriver(driver);
LOG.info(String.format("Unregistered jdbc driver: %s", driver.getClass().getName()));
} catch (SQLException e) {
LOG.info(String.format("Error unregister jdbc driver: %s, msg: %s", driver.getClass().getName(), e.getMessage()));
}
}
}
}
}
6 changes: 1 addition & 5 deletions src/org/scada_lts/dao/DataPointDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
*/
package org.scada_lts.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -40,7 +37,6 @@
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.mysql.jdbc.Statement;
import com.serotonin.mango.rt.event.type.EventType;
import com.serotonin.mango.vo.DataPointVO;

Expand Down
2 changes: 1 addition & 1 deletion src/org/scada_lts/dao/DataSourceDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package org.scada_lts.dao;

import com.mysql.jdbc.Statement;

import com.serotonin.mango.rt.event.type.EventType;
import com.serotonin.mango.view.ShareUser;
import com.serotonin.mango.vo.User;
Expand Down
2 changes: 1 addition & 1 deletion src/org/scada_lts/dao/FlexProjectDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.mysql.jdbc.Statement;
import java.sql.Statement;

/*
* (c) 2016 Abil'I.T. http://abilit.eu/
Expand Down
2 changes: 1 addition & 1 deletion src/org/scada_lts/dao/MaintenanceEventDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.mysql.jdbc.Statement;
import java.sql.Statement;
import com.serotonin.mango.rt.event.type.EventType;
import com.serotonin.mango.vo.event.MaintenanceEventVO;

Expand Down
2 changes: 1 addition & 1 deletion src/org/scada_lts/dao/PointEventDetectorDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.mysql.jdbc.Statement;
import java.sql.Statement;
import com.serotonin.mango.rt.event.type.EventType;
import com.serotonin.mango.vo.DataPointVO;
import com.serotonin.mango.vo.event.PointEventDetectorVO;
Expand Down
2 changes: 1 addition & 1 deletion src/org/scada_lts/dao/PointLinkDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package org.scada_lts.dao;

import com.mysql.jdbc.Statement;
import java.sql.Statement;
import com.serotonin.mango.vo.link.PointLinkVO;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down
2 changes: 1 addition & 1 deletion src/org/scada_lts/dao/PublisherDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package org.scada_lts.dao;

import com.mysql.jdbc.Statement;
import java.sql.Statement;
import com.serotonin.mango.rt.event.type.EventType;
import com.serotonin.mango.vo.publish.PublishedPointVO;
import com.serotonin.mango.vo.publish.PublisherVO;
Expand Down
2 changes: 1 addition & 1 deletion src/org/scada_lts/dao/ScheduledEventDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
*/

import com.mysql.jdbc.Statement;
import java.sql.Statement;
import com.serotonin.mango.rt.event.type.EventType;
import com.serotonin.mango.vo.event.ScheduledEventVO;
import org.apache.commons.logging.Log;
Expand Down
2 changes: 1 addition & 1 deletion src/org/scada_lts/dao/UserCommentDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package org.scada_lts.dao;

import com.mysql.jdbc.Statement;
import java.sql.Statement;
import com.serotonin.mango.rt.event.EventInstance;
import com.serotonin.mango.vo.DataPointVO;
import com.serotonin.mango.vo.UserComment;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.scada_lts.dao.event;

import com.mysql.jdbc.Statement;
import java.sql.Statement;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.scada_lts.dao.DAO;
Expand Down
2 changes: 1 addition & 1 deletion src/org/scada_lts/dao/mailingList/MailingListDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package org.scada_lts.dao.mailingList;

import com.mysql.jdbc.Statement;
import java.sql.Statement;
import com.serotonin.mango.vo.mailingList.MailingList;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down
2 changes: 1 addition & 1 deletion src/org/scada_lts/dao/report/ReportDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package org.scada_lts.dao.report;

import com.mysql.jdbc.Statement;
import java.sql.Statement;
import com.serotonin.mango.Common;
import com.serotonin.mango.vo.report.ReportVO;
import org.apache.commons.logging.Log;
Expand Down
2 changes: 1 addition & 1 deletion src/org/scada_lts/dao/report/ReportInstanceDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.mysql.jdbc.Statement;
import java.sql.Statement;
import com.serotonin.mango.rt.event.EventInstance;
import com.serotonin.mango.vo.report.ReportInstance;

Expand Down
2 changes: 1 addition & 1 deletion src/org/scada_lts/dao/report/ReportInstanceDataDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package org.scada_lts.dao.report;

import com.mysql.jdbc.Statement;
import java.sql.Statement;
import com.serotonin.mango.DataTypes;
import com.serotonin.mango.rt.dataImage.types.*;
import com.serotonin.mango.vo.report.ReportDataStreamHandler;
Expand Down
2 changes: 1 addition & 1 deletion src/org/scada_lts/dao/report/ReportInstancePointDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package org.scada_lts.dao.report;

import com.mysql.jdbc.Statement;
import java.sql.Statement;
import com.serotonin.mango.DataTypes;
import com.serotonin.mango.rt.dataImage.types.MangoValue;
import com.serotonin.mango.view.text.TextRenderer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package org.scada_lts.permissions.migration.dao;

import com.mysql.jdbc.Statement;
import java.sql.Statement;
import com.serotonin.mango.rt.event.type.EventType;
import com.serotonin.mango.vo.DataPointVO;
import org.apache.commons.logging.Log;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package org.scada_lts.permissions.migration.dao;

import com.mysql.jdbc.Statement;
import java.sql.Statement;
import com.serotonin.mango.rt.event.type.EventType;
import com.serotonin.mango.vo.User;
import com.serotonin.mango.vo.dataSource.DataSourceVO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package org.scada_lts.permissions.migration.dao;

import com.mysql.jdbc.Statement;
import java.sql.Statement;
import com.serotonin.mango.rt.event.EventInstance;
import com.serotonin.mango.vo.DataPointVO;
import com.serotonin.mango.vo.UserComment;
Expand Down
1 change: 1 addition & 0 deletions src/org/scada_lts/quartz/ScadaScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public void destroy() {
}
}
scheduler.shutdown(false);
Thread.sleep(1000);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions webapp-resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<!-- Lifecycle Logging-->
<Property name="startupLoggingLevel">INFO</Property>
<Property name="processingBackgroundLoggingLevel">ERROR</Property>
<Property name="backgroundProcessingLoggingLevel">ERROR</Property>
<Property name="pollingDataSourceLoggingLevel">ERROR</Property>
<Property name="runtimeManagerLoggingLevel">INFO</Property>

Expand Down Expand Up @@ -153,7 +153,7 @@
</Logger>

<!-- BackgroundProcessing Logging-->
<Logger name="com.serotonin.mango.rt.maint.BackgroundProcessing" level="${backgroundLoggingLevel}"/>
<Logger name="com.serotonin.mango.rt.maint.BackgroundProcessing" level="${backgroundProcessingLoggingLevel}"/>

<!-- PollingDataSource Logging-->
<Logger name="com.serotonin.mango.rt.dataSource.PollingDataSource" level="${pollingDataSourceLoggingLevel}"/>
Expand Down

0 comments on commit 8248acf

Please sign in to comment.