From 74aa6662081d5704f75ef63283fc8f3e8ae68ae4 Mon Sep 17 00:00:00 2001 From: Rohit Awate Date: Fri, 2 Feb 2018 16:42:37 +0530 Subject: [PATCH] Added ErrorLayer over ResponseArea and made minor UI tweaks --- .../dashboard/DashboardController.java | 40 ++++++++++++++---- .../requestsmanager/POSTRequestManager.java | 8 +++- src/main/resources/assets/Explosion.png | Bin 0 -> 4676 bytes src/main/resources/css/Default.css | 4 ++ .../resources/fxml/dashboard/Dashboard.fxml | 22 ++++++++++ .../resources/fxml/dashboard/HeaderTab.fxml | 4 +- src/main/resources/fxml/dashboard/URLTab.fxml | 2 +- 7 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 src/main/resources/assets/Explosion.png diff --git a/src/main/java/com/rohitawate/restaurant/dashboard/DashboardController.java b/src/main/java/com/rohitawate/restaurant/dashboard/DashboardController.java index 7f00448..339addf 100644 --- a/src/main/java/com/rohitawate/restaurant/dashboard/DashboardController.java +++ b/src/main/java/com/rohitawate/restaurant/dashboard/DashboardController.java @@ -35,9 +35,12 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javax.ws.rs.core.Response; +import java.io.FileNotFoundException; import java.io.IOException; +import java.net.ConnectException; import java.net.MalformedURLException; import java.net.URL; +import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; import java.util.ResourceBundle; @@ -50,13 +53,13 @@ public class DashboardController implements Initializable { @FXML private ComboBox httpMethodBox; @FXML - private VBox responseBox, loadingLayer, promptLayer, paramsBox; + private VBox responseBox, loadingLayer, promptLayer, errorLayer, paramsBox; @FXML private HBox responseDetails; @FXML private TextArea responseArea; @FXML - private Label statusCode, statusCodeDescription, responseTime, responseSize; + private Label statusCode, statusCodeDescription, responseTime, responseSize, errorTitle, errorDetails; @FXML private JFXButton cancelButton; @FXML @@ -92,11 +95,13 @@ public class DashboardController implements Initializable { IOE.printStackTrace(); } - addressField.setText("http://localhost:8080/api/members/file"); + addressField.setText("https://anapioficeandfire.com/api/characters/583"); responseBox.getChildren().remove(0); promptLayer.setVisible(true); httpMethodBox.getItems().addAll(httpMethods); - httpMethodBox.getSelectionModel().select(1); + + // Selects GET by default + httpMethodBox.getSelectionModel().select(0); paramsControllers = new ArrayList<>(); appendedParams = new ArrayList<>(); @@ -139,10 +144,12 @@ public class DashboardController implements Initializable { cancelButton.setOnAction(e -> requestManager.cancel()); requestManager.setOnRunning(e -> { responseArea.clear(); + errorLayer.setVisible(false); loadingLayer.setVisible(true); }); requestManager.setOnSucceeded(e -> { updateDashboard(requestManager.getValue()); + errorLayer.setVisible(false); loadingLayer.setVisible(false); requestManager.reset(); }); @@ -154,8 +161,13 @@ public class DashboardController implements Initializable { }); requestManager.setOnFailed(e -> { loadingLayer.setVisible(false); - promptLayer.setVisible(true); - snackBar.show("Request timed out. Server is unavailable or didn't respond.", 10000); + errorLayer.setVisible(true); + Throwable exception = requestManager.getException().getCause(); + + if (exception.getClass() == UnknownHostException.class) { + errorTitle.setText("No Internet Connection"); + errorDetails.setText("Could not connect to the server. Please check your connection."); + } requestManager.reset(); }); requestManager.start(); @@ -176,10 +188,12 @@ public class DashboardController implements Initializable { cancelButton.setOnAction(e -> requestManager.cancel()); requestManager.setOnRunning(e -> { responseArea.clear(); + errorLayer.setVisible(false); loadingLayer.setVisible(true); }); requestManager.setOnSucceeded(e -> { updateDashboard(requestManager.getValue()); + errorLayer.setVisible(false); loadingLayer.setVisible(false); requestManager.reset(); }); @@ -189,7 +203,15 @@ public class DashboardController implements Initializable { snackBar.show("Request canceled.", 2000); requestManager.reset(); }); - requestManager.setOnFailed(e -> requestManager.getException().printStackTrace()); + requestManager.setOnFailed(e -> { + loadingLayer.setVisible(false); + promptLayer.setVisible(true); + if (requestManager.getException().getClass() == ConnectException.class) + snackBar.show("Request timed out. Server is unavailable or didn't respond.", 10000); + else if (requestManager.getException().getClass() == FileNotFoundException.class) + snackBar.show("File could not be found.", 5000); + requestManager.reset(); + }); requestManager.start(); break; default: @@ -198,7 +220,9 @@ public class DashboardController implements Initializable { } catch (MalformedURLException MURLE) { snackBar.show("Invalid address. Please verify and try again.", 3000); } catch (Exception E) { - snackBar.show("Something went wrong. Couldn't process request.", 5000); + errorLayer.setVisible(true); + errorTitle.setText("Oops... That's embarrassing!"); + errorDetails.setText("Something went wrong. Try to make another request.\nRestart RESTaurant if that doesn't work."); } } diff --git a/src/main/java/com/rohitawate/restaurant/requestsmanager/POSTRequestManager.java b/src/main/java/com/rohitawate/restaurant/requestsmanager/POSTRequestManager.java index 910a911..4c9952f 100644 --- a/src/main/java/com/rohitawate/restaurant/requestsmanager/POSTRequestManager.java +++ b/src/main/java/com/rohitawate/restaurant/requestsmanager/POSTRequestManager.java @@ -73,11 +73,17 @@ public class POSTRequestManager extends RequestManager { String filePath; File file; + InputStream stream; pairs = postRequest.getFileTuples(); for (Map.Entry entry : pairs.entrySet()) { mapEntry = (Map.Entry) entry; filePath = mapEntry.getValue(); file = new File(filePath); + /* + Creating a stream only because it throws + FileNotFoundException if file doesn't exist. + */ + stream = new FileInputStream(file); formData.bodyPart(new FileDataBodyPart(mapEntry.getKey(), file, MediaType.APPLICATION_OCTET_STREAM_TYPE)); } @@ -87,7 +93,7 @@ public class POSTRequestManager extends RequestManager { invocation = requestBuilder.buildPost(Entity.entity(formData, MediaType.MULTIPART_FORM_DATA_TYPE)); break; case MediaType.APPLICATION_OCTET_STREAM: - InputStream stream = new FileInputStream(postRequest.getBody()); + stream = new FileInputStream(postRequest.getBody()); invocation = requestBuilder.buildPost(Entity.entity(stream, MediaType.APPLICATION_OCTET_STREAM_TYPE)); break; case MediaType.APPLICATION_FORM_URLENCODED: diff --git a/src/main/resources/assets/Explosion.png b/src/main/resources/assets/Explosion.png new file mode 100644 index 0000000000000000000000000000000000000000..8de0e28c3f73be9b82153128e04a004d2f97611f GIT binary patch literal 4676 zcmZ{o_dgU4;Q#OJ9pR3wWL3nGkuCe|l`UtJ-DM=lDI-$2IAn!0LUv~MUWcP>cad=! zhh&e>`}=r&fBbxYc&&fn`NJ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w>Jv?F3Drtw*a|NL`4UpUqPaSF11=aje z^;j!e%4?i7c2Pry3dL$_$KOnHhYhiZIGIZBKqeB|vpela-hdR*gl7V$N~tRx`I&OG zb`<)M9u0P{xmZYJ#hU9QFXxx!l|9cd(hSLDK!J2{SH^>@E|k-{>TE1ztQ6dbcebTOEG`DkMNKOZd(|19INQ zK5^akf#tS&57kK3G$H$}nUHO%e3;-nq+W?0rTh`UdMnAeg(D^ID4rW!rMsbz5)3!h zj1;G0U_!V&W8{ZE5ej-CDdbD9-g272_$oUCBolRcOdK$xf3 z@_ltF-+KC&A`zTF3@+$rm0swu4uc!x9$3J0xcaf@_U>k4zsoks4c&-{RAhY8CU>W- zVP?F)rmt9GdO@6IoPvTPQ6mv$;}VOl&-RPx-32$be+!!J~bo zxbb{#cc7`iNXpjn1r~t=4gcRai_9|v`wP|a^ifAJ6V&&=cL)I0GSaM6hrRwE3a0_E literal 0 HcmV?d00001 diff --git a/src/main/resources/css/Default.css b/src/main/resources/css/Default.css index 4b3fc24..18ffaec 100644 --- a/src/main/resources/css/Default.css +++ b/src/main/resources/css/Default.css @@ -66,6 +66,10 @@ -fx-background-color: #273154; } +#errorLayer { + -fx-background-color: #822f2f; +} + #cancelButton { -fx-background-color: black; } diff --git a/src/main/resources/fxml/dashboard/Dashboard.fxml b/src/main/resources/fxml/dashboard/Dashboard.fxml index 4df9fe9..839566a 100644 --- a/src/main/resources/fxml/dashboard/Dashboard.fxml +++ b/src/main/resources/fxml/dashboard/Dashboard.fxml @@ -264,6 +264,28 @@ + + + + + + + + + + + diff --git a/src/main/resources/fxml/dashboard/HeaderTab.fxml b/src/main/resources/fxml/dashboard/HeaderTab.fxml index 544bc5a..f406ceb 100644 --- a/src/main/resources/fxml/dashboard/HeaderTab.fxml +++ b/src/main/resources/fxml/dashboard/HeaderTab.fxml @@ -46,10 +46,10 @@ - + - + diff --git a/src/main/resources/fxml/dashboard/URLTab.fxml b/src/main/resources/fxml/dashboard/URLTab.fxml index b70e4af..a0b12e9 100644 --- a/src/main/resources/fxml/dashboard/URLTab.fxml +++ b/src/main/resources/fxml/dashboard/URLTab.fxml @@ -25,7 +25,7 @@ - +