Fixed NullPointerException
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>org.openautonomousconnection</groupId>
|
<groupId>org.openautonomousconnection</groupId>
|
||||||
<artifactId>Protocol</artifactId>
|
<artifactId>Protocol</artifactId>
|
||||||
<version>1.0.0-BETA.5.2</version>
|
<version>1.0.0-BETA.5.3</version>
|
||||||
<organization>
|
<organization>
|
||||||
<name>Open Autonomous Connection</name>
|
<name>Open Autonomous Connection</name>
|
||||||
<url>https://open-autonomous-connection.org/</url>
|
<url>https://open-autonomous-connection.org/</url>
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ public final class ProtocolBridge {
|
|||||||
registerPackets();
|
registerPackets();
|
||||||
|
|
||||||
// Assign Bridge
|
// Assign Bridge
|
||||||
protocolINSServer.attachBridge(this);
|
protocolWebServer.attachBridge(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -173,6 +173,8 @@ public final class ProtocolBridge {
|
|||||||
// Register the appropriate listeners and packets
|
// Register the appropriate listeners and packets
|
||||||
registerListeners();
|
registerListeners();
|
||||||
registerPackets();
|
registerPackets();
|
||||||
|
|
||||||
|
protocolClient.attachBridge(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -48,11 +48,6 @@ public abstract class ProtocolWebServer {
|
|||||||
@Getter
|
@Getter
|
||||||
private final ServerCertificateFolderStructure folderStructure;
|
private final ServerCertificateFolderStructure folderStructure;
|
||||||
|
|
||||||
/**
|
|
||||||
* Configuration manager for server settings.
|
|
||||||
*/
|
|
||||||
private final ConfigurationManager configurationManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Certificate files for SSL.
|
* Certificate files for SSL.
|
||||||
*/
|
*/
|
||||||
@@ -62,9 +57,9 @@ public abstract class ProtocolWebServer {
|
|||||||
*/
|
*/
|
||||||
private final File keyFile;
|
private final File keyFile;
|
||||||
/**
|
/**
|
||||||
* The configuration file for the web server.
|
* The configuration for the web server.
|
||||||
*/
|
*/
|
||||||
private final File configFile;
|
private final WebServerConfig serverConfig;
|
||||||
/**
|
/**
|
||||||
* The reference to the ProtocolBridge Object
|
* The reference to the ProtocolBridge Object
|
||||||
*/
|
*/
|
||||||
@@ -94,17 +89,18 @@ public abstract class ProtocolWebServer {
|
|||||||
/**
|
/**
|
||||||
* Initializes the web server with the given configuration, authentication, and rules files.
|
* Initializes the web server with the given configuration, authentication, and rules files.
|
||||||
*
|
*
|
||||||
* @param configFile The configuration file.
|
* @param serverConfig The configuration.
|
||||||
* @param authFile The authentication file.
|
* @param authFile The authentication file.
|
||||||
* @param rulesFile The rules file.
|
* @param rulesFile The rules file.
|
||||||
* @throws Exception If an error occurs during initialization.
|
* @throws Exception If an error occurs during initialization.
|
||||||
*/
|
*/
|
||||||
public ProtocolWebServer(File configFile, File authFile, File rulesFile) throws Exception {
|
public ProtocolWebServer(WebServerConfig serverConfig, File authFile, File rulesFile) throws Exception {
|
||||||
// Initialize the list of connected clients
|
// Initialize the list of connected clients
|
||||||
this.clients = new ArrayList<>();
|
this.clients = new ArrayList<>();
|
||||||
|
|
||||||
// Store the configuration file
|
// Store the configuration file
|
||||||
this.configFile = configFile;
|
this.serverConfig = serverConfig;
|
||||||
|
this.serverConfig.attachWebServer(this);
|
||||||
|
|
||||||
// Set up folder structure for certificates
|
// Set up folder structure for certificates
|
||||||
folderStructure = new ServerCertificateFolderStructure();
|
folderStructure = new ServerCertificateFolderStructure();
|
||||||
@@ -113,9 +109,6 @@ public abstract class ProtocolWebServer {
|
|||||||
checkFileExists(folderStructure.publicServerFolder, folderStructure.certPrefix, ".crt");
|
checkFileExists(folderStructure.publicServerFolder, folderStructure.certPrefix, ".crt");
|
||||||
checkFileExists(folderStructure.privateServerFolder, folderStructure.certPrefix, ".key");
|
checkFileExists(folderStructure.privateServerFolder, folderStructure.certPrefix, ".key");
|
||||||
|
|
||||||
// Load configuration settings
|
|
||||||
this.configurationManager = getConfigurationManager(configFile);
|
|
||||||
|
|
||||||
// Set up content and error folders
|
// Set up content and error folders
|
||||||
contentFolder = new File("content");
|
contentFolder = new File("content");
|
||||||
errorsFolder = new File("errors");
|
errorsFolder = new File("errors");
|
||||||
@@ -183,7 +176,7 @@ public abstract class ProtocolWebServer {
|
|||||||
*/
|
*/
|
||||||
private void createNetworkServer() {
|
private void createNetworkServer() {
|
||||||
pipelineServer = new NetworkServer.ServerBuilder().
|
pipelineServer = new NetworkServer.ServerBuilder().
|
||||||
setPort(configurationManager.getInt("port.pipeline")).setTimeout(0).
|
setPort(protocolBridge.getProtocolSettings().port).setTimeout(0).
|
||||||
setPacketHandler(protocolBridge.getProtocolSettings().packetHandler).setEventManager(protocolBridge.getProtocolSettings().eventManager).
|
setPacketHandler(protocolBridge.getProtocolSettings().packetHandler).setEventManager(protocolBridge.getProtocolSettings().eventManager).
|
||||||
setLogger(protocolBridge.getLogger()).
|
setLogger(protocolBridge.getLogger()).
|
||||||
setServerCertificate(certFile, keyFile).setRootCAFolder(folderStructure.publicCAFolder).
|
setServerCertificate(certFile, keyFile).setRootCAFolder(folderStructure.publicCAFolder).
|
||||||
@@ -214,7 +207,7 @@ public abstract class ProtocolWebServer {
|
|||||||
// Create the SSL server socket for web connections
|
// Create the SSL server socket for web connections
|
||||||
webServer = (SSLServerSocket) NetworkServer.ServerBuilder.
|
webServer = (SSLServerSocket) NetworkServer.ServerBuilder.
|
||||||
createSSLServerSocketFactory(folderStructure.publicCAFolder, certFile, keyFile).
|
createSSLServerSocketFactory(folderStructure.publicCAFolder, certFile, keyFile).
|
||||||
createServerSocket(configurationManager.getInt("port"));
|
createServerSocket(serverConfig.getPort());
|
||||||
webServer.setSoTimeout(0);
|
webServer.setSoTimeout(0);
|
||||||
webServer.setEnabledProtocols(pipelineServer.getServerSocket().getEnabledProtocols());
|
webServer.setEnabledProtocols(pipelineServer.getServerSocket().getEnabledProtocols());
|
||||||
|
|
||||||
@@ -320,52 +313,6 @@ public abstract class ProtocolWebServer {
|
|||||||
if (!found) throw new CertificateException("Missing " + prefix + NetworkUtils.getPublicIPAddress() + extension);
|
if (!found) throw new CertificateException("Missing " + prefix + NetworkUtils.getPublicIPAddress() + extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the configuration manager for the web server.
|
|
||||||
*
|
|
||||||
* @return The configuration manager.
|
|
||||||
* @throws IOException If an I/O error occurs while loading or saving the configuration.
|
|
||||||
*/
|
|
||||||
public final ConfigurationManager getConfigurationManager() throws IOException {
|
|
||||||
return getConfigurationManager(configFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads and initializes the configuration manager with default settings if necessary.
|
|
||||||
*
|
|
||||||
* @param configFile The configuration file to load.
|
|
||||||
* @return The initialized configuration manager.
|
|
||||||
* @throws IOException If an I/O error occurs while loading or saving the configuration.
|
|
||||||
*/
|
|
||||||
private ConfigurationManager getConfigurationManager(File configFile) throws IOException {
|
|
||||||
if (!configFile.exists()) configFile.createNewFile();
|
|
||||||
|
|
||||||
ConfigurationManager configurationManager = new ConfigurationManager(configFile);
|
|
||||||
configurationManager.loadProperties();
|
|
||||||
|
|
||||||
if (!configurationManager.isSet("port.webserver")) {
|
|
||||||
configurationManager.set("port.webserver", 9824);
|
|
||||||
configurationManager.saveProperties();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!configurationManager.isSet("port.pipeline")) {
|
|
||||||
configurationManager.set("port.pipeline", 9389);
|
|
||||||
configurationManager.saveProperties();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!configurationManager.isSet("filemaxuploadmb")) {
|
|
||||||
configurationManager.set("filemaxuploadmb", 1000);
|
|
||||||
configurationManager.saveProperties();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!configurationManager.isSet("sessionexpireminutes")) {
|
|
||||||
configurationManager.set("sessionexpireminutes", 60);
|
|
||||||
configurationManager.saveProperties();
|
|
||||||
}
|
|
||||||
|
|
||||||
return configurationManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the folder structure for server certificates.
|
* Represents the folder structure for server certificates.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package org.openautonomousconnection.protocol.side.web;
|
||||||
|
|
||||||
|
import dev.unlegitdqrk.unlegitlibrary.file.ConfigurationManager;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.module.Configuration;
|
||||||
|
|
||||||
|
public class WebServerConfig {
|
||||||
|
|
||||||
|
private final File configFile;
|
||||||
|
private final ConfigurationManager configuration;
|
||||||
|
private ProtocolWebServer webServer;
|
||||||
|
|
||||||
|
public WebServerConfig(File configFile) throws IOException {
|
||||||
|
this.configFile = configFile;
|
||||||
|
if (!configFile.exists()) configFile.createNewFile();
|
||||||
|
configuration = new ConfigurationManager(configFile);
|
||||||
|
|
||||||
|
if (!configuration.isSet("sessionexpireMIN")) configuration.set("sessionexpireMIN", 60);
|
||||||
|
if (!configuration.isSet("maxuploadMB")) configuration.set("maxuploadMB", 10000);
|
||||||
|
if (!configuration.isSet("port")) configuration.set("port", 20);
|
||||||
|
|
||||||
|
configuration.saveProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void attachWebServer(ProtocolWebServer webServer) {
|
||||||
|
if (this.webServer != null) return;
|
||||||
|
this.webServer = webServer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Web port
|
||||||
|
*/
|
||||||
|
public int getPort() {
|
||||||
|
return configuration.getInt("port");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The Session expiration time in minutes
|
||||||
|
*/
|
||||||
|
public int getSessionExpiration() {
|
||||||
|
return configuration.getInt("sessionexpireMIN");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Max upload size in MB
|
||||||
|
*/
|
||||||
|
public int getMaxUpload() {
|
||||||
|
return configuration.getInt("maxuploadMB");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user