diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF index df98b61..adea47c 100644 --- a/src/META-INF/MANIFEST.MF +++ b/src/META-INF/MANIFEST.MF @@ -1,3 +1,3 @@ Manifest-Version: 1.0 -Main-Class: main +Main-Class: com.wasteinformationserver.main diff --git a/src/Date.java b/src/com/wasteinformationserver/Date.java similarity index 98% rename from src/Date.java rename to src/com/wasteinformationserver/Date.java index 2638216..abd507c 100644 --- a/src/Date.java +++ b/src/com/wasteinformationserver/Date.java @@ -1,3 +1,5 @@ +package com.wasteinformationserver; + import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; diff --git a/src/website/Log.java b/src/com/wasteinformationserver/basicutils/Log.java similarity index 96% rename from src/website/Log.java rename to src/com/wasteinformationserver/basicutils/Log.java index 797c95b..7efb911 100644 --- a/src/website/Log.java +++ b/src/com/wasteinformationserver/basicutils/Log.java @@ -1,10 +1,9 @@ -package website; +package com.wasteinformationserver.basicutils; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; -import java.util.logging.*; public class Log { @@ -79,7 +78,7 @@ public class Log { builder.append("]"); builder.append(" ["); - builder.append(new Exception().getStackTrace()[1].getClassName()); + builder.append(new Exception().getStackTrace()[2].getClassName()); builder.append("]"); builder.append(" ["); diff --git a/src/db/Database.java b/src/com/wasteinformationserver/db/Database.java similarity index 95% rename from src/db/Database.java rename to src/com/wasteinformationserver/db/Database.java index 7b79229..8f3181a 100755 --- a/src/db/Database.java +++ b/src/com/wasteinformationserver/db/Database.java @@ -1,4 +1,4 @@ -package db; +package com.wasteinformationserver.db; import javax.swing.table.DefaultTableModel; import java.sql.Connection; @@ -25,7 +25,7 @@ public abstract class Database { this.dbName = dbName; } - public abstract Connection getConnection(); + public abstract Connection getConnection() throws SQLException; public static void logToConsole(ResultSet res) { try { diff --git a/src/db/MySQLConnector.java b/src/com/wasteinformationserver/db/MySQLConnector.java similarity index 67% rename from src/db/MySQLConnector.java rename to src/com/wasteinformationserver/db/MySQLConnector.java index f518454..cc68023 100755 --- a/src/db/MySQLConnector.java +++ b/src/com/wasteinformationserver/db/MySQLConnector.java @@ -1,4 +1,4 @@ -package db; +package com.wasteinformationserver.db; import java.sql.Connection; import java.sql.DriverManager; @@ -18,20 +18,11 @@ public class MySQLConnector extends Database { super(user, password, host, port, dbName); } - public Connection getConnection() { - Connection con = null; - - try { - con = DriverManager.getConnection( + public Connection getConnection() throws SQLException { + return DriverManager.getConnection( "jdbc:mysql://" + host + ":" + port + "/" + dbName + "?useSSL=false", user, password); - - } catch (SQLException e) { - System.err.println("no connection to database! start database server"); - } - - return con; } } diff --git a/src/website/PostRequest.java b/src/com/wasteinformationserver/db/PostRequest.java similarity index 97% rename from src/website/PostRequest.java rename to src/com/wasteinformationserver/db/PostRequest.java index 627779c..35331d1 100644 --- a/src/website/PostRequest.java +++ b/src/com/wasteinformationserver/db/PostRequest.java @@ -1,4 +1,4 @@ -package website; +package com.wasteinformationserver.db; import com.sun.net.httpserver.Headers; import com.sun.net.httpserver.HttpExchange; diff --git a/src/db/PostgreSQLConnector.java b/src/com/wasteinformationserver/db/PostgreSQLConnector.java similarity index 95% rename from src/db/PostgreSQLConnector.java rename to src/com/wasteinformationserver/db/PostgreSQLConnector.java index 6ecccaa..6dbe33d 100755 --- a/src/db/PostgreSQLConnector.java +++ b/src/com/wasteinformationserver/db/PostgreSQLConnector.java @@ -1,4 +1,4 @@ -package db; +package com.wasteinformationserver.db; import java.sql.Connection; import java.sql.DriverManager; diff --git a/src/db/jdcb.java b/src/com/wasteinformationserver/db/jdcb.java similarity index 72% rename from src/db/jdcb.java rename to src/com/wasteinformationserver/db/jdcb.java index cf35a51..f683576 100644 --- a/src/db/jdcb.java +++ b/src/com/wasteinformationserver/db/jdcb.java @@ -1,4 +1,8 @@ -package db; +package com.wasteinformationserver.db; + +import com.wasteinformationserver.basicutils.Log; +import com.wasteinformationserver.db.Database; +import com.wasteinformationserver.db.MySQLConnector; import java.sql.Connection; import java.sql.PreparedStatement; @@ -16,7 +20,11 @@ Connection conn; 3306, dbName); - conn = db.getConnection(); + try { + conn = db.getConnection(); + } catch (SQLException e) { + Log.error("no connection to Database! DB Server not started...?"); + } } diff --git a/src/main.java b/src/com/wasteinformationserver/main.java similarity index 63% rename from src/main.java rename to src/com/wasteinformationserver/main.java index 0cc4b89..01c9e96 100644 --- a/src/main.java +++ b/src/com/wasteinformationserver/main.java @@ -1,14 +1,12 @@ -import db.jdcb; -import website.Log; +package com.wasteinformationserver; -import java.io.IOException; -import java.sql.ResultSet; -import java.sql.SQLException; +import com.wasteinformationserver.basicutils.Log; +import com.wasteinformationserver.website.Webserver; public class main { public static void main(String[] args) { /* - Date D=new Date(); + com.wasteinformationserver.Date D=new com.wasteinformationserver.Date(); D.getdata(); D.printList(); */ @@ -24,7 +22,7 @@ public class main { } })); - Thread mythread = new Thread(() -> new website.Webserver().startserver()); + Thread mythread = new Thread(() -> new Webserver().startserver()); mythread.start(); Log.message("thread started"); diff --git a/src/mqtt.java b/src/com/wasteinformationserver/mqtt.java similarity index 97% rename from src/mqtt.java rename to src/com/wasteinformationserver/mqtt.java index 963bbf8..a30178f 100644 --- a/src/mqtt.java +++ b/src/com/wasteinformationserver/mqtt.java @@ -1,3 +1,5 @@ +package com.wasteinformationserver; + import org.eclipse.paho.client.mqttv3.MqttClient; import org.eclipse.paho.client.mqttv3.MqttConnectOptions; import org.eclipse.paho.client.mqttv3.MqttException; diff --git a/src/website/CheckLoginState.java b/src/com/wasteinformationserver/website/CheckLoginState.java similarity index 88% rename from src/website/CheckLoginState.java rename to src/com/wasteinformationserver/website/CheckLoginState.java index 8051f2d..cf464b1 100644 --- a/src/website/CheckLoginState.java +++ b/src/com/wasteinformationserver/website/CheckLoginState.java @@ -1,4 +1,6 @@ -package website; +package com.wasteinformationserver.website; + +import com.wasteinformationserver.db.PostRequest; import java.util.HashMap; diff --git a/src/website/GetRequest.java b/src/com/wasteinformationserver/website/GetRequest.java similarity index 84% rename from src/website/GetRequest.java rename to src/com/wasteinformationserver/website/GetRequest.java index 0f3ffe8..56e2ff3 100644 --- a/src/website/GetRequest.java +++ b/src/com/wasteinformationserver/website/GetRequest.java @@ -1,4 +1,4 @@ -package website; +package com.wasteinformationserver.website; import com.sun.net.httpserver.Headers; import com.sun.net.httpserver.HttpExchange; @@ -6,9 +6,6 @@ import com.sun.net.httpserver.HttpHandler; import java.io.IOException; import java.io.OutputStream; -import java.math.BigInteger; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; import java.util.HashMap; public abstract class GetRequest implements HttpHandler { @@ -41,8 +38,8 @@ public abstract class GetRequest implements HttpHandler { /** * - * @param params received get params from website - * @return json reply to website + * @param params received get params from com.wasteinformationserver.website + * @return json reply to com.wasteinformationserver.website */ public abstract String myrequest(HashMap params); diff --git a/src/website/HttpTools.java b/src/com/wasteinformationserver/website/HttpTools.java similarity index 92% rename from src/website/HttpTools.java rename to src/com/wasteinformationserver/website/HttpTools.java index 2dcb8c5..8bd51b5 100644 --- a/src/website/HttpTools.java +++ b/src/com/wasteinformationserver/website/HttpTools.java @@ -1,4 +1,4 @@ -package website; +package com.wasteinformationserver.website; import java.math.BigInteger; import java.security.MessageDigest; diff --git a/src/website/LoginRequest.java b/src/com/wasteinformationserver/website/LoginRequest.java similarity index 91% rename from src/website/LoginRequest.java rename to src/com/wasteinformationserver/website/LoginRequest.java index 4aaf6db..44aac5c 100644 --- a/src/website/LoginRequest.java +++ b/src/com/wasteinformationserver/website/LoginRequest.java @@ -1,6 +1,7 @@ -package website; +package com.wasteinformationserver.website; -import db.jdcb; +import com.wasteinformationserver.db.PostRequest; +import com.wasteinformationserver.db.jdcb; import java.sql.ResultSet; import java.sql.SQLException; diff --git a/src/website/LoginState.java b/src/com/wasteinformationserver/website/LoginState.java similarity index 95% rename from src/website/LoginState.java rename to src/com/wasteinformationserver/website/LoginState.java index 7921eca..bda04c7 100644 --- a/src/website/LoginState.java +++ b/src/com/wasteinformationserver/website/LoginState.java @@ -1,4 +1,4 @@ -package website; +package com.wasteinformationserver.website; public class LoginState { private LoginState() {} diff --git a/src/website/MainPage.java b/src/com/wasteinformationserver/website/MainPage.java similarity index 95% rename from src/website/MainPage.java rename to src/com/wasteinformationserver/website/MainPage.java index e879e65..c727ab8 100644 --- a/src/website/MainPage.java +++ b/src/com/wasteinformationserver/website/MainPage.java @@ -1,8 +1,9 @@ -package website; +package com.wasteinformationserver.website; import com.sun.net.httpserver.Headers; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; +import com.wasteinformationserver.basicutils.Log; import java.io.File; import java.io.FileInputStream; diff --git a/src/website/RegisterRequest.java b/src/com/wasteinformationserver/website/RegisterRequest.java similarity index 79% rename from src/website/RegisterRequest.java rename to src/com/wasteinformationserver/website/RegisterRequest.java index 652d076..dc00441 100644 --- a/src/website/RegisterRequest.java +++ b/src/com/wasteinformationserver/website/RegisterRequest.java @@ -1,10 +1,11 @@ -package website; +package com.wasteinformationserver.website; -import db.jdcb; +import com.wasteinformationserver.db.PostRequest; +import com.wasteinformationserver.db.jdcb; import java.util.HashMap; -public class RegisterRequest extends PostRequest{ +public class RegisterRequest extends PostRequest { @Override public String request(HashMap params) { System.out.println(params.toString()); diff --git a/src/website/Webserver.java b/src/com/wasteinformationserver/website/Webserver.java similarity index 90% rename from src/website/Webserver.java rename to src/com/wasteinformationserver/website/Webserver.java index 9c8bca6..fd052da 100644 --- a/src/website/Webserver.java +++ b/src/com/wasteinformationserver/website/Webserver.java @@ -1,11 +1,11 @@ -package website; +package com.wasteinformationserver.website; import com.sun.net.httpserver.HttpServer; +import com.wasteinformationserver.basicutils.Log; import java.io.IOException; import java.net.InetSocketAddress; -import java.util.logging.Level; public class Webserver {