Merge branch 'develop' into f/message_notification
This commit is contained in:
commit
e4249919ad
@ -1,5 +1,7 @@
|
||||
package envoy.client;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.ws.rs.client.ClientBuilder;
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.client.WebTarget;
|
||||
@ -28,16 +30,18 @@ public class Client {
|
||||
private Config config;
|
||||
private User sender, recipient;
|
||||
|
||||
private static final Logger logger = Logger.getLogger(Client.class.getSimpleName());
|
||||
|
||||
public Client(Config config, String username) {
|
||||
this.config = config;
|
||||
sender = getUser(username);
|
||||
System.out.println("ID: " + sender.getID());
|
||||
|
||||
logger.info("ID: " + sender.getID());
|
||||
}
|
||||
|
||||
private <T, R> R post(String uri, T body, Class<R> responseBodyClass) {
|
||||
javax.ws.rs.client.Client client = ClientBuilder.newClient();
|
||||
WebTarget target = client.target(uri);
|
||||
|
||||
Response response = target.request().post(Entity.entity(body, "application/xml"));
|
||||
R responseBody = response.readEntity(responseBodyClass);
|
||||
response.close();
|
||||
@ -92,7 +96,7 @@ public class Client {
|
||||
if (returnSenderSync.getUsers().size() == 1) {
|
||||
returnSender = returnSenderSync.getUsers().get(0);
|
||||
} else {
|
||||
System.out.println("ERROR exiting...");
|
||||
logger.warning("ERROR exiting...");
|
||||
}
|
||||
|
||||
return returnSender;
|
||||
|
@ -32,7 +32,7 @@ public class Config {
|
||||
*
|
||||
* @param properties a {@link Properties} object containing information about
|
||||
* the server and port, as well as the path to the local
|
||||
* database
|
||||
* database and the synchronization timeout
|
||||
* @since Envoy v0.1-alpha
|
||||
*/
|
||||
public void load(Properties properties) {
|
||||
@ -64,8 +64,6 @@ public class Config {
|
||||
case "-db":
|
||||
localDB = new File(args[++i]);
|
||||
}
|
||||
if (localDB == null) localDB = new File(".\\localDB");
|
||||
if (syncTimeout == 0) syncTimeout = 1000;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,6 +10,7 @@ import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JButton;
|
||||
@ -57,6 +58,8 @@ public class ChatWindow extends JFrame {
|
||||
|
||||
private JTextArea messageEnterTextArea;
|
||||
|
||||
private static final Logger logger = Logger.getLogger(ChatWindow.class.getSimpleName());
|
||||
|
||||
public ChatWindow(Client client, LocalDB localDB) {
|
||||
this.client = client;
|
||||
this.localDB = localDB;
|
||||
@ -184,7 +187,7 @@ public class ChatWindow extends JFrame {
|
||||
SettingsScreen.open(localDB.getUser().getName());
|
||||
} catch (Exception e) {
|
||||
SettingsScreen.open();
|
||||
System.err.println("An error occured while opening the settings screen: " + e);
|
||||
logger.warning("An error occured while opening the settings screen: " + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
@ -3,6 +3,8 @@ package envoy.client.ui;
|
||||
import java.awt.EventQueue;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
@ -24,41 +26,48 @@ import envoy.exception.EnvoyException;
|
||||
*/
|
||||
public class Startup {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(Client.class.getSimpleName());
|
||||
|
||||
public static void main(String[] args) {
|
||||
logger.setLevel(Level.ALL);
|
||||
|
||||
Config config = Config.getInstance();
|
||||
if (args.length > 0) {
|
||||
config.load(args);
|
||||
} else {
|
||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
try {
|
||||
Properties configProperties = new Properties();
|
||||
configProperties.load(loader.getResourceAsStream("client.properties"));
|
||||
config.load(configProperties);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Load the configuration from client.properties first
|
||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
try {
|
||||
Properties configProperties = new Properties();
|
||||
configProperties.load(loader.getResourceAsStream("client.properties"));
|
||||
config.load(configProperties);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Override configuration values with command line arguments
|
||||
if (args.length > 0)
|
||||
config.load(args);
|
||||
|
||||
if (!config.isInitialized()) {
|
||||
System.err.println("Server or port are not defined. Exiting...");
|
||||
logger.warning("Server or port are not defined. Exiting...");
|
||||
JOptionPane.showMessageDialog(null, "Error loading configuration values.", "Configuration error",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
String userName = JOptionPane.showInputDialog("Please enter your username");
|
||||
if (userName == null || userName.isEmpty()) {
|
||||
System.err.println("User name is not set or empty. Exiting...");
|
||||
logger.warning("User name is not set or empty. Exiting...");
|
||||
System.exit(1);
|
||||
}
|
||||
Client client = new Client(config, userName);
|
||||
LocalDB localDB = new LocalDB(client.getSender());
|
||||
Client client = new Client(config, userName);
|
||||
LocalDB localDB = new LocalDB(client.getSender());
|
||||
try {
|
||||
localDB.initializeDBFile(config.getLocalDB());
|
||||
} catch (EnvoyException e) {
|
||||
e.printStackTrace();
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"Error while loading local database: " + e.toString() + "\nChats will not be stored locally.",
|
||||
"Local DB error",
|
||||
JOptionPane.WARNING_MESSAGE);
|
||||
"Local DB error", JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
|
||||
EventQueue.invokeLater(() -> {
|
||||
|
Reference in New Issue
Block a user