mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 19:22:22 -05:00
DavGateway class cleanup
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@194 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
8d8fb5b7cd
commit
67ff8ec99d
@ -14,6 +14,14 @@ public abstract class AbstractServer extends Thread {
|
|||||||
private int port;
|
private int port;
|
||||||
private ServerSocket serverSocket;
|
private ServerSocket serverSocket;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Server socket TCP port
|
||||||
|
* @return port
|
||||||
|
*/
|
||||||
|
public int getPort() {
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a ServerSocket to listen for connections.
|
* Create a ServerSocket to listen for connections.
|
||||||
* Start the thread.
|
* Start the thread.
|
||||||
|
@ -3,10 +3,10 @@ package davmail;
|
|||||||
import davmail.caldav.CaldavServer;
|
import davmail.caldav.CaldavServer;
|
||||||
import davmail.http.DavGatewayHttpClientFacade;
|
import davmail.http.DavGatewayHttpClientFacade;
|
||||||
import davmail.http.DavGatewaySSLProtocolSocketFactory;
|
import davmail.http.DavGatewaySSLProtocolSocketFactory;
|
||||||
|
import davmail.ldap.LdapServer;
|
||||||
import davmail.pop.PopServer;
|
import davmail.pop.PopServer;
|
||||||
import davmail.smtp.SmtpServer;
|
import davmail.smtp.SmtpServer;
|
||||||
import davmail.tray.DavGatewayTray;
|
import davmail.tray.DavGatewayTray;
|
||||||
import davmail.ldap.LdapServer;
|
|
||||||
import org.apache.commons.httpclient.HttpClient;
|
import org.apache.commons.httpclient.HttpClient;
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
import org.apache.commons.httpclient.methods.GetMethod;
|
||||||
@ -47,44 +47,29 @@ public class DavGateway {
|
|||||||
public static void start() {
|
public static void start() {
|
||||||
// first stop existing servers
|
// first stop existing servers
|
||||||
DavGateway.stop();
|
DavGateway.stop();
|
||||||
int smtpPort = Settings.getIntProperty("davmail.smtpPort");
|
|
||||||
if (smtpPort == 0) {
|
|
||||||
smtpPort = SmtpServer.DEFAULT_PORT;
|
|
||||||
}
|
|
||||||
int popPort = Settings.getIntProperty("davmail.popPort");
|
|
||||||
if (popPort == 0) {
|
|
||||||
popPort = PopServer.DEFAULT_PORT;
|
|
||||||
}
|
|
||||||
int caldavPort = Settings.getIntProperty("davmail.caldavPort");
|
|
||||||
if (caldavPort == 0) {
|
|
||||||
caldavPort = CaldavServer.DEFAULT_PORT;
|
|
||||||
}
|
|
||||||
int ldapPort = Settings.getIntProperty("davmail.ldapPort");
|
|
||||||
if (ldapPort == 0) {
|
|
||||||
ldapPort = LdapServer.DEFAULT_PORT;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
smtpServer = new SmtpServer(smtpPort);
|
smtpServer = new SmtpServer(Settings.getIntProperty("davmail.smtpPort"));
|
||||||
popServer = new PopServer(popPort);
|
popServer = new PopServer(Settings.getIntProperty("davmail.popPort"));
|
||||||
caldavServer = new CaldavServer(caldavPort);
|
caldavServer = new CaldavServer(Settings.getIntProperty("davmail.caldavPort"));
|
||||||
ldapServer = new LdapServer(ldapPort);
|
ldapServer = new LdapServer(Settings.getIntProperty("davmail.ldapPort"));
|
||||||
smtpServer.start();
|
smtpServer.start();
|
||||||
popServer.start();
|
popServer.start();
|
||||||
caldavServer.start();
|
caldavServer.start();
|
||||||
ldapServer.start();
|
ldapServer.start();
|
||||||
|
|
||||||
String message = "DavMail gateway listening on SMTP port " + smtpPort +
|
String message = "DavMail gateway listening on SMTP port " + smtpServer.getPort() +
|
||||||
", Caldav port " + caldavPort +
|
", Caldav port " + caldavServer.getPort() +
|
||||||
", LDAP port " + ldapPort +
|
", LDAP port " + ldapServer.getPort() +
|
||||||
" and POP port " + popPort;
|
" and POP port " + popServer.getPort();
|
||||||
|
DavGatewayTray.info(message);
|
||||||
|
|
||||||
|
// check for new version
|
||||||
String releasedVersion = getReleasedVersion();
|
String releasedVersion = getReleasedVersion();
|
||||||
String currentVersion = getCurrentVersion();
|
String currentVersion = getCurrentVersion();
|
||||||
if (currentVersion != null && releasedVersion != null && currentVersion.compareTo(releasedVersion) < 0) {
|
if (currentVersion != null && releasedVersion != null && currentVersion.compareTo(releasedVersion) < 0) {
|
||||||
message += " A new version (" + releasedVersion + ") of DavMail Gateway is available !";
|
DavGatewayTray.info("A new version (" + releasedVersion + ") of DavMail Gateway is available !");
|
||||||
}
|
}
|
||||||
|
|
||||||
DavGatewayTray.info(message);
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
DavGatewayTray.error("Exception creating server socket", e);
|
DavGatewayTray.error("Exception creating server socket", e);
|
||||||
}
|
}
|
||||||
@ -93,39 +78,22 @@ public class DavGateway {
|
|||||||
DavGatewaySSLProtocolSocketFactory.register();
|
DavGatewaySSLProtocolSocketFactory.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static void stopServer(AbstractServer server) {
|
||||||
|
if (server != null) {
|
||||||
|
server.close();
|
||||||
|
try {
|
||||||
|
server.join();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
DavGatewayTray.warn("Exception waiting for listener to die", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void stop() {
|
public static void stop() {
|
||||||
if (smtpServer != null) {
|
stopServer(smtpServer);
|
||||||
smtpServer.close();
|
stopServer(popServer);
|
||||||
try {
|
stopServer(caldavServer);
|
||||||
smtpServer.join();
|
stopServer(ldapServer);
|
||||||
} catch (InterruptedException e) {
|
|
||||||
DavGatewayTray.warn("Exception waiting for listener to die", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (popServer != null) {
|
|
||||||
popServer.close();
|
|
||||||
try {
|
|
||||||
popServer.join();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
DavGatewayTray.warn("Exception waiting for listener to die", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (caldavServer != null) {
|
|
||||||
caldavServer.close();
|
|
||||||
try {
|
|
||||||
caldavServer.join();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
DavGatewayTray.warn("Exception waiting for listener to die", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ldapServer != null) {
|
|
||||||
ldapServer.close();
|
|
||||||
try {
|
|
||||||
ldapServer.join();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
DavGatewayTray.warn("Exception waiting for listener to die", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getCurrentVersion() {
|
public static String getCurrentVersion() {
|
||||||
|
Loading…
Reference in New Issue
Block a user