From decf114f49eae2771276eb688e3220d3c16dd1e8 Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Sun, 22 Aug 2021 16:04:53 +0200 Subject: [PATCH] Fixed test cases --- build.gradle | 2 +- pom.xml | 26 +++++++++---------- .../threaded/ThreadedTCPNetworkServer.java | 23 +++++++++------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/build.gradle b/build.gradle index 305add0..33ca367 100644 --- a/build.gradle +++ b/build.gradle @@ -11,8 +11,8 @@ repositories { dependencies { implementation 'org.dom4j:dom4j:2.1.3' + implementation 'org.xerial:sqlite-jdbc:3.8.11.2' compileOnly 'mysql:mysql-connector-java:8.0.16' - compileOnly 'org.xerial:sqlite-jdbc:3.8.11.2' compileOnly 'javax.servlet:javax.servlet-api:3.1.0' diff --git a/pom.xml b/pom.xml index ed2695b..0161cd0 100644 --- a/pom.xml +++ b/pom.xml @@ -48,17 +48,17 @@ - commons-fileupload - commons-fileupload - 1.4 - provided + org.xerial + sqlite-jdbc + 3.8.11.2 - commons-io - commons-io - 2.7 + mysql + mysql-connector-java + 8.0.16 provided + javax.servlet javax.servlet-api @@ -92,15 +92,15 @@ - mysql - mysql-connector-java - 8.0.16 + commons-fileupload + commons-fileupload + 1.4 provided - org.xerial - sqlite-jdbc - 3.8.11.2 + commons-io + commons-io + 2.7 provided diff --git a/src/zutil/net/threaded/ThreadedTCPNetworkServer.java b/src/zutil/net/threaded/ThreadedTCPNetworkServer.java index 4bde44e..8f91d79 100755 --- a/src/zutil/net/threaded/ThreadedTCPNetworkServer.java +++ b/src/zutil/net/threaded/ThreadedTCPNetworkServer.java @@ -53,16 +53,16 @@ public abstract class ThreadedTCPNetworkServer extends Thread { private Executor executor = Executors.newCachedThreadPool(); private final int port; - private ServerSocket serverSocket; + private ServerSocketFactory serverSocketFactory; /** * Creates a new instance of the sever. * * @param port the port that the server should listen to */ - public ThreadedTCPNetworkServer(int port) throws IOException { + public ThreadedTCPNetworkServer(int port) { this.port = port; - this.serverSocket = ServerSocketFactory.getDefault().createServerSocket(port); + this.serverSocketFactory = ServerSocketFactory.getDefault(); } /** * Creates a new SSL instance of the sever. @@ -91,13 +91,13 @@ public abstract class ThreadedTCPNetworkServer extends Thread { * @param keyStore the KeyStore that contains the certificate to be used by the server * @param keyStorePass the password to decrypt the key store file, null if there is no password set */ - public ThreadedTCPNetworkServer(int port, KeyStore keyStore, char[] keyStorePass) throws IOException, GeneralSecurityException { + public ThreadedTCPNetworkServer(int port, KeyStore keyStore, char[] keyStorePass) throws GeneralSecurityException { this.port = port; - this.serverSocket = getSSLServerSocketFactory(keyStore, keyStorePass).createServerSocket(port); + this.serverSocketFactory = getSSLServerSocketFactory(keyStore, keyStorePass); } /** - * Initiates a SSLServerSocket + * Initiates a SSLServerSocketFactory * * @param privateKey the private key for the certificate * @param certificate the certificate for the server domain. @@ -113,7 +113,7 @@ public abstract class ThreadedTCPNetworkServer extends Thread { return keyStore; } /** - * Initiates a SSLServerSocket + * Initiates a SSLServerSocketFactory * * @param keyStoreFile the cert file location * @param keyStorePass the password for the cert file, null if there is no password set @@ -152,7 +152,11 @@ public abstract class ThreadedTCPNetworkServer extends Thread { } public void run() { + ServerSocket serverSocket = null; + try { + serverSocket = serverSocketFactory.createServerSocket(port); + logger.info("Accepting TCP Connections on port: " + port); while (true) { @@ -173,15 +177,14 @@ public abstract class ThreadedTCPNetworkServer extends Thread { try { logger.info("Closing TCP socket listener (Port: " + port + ")."); serverSocket.close(); - serverSocket = null; } catch(IOException e) { logger.log(Level.SEVERE, null, e); } } } } /** - * This method returns an new instance of the ThreadedTCPNetworkServerThread - * that will handle the newly made connection, if an null value is returned + * This method returns a new instance of the ThreadedTCPNetworkServerThread + * that will handle the newly made connection, if a null value is returned * then the ThreadedTCPNetworkServer will close the new connection. * * @param socket is an new connection to an host