Added BugReporter and added logging when RequestManagers fail
This commit is contained in:
parent
2361da62eb
commit
a679c6d1a2
6 changed files with 223 additions and 19 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,3 +7,4 @@ src/main/java/META-INF/
|
|||
dependency-reduced-pom.xml
|
||||
config/
|
||||
logs/
|
||||
/RESTaurant/BugReporter.jar
|
||||
|
|
|
@ -180,14 +180,15 @@ public class DashboardController implements Initializable {
|
|||
requestManager.setOnFailed(e -> {
|
||||
loadingLayer.setVisible(false);
|
||||
promptLayer.setVisible(false);
|
||||
Throwable exception = requestManager.getException();
|
||||
exception.printStackTrace();
|
||||
Throwable throwable = requestManager.getException();
|
||||
Exception exception = (Exception) throwable;
|
||||
Services.loggingService.logWarning("GET request could not be processed.", exception, LocalDateTime.now());
|
||||
|
||||
if (exception.getClass() == UnreliableResponseException.class) {
|
||||
UnreliableResponseException URE = (UnreliableResponseException) exception;
|
||||
if (throwable.getClass() == UnreliableResponseException.class) {
|
||||
UnreliableResponseException URE = (UnreliableResponseException) throwable;
|
||||
errorTitle.setText(URE.getExceptionTitle());
|
||||
errorDetails.setText(URE.getExceptionDetails());
|
||||
} else if (exception.getClass() == ProcessingException.class) {
|
||||
} else if (throwable.getClass() == ProcessingException.class) {
|
||||
errorTitle.setText("RESTaurant couldn't connect.");
|
||||
errorDetails.setText("Either you are not connected to the Internet or the server is offline.");
|
||||
}
|
||||
|
@ -233,23 +234,24 @@ public class DashboardController implements Initializable {
|
|||
requestManager.setOnFailed(e -> {
|
||||
loadingLayer.setVisible(false);
|
||||
promptLayer.setVisible(false);
|
||||
Throwable exception = requestManager.getException();
|
||||
exception.printStackTrace();
|
||||
Throwable throwable = requestManager.getException();
|
||||
Exception exception = (Exception) throwable;
|
||||
Services.loggingService.logWarning(httpMethodBox.getValue() + " request could not be processed.", exception, LocalDateTime.now());
|
||||
|
||||
if (exception.getClass() == UnreliableResponseException.class) {
|
||||
UnreliableResponseException URE = (UnreliableResponseException) exception;
|
||||
if (throwable.getClass() == UnreliableResponseException.class) {
|
||||
UnreliableResponseException URE = (UnreliableResponseException) throwable;
|
||||
errorTitle.setText(URE.getExceptionTitle());
|
||||
errorDetails.setText(URE.getExceptionDetails());
|
||||
} else if (exception.getClass() == ProcessingException.class) {
|
||||
if (exception.getCause().getClass() == UnknownHostException.class ||
|
||||
exception.getCause().getClass() == ConnectException.class) {
|
||||
} else if (throwable.getClass() == ProcessingException.class) {
|
||||
if (throwable.getCause().getClass() == UnknownHostException.class ||
|
||||
throwable.getCause().getClass() == ConnectException.class) {
|
||||
errorTitle.setText("RESTaurant couldn't connect.");
|
||||
errorDetails.setText("Either you are not connected to the Internet or the server is offline.");
|
||||
} else if (exception.getCause().getClass() == IllegalArgumentException.class) {
|
||||
} else if (throwable.getCause().getClass() == IllegalArgumentException.class) {
|
||||
errorTitle.setText("Did you forget something?");
|
||||
errorDetails.setText("Please specify at least one body part for your " + httpMethodBox.getValue() + " request.");
|
||||
}
|
||||
} else if (exception.getClass() == FileNotFoundException.class)
|
||||
} else if (throwable.getClass() == FileNotFoundException.class)
|
||||
snackBar.show("File could not be found.", 5000);
|
||||
errorLayer.setVisible(true);
|
||||
requestManager.reset();
|
||||
|
@ -288,14 +290,15 @@ public class DashboardController implements Initializable {
|
|||
requestManager.setOnFailed(e -> {
|
||||
loadingLayer.setVisible(false);
|
||||
promptLayer.setVisible(false);
|
||||
Throwable exception = requestManager.getException();
|
||||
exception.printStackTrace();
|
||||
Throwable throwable = requestManager.getException();
|
||||
Exception exception = (Exception) throwable;
|
||||
Services.loggingService.logWarning("DELETE request could not be processed.", exception, LocalDateTime.now());
|
||||
|
||||
if (exception.getClass() == UnreliableResponseException.class) {
|
||||
UnreliableResponseException URE = (UnreliableResponseException) exception;
|
||||
if (throwable.getClass() == UnreliableResponseException.class) {
|
||||
UnreliableResponseException URE = (UnreliableResponseException) throwable;
|
||||
errorTitle.setText(URE.getExceptionTitle());
|
||||
errorDetails.setText(URE.getExceptionDetails());
|
||||
} else if (exception.getClass() == ProcessingException.class) {
|
||||
} else if (throwable.getClass() == ProcessingException.class) {
|
||||
errorTitle.setText("No Internet Connection");
|
||||
errorDetails.setText("Could not connect to the server. Please check your connection.");
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package com.rohitawate.restaurant.main;
|
||||
|
||||
import com.rohitawate.restaurant.util.MiscUtils;
|
||||
import com.rohitawate.restaurant.util.Services;
|
||||
import com.rohitawate.restaurant.util.settings.SettingsLoader;
|
||||
import com.rohitawate.restaurant.util.themes.ThemeManager;
|
||||
|
@ -44,6 +45,8 @@ public class Main extends Application {
|
|||
dashboardStage.setScene(new Scene(homeWindow));
|
||||
dashboardStage.setTitle("RESTaurant");
|
||||
dashboardStage.show();
|
||||
|
||||
MiscUtils.createBugReporter();
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
|
|
168
src/main/java/com/rohitawate/restaurant/util/BugReporter.java
Normal file
168
src/main/java/com/rohitawate/restaurant/util/BugReporter.java
Normal file
|
@ -0,0 +1,168 @@
|
|||
/*
|
||||
* Copyright 2018 Rohit Awate.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.rohitawate.restaurant.util;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Scanner;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
public class BugReporter {
|
||||
public static void main(String args[]) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.println("RESTaurant Bug Reporting Service");
|
||||
System.out.println();
|
||||
System.out.println("Please describe the issue with as much detail and clarity as possible: ");
|
||||
String userMessage = scanner.nextLine();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("\nThank you for your input! The issue was recorded.\n\n");
|
||||
builder.append("With your permission, this service can collect some anonymous, non-personal information about your system.\n");
|
||||
builder.append("This information will help us to better reproduce the issue and fix it quickly.\n");
|
||||
builder.append("This includes:\n");
|
||||
builder.append(" - Operating system details.\n");
|
||||
builder.append(" - Details about your Java Runtime Environment.\n\n");
|
||||
builder.append("Allow? (Y/N)\n>> ");
|
||||
System.out.print(builder.toString());
|
||||
String allowSystemData = scanner.nextLine();
|
||||
|
||||
allowSystemData = allowSystemData.toLowerCase();
|
||||
|
||||
StringBuilder report = new StringBuilder();
|
||||
report.append("Log date: ");
|
||||
report.append(LocalDateTime.now());
|
||||
report.append("\n\n");
|
||||
if (allowSystemData.equals("y") || allowSystemData.equals("yes")) {
|
||||
report.append(generateSystemDetails());
|
||||
System.out.println("\nThat's great! We will include your system details in with the bug report.");
|
||||
} else {
|
||||
System.out.println("\nAlrighty! We will only include RESTaurant's log files in the report.");
|
||||
}
|
||||
|
||||
scanner.close();
|
||||
report.append("User Message:\n");
|
||||
report.append(userMessage);
|
||||
generateReport(report.toString());
|
||||
generateZipFile();
|
||||
|
||||
System.out.println("\nYour issue was successfully reported and will be fixed soon.");
|
||||
System.out.println("Thank you! :)");
|
||||
}
|
||||
|
||||
private static String generateSystemDetails() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String OS = System.getProperty("os.name");
|
||||
if (OS.equals("Linux")) {
|
||||
builder.append(getLinuxDetails());
|
||||
}
|
||||
builder.append("OS: ");
|
||||
builder.append(OS);
|
||||
builder.append(" ");
|
||||
builder.append(System.getProperty("os.arch"));
|
||||
builder.append(" ");
|
||||
builder.append(System.getProperty("os.version"));
|
||||
builder.append("\n");
|
||||
builder.append("Java VM: ");
|
||||
builder.append(System.getProperty("java.vm.name"));
|
||||
builder.append(" ");
|
||||
builder.append(System.getProperty("java.version"));
|
||||
builder.append("\nJava VM Vendor: ");
|
||||
builder.append(System.getProperty("java.vendor"));
|
||||
builder.append("\n\n");
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static void generateReport(String reportContents) {
|
||||
String reportFileName = "Report - " + LocalDate.now() + ".txt";
|
||||
try {
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter("logs/" + reportFileName));
|
||||
writer.write(reportContents);
|
||||
writer.close();
|
||||
} catch (IOException IOE) {
|
||||
IOE.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateZipFile() {
|
||||
try {
|
||||
Scanner scanner;
|
||||
FileInputStream fileInputStream;
|
||||
ZipOutputStream zipStream = new ZipOutputStream(new FileOutputStream("Logs.zip"), Charset.forName("UTF-8"));
|
||||
File sourceDir = new File("logs/");
|
||||
String[] logFiles = sourceDir.list();
|
||||
|
||||
for (String logFile : logFiles) {
|
||||
zipStream.putNextEntry(new ZipEntry(logFile));
|
||||
|
||||
fileInputStream = new FileInputStream("logs/" + logFile);
|
||||
scanner = new Scanner(fileInputStream);
|
||||
|
||||
while (scanner.hasNext()) {
|
||||
zipStream.flush();
|
||||
zipStream.write(scanner.nextLine().getBytes());
|
||||
zipStream.write('\n');
|
||||
}
|
||||
|
||||
zipStream.closeEntry();
|
||||
scanner.close();
|
||||
fileInputStream.close();
|
||||
}
|
||||
|
||||
zipStream.close();
|
||||
} catch (IOException IOE) {
|
||||
IOE.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static String getLinuxDetails() {
|
||||
String line = "";
|
||||
|
||||
try {
|
||||
File etcDir = new File("/etc/");
|
||||
String releaseFile = "";
|
||||
for (String file : etcDir.list()) {
|
||||
if (file.endsWith("-release")) {
|
||||
releaseFile = file;
|
||||
break;
|
||||
}
|
||||
}
|
||||
BufferedReader reader = new BufferedReader(new FileReader("/etc/" + releaseFile));
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.startsWith("PRETTY_NAME"))
|
||||
break;
|
||||
}
|
||||
reader.close();
|
||||
if (!line.equals("")) {
|
||||
line = "Distribution: " + line.substring(13, line.length() - 1) + "\n";
|
||||
}
|
||||
} catch (IOException IOE) {
|
||||
line = "";
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.println("We couldn't fetch information about your Linux distribution. Please fill in the following details:");
|
||||
System.out.println("Distribution name: ");
|
||||
line += "Distribution: " + scanner.nextLine() + "\n";
|
||||
System.out.println("Version: ");
|
||||
line += "Version: " + scanner.nextLine() + "\n";
|
||||
scanner.close();
|
||||
}
|
||||
return line;
|
||||
}
|
||||
}
|
|
@ -16,6 +16,14 @@
|
|||
|
||||
package com.rohitawate.restaurant.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class MiscUtils {
|
||||
/**
|
||||
* Removes leading and trailing quotation marks from strings.
|
||||
|
@ -26,4 +34,25 @@ public class MiscUtils {
|
|||
public static String trimString(String input) {
|
||||
return input.replaceAll("\"", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the BugReporter from within the JAR to the installation directory.
|
||||
*/
|
||||
public static void createBugReporter() {
|
||||
new Thread(() -> {
|
||||
File bugReporterFile = new File("RESTaurant/BugReporter.jar");
|
||||
if (!bugReporterFile.exists()) {
|
||||
InputStream inputStream = MiscUtils.class.getResourceAsStream("/BugReporter.jar");
|
||||
Path bugReporter = Paths.get("RESTaurant/BugReporter.jar");
|
||||
try {
|
||||
Files.copy(inputStream, bugReporter);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Services.loggingService.logInfo("BugReporter was copied to installation folder.", LocalDateTime.now());
|
||||
} else {
|
||||
Services.loggingService.logInfo("BugReporter was found.", LocalDateTime.now());
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
|
|
BIN
src/main/resources/BugReporter.jar
Normal file
BIN
src/main/resources/BugReporter.jar
Normal file
Binary file not shown.
Loading…
Reference in a new issue