Added ResponseHeadersViewer and minor UI tweaks

This commit is contained in:
Rohit Awate 2018-04-29 15:39:21 +05:30
parent 6d06518693
commit 861b5deab1
No known key found for this signature in database
GPG key ID: 9C04E52F6B625A85
8 changed files with 118 additions and 27 deletions

View file

@ -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<HBox> root = new TreeItem<>();
visualizer.setRoot(root);
visualizer.populate(root, "root", node);
visualizer.populate(node);
break;
case "application/xml":
responseType.setText("XML");

View file

@ -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));
});
}
}

View file

@ -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<HBox> {
class Visualizer extends ScrollPane {
private TreeView<HBox> 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<HBox> rootItem, String rootName, JsonNode root) {
void populate(JsonNode node) {
this.populate(new TreeItem<>(), "root", node);
}
private void populate(TreeItem<HBox> 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));

View file

@ -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<String, String> headers;
public String getBody() {
return body;
@ -64,4 +66,12 @@ public class EverestResponse {
public void setStatusCode(int statusCode) {
this.statusCode = statusCode;
}
public MultivaluedMap<String, String> getHeaders() {
return headers;
}
public void setHeaders(MultivaluedMap<String, String> headers) {
this.headers = headers;
}
}

View file

@ -88,6 +88,7 @@ public abstract class RequestManager extends Service<EverestResponse> {
String responseBody = serverResponse.readEntity(String.class);
response = new EverestResponse();
response.setHeaders(serverResponse.getStringHeaders());
response.setTime(initialTime, finalTime);
response.setBody(responseBody);
response.setMediaType(serverResponse.getMediaType());

Binary file not shown.

After

Width:  |  Height:  |  Size: 203 B

View file

@ -71,6 +71,10 @@
-fx-background-color: #1b1b1b;
}
#copyBodyButton {
-fx-background-color: transparent;
}
#clearResponseAreaButton {
-fx-background-color: #822f2f;
}
@ -317,19 +321,19 @@
}
.visualizerRootLabel {
-fx-font-size: 18px;
-fx-font-size: 17px;
-fx-text-fill: #dedede;
-fx-font-weight: bold;
}
.visualizerKeyLabel {
-fx-font-size: 18px;
-fx-font-size: 17px;
-fx-text-fill: #bababa;
-fx-font-weight: bold;
}
.visualizerValueLabel {
-fx-font-size: 18px;
-fx-font-size: 16px;
-fx-text-fill: #959595;
}

View file

@ -181,6 +181,16 @@
<Insets/>
</HBox.margin>
</Label>
<JFXButton fx:id="copyBodyButton" textFill="WHITE">
<graphic>
<ImageView fitHeight="20.0" fitWidth="20.0" pickOnBounds="true"
preserveRatio="true">
<image>
<Image url="@../../assets/Copy.png"/>
</image>
</ImageView>
</graphic>
</JFXButton>
<JFXButton fx:id="clearResponseAreaButton" buttonType="RAISED" onAction="#clearResponseArea" ripplerFill="WHITE" text=" CLEAR" textFill="WHITE" HBox.hgrow="ALWAYS">
<graphic>
<ImageView fitHeight="15.0" fitWidth="15.0" pickOnBounds="true" preserveRatio="true">
@ -208,13 +218,8 @@
wrapText="true"/>
</content>
</Tab>
<Tab fx:id="visualizerTab" closable="false" text="VISUALIZER">
<content>
<ScrollPane fx:id="scrollPane" fitToHeight="true"
fitToWidth="true" hbarPolicy="NEVER"/>
</content>
</Tab>
<Tab closable="false" text="HEADERS"/>
<Tab fx:id="visualizerTab" closable="false" text="VISUALIZER"/>
<Tab fx:id="responseHeadersTab" closable="false" text="HEADERS"/>
</tabs>
</TabPane>
<VBox fx:id="loadingLayer" alignment="CENTER" visible="false">