Skip to content

Commit 0bb6a80

Browse files
author
NoteFox
committed
automatically creating all needed files and bug fix
1 parent 1c458d0 commit 0bb6a80

5 files changed

Lines changed: 41 additions & 26 deletions

File tree

src/main/java/Playground.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import java.io.File;
2-
31
public class Playground {
42
public static void main(String[] args) {
5-
File file = new File("./maps/map/helluw.txt");
6-
System.out.println(file.exists());
73

84
}
95
}

src/main/java/Server/FTPServer/FTPService.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class FTPService implements Runnable {
3232
private UserManager um;
3333
private PropertiesUserManagerFactory userManagerFactory;
3434

35-
private boolean LOGGING = true;
35+
private boolean LOGGING = doesFTPServiceLog;
3636
private File logFile = new File(ftpLogFile);
3737
private PrintStream logStream;
3838

@@ -67,7 +67,7 @@ public void ftpServerSetUp() throws IOException {
6767
serverFactory = new FtpServerFactory();
6868
listenerFactory = new ListenerFactory();
6969

70-
//defineSSLConf();
70+
defineSSLConf();
7171
defineListener();
7272
setUpUser();
7373

@@ -92,12 +92,6 @@ private void defineSSLConf() {
9292
// set the SSL configuration for the listener
9393
listenerFactory.setSslConfiguration(ssl.createSslConfiguration());
9494
listenerFactory.setImplicitSsl(true);
95-
96-
// replace the default listener
97-
serverFactory.addListener("default", listenerFactory.createListener());
98-
PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
99-
userManagerFactory.setFile(new File("myusers.properties"));
100-
serverFactory.setUserManager(userManagerFactory.createUserManager());
10195
}
10296

10397
private void defineListener() {
@@ -106,7 +100,7 @@ private void defineListener() {
106100
userManagerFactory = new PropertiesUserManagerFactory(); // adding a new UserManagementClass
107101
userManagerFactory.setFile(new File(ftpServiceUserPropertiesFile));//choose any. We're telling the FTP-server where to read its user list
108102
userManagerFactory.setPasswordEncryptor(new PasswordEncryptorsImpl()); // encrypts passwords of users by using the EncrImpl
109-
serverFactory.setUserManager(userManagerFactory.createUserManager());
103+
serverFactory.setUserManager(um);
110104
}
111105

112106
private void setUpUser() throws IOException {
@@ -124,14 +118,11 @@ private void setUpUser() throws IOException {
124118
try {
125119
um = userManagerFactory.createUserManager();
126120
} catch (FtpServerConfigurationException e) {
127-
try {
121+
new File(ftpDefaultDir).mkdirs();
128122
new File(ftpServiceUserPropertiesFile).createNewFile();
129-
} catch (IOException ex) {
130-
new File("./ftp").mkdir();
131-
new File(ftpServiceUserPropertiesFile).createNewFile();
132-
}
133123
um = userManagerFactory.createUserManager();
134124
}
125+
135126
try {
136127
um.save(user);//Save the user to the user list on the filesystem
137128
} catch (FtpException e1) {

src/main/java/Server/Service.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@
1313
import static Server.StaticVariables.*;
1414

1515
public class Service implements Runnable, srvInterface{
16-
private String LISTEN_IP = "0.0.0.0"; // "::" ipv6 , "0.0.0.0" ipv4
17-
private int LISTEN_PORT = 5000;
16+
// this is currently not in use
17+
//private String LISTEN_IP = "0.0.0.0"; // "::" ipv6 , "0.0.0.0" ipv4
18+
//private int LISTEN_PORT = 5000;
1819

1920
//fetching DirStrings from StaticVariables Class
2021
private String OSM_DIR = osmDir;
2122
private String MAP_DIR = mapDir;
2223
private String OHDM_DIR = ohdmDir;
2324

24-
private boolean LOGGING = true;
25+
private boolean LOGGING = doesWebServiceLog;
26+
2527
// fetching ftpLogFile from StaticVariables Class
2628
private File logFile = new File(webServiceLogFile);
2729
private PrintStream logStream;

src/main/java/Server/SpringClass.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public class SpringClass {
2828
public static Thread ftpThread;
2929

3030
public static void main(String[] args) {
31+
try {
32+
setUpLogger();
33+
} catch (IOException e) {
34+
System.err.println("wasn't able to create loggerFiles ");
35+
}
36+
3137
serviceInstance = new Service();
3238
serviceThread = new Thread(serviceInstance);
3339
serviceThread.start();
@@ -39,6 +45,18 @@ public static void main(String[] args) {
3945
SpringApplication.run(SpringClass.class, args);
4046
}
4147

48+
private static void setUpLogger() throws IOException {
49+
if (!(new File(StaticVariables.webServiceLogFile).exists())) {
50+
new File(StaticVariables.logDefaultDir).mkdirs();
51+
new File(StaticVariables.webServiceLogFile).createNewFile();
52+
}
53+
54+
if (!(new File(StaticVariables.ftpLogFile).exists())) {
55+
new File(StaticVariables.logDefaultDir).mkdirs();
56+
new File(StaticVariables.ftpLogFile);
57+
}
58+
}
59+
4260
/**
4361
* method to queue a map into the "REQUEST QUEUE"
4462
*/

src/main/java/Server/StaticVariables.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
package Server;
22

33
public class StaticVariables {
4-
public static final String ftpLogFile = "ftpLog.txt";
5-
public static final String webServiceLogFile = "webServiceLog.txt";
4+
public static final String logDefaultDir = "./log";
65

7-
public static final String osmDir = "./maps/osm";
8-
public static final String mapDir = "./maps/map";
6+
public static final boolean doesFTPServiceLog = true;
7+
public static final boolean doesWebServiceLog = true;
8+
9+
public static final String ftpLogFile = logDefaultDir + "/ftpLog.txt";
10+
public static final String webServiceLogFile = logDefaultDir + "/webServiceLog.txt";
11+
12+
public static final String mapsDefalutDir = "./maps";
13+
public static final String osmDir = mapsDefalutDir + "/osm";
14+
public static final String mapDir = mapsDefalutDir + "/map";
915
public static final String ohdmDir = "";
1016

1117
public static final String ftpServiceMapDir = mapDir;
12-
public static final String ftpServiceUserPropertiesFile = "./ftp/userList.properties";
18+
public static final String ftpDefaultDir = "./ftp";
19+
public static final String ftpServiceUserPropertiesFile = ftpDefaultDir + "/userList.properties";
20+
1321
public static final int ftpPort = 5000;
1422

1523
// will later be read from a File instead of being HardCoded

0 commit comments

Comments
 (0)