From 4753d433b59396935b2f13629c2c501f2033c263 Mon Sep 17 00:00:00 2001
From: Rohit Awate
Date: Sat, 28 Apr 2018 21:54:36 +0530
Subject: [PATCH 01/15] Added RequestManagersPool to re-use managers
---
.../controllers/DashboardController.java | 37 ++------
.../requestmanager/DELETERequestManager.java | 9 +-
.../DataDispatchRequestManager.java | 9 +-
.../requestmanager/GETRequestManager.java | 9 +-
.../requestmanager/RequestManager.java | 16 +++-
.../requestmanager/RequestManagersPool.java | 94 +++++++++++++++++++
.../com/rohitawate/everest/util/Services.java | 3 +
src/main/resources/templates/LogsFile.html | 2 +-
8 files changed, 128 insertions(+), 51 deletions(-)
create mode 100644 src/main/java/com/rohitawate/everest/requestmanager/RequestManagersPool.java
diff --git a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java
index 8e2b1c4..fe04cfc 100644
--- a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java
+++ b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java
@@ -25,9 +25,7 @@ import com.rohitawate.everest.models.requests.DELETERequest;
import com.rohitawate.everest.models.requests.DataDispatchRequest;
import com.rohitawate.everest.models.requests.GETRequest;
import com.rohitawate.everest.models.responses.EverestResponse;
-import com.rohitawate.everest.requestmanager.DELETERequestManager;
import com.rohitawate.everest.requestmanager.DataDispatchRequestManager;
-import com.rohitawate.everest.requestmanager.GETRequestManager;
import com.rohitawate.everest.requestmanager.RequestManager;
import com.rohitawate.everest.util.EverestUtilities;
import com.rohitawate.everest.util.Services;
@@ -169,18 +167,8 @@ public class DashboardController implements Initializable {
GETRequest getRequest = new GETRequest(addressField.getText());
getRequest.setHeaders(headerTabController.getHeaders());
- /*
- Creates a new instance if its the first request of that session or
- the HTTP method type was changed. Also checks if a request is already being processed.
- */
- if (requestManager == null || requestManager.getClass() != GETRequestManager.class)
- requestManager = new GETRequestManager(getRequest);
- else if (requestManager.isRunning()) {
- snackbar.show("Please wait while the current request is processed.", 3000);
- return;
- } else {
- requestManager.setRequest(getRequest);
- }
+ requestManager = Services.pool.get();
+ requestManager.setRequest(getRequest);
cancelButton.setOnAction(e -> requestManager.cancel());
configureRequestManager();
@@ -195,14 +183,8 @@ public class DashboardController implements Initializable {
dataDispatchRequest.setTarget(addressField.getText());
dataDispatchRequest.setHeaders(headerTabController.getHeaders());
- if (requestManager == null || requestManager.getClass() != DataDispatchRequestManager.class)
- requestManager = new DataDispatchRequestManager(dataDispatchRequest);
- else if (requestManager.isRunning()) {
- snackbar.show("Please wait while the current request is processed.", 3000);
- return;
- } else {
- requestManager.setRequest(dataDispatchRequest);
- }
+ requestManager = Services.pool.data();
+ requestManager.setRequest(dataDispatchRequest);
cancelButton.setOnAction(e -> requestManager.cancel());
configureRequestManager();
@@ -212,16 +194,9 @@ public class DashboardController implements Initializable {
DELETERequest deleteRequest = new DELETERequest(addressField.getText());
deleteRequest.setHeaders(headerTabController.getHeaders());
- if (requestManager == null || requestManager.getClass() != DELETERequestManager.class)
- requestManager = new DELETERequestManager(deleteRequest);
- else if (requestManager.isRunning()) {
- snackbar.show("Please wait while the current request is processed.", 3000);
- return;
- } else {
- requestManager.setRequest(deleteRequest);
- }
-
+ requestManager = Services.pool.delete();
requestManager.setRequest(deleteRequest);
+
cancelButton.setOnAction(e -> requestManager.cancel());
configureRequestManager();
requestManager.start();
diff --git a/src/main/java/com/rohitawate/everest/requestmanager/DELETERequestManager.java b/src/main/java/com/rohitawate/everest/requestmanager/DELETERequestManager.java
index 693167a..61ae6b6 100644
--- a/src/main/java/com/rohitawate/everest/requestmanager/DELETERequestManager.java
+++ b/src/main/java/com/rohitawate/everest/requestmanager/DELETERequestManager.java
@@ -16,7 +16,6 @@
package com.rohitawate.everest.requestmanager;
-import com.rohitawate.everest.models.requests.EverestRequest;
import com.rohitawate.everest.models.responses.EverestResponse;
import javafx.concurrent.Task;
@@ -25,8 +24,8 @@ import javax.ws.rs.core.Response;
public class DELETERequestManager extends RequestManager {
- public DELETERequestManager(EverestRequest request) {
- super(request);
+ DELETERequestManager() {
+
}
@Override
@@ -36,9 +35,9 @@ public class DELETERequestManager extends RequestManager {
protected EverestResponse call() throws Exception {
Invocation invocation = requestBuilder.buildDelete();
- long initialTime = System.currentTimeMillis();
+ initialTime = System.currentTimeMillis();
Response serverResponse = invocation.invoke();
- response.setTime(initialTime, System.currentTimeMillis());
+ finalTime = System.currentTimeMillis();
processServerResponse(serverResponse);
diff --git a/src/main/java/com/rohitawate/everest/requestmanager/DataDispatchRequestManager.java b/src/main/java/com/rohitawate/everest/requestmanager/DataDispatchRequestManager.java
index 42d0ce8..ede26dc 100644
--- a/src/main/java/com/rohitawate/everest/requestmanager/DataDispatchRequestManager.java
+++ b/src/main/java/com/rohitawate/everest/requestmanager/DataDispatchRequestManager.java
@@ -17,7 +17,6 @@
package com.rohitawate.everest.requestmanager;
import com.rohitawate.everest.models.requests.DataDispatchRequest;
-import com.rohitawate.everest.models.requests.EverestRequest;
import com.rohitawate.everest.models.responses.EverestResponse;
import javafx.concurrent.Task;
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
@@ -42,8 +41,8 @@ public class DataDispatchRequestManager extends RequestManager {
private DataDispatchRequest dataDispatchRequest;
private String requestType;
- public DataDispatchRequestManager(EverestRequest request) {
- super(request);
+ DataDispatchRequestManager() {
+
}
@Override
@@ -55,9 +54,9 @@ public class DataDispatchRequestManager extends RequestManager {
requestType = dataDispatchRequest.getRequestType();
Invocation invocation = appendBody();
- long initialTime = System.currentTimeMillis();
+ initialTime = System.currentTimeMillis();
Response serverResponse = invocation.invoke();
- response.setTime(initialTime, System.currentTimeMillis());
+ finalTime = System.currentTimeMillis();
processServerResponse(serverResponse);
diff --git a/src/main/java/com/rohitawate/everest/requestmanager/GETRequestManager.java b/src/main/java/com/rohitawate/everest/requestmanager/GETRequestManager.java
index bbf18dc..951510f 100644
--- a/src/main/java/com/rohitawate/everest/requestmanager/GETRequestManager.java
+++ b/src/main/java/com/rohitawate/everest/requestmanager/GETRequestManager.java
@@ -16,7 +16,6 @@
package com.rohitawate.everest.requestmanager;
-import com.rohitawate.everest.models.requests.EverestRequest;
import com.rohitawate.everest.models.responses.EverestResponse;
import javafx.concurrent.Task;
@@ -24,8 +23,8 @@ import javax.ws.rs.core.Response;
public class GETRequestManager extends RequestManager {
- public GETRequestManager(EverestRequest request) {
- super(request);
+ GETRequestManager() {
+
}
@Override
@@ -33,9 +32,9 @@ public class GETRequestManager extends RequestManager {
return new Task() {
@Override
protected EverestResponse call() throws Exception {
- long initialTime = System.currentTimeMillis();
+ initialTime = System.currentTimeMillis();
Response serverResponse = requestBuilder.get();
- response.setTime(initialTime, System.currentTimeMillis());
+ finalTime = System.currentTimeMillis();
processServerResponse(serverResponse);
diff --git a/src/main/java/com/rohitawate/everest/requestmanager/RequestManager.java b/src/main/java/com/rohitawate/everest/requestmanager/RequestManager.java
index 532183f..405fd05 100644
--- a/src/main/java/com/rohitawate/everest/requestmanager/RequestManager.java
+++ b/src/main/java/com/rohitawate/everest/requestmanager/RequestManager.java
@@ -34,11 +34,19 @@ import java.util.Map;
public abstract class RequestManager extends Service {
private final Client client;
+ long initialTime;
+ long finalTime;
+
EverestRequest request;
EverestResponse response;
Builder requestBuilder;
- RequestManager(EverestRequest request) {
+ RequestManager() {
+ this.client = initClient();
+ }
+
+ private Client initClient() {
+ Client client;
client = ClientBuilder.newBuilder()
.register(MultiPartFeature.class)
.build();
@@ -48,9 +56,7 @@ public abstract class RequestManager extends Service {
client.property(ClientProperties.CONNECT_TIMEOUT, Settings.connectionTimeOut);
if (Settings.connectionReadTimeOutEnable)
client.property(ClientProperties.READ_TIMEOUT, Settings.connectionReadTimeOut);
-
- response = new EverestResponse();
- setRequest(request);
+ return client;
}
public void setRequest(EverestRequest request) {
@@ -80,7 +86,9 @@ public abstract class RequestManager extends Service {
}
String responseBody = serverResponse.readEntity(String.class);
+ response = new EverestResponse();
+ response.setTime(initialTime, finalTime);
response.setBody(responseBody);
response.setMediaType(serverResponse.getMediaType());
response.setStatusCode(serverResponse.getStatus());
diff --git a/src/main/java/com/rohitawate/everest/requestmanager/RequestManagersPool.java b/src/main/java/com/rohitawate/everest/requestmanager/RequestManagersPool.java
new file mode 100644
index 0000000..a081c0e
--- /dev/null
+++ b/src/main/java/com/rohitawate/everest/requestmanager/RequestManagersPool.java
@@ -0,0 +1,94 @@
+/*
+ * 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.everest.requestmanager;
+
+import java.util.LinkedList;
+
+public class RequestManagersPool {
+ private LinkedList getManagers;
+ private LinkedList dataManagers;
+ private LinkedList deleteManagers;
+
+ public GETRequestManager get() {
+ if (getManagers == null) {
+ GETRequestManager newManager = new GETRequestManager();
+
+ new Thread(() -> {
+ getManagers = new LinkedList<>();
+ getManagers.add(newManager);
+ }).start();
+
+ return newManager;
+ } else {
+ for (GETRequestManager getManager : getManagers) {
+ if (!getManager.isRunning())
+ return getManager;
+ }
+
+ GETRequestManager newManager = new GETRequestManager();
+ getManagers.add(newManager);
+
+ return newManager;
+ }
+ }
+
+ public DataDispatchRequestManager data() {
+ if (dataManagers == null) {
+ DataDispatchRequestManager newManager = new DataDispatchRequestManager();
+
+ new Thread(() -> {
+ dataManagers = new LinkedList<>();
+ dataManagers.add(newManager);
+ }).start();
+
+ return newManager;
+ } else {
+ for (DataDispatchRequestManager dataManager : dataManagers) {
+ if (!dataManager.isRunning())
+ return dataManager;
+ }
+
+ DataDispatchRequestManager newManager = new DataDispatchRequestManager();
+ dataManagers.add(newManager);
+
+ return newManager;
+ }
+ }
+
+ public DELETERequestManager delete() {
+ if (deleteManagers == null) {
+ DELETERequestManager newManager = new DELETERequestManager();
+
+ new Thread(() -> {
+ deleteManagers = new LinkedList<>();
+ deleteManagers.add(newManager);
+ }).start();
+
+ return newManager;
+ } else {
+ for (DELETERequestManager deleteManager : deleteManagers) {
+ if (!deleteManager.isRunning())
+ return deleteManager;
+ }
+
+ DELETERequestManager newManager = new DELETERequestManager();
+ deleteManagers.add(newManager);
+
+ return newManager;
+ }
+ }
+}
diff --git a/src/main/java/com/rohitawate/everest/util/Services.java b/src/main/java/com/rohitawate/everest/util/Services.java
index d165e1a..4f84c57 100644
--- a/src/main/java/com/rohitawate/everest/util/Services.java
+++ b/src/main/java/com/rohitawate/everest/util/Services.java
@@ -18,6 +18,7 @@ package com.rohitawate.everest.util;
import com.google.common.util.concurrent.MoreExecutors;
import com.rohitawate.everest.controllers.HomeWindowController;
+import com.rohitawate.everest.requestmanager.RequestManagersPool;
import com.rohitawate.everest.util.history.HistoryManager;
import com.rohitawate.everest.util.logging.Level;
import com.rohitawate.everest.util.logging.LoggingService;
@@ -30,12 +31,14 @@ public class Services {
public static LoggingService loggingService;
public static HomeWindowController homeWindowController;
public static Executor singleExecutor;
+ public static RequestManagersPool pool;
public static void start() {
startServicesThread = new Thread(() -> {
loggingService = new LoggingService(Level.INFO);
historyManager = new HistoryManager();
singleExecutor = MoreExecutors.directExecutor();
+ pool = new RequestManagersPool();
});
startServicesThread.start();
diff --git a/src/main/resources/templates/LogsFile.html b/src/main/resources/templates/LogsFile.html
index 927daf1..5cf28b2 100644
--- a/src/main/resources/templates/LogsFile.html
+++ b/src/main/resources/templates/LogsFile.html
@@ -24,7 +24,7 @@
margin: 0px;
background-color: #282828;
font-size: 15px;
- font-family: monospace;
+ font-family: "Liberation Mono", monospace;
}
h1 {
From b81b67cc6fd7d27d35ee66a04bb8c8f2a16d9c13 Mon Sep 17 00:00:00 2001
From: Rohit Awate
Date: Sat, 28 Apr 2018 22:43:02 +0530
Subject: [PATCH 02/15] Added Request object recycling to DashboardController
---
.../controllers/BodyTabController.java | 12 ++--
.../controllers/DashboardController.java | 71 +++++++++++++++----
.../models/requests/DataDispatchRequest.java | 4 ++
3 files changed, 68 insertions(+), 19 deletions(-)
diff --git a/src/main/java/com/rohitawate/everest/controllers/BodyTabController.java b/src/main/java/com/rohitawate/everest/controllers/BodyTabController.java
index e9147f9..2ea9289 100644
--- a/src/main/java/com/rohitawate/everest/controllers/BodyTabController.java
+++ b/src/main/java/com/rohitawate/everest/controllers/BodyTabController.java
@@ -44,16 +44,16 @@ public class BodyTabController implements Initializable {
@FXML
private TabPane bodyTabPane;
@FXML
- private ComboBox rawInputTypeBox;
+ ComboBox rawInputTypeBox;
@FXML
- private TextArea rawInputArea;
+ TextArea rawInputArea;
@FXML
- private Tab rawTab, binaryTab, formTab, urlTab;
+ Tab rawTab, binaryTab, formTab, urlTab;
@FXML
- private TextField filePathField;
+ TextField filePathField;
- private FormDataTabController formDataTabController;
- private URLTabController urlTabController;
+ FormDataTabController formDataTabController;
+ URLTabController urlTabController;
@Override
public void initialize(URL location, ResourceBundle resources) {
diff --git a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java
index fe04cfc..003e349 100644
--- a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java
+++ b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java
@@ -47,6 +47,7 @@ import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javax.ws.rs.ProcessingException;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -73,7 +74,7 @@ public class DashboardController implements Initializable {
private Label statusCode, statusCodeDescription, responseTime,
responseSize, errorTitle, errorDetails, responseType;
@FXML
- private JFXButton sendButton, cancelButton;
+ private JFXButton cancelButton;
@FXML
TabPane requestOptionsTab;
@FXML
@@ -93,6 +94,10 @@ public class DashboardController implements Initializable {
private IntegerProperty paramsCountProperty;
private Accordion accordion;
+ private GETRequest getRequest;
+ private DataDispatchRequest dataRequest;
+ private DELETERequest deleteRequest;
+
@Override
public void initialize(URL url, ResourceBundle rb) {
applyDashboardSettings();
@@ -142,7 +147,7 @@ public class DashboardController implements Initializable {
});
errorTitle.setText("Oops... That's embarrassing!");
- errorDetails.setText("Something went wrong. Try to make another request.\nRestart Everest if that doesn't work.");
+ errorDetails.setText("Something went wrong. Try to make another getRequest.\nRestart Everest if that doesn't work.");
setupVisualizer();
}
@@ -164,7 +169,10 @@ public class DashboardController implements Initializable {
}
switch (httpMethodBox.getValue()) {
case "GET":
- GETRequest getRequest = new GETRequest(addressField.getText());
+ if (getRequest == null)
+ getRequest = new GETRequest();
+
+ getRequest.setTarget(addressField.getText());
getRequest.setHeaders(headerTabController.getHeaders());
requestManager = Services.pool.get();
@@ -174,24 +182,61 @@ public class DashboardController implements Initializable {
configureRequestManager();
requestManager.start();
break;
- // DataDispatchRequestManager will generate appropriate request based on the type.
+ // DataDispatchRequestManager will generate appropriate getRequest based on the type.
case "POST":
case "PUT":
case "PATCH":
- DataDispatchRequest dataDispatchRequest =
- bodyTabController.getBasicRequest(httpMethodBox.getValue());
- dataDispatchRequest.setTarget(addressField.getText());
- dataDispatchRequest.setHeaders(headerTabController.getHeaders());
+ if (dataRequest == null)
+ dataRequest = new DataDispatchRequest();
+
+ dataRequest.setRequestType(httpMethodBox.getValue());
+ dataRequest.setTarget(addressField.getText());
+ dataRequest.setHeaders(headerTabController.getHeaders());
+
+ if (bodyTabController.rawTab.isSelected()) {
+ String contentType;
+ switch (bodyTabController.rawInputTypeBox.getValue()) {
+ case "PLAIN TEXT":
+ contentType = MediaType.TEXT_PLAIN;
+ break;
+ case "JSON":
+ contentType = MediaType.APPLICATION_JSON;
+ break;
+ case "XML":
+ contentType = MediaType.APPLICATION_XML;
+ break;
+ case "HTML":
+ contentType = MediaType.TEXT_HTML;
+ break;
+ default:
+ contentType = MediaType.TEXT_PLAIN;
+ }
+ dataRequest.setContentType(contentType);
+ dataRequest.setBody(bodyTabController.rawInputArea.getText());
+ } else if (bodyTabController.formTab.isSelected()) {
+ dataRequest.setStringTuples(bodyTabController.formDataTabController.getStringTuples());
+ dataRequest.setFileTuples(bodyTabController.formDataTabController.getFileTuples());
+ dataRequest.setContentType(MediaType.MULTIPART_FORM_DATA);
+ } else if (bodyTabController.binaryTab.isSelected()) {
+ dataRequest.setBody(bodyTabController.filePathField.getText());
+ dataRequest.setContentType(MediaType.APPLICATION_OCTET_STREAM);
+ } else if (bodyTabController.urlTab.isSelected()) {
+ dataRequest.setStringTuples(bodyTabController.urlTabController.getStringTuples());
+ dataRequest.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
+ }
requestManager = Services.pool.data();
- requestManager.setRequest(dataDispatchRequest);
+ requestManager.setRequest(dataRequest);
cancelButton.setOnAction(e -> requestManager.cancel());
configureRequestManager();
requestManager.start();
break;
case "DELETE":
- DELETERequest deleteRequest = new DELETERequest(addressField.getText());
+ if (deleteRequest == null)
+ deleteRequest = new DELETERequest();
+
+ deleteRequest.setTarget(addressField.getText());
deleteRequest.setHeaders(headerTabController.getHeaders());
requestManager = Services.pool.delete();
@@ -212,7 +257,7 @@ public class DashboardController implements Initializable {
Services.loggingService.logSevere("Request execution failed.", E, LocalDateTime.now());
errorLayer.setVisible(true);
errorTitle.setText("Oops... That's embarrassing!");
- errorDetails.setText("Something went wrong. Try to make another request.\nRestart Everest if that doesn't work.");
+ errorDetails.setText("Something went wrong. Try to make another getRequest.\nRestart Everest if that doesn't work.");
}
}
@@ -228,7 +273,7 @@ public class DashboardController implements Initializable {
promptLayer.setVisible(false);
Throwable throwable = requestManager.getException();
Exception exception = (Exception) throwable;
- Services.loggingService.logWarning(httpMethodBox.getValue() + " request could not be processed.", exception, LocalDateTime.now());
+ Services.loggingService.logWarning(httpMethodBox.getValue() + " getRequest could not be processed.", exception, LocalDateTime.now());
if (throwable.getClass() == UnreliableResponseException.class) {
UnreliableResponseException URE = (UnreliableResponseException) throwable;
@@ -249,7 +294,7 @@ public class DashboardController implements Initializable {
if (requestManager.getClass() == DataDispatchRequestManager.class) {
if (throwable.getCause() != null && 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.");
+ errorDetails.setText("Please specify at least one body part for your " + httpMethodBox.getValue() + " getRequest.");
} else if (throwable.getClass() == FileNotFoundException.class) {
errorTitle.setText("File(s) not found:");
errorDetails.setText(throwable.getMessage());
diff --git a/src/main/java/com/rohitawate/everest/models/requests/DataDispatchRequest.java b/src/main/java/com/rohitawate/everest/models/requests/DataDispatchRequest.java
index d8a499a..2638b3b 100644
--- a/src/main/java/com/rohitawate/everest/models/requests/DataDispatchRequest.java
+++ b/src/main/java/com/rohitawate/everest/models/requests/DataDispatchRequest.java
@@ -71,4 +71,8 @@ public class DataDispatchRequest extends EverestRequest implements Serializable
public String getRequestType() {
return requestType;
}
+
+ public void setRequestType(String requestType) {
+ this.requestType = requestType;
+ }
}
From c0e4d3f72ba175a451d7fac84cf010f688e2c177 Mon Sep 17 00:00:00 2001
From: Rohit Awate
Date: Sat, 28 Apr 2018 23:54:09 +0530
Subject: [PATCH 03/15] Heavily optimized Visualizer by switching from
Accordions to TreeView
---
.../controllers/DashboardController.java | 60 +++++++++----------
src/main/resources/css/Adreana.css | 52 +++++++++-------
2 files changed, 61 insertions(+), 51 deletions(-)
diff --git a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java
index 003e349..7ebf50a 100644
--- a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java
+++ b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java
@@ -38,7 +38,6 @@ import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
-import javafx.scene.CacheHint;
import javafx.scene.Parent;
import javafx.scene.control.*;
import javafx.scene.input.KeyCode;
@@ -92,7 +91,7 @@ public class DashboardController implements Initializable {
private HeaderTabController headerTabController;
private BodyTabController bodyTabController;
private IntegerProperty paramsCountProperty;
- private Accordion accordion;
+ private TreeView treeView;
private GETRequest getRequest;
private DataDispatchRequest dataRequest;
@@ -355,9 +354,10 @@ public class DashboardController implements Initializable {
responseType.setText("JSON");
JsonNode node = EverestUtilities.mapper.readTree(responseBody);
responseArea.setText(EverestUtilities.mapper.writeValueAsString(node));
- accordion.getPanes().clear();
visualizerTab.setDisable(false);
- populateVisualizer(accordion, "root", node);
+ TreeItem root = new TreeItem<>();
+ treeView.setRoot(root);
+ populateVisualizer(root, "root", node);
break;
case "application/xml":
responseType.setText("XML");
@@ -385,18 +385,19 @@ public class DashboardController implements Initializable {
}
private void setupVisualizer() {
- accordion = new Accordion();
- accordion.setCache(true);
- accordion.setCacheHint(CacheHint.SPEED);
- visualizer.setContent(accordion);
+ treeView = new TreeView<>();
+ visualizer.setContent(treeView);
}
- private void populateVisualizer(Accordion rootAccordion, String rootName, JsonNode root) {
+ private void populateVisualizer(TreeItem rootItem, String rootName, JsonNode root) {
+ Label rootLabel = new Label(rootName);
+ rootLabel.getStyleClass().addAll("visualizerRootLabel", "visualizerLabel");
+ rootItem.setValue(new HBox(rootLabel));
+
JsonNode currentNode;
- VBox container = new VBox();
- container.setStyle("-fx-padding: 3px 30px");
Label valueLabel;
- TitledPane pane = new TitledPane(rootName, container);
+ HBox valueContainer;
+ List> items = new LinkedList<>();
Tooltip valueTooltip;
if (root.isArray()) {
@@ -407,23 +408,22 @@ public class DashboardController implements Initializable {
if (currentNode.isValueNode()) {
valueLabel = new Label(currentNode.toString());
- valueLabel.getStyleClass().add("visualizerValueLabel");
+ valueLabel.getStyleClass().addAll("visualizerValueLabel", "visualizerLabel");
valueLabel.setWrapText(true);
valueTooltip = new Tooltip(currentNode.toString());
valueLabel.setTooltip(valueTooltip);
- container.getChildren().add(valueLabel);
+ valueContainer = new HBox(valueLabel);
+ items.add(new TreeItem<>(valueContainer));
} else if (currentNode.isObject()) {
- Accordion arrayAccordion = new Accordion();
- container.getChildren().add(arrayAccordion);
- populateVisualizer(arrayAccordion, "", currentNode);
+ TreeItem newRoot = new TreeItem<>();
+ items.add(newRoot);
+ populateVisualizer(newRoot, "", currentNode);
}
}
- rootAccordion.getPanes().add(pane);
} else {
Iterator> iterator = root.fields();
Entry currentEntry;
- HBox valueContainer;
Label keyLabel;
Tooltip keyTooltip;
@@ -433,32 +433,30 @@ public class DashboardController implements Initializable {
if (currentNode.isValueNode()) {
keyLabel = new Label(currentEntry.getKey() + ": ");
- keyLabel.setStyle("-fx-font-weight: bold");
- keyLabel.getStyleClass().add("visualizerKeyLabel");
+ keyLabel.getStyleClass().addAll("visualizerKeyLabel", "visualizerLabel");
keyTooltip = new Tooltip(currentEntry.getKey());
keyLabel.setTooltip(keyTooltip);
valueLabel = new Label(currentNode.toString());
- valueLabel.getStyleClass().add("visualizerValueLabel");
+ valueLabel.getStyleClass().addAll("visualizerValueLabel", "visualizerLabel");
valueLabel.setWrapText(true);
valueTooltip = new Tooltip(currentNode.toString());
valueLabel.setTooltip(valueTooltip);
valueContainer = new HBox(keyLabel, valueLabel);
- container.getChildren().add(valueContainer);
+ items.add(new TreeItem<>(valueContainer));
} else if (currentNode.isArray() || currentNode.isObject()) {
- Accordion arrayAccordion = new Accordion();
- container.getChildren().add(arrayAccordion);
- populateVisualizer(arrayAccordion, currentEntry.getKey(), currentNode);
+ TreeItem newRoot = new TreeItem<>();
+ items.add(newRoot);
+ populateVisualizer(newRoot, currentEntry.getKey(), currentNode);
}
}
- rootAccordion.getPanes().add(pane);
}
- if (!rootName.equals("root")) {
- pane.getStyleClass().add("nonRootTitledPane"); // Special CSS class to set padding for non-root panes only
- } else {
- rootAccordion.setExpandedPane(pane);
+ rootItem.getChildren().addAll(items);
+
+ if (rootName.equals("root")) {
+ rootItem.setExpanded(true);
}
}
diff --git a/src/main/resources/css/Adreana.css b/src/main/resources/css/Adreana.css
index ae9f53f..46aa69c 100644
--- a/src/main/resources/css/Adreana.css
+++ b/src/main/resources/css/Adreana.css
@@ -312,41 +312,53 @@
-fx-background-color: #2a2a2a;
}
-.nonRootTitledPane {
- -fx-padding: 3px 0px;
-}
-
-.titled-pane .title {
+.visualizerLabel {
-fx-font-family: "Liberation Mono", monospace;
- -fx-background-color: #404040;
}
-.titled-pane .content {
- -fx-background-color: #282828;
- -fx-border-width: 0px;
-}
-
-.titled-pane .content {
- -fx-font-family: "Liberation Mono", monospace;
- -fx-padding: 3px 0px;
+.visualizerRootLabel {
+ -fx-font-size: 19px;
+ -fx-text-fill: white;
+ -fx-font-weight: bold;
}
.visualizerKeyLabel {
-fx-font-size: 18px;
-fx-text-fill: #bababa;
- -fx-text-alignment: left;
+ -fx-font-weight: bold;
}
.visualizerValueLabel {
-fx-font-size: 18px;
-fx-text-fill: #959595;
- -fx-text-alignment: left;
}
-.titled-pane .title .text,
-.titled-pane .title .arrow-button .arrow {
- -fx-background-color: #dadada;
- -fx-fill: #dadada;
+/* Visualizer tree */
+.tree-view {
+ -fx-background-color: #353535;
+ -fx-padding: 0px;
+}
+
+.tree-cell .tree-disclosure-node .arrow {
+ -fx-background-color: orangered;
+}
+
+.tree-cell {
+ -fx-background-color: #282828;
+ -fx-border-width: 0px;
+}
+
+.tree-cell:selected,
+.tree-cell:expanded,
+.tree-cell:focused {
+ -fx-background-color: #454545;
+}
+
+.tree-view .scroll-bar:horizontal .increment-arrow,
+.tree-view .scroll-bar:horizontal .decrement-arrow,
+.tree-view .scroll-bar:horizontal .increment-button,
+.tree-view .scroll-bar:horizontal .decrement-button {
+ -fx-padding: 0;
}
/* SnackBar */
From 6d065186933a15e0641b1cb915cefcac99bddece Mon Sep 17 00:00:00 2001
From: Rohit Awate
Date: Sun, 29 Apr 2018 12:46:05 +0530
Subject: [PATCH 04/15] Minor improvements to Visualizer and moved its logic
into new class
---
.../controllers/DashboardController.java | 97 +++--------------
.../everest/controllers/Visualizer.java | 102 ++++++++++++++++++
src/main/resources/css/Adreana.css | 23 ++--
.../resources/fxml/homewindow/Dashboard.fxml | 2 +-
4 files changed, 135 insertions(+), 89 deletions(-)
create mode 100644 src/main/java/com/rohitawate/everest/controllers/Visualizer.java
diff --git a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java
index 7ebf50a..4f49e6a 100644
--- a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java
+++ b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java
@@ -53,8 +53,11 @@ import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.LocalDateTime;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
import java.util.Map.Entry;
+import java.util.ResourceBundle;
public class DashboardController implements Initializable {
@FXML
@@ -81,7 +84,7 @@ public class DashboardController implements Initializable {
@FXML
private Tab visualizerTab;
@FXML
- private ScrollPane visualizer;
+ private ScrollPane scrollPane;
private JFXSnackbar snackbar;
private final String[] httpMethods = {"GET", "POST", "PUT", "DELETE", "PATCH"};
@@ -91,7 +94,7 @@ public class DashboardController implements Initializable {
private HeaderTabController headerTabController;
private BodyTabController bodyTabController;
private IntegerProperty paramsCountProperty;
- private TreeView treeView;
+ private Visualizer visualizer;
private GETRequest getRequest;
private DataDispatchRequest dataRequest;
@@ -148,11 +151,17 @@ public class DashboardController implements Initializable {
errorTitle.setText("Oops... That's embarrassing!");
errorDetails.setText("Something went wrong. Try to make another getRequest.\nRestart Everest if that doesn't work.");
- setupVisualizer();
+ visualizer = new Visualizer();
+ scrollPane.setContent(visualizer);
}
@FXML
void sendRequest() {
+ if (requestManager != null && requestManager.isRunning()) {
+ snackbar.show("Please wait while the current request is processed.", 5000);
+ return;
+ }
+
promptLayer.setVisible(false);
if (responseBox.getChildren().size() == 2) {
responseBox.getChildren().remove(0);
@@ -356,8 +365,8 @@ public class DashboardController implements Initializable {
responseArea.setText(EverestUtilities.mapper.writeValueAsString(node));
visualizerTab.setDisable(false);
TreeItem root = new TreeItem<>();
- treeView.setRoot(root);
- populateVisualizer(root, "root", node);
+ visualizer.setRoot(root);
+ visualizer.populate(root, "root", node);
break;
case "application/xml":
responseType.setText("XML");
@@ -384,82 +393,6 @@ public class DashboardController implements Initializable {
}
}
- private void setupVisualizer() {
- treeView = new TreeView<>();
- visualizer.setContent(treeView);
- }
-
- private void populateVisualizer(TreeItem rootItem, String rootName, JsonNode root) {
- Label rootLabel = new Label(rootName);
- rootLabel.getStyleClass().addAll("visualizerRootLabel", "visualizerLabel");
- rootItem.setValue(new HBox(rootLabel));
-
- JsonNode currentNode;
- Label valueLabel;
- HBox valueContainer;
- List> items = new LinkedList<>();
- Tooltip valueTooltip;
-
- if (root.isArray()) {
- Iterator iterator = root.elements();
-
- while (iterator.hasNext()) {
- currentNode = iterator.next();
-
- if (currentNode.isValueNode()) {
- valueLabel = new Label(currentNode.toString());
- valueLabel.getStyleClass().addAll("visualizerValueLabel", "visualizerLabel");
- valueLabel.setWrapText(true);
- valueTooltip = new Tooltip(currentNode.toString());
- valueLabel.setTooltip(valueTooltip);
-
- valueContainer = new HBox(valueLabel);
- items.add(new TreeItem<>(valueContainer));
- } else if (currentNode.isObject()) {
- TreeItem newRoot = new TreeItem<>();
- items.add(newRoot);
- populateVisualizer(newRoot, "", currentNode);
- }
- }
- } else {
- Iterator> iterator = root.fields();
- Entry currentEntry;
- Label keyLabel;
- Tooltip keyTooltip;
-
- while (iterator.hasNext()) {
- currentEntry = iterator.next();
- currentNode = currentEntry.getValue();
-
- if (currentNode.isValueNode()) {
- keyLabel = new Label(currentEntry.getKey() + ": ");
- keyLabel.getStyleClass().addAll("visualizerKeyLabel", "visualizerLabel");
- keyTooltip = new Tooltip(currentEntry.getKey());
- keyLabel.setTooltip(keyTooltip);
-
- valueLabel = new Label(currentNode.toString());
- valueLabel.getStyleClass().addAll("visualizerValueLabel", "visualizerLabel");
- valueLabel.setWrapText(true);
- valueTooltip = new Tooltip(currentNode.toString());
- valueLabel.setTooltip(valueTooltip);
-
- valueContainer = new HBox(keyLabel, valueLabel);
- items.add(new TreeItem<>(valueContainer));
- } else if (currentNode.isArray() || currentNode.isObject()) {
- TreeItem newRoot = new TreeItem<>();
- items.add(newRoot);
- populateVisualizer(newRoot, currentEntry.getKey(), currentNode);
- }
- }
- }
-
- rootItem.getChildren().addAll(items);
-
- if (rootName.equals("root")) {
- rootItem.setExpanded(true);
- }
- }
-
private void applyDashboardSettings() {
String responseAreaCSS = "-fx-font-family: " + Settings.responseAreaFont + ";" +
"-fx-font-size: " + Settings.responseAreaFontSize;
diff --git a/src/main/java/com/rohitawate/everest/controllers/Visualizer.java b/src/main/java/com/rohitawate/everest/controllers/Visualizer.java
new file mode 100644
index 0000000..3523ef7
--- /dev/null
+++ b/src/main/java/com/rohitawate/everest/controllers/Visualizer.java
@@ -0,0 +1,102 @@
+/*
+ * 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.everest.controllers;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import javafx.scene.control.Label;
+import javafx.scene.control.Tooltip;
+import javafx.scene.control.TreeItem;
+import javafx.scene.control.TreeView;
+import javafx.scene.layout.HBox;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+class Visualizer extends TreeView {
+ Visualizer() {
+ this.setShowRoot(false);
+ }
+
+ void populate(TreeItem rootItem, String rootName, JsonNode root) {
+ Label rootLabel = new Label(rootName);
+ rootLabel.getStyleClass().addAll("visualizerRootLabel", "visualizerLabel");
+ rootItem.setValue(new HBox(rootLabel));
+
+ JsonNode currentNode;
+ Label valueLabel;
+ HBox valueContainer;
+ List> items = new LinkedList<>();
+ Tooltip valueTooltip;
+
+ if (root.isArray()) {
+ Iterator iterator = root.elements();
+
+ while (iterator.hasNext()) {
+ currentNode = iterator.next();
+
+ if (currentNode.isValueNode()) {
+ valueLabel = new Label(currentNode.toString());
+ valueLabel.getStyleClass().addAll("visualizerValueLabel", "visualizerLabel");
+ valueLabel.setWrapText(true);
+ valueTooltip = new Tooltip(currentNode.toString());
+ valueLabel.setTooltip(valueTooltip);
+
+ valueContainer = new HBox(valueLabel);
+ items.add(new TreeItem<>(valueContainer));
+ } else if (currentNode.isObject()) {
+ TreeItem newRoot = new TreeItem<>();
+ items.add(newRoot);
+ populate(newRoot, "[Anonymous Object]", currentNode);
+ }
+ }
+ } else {
+ Iterator> iterator = root.fields();
+ Map.Entry currentEntry;
+ Label keyLabel;
+ Tooltip keyTooltip;
+
+ while (iterator.hasNext()) {
+ currentEntry = iterator.next();
+ currentNode = currentEntry.getValue();
+
+ if (currentNode.isValueNode()) {
+ keyLabel = new Label(currentEntry.getKey() + ": ");
+ keyLabel.getStyleClass().addAll("visualizerKeyLabel", "visualizerLabel");
+ keyTooltip = new Tooltip(currentEntry.getKey());
+ keyLabel.setTooltip(keyTooltip);
+
+ valueLabel = new Label(currentNode.toString());
+ valueLabel.getStyleClass().addAll("visualizerValueLabel", "visualizerLabel");
+ valueLabel.setWrapText(true);
+ valueTooltip = new Tooltip(currentNode.toString());
+ valueLabel.setTooltip(valueTooltip);
+
+ valueContainer = new HBox(keyLabel, valueLabel);
+ items.add(new TreeItem<>(valueContainer));
+ } else if (currentNode.isArray() || currentNode.isObject()) {
+ TreeItem newRoot = new TreeItem<>();
+ items.add(newRoot);
+ populate(newRoot, currentEntry.getKey(), currentNode);
+ }
+ }
+ }
+
+ rootItem.getChildren().addAll(items);
+ }
+}
diff --git a/src/main/resources/css/Adreana.css b/src/main/resources/css/Adreana.css
index 46aa69c..aed6d41 100644
--- a/src/main/resources/css/Adreana.css
+++ b/src/main/resources/css/Adreana.css
@@ -317,8 +317,8 @@
}
.visualizerRootLabel {
- -fx-font-size: 19px;
- -fx-text-fill: white;
+ -fx-font-size: 18px;
+ -fx-text-fill: #dedede;
-fx-font-weight: bold;
}
@@ -336,24 +336,35 @@
/* Visualizer tree */
.tree-view {
-fx-background-color: #353535;
- -fx-padding: 0px;
}
.tree-cell .tree-disclosure-node .arrow {
-fx-background-color: orangered;
}
+.tree-cell:selected .tree-disclosure-node .arrow,
+.tree-cell:focused .tree-disclosure-node .arrow {
+ -fx-background-color: white;
+}
+
.tree-cell {
-fx-background-color: #282828;
-fx-border-width: 0px;
}
-.tree-cell:selected,
-.tree-cell:expanded,
-.tree-cell:focused {
+.tree-cell:expanded {
-fx-background-color: #454545;
}
+.tree-cell:selected,
+.tree-cell:focused {
+ -fx-background-color: cornflowerblue;
+}
+
+.tree-cell:selected .label {
+ -fx-text-fill: white;
+}
+
.tree-view .scroll-bar:horizontal .increment-arrow,
.tree-view .scroll-bar:horizontal .decrement-arrow,
.tree-view .scroll-bar:horizontal .increment-button,
diff --git a/src/main/resources/fxml/homewindow/Dashboard.fxml b/src/main/resources/fxml/homewindow/Dashboard.fxml
index c340562..fd3bc3d 100644
--- a/src/main/resources/fxml/homewindow/Dashboard.fxml
+++ b/src/main/resources/fxml/homewindow/Dashboard.fxml
@@ -210,7 +210,7 @@
-
From 861b5deab176876979e41a2520244d9b79dc213a Mon Sep 17 00:00:00 2001
From: Rohit Awate
Date: Sun, 29 Apr 2018 15:39:21 +0530
Subject: [PATCH 05/15] Added ResponseHeadersViewer and minor UI tweaks
---
.../controllers/DashboardController.java | 28 ++++++----
.../controllers/ResponseHeadersViewer.java | 51 ++++++++++++++++++
.../everest/controllers/Visualizer.java | 26 ++++++---
.../models/responses/EverestResponse.java | 10 ++++
.../requestmanager/RequestManager.java | 1 +
src/main/resources/assets/Copy.png | Bin 0 -> 203 bytes
src/main/resources/css/Adreana.css | 10 ++--
.../resources/fxml/homewindow/Dashboard.fxml | 19 ++++---
8 files changed, 118 insertions(+), 27 deletions(-)
create mode 100644 src/main/java/com/rohitawate/everest/controllers/ResponseHeadersViewer.java
create mode 100644 src/main/resources/assets/Copy.png
diff --git a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java
index 4f49e6a..8928d40 100644
--- a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java
+++ b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java
@@ -76,15 +76,13 @@ public class DashboardController implements Initializable {
private Label statusCode, statusCodeDescription, responseTime,
responseSize, errorTitle, errorDetails, responseType;
@FXML
- private JFXButton cancelButton;
+ private JFXButton cancelButton, copyBodyButton;
@FXML
TabPane requestOptionsTab;
@FXML
Tab paramsTab, authTab, headersTab, bodyTab;
@FXML
- private Tab visualizerTab;
- @FXML
- private ScrollPane scrollPane;
+ private Tab visualizerTab, responseHeadersTab;
private JFXSnackbar snackbar;
private final String[] httpMethods = {"GET", "POST", "PUT", "DELETE", "PATCH"};
@@ -95,6 +93,7 @@ public class DashboardController implements Initializable {
private BodyTabController bodyTabController;
private IntegerProperty paramsCountProperty;
private Visualizer visualizer;
+ private ResponseHeadersViewer responseHeadersViewer;
private GETRequest getRequest;
private DataDispatchRequest dataRequest;
@@ -148,11 +147,21 @@ public class DashboardController implements Initializable {
}
});
+ copyBodyButton.setOnAction(e -> {
+ responseArea.selectAll();
+ responseArea.copy();
+ responseArea.deselect();
+ snackbar.show("Request body copied to clipboard.", 5000);
+ });
+
errorTitle.setText("Oops... That's embarrassing!");
errorDetails.setText("Something went wrong. Try to make another getRequest.\nRestart Everest if that doesn't work.");
visualizer = new Visualizer();
- scrollPane.setContent(visualizer);
+ visualizerTab.setContent(visualizer);
+
+ responseHeadersViewer = new ResponseHeadersViewer();
+ responseHeadersTab.setContent(responseHeadersViewer);
}
@FXML
@@ -321,7 +330,7 @@ public class DashboardController implements Initializable {
}
private void onSucceeded() {
- updateDashboard(requestManager.getValue());
+ displayResponse(requestManager.getValue());
errorLayer.setVisible(false);
loadingLayer.setVisible(false);
requestManager.reset();
@@ -333,13 +342,14 @@ public class DashboardController implements Initializable {
loadingLayer.setVisible(true);
}
- private void updateDashboard(EverestResponse response) {
+ private void displayResponse(EverestResponse response) {
prettifyResponseBody(response);
responseBox.getChildren().add(0, responseDetails);
statusCode.setText(Integer.toString(response.getStatusCode()));
statusCodeDescription.setText(Response.Status.fromStatusCode(response.getStatusCode()).getReasonPhrase());
responseTime.setText(Long.toString(response.getTime()) + " ms");
responseSize.setText(Integer.toString(response.getSize()) + " B");
+ responseHeadersViewer.populate(response);
}
private void prettifyResponseBody(EverestResponse response) {
@@ -364,9 +374,7 @@ public class DashboardController implements Initializable {
JsonNode node = EverestUtilities.mapper.readTree(responseBody);
responseArea.setText(EverestUtilities.mapper.writeValueAsString(node));
visualizerTab.setDisable(false);
- TreeItem root = new TreeItem<>();
- visualizer.setRoot(root);
- visualizer.populate(root, "root", node);
+ visualizer.populate(node);
break;
case "application/xml":
responseType.setText("XML");
diff --git a/src/main/java/com/rohitawate/everest/controllers/ResponseHeadersViewer.java b/src/main/java/com/rohitawate/everest/controllers/ResponseHeadersViewer.java
new file mode 100644
index 0000000..23f2dce
--- /dev/null
+++ b/src/main/java/com/rohitawate/everest/controllers/ResponseHeadersViewer.java
@@ -0,0 +1,51 @@
+/*
+ * 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.everest.controllers;
+
+import com.rohitawate.everest.models.responses.EverestResponse;
+import javafx.geometry.Insets;
+import javafx.scene.control.Label;
+import javafx.scene.control.ScrollPane;
+import javafx.scene.layout.HBox;
+import javafx.scene.layout.VBox;
+
+class ResponseHeadersViewer extends ScrollPane {
+ private VBox container;
+
+ ResponseHeadersViewer() {
+ this.container = new VBox();
+ container.setPadding(new Insets(10, 20, 10, 20));
+ this.setContent(container);
+
+ this.setFitToHeight(true);
+ this.setFitToWidth(true);
+ }
+
+ void populate(EverestResponse response) {
+ container.getChildren().clear();
+
+ response.getHeaders().forEach((key, value) -> {
+ Label keyLabel = new Label(key + ": ");
+ keyLabel.getStyleClass().addAll("visualizerKeyLabel", "visualizerLabel");
+
+ Label valueLabel = new Label(value.get(0));
+ valueLabel.getStyleClass().addAll("visualizerValueLabel", "visualizerLabel");
+
+ container.getChildren().add(new HBox(keyLabel, valueLabel));
+ });
+ }
+}
diff --git a/src/main/java/com/rohitawate/everest/controllers/Visualizer.java b/src/main/java/com/rohitawate/everest/controllers/Visualizer.java
index 3523ef7..b31215a 100644
--- a/src/main/java/com/rohitawate/everest/controllers/Visualizer.java
+++ b/src/main/java/com/rohitawate/everest/controllers/Visualizer.java
@@ -17,10 +17,7 @@
package com.rohitawate.everest.controllers;
import com.fasterxml.jackson.databind.JsonNode;
-import javafx.scene.control.Label;
-import javafx.scene.control.Tooltip;
-import javafx.scene.control.TreeItem;
-import javafx.scene.control.TreeView;
+import javafx.scene.control.*;
import javafx.scene.layout.HBox;
import java.util.Iterator;
@@ -28,12 +25,27 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-class Visualizer extends TreeView {
+class Visualizer extends ScrollPane {
+ private TreeView visualizer;
+
Visualizer() {
- this.setShowRoot(false);
+ this.visualizer = new TreeView<>();
+ this.visualizer.setShowRoot(false);
+ this.setContent(this.visualizer);
+
+ this.setFitToHeight(true);
+ this.setFitToWidth(true);
}
- void populate(TreeItem rootItem, String rootName, JsonNode root) {
+ void populate(JsonNode node) {
+ this.populate(new TreeItem<>(), "root", node);
+ }
+
+ private void populate(TreeItem rootItem, String rootName, JsonNode root) {
+ if (rootName.equals("root")) {
+ this.visualizer.setRoot(rootItem);
+ }
+
Label rootLabel = new Label(rootName);
rootLabel.getStyleClass().addAll("visualizerRootLabel", "visualizerLabel");
rootItem.setValue(new HBox(rootLabel));
diff --git a/src/main/java/com/rohitawate/everest/models/responses/EverestResponse.java b/src/main/java/com/rohitawate/everest/models/responses/EverestResponse.java
index d538920..1d7f0b6 100644
--- a/src/main/java/com/rohitawate/everest/models/responses/EverestResponse.java
+++ b/src/main/java/com/rohitawate/everest/models/responses/EverestResponse.java
@@ -17,6 +17,7 @@
package com.rohitawate.everest.models.responses;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
public class EverestResponse {
private String body;
@@ -24,6 +25,7 @@ public class EverestResponse {
private long time;
private int size;
private MediaType mediaType;
+ private MultivaluedMap headers;
public String getBody() {
return body;
@@ -64,4 +66,12 @@ public class EverestResponse {
public void setStatusCode(int statusCode) {
this.statusCode = statusCode;
}
+
+ public MultivaluedMap getHeaders() {
+ return headers;
+ }
+
+ public void setHeaders(MultivaluedMap headers) {
+ this.headers = headers;
+ }
}
diff --git a/src/main/java/com/rohitawate/everest/requestmanager/RequestManager.java b/src/main/java/com/rohitawate/everest/requestmanager/RequestManager.java
index 405fd05..58a1202 100644
--- a/src/main/java/com/rohitawate/everest/requestmanager/RequestManager.java
+++ b/src/main/java/com/rohitawate/everest/requestmanager/RequestManager.java
@@ -88,6 +88,7 @@ public abstract class RequestManager extends Service {
String responseBody = serverResponse.readEntity(String.class);
response = new EverestResponse();
+ response.setHeaders(serverResponse.getStringHeaders());
response.setTime(initialTime, finalTime);
response.setBody(responseBody);
response.setMediaType(serverResponse.getMediaType());
diff --git a/src/main/resources/assets/Copy.png b/src/main/resources/assets/Copy.png
new file mode 100644
index 0000000000000000000000000000000000000000..70eb0737882e53ec326b7a37cf335fea48f7b605
GIT binary patch
literal 203
zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k0wldT1B8LpBu^K|kP61+1y(=wf7}1BXBM2m
zXx(C%^S}P5zlcK01p!(4V=PuM2d#+)QjXc+PR{(F06zGjcUgI^OC8}K$A
zSNM29e6^#>(FcqhRzo5hq8j?
z)rtIe%{d+G6v7vWO_&kTRxp+K%M|{sslKWl4DUBa=UZy6U
+
+
+
+
+
+
+
+
+
@@ -208,13 +218,8 @@
wrapText="true"/>
-
-
-
-
-
-
+
+
From 6f063a01c885719aa6a66e9212290f59544792cf Mon Sep 17 00:00:00 2001
From: Rohit Awate
Date: Thu, 3 May 2018 13:08:35 +0530
Subject: [PATCH 06/15] Fixed crucial typo in DashboardController
---
.../com/rohitawate/everest/controllers/DashboardController.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java
index 8928d40..722bca1 100644
--- a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java
+++ b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java
@@ -151,7 +151,7 @@ public class DashboardController implements Initializable {
responseArea.selectAll();
responseArea.copy();
responseArea.deselect();
- snackbar.show("Request body copied to clipboard.", 5000);
+ snackbar.show("Response body copied to clipboard.", 5000);
});
errorTitle.setText("Oops... That's embarrassing!");
From 411214311b2f36fdee43a46629093738de86e65a Mon Sep 17 00:00:00 2001
From: Rohit Awate
Date: Thu, 3 May 2018 13:51:20 +0530
Subject: [PATCH 07/15] Added Travis CI
---
.travis.yml | 10 ++++++++++
1 file changed, 10 insertions(+)
create mode 100644 .travis.yml
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..4e62807
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,10 @@
+language: java
+sudo: true
+
+script: mvn clean package
+
+deploy:
+ provider: releases
+ api_key:
+ secure: yep
+ file: target/Everest-Alpha-1.0.jar
\ No newline at end of file
From ee956baed6dd54a4ea786f4110cdcf3489696f88 Mon Sep 17 00:00:00 2001
From: Rohit Awate
Date: Tue, 8 May 2018 21:56:34 +0530
Subject: [PATCH 08/15] Fixed #9: Custom content types now override the ones
determined automatically
---
.travis.yml | 2 +-
.../DataDispatchRequestManager.java | 39 +++++++++++++------
.../requestmanager/RequestManager.java | 3 ++
3 files changed, 31 insertions(+), 13 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 4e62807..ba18bd4 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,4 +7,4 @@ deploy:
provider: releases
api_key:
secure: yep
- file: target/Everest-Alpha-1.0.jar
\ No newline at end of file
+ file: target/Everest-Alpha-1.0.jar
diff --git a/src/main/java/com/rohitawate/everest/requestmanager/DataDispatchRequestManager.java b/src/main/java/com/rohitawate/everest/requestmanager/DataDispatchRequestManager.java
index ede26dc..1ada390 100644
--- a/src/main/java/com/rohitawate/everest/requestmanager/DataDispatchRequestManager.java
+++ b/src/main/java/com/rohitawate/everest/requestmanager/DataDispatchRequestManager.java
@@ -72,6 +72,11 @@ public class DataDispatchRequestManager extends RequestManager {
* @return invocation object
*/
private Invocation appendBody() throws Exception {
+ /*
+ Checks if a custom mime-type is mentioned in the headers.
+ If present, it will override the logical Content-Type.
+ */
+ String overriddenContentType = request.getHeaders().get("Content-Type");
Invocation invocation = null;
Map.Entry mapEntry;
@@ -79,6 +84,7 @@ public class DataDispatchRequestManager extends RequestManager {
case MediaType.MULTIPART_FORM_DATA:
FormDataMultiPart formData = new FormDataMultiPart();
+ // Adding the string tuples to the request
HashMap pairs = dataDispatchRequest.getStringTuples();
for (Map.Entry entry : pairs.entrySet()) {
mapEntry = (Map.Entry) entry;
@@ -88,8 +94,10 @@ public class DataDispatchRequestManager extends RequestManager {
String filePath;
File file;
boolean fileException = false;
- StringBuilder fileExceptionMessage = new StringBuilder();
+ String fileExceptionMessage = null;
pairs = dataDispatchRequest.getFileTuples();
+
+ // Adding the file tuples to the request
for (Map.Entry entry : pairs.entrySet()) {
mapEntry = (Map.Entry) entry;
filePath = mapEntry.getValue();
@@ -100,14 +108,13 @@ public class DataDispatchRequestManager extends RequestManager {
file, MediaType.APPLICATION_OCTET_STREAM_TYPE));
else {
fileException = true;
- fileExceptionMessage.append(" - ");
- fileExceptionMessage.append(filePath);
- fileExceptionMessage.append("\n");
+ // For pretty-printing FileNotFoundException to the UI
+ fileExceptionMessage = " - " + filePath + "\n";
}
}
if (fileException) {
- throw new FileNotFoundException(fileExceptionMessage.toString());
+ throw new FileNotFoundException(fileExceptionMessage);
}
formData.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
@@ -118,6 +125,8 @@ public class DataDispatchRequestManager extends RequestManager {
invocation = requestBuilder.buildPut(Entity.entity(formData, MediaType.MULTIPART_FORM_DATA_TYPE));
break;
case MediaType.APPLICATION_OCTET_STREAM:
+ if (overriddenContentType == null)
+ overriddenContentType = MediaType.APPLICATION_OCTET_STREAM;
filePath = dataDispatchRequest.getBody();
File check = new File(filePath);
@@ -129,11 +138,14 @@ public class DataDispatchRequestManager extends RequestManager {
FileInputStream stream = new FileInputStream(filePath);
if (requestType.equals("POST"))
- invocation = requestBuilder.buildPost(Entity.entity(stream, MediaType.APPLICATION_OCTET_STREAM_TYPE));
+ invocation = requestBuilder.buildPost(Entity.entity(stream, overriddenContentType));
else
- invocation = requestBuilder.buildPut(Entity.entity(stream, MediaType.APPLICATION_OCTET_STREAM_TYPE));
+ invocation = requestBuilder.buildPut(Entity.entity(stream, overriddenContentType));
break;
case MediaType.APPLICATION_FORM_URLENCODED:
+ if (overriddenContentType == null)
+ overriddenContentType = MediaType.APPLICATION_FORM_URLENCODED;
+
Form form = new Form();
for (Map.Entry entry : dataDispatchRequest.getStringTuples().entrySet()) {
@@ -142,24 +154,27 @@ public class DataDispatchRequestManager extends RequestManager {
}
if (requestType.equals("POST"))
- invocation = requestBuilder.buildPost(Entity.form(form));
+ invocation = requestBuilder.buildPost(Entity.entity(form, overriddenContentType));
else
- invocation = requestBuilder.buildPut(Entity.form(form));
+ invocation = requestBuilder.buildPut(Entity.entity(form, overriddenContentType));
break;
default:
// Handles raw data types (JSON, Plain text, XML, HTML)
+ String originalContentType = dataDispatchRequest.getContentType();
+ if (overriddenContentType == null)
+ overriddenContentType = originalContentType;
switch (requestType) {
case "POST":
invocation = requestBuilder
- .buildPost(Entity.entity(dataDispatchRequest.getBody(), dataDispatchRequest.getContentType()));
+ .buildPost(Entity.entity(dataDispatchRequest.getBody(), overriddenContentType));
break;
case "PUT":
invocation = requestBuilder
- .buildPut(Entity.entity(dataDispatchRequest.getBody(), dataDispatchRequest.getContentType()));
+ .buildPut(Entity.entity(dataDispatchRequest.getBody(), overriddenContentType));
break;
case "PATCH":
invocation = requestBuilder
- .build("PATCH", Entity.entity(dataDispatchRequest.getBody(), dataDispatchRequest.getContentType()));
+ .build("PATCH", Entity.entity(dataDispatchRequest.getBody(), overriddenContentType));
break;
}
}
diff --git a/src/main/java/com/rohitawate/everest/requestmanager/RequestManager.java b/src/main/java/com/rohitawate/everest/requestmanager/RequestManager.java
index 58a1202..2e9f84a 100644
--- a/src/main/java/com/rohitawate/everest/requestmanager/RequestManager.java
+++ b/src/main/java/com/rohitawate/everest/requestmanager/RequestManager.java
@@ -51,11 +51,14 @@ public abstract class RequestManager extends Service {
.register(MultiPartFeature.class)
.build();
+ // Required for making PATCH requests through Jersey
client.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
+
if (Settings.connectionTimeOutEnable)
client.property(ClientProperties.CONNECT_TIMEOUT, Settings.connectionTimeOut);
if (Settings.connectionReadTimeOutEnable)
client.property(ClientProperties.READ_TIMEOUT, Settings.connectionReadTimeOut);
+
return client;
}
From 79861e0d7ec0fea5b1e6be07d7b687782f8cbbee Mon Sep 17 00:00:00 2001
From: Rohit Awate
Date: Tue, 8 May 2018 22:35:40 +0530
Subject: [PATCH 09/15] Fixed #11: Application now scales correctly
---
.../everest/controllers/DashboardController.java | 9 ++++-----
src/main/java/com/rohitawate/everest/main/Main.java | 6 ++++++
src/main/resources/fxml/homewindow/Dashboard.fxml | 5 ++---
src/main/resources/fxml/homewindow/HomeWindow.fxml | 4 ++--
4 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java
index 722bca1..941c252 100644
--- a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java
+++ b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java
@@ -155,7 +155,7 @@ public class DashboardController implements Initializable {
});
errorTitle.setText("Oops... That's embarrassing!");
- errorDetails.setText("Something went wrong. Try to make another getRequest.\nRestart Everest if that doesn't work.");
+ errorDetails.setText("Something went wrong. Try to make another request.\nRestart Everest if that doesn't work.");
visualizer = new Visualizer();
visualizerTab.setContent(visualizer);
@@ -199,7 +199,6 @@ public class DashboardController implements Initializable {
configureRequestManager();
requestManager.start();
break;
- // DataDispatchRequestManager will generate appropriate getRequest based on the type.
case "POST":
case "PUT":
case "PATCH":
@@ -274,7 +273,7 @@ public class DashboardController implements Initializable {
Services.loggingService.logSevere("Request execution failed.", E, LocalDateTime.now());
errorLayer.setVisible(true);
errorTitle.setText("Oops... That's embarrassing!");
- errorDetails.setText("Something went wrong. Try to make another getRequest.\nRestart Everest if that doesn't work.");
+ errorDetails.setText("Something went wrong. Try to make another request.\nRestart Everest if that doesn't work.");
}
}
@@ -290,7 +289,7 @@ public class DashboardController implements Initializable {
promptLayer.setVisible(false);
Throwable throwable = requestManager.getException();
Exception exception = (Exception) throwable;
- Services.loggingService.logWarning(httpMethodBox.getValue() + " getRequest could not be processed.", exception, LocalDateTime.now());
+ Services.loggingService.logWarning(httpMethodBox.getValue() + " request could not be processed.", exception, LocalDateTime.now());
if (throwable.getClass() == UnreliableResponseException.class) {
UnreliableResponseException URE = (UnreliableResponseException) throwable;
@@ -311,7 +310,7 @@ public class DashboardController implements Initializable {
if (requestManager.getClass() == DataDispatchRequestManager.class) {
if (throwable.getCause() != null && throwable.getCause().getClass() == IllegalArgumentException.class) {
errorTitle.setText("Did you forget something?");
- errorDetails.setText("Please specify at least one body part for your " + httpMethodBox.getValue() + " getRequest.");
+ errorDetails.setText("Please specify at least one body part for your " + httpMethodBox.getValue() + " request.");
} else if (throwable.getClass() == FileNotFoundException.class) {
errorTitle.setText("File(s) not found:");
errorDetails.setText(throwable.getMessage());
diff --git a/src/main/java/com/rohitawate/everest/main/Main.java b/src/main/java/com/rohitawate/everest/main/Main.java
index eaf7870..71976b8 100644
--- a/src/main/java/com/rohitawate/everest/main/Main.java
+++ b/src/main/java/com/rohitawate/everest/main/Main.java
@@ -21,9 +21,11 @@ import com.rohitawate.everest.util.settings.SettingsLoader;
import com.rohitawate.everest.util.themes.ThemeManager;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
+import javafx.geometry.Rectangle2D;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
+import javafx.stage.Screen;
import javafx.stage.Stage;
public class Main extends Application {
@@ -41,6 +43,10 @@ public class Main extends Application {
Stage dashboardStage = new Stage();
ThemeManager.setTheme(homeWindow);
+ Rectangle2D screenBounds = Screen.getPrimary().getBounds();
+ dashboardStage.setWidth(screenBounds.getWidth() * 0.83);
+ dashboardStage.setHeight(screenBounds.getHeight() * 0.74);
+
dashboardStage.getIcons().add(new Image(getClass().getResource("/assets/Logo.png").toExternalForm()));
dashboardStage.setScene(new Scene(homeWindow));
dashboardStage.setTitle("Everest");
diff --git a/src/main/resources/fxml/homewindow/Dashboard.fxml b/src/main/resources/fxml/homewindow/Dashboard.fxml
index 1d61d78..febed9f 100644
--- a/src/main/resources/fxml/homewindow/Dashboard.fxml
+++ b/src/main/resources/fxml/homewindow/Dashboard.fxml
@@ -22,9 +22,8 @@
-
+
diff --git a/src/main/resources/fxml/homewindow/HomeWindow.fxml b/src/main/resources/fxml/homewindow/HomeWindow.fxml
index c160f68..63b6580 100644
--- a/src/main/resources/fxml/homewindow/HomeWindow.fxml
+++ b/src/main/resources/fxml/homewindow/HomeWindow.fxml
@@ -22,12 +22,12 @@
-
-
From c2f12d146edf41e325530f5fb0ec84586bc9fd02 Mon Sep 17 00:00:00 2001
From: Rohit Awate
Date: Sat, 12 May 2018 12:19:15 +0530
Subject: [PATCH 10/15] Optimized and cleaned up the logging service
---
.../rohitawate/everest/util/logging/Log.java | 40 ++---------
.../everest/util/logging/Logger.java | 47 ++++---------
.../everest/util/logging/LoggingService.java | 67 ++++++-------------
src/main/resources/templates/LogEntry.html | 3 +-
src/main/resources/templates/LogsFile.html | 3 -
5 files changed, 36 insertions(+), 124 deletions(-)
diff --git a/src/main/java/com/rohitawate/everest/util/logging/Log.java b/src/main/java/com/rohitawate/everest/util/logging/Log.java
index 397493c..8cb9032 100644
--- a/src/main/java/com/rohitawate/everest/util/logging/Log.java
+++ b/src/main/java/com/rohitawate/everest/util/logging/Log.java
@@ -17,40 +17,8 @@
package com.rohitawate.everest.util.logging;
class Log {
- private Level level;
- private String message;
- private String time;
- private Exception exception;
-
- public Level getLevel() {
- return level;
- }
-
- public void setLevel(Level level) {
- this.level = level;
- }
-
- public String getMessage() {
- return message;
- }
-
- public void setMessage(String message) {
- this.message = message;
- }
-
- public String getTime() {
- return time;
- }
-
- public void setTime(String time) {
- this.time = time;
- }
-
- public Exception getException() {
- return exception;
- }
-
- public void setException(Exception exception) {
- this.exception = exception;
- }
+ Level level;
+ String message;
+ String time;
+ Exception exception;
}
diff --git a/src/main/java/com/rohitawate/everest/util/logging/Logger.java b/src/main/java/com/rohitawate/everest/util/logging/Logger.java
index cf678c3..ac21aef 100644
--- a/src/main/java/com/rohitawate/everest/util/logging/Logger.java
+++ b/src/main/java/com/rohitawate/everest/util/logging/Logger.java
@@ -39,15 +39,11 @@ class Logger {
* @param log - The log to be written to file.
*/
synchronized void log(Log log) {
- if (log.getLevel().greaterThanEqualTo(this.writerLevel)) {
- try {
- String logFileContents = readFile(logFilePath);
- String logEntry = generateLogEntry(log);
- logFileContents = logFileContents.replace("", logEntry);
- BufferedWriter writer = new BufferedWriter(new FileWriter(logFilePath));
+ System.out.println(log.message);
+ if (log.level.greaterThanEqualTo(this.writerLevel)) {
+ try (BufferedWriter writer = new BufferedWriter(new FileWriter(logFilePath, true))) {
writer.flush();
- writer.write(logFileContents);
- writer.close();
+ writer.append(getLogEntry(log));
} catch (IOException e) {
e.printStackTrace();
}
@@ -63,19 +59,19 @@ class Logger {
* Yellow = Warning
* Green = Info
*/
- private String generateLogEntry(Log log) {
+ private String getLogEntry(Log log) {
String logEntry = this.logEntryTemplate;
- logEntry = logEntry.replace("%% LogLevel %%", log.getLevel().toString());
- logEntry = logEntry.replace("%% Time %%", log.getTime());
- logEntry = logEntry.replace("%% Message %%", log.getMessage());
+ logEntry = logEntry.replace("%% LogLevel %%", log.level.toString());
+ logEntry = logEntry.replace("%% Time %%", log.time);
+ logEntry = logEntry.replace("%% Message %%", log.message);
StringBuilder builder = new StringBuilder();
- if (log.getException() != null) {
- StackTraceElement[] stackTrace = log.getException().getStackTrace();
- builder.append(log.getException().toString());
+ if (log.exception != null) {
+ StackTraceElement[] stackTrace = log.exception.getStackTrace();
+ builder.append(log.exception.toString());
builder.append("
\n");
if (stackTrace.length != 0) {
- for (StackTraceElement element : log.getException().getStackTrace()) {
+ for (StackTraceElement element : log.exception.getStackTrace()) {
builder.append(" -- ");
builder.append(element.toString());
builder.append("
\n");
@@ -129,23 +125,4 @@ class Logger {
return builder.toString();
}
-
- private String readFile(String filePath) {
- StringBuilder builder = new StringBuilder();
- try {
- BufferedReader bufferedReader = new BufferedReader(new FileReader(filePath));
- Scanner scanner = new Scanner(bufferedReader);
-
- while (scanner.hasNext()) {
- builder.append(scanner.nextLine());
- builder.append("\n");
- }
- scanner.close();
- bufferedReader.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- return builder.toString();
- }
}
diff --git a/src/main/java/com/rohitawate/everest/util/logging/LoggingService.java b/src/main/java/com/rohitawate/everest/util/logging/LoggingService.java
index 84f582c..b0d8c31 100644
--- a/src/main/java/com/rohitawate/everest/util/logging/LoggingService.java
+++ b/src/main/java/com/rohitawate/everest/util/logging/LoggingService.java
@@ -24,17 +24,12 @@ import java.time.format.DateTimeFormatter;
public class LoggingService {
private Logger logger;
private DateTimeFormatter dateFormat;
- private String message;
- private Exception exception;
- private LocalDateTime time;
-
- private SevereLogger severeLogger = new SevereLogger();
- private WarningLogger warningLogger = new WarningLogger();
- private InfoLogger infoLogger = new InfoLogger();
+ private Log log;
public LoggingService(Level writerLevel) {
- logger = new Logger(writerLevel);
- dateFormat = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss");
+ this.log = new Log();
+ this.logger = new Logger(writerLevel);
+ this.dateFormat = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss");
}
public void logSevere(String message, Exception exception, LocalDateTime time) {
@@ -53,47 +48,23 @@ public class LoggingService {
}
private void setValues(String message, Exception exception, LocalDateTime time) {
- this.message = message;
- this.exception = exception;
- this.time = time;
+ this.log.message = message;
+ this.log.exception = exception;
+ this.log.time = dateFormat.format(time);
}
- private class SevereLogger implements Runnable {
- @Override
- public void run() {
- System.out.println(message);
- Log log = new Log();
- log.setLevel(Level.SEVERE);
- log.setMessage(message);
- log.setException(exception);
- log.setTime(dateFormat.format(time));
- logger.log(log);
- }
- }
+ private Runnable severeLogger = () -> {
+ this.log.level = Level.SEVERE;
+ this.logger.log(this.log);
+ };
- private class WarningLogger implements Runnable {
- @Override
- public void run() {
- System.out.println(message);
- Log log = new Log();
- log.setLevel(Level.WARNING);
- log.setMessage(message);
- log.setException(exception);
- log.setTime(dateFormat.format(time));
- logger.log(log);
- }
- }
+ private Runnable warningLogger = () -> {
+ this.log.level = Level.WARNING;
+ this.logger.log(log);
+ };
-
- private class InfoLogger implements Runnable {
- @Override
- public void run() {
- System.out.println(message);
- Log log = new Log();
- log.setLevel(Level.INFO);
- log.setMessage(message);
- log.setTime(dateFormat.format(time));
- logger.log(log);
- }
- }
+ private Runnable infoLogger = () -> {
+ this.log.level = Level.INFO;
+ this.logger.log(log);
+ };
}
diff --git a/src/main/resources/templates/LogEntry.html b/src/main/resources/templates/LogEntry.html
index 257d07f..579419f 100644
--- a/src/main/resources/templates/LogEntry.html
+++ b/src/main/resources/templates/LogEntry.html
@@ -2,5 +2,4 @@
%% LogLevel %% %% Time %%
%% Message %%
%% StackTrace %%
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/src/main/resources/templates/LogsFile.html b/src/main/resources/templates/LogsFile.html
index 5cf28b2..bc47a82 100644
--- a/src/main/resources/templates/LogsFile.html
+++ b/src/main/resources/templates/LogsFile.html
@@ -55,6 +55,3 @@
Everest Log: %% Date %%
-
-
-