提交 7146e176 authored 作者: Thomas Mueller's avatar Thomas Mueller

The WebServlet did not close the database when undeploying the web application.

上级 a8693704
...@@ -15,7 +15,6 @@ import java.net.ServerSocket; ...@@ -15,7 +15,6 @@ import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
...@@ -332,12 +331,14 @@ public class WebServer implements Service { ...@@ -332,12 +331,14 @@ public class WebServer implements Service {
} }
public void stop() { public void stop() {
if (serverSocket != null) {
try { try {
serverSocket.close(); serverSocket.close();
} catch (IOException e) { } catch (IOException e) {
// TODO log exception traceError(e);
} }
serverSocket = null; serverSocket = null;
}
if (listenerThread != null) { if (listenerThread != null) {
try { try {
listenerThread.join(1000); listenerThread.join(1000);
...@@ -349,14 +350,7 @@ public class WebServer implements Service { ...@@ -349,14 +350,7 @@ public class WebServer implements Service {
ArrayList list = new ArrayList(sessions.values()); ArrayList list = new ArrayList(sessions.values());
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
WebSession session = (WebSession) list.get(i); WebSession session = (WebSession) list.get(i);
Statement stat = session.executingStatement; session.close();
if (stat != null) {
try {
stat.cancel();
} catch (Exception e) {
// ignore
}
}
} }
list = new ArrayList(running); list = new ArrayList(running);
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
...@@ -365,8 +359,7 @@ public class WebServer implements Service { ...@@ -365,8 +359,7 @@ public class WebServer implements Service {
c.stopNow(); c.stopNow();
c.join(100); c.join(100);
} catch (Exception e) { } catch (Exception e) {
// TODO log exception traceError(e);
e.printStackTrace();
} }
} }
} }
...@@ -387,9 +380,11 @@ public class WebServer implements Service { ...@@ -387,9 +380,11 @@ public class WebServer implements Service {
* *
* @param e the exception * @param e the exception
*/ */
void traceError(Exception e) { void traceError(Throwable e) {
if (trace) {
e.printStackTrace(); e.printStackTrace();
} }
}
/** /**
* Check if this language is supported / translated. * Check if this language is supported / translated.
...@@ -676,7 +671,7 @@ public class WebServer implements Service { ...@@ -676,7 +671,7 @@ public class WebServer implements Service {
* The translate thread reads and writes the file translation.properties * The translate thread reads and writes the file translation.properties
* once a second. * once a second.
*/ */
private static class TranslateThread extends Thread { private class TranslateThread extends Thread {
private final File file = new File("translation.properties"); private final File file = new File("translation.properties");
private final Map translation; private final Map translation;
...@@ -714,8 +709,7 @@ public class WebServer implements Service { ...@@ -714,8 +709,7 @@ public class WebServer implements Service {
} }
Thread.sleep(1000); Thread.sleep(1000);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); traceError(e);
// ignore
} }
} }
} }
......
...@@ -53,6 +53,10 @@ public class WebServlet extends HttpServlet { ...@@ -53,6 +53,10 @@ public class WebServlet extends HttpServlet {
server.init(args); server.init(args);
} }
public void destroy() {
server.stop();
}
private boolean allow(HttpServletRequest req) { private boolean allow(HttpServletRequest req) {
if (server.getAllowOthers()) { if (server.getAllowOthers()) {
return true; return true;
......
...@@ -125,29 +125,17 @@ class WebSession { ...@@ -125,29 +125,17 @@ class WebSession {
tableRule = new DbContextRule(contents, DbContextRule.TABLE); tableRule = new DbContextRule(contents, DbContextRule.TABLE);
schemaRule = new DbContextRule(contents, DbContextRule.SCHEMA); schemaRule = new DbContextRule(contents, DbContextRule.SCHEMA);
columnAliasRule = new DbContextRule(contents, DbContextRule.COLUMN_ALIAS); columnAliasRule = new DbContextRule(contents, DbContextRule.COLUMN_ALIAS);
// bnf.updateTopic("newTableName", new String[]{"TEST"});
// String[] schemas;
// if(contents.isMySQL) {
// schemas = new String[0];
// } else {
// schemas = new String[contents.schemas.length];
// for(int i=0; i<contents.schemas.length; i++) {
// schemas[i] = contents.schemas[i].quotedName + ".";
// }
// }
// bnf.updateTopic("schemaName", schemas);
newBnf.updateTopic("columnName", columnRule); newBnf.updateTopic("columnName", columnRule);
newBnf.updateTopic("newTableAlias", newAliasRule); newBnf.updateTopic("newTableAlias", newAliasRule);
newBnf.updateTopic("tableAlias", aliasRule); newBnf.updateTopic("tableAlias", aliasRule);
newBnf.updateTopic("columnAlias", columnAliasRule); newBnf.updateTopic("columnAlias", columnAliasRule);
newBnf.updateTopic("tableName", tableRule); newBnf.updateTopic("tableName", tableRule);
newBnf.updateTopic("schemaName", schemaRule); newBnf.updateTopic("schemaName", schemaRule);
// bnf.updateTopic("name", new String[]{""});
newBnf.linkStatements(); newBnf.linkStatements();
bnf = newBnf; bnf = newBnf;
} catch (Exception e) { } catch (Exception e) {
// ok we don't have the bnf // ok we don't have the bnf
e.printStackTrace(); server.traceError(e);
} }
} }
...@@ -246,4 +234,22 @@ class WebSession { ...@@ -246,4 +234,22 @@ class WebSession {
return shutdownServerOnDisconnect; return shutdownServerOnDisconnect;
} }
void close() {
if (executingStatement != null) {
try {
executingStatement.cancel();
} catch (Exception e) {
// ignore
}
}
if (conn != null) {
try {
conn.close();
} catch (Exception e) {
// ignore
}
}
}
} }
...@@ -552,7 +552,7 @@ class WebThread extends Thread implements DatabaseEventListener { ...@@ -552,7 +552,7 @@ class WebThread extends Thread implements DatabaseEventListener {
} }
session.put("autoCompleteList", result); session.put("autoCompleteList", result);
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); server.traceError(e);
} }
return "autoCompleteList.jsp"; return "autoCompleteList.jsp";
} }
...@@ -974,7 +974,7 @@ class WebThread extends Thread implements DatabaseEventListener { ...@@ -974,7 +974,7 @@ class WebThread extends Thread implements DatabaseEventListener {
error = formatAsError(error); error = formatAsError(error);
return error; return error;
} catch (OutOfMemoryError e2) { } catch (OutOfMemoryError e2) {
e.printStackTrace(); server.traceError(e);
return e.toString(); return e.toString();
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论