From ac0fb816f22ca77efb67c540964c3a5deb6f4f4a Mon Sep 17 00:00:00 2001 From: Rohit Awate Date: Tue, 17 Jul 2018 20:30:50 +0530 Subject: [PATCH] Fix issue where responseHeaders were lost in tab-switching --- .../everest/controllers/DashboardController.java | 3 ++- .../controllers/ResponseHeadersViewer.java | 15 +++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java index fbdf8c9..854c0e6 100644 --- a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java +++ b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java @@ -437,6 +437,7 @@ public class DashboardController implements Initializable { statusCodeDescription.setText(Response.Status.fromStatusCode(state.statusCode).getReasonPhrase()); responseTime.setText(Long.toString(state.responseTime) + " ms"); responseSize.setText(Integer.toString(state.responseSize) + " B"); + System.out.println(state.responseHeaders.size()); responseHeadersViewer.populate(state.responseHeaders); } @@ -627,7 +628,7 @@ public class DashboardController implements Initializable { dashboardState.showResponse = responseLayer.isVisible(); if (dashboardState.showResponse) { - dashboardState.responseHeaders = headerTabController.getHeaders(); + dashboardState.responseHeaders = responseHeadersViewer.getHeaders(); dashboardState.statusCode = Integer.parseInt(statusCode.getText()); String temp = responseSize.getText(); diff --git a/src/main/java/com/rohitawate/everest/controllers/ResponseHeadersViewer.java b/src/main/java/com/rohitawate/everest/controllers/ResponseHeadersViewer.java index 8d14f30..40dc78a 100644 --- a/src/main/java/com/rohitawate/everest/controllers/ResponseHeadersViewer.java +++ b/src/main/java/com/rohitawate/everest/controllers/ResponseHeadersViewer.java @@ -23,12 +23,11 @@ import javafx.scene.control.ScrollPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; -import javax.ws.rs.core.MultivaluedHashMap; import java.util.HashMap; class ResponseHeadersViewer extends ScrollPane { private VBox container; - private MultivaluedHashMap map; + private HashMap map; ResponseHeadersViewer() { this.container = new VBox(); @@ -38,18 +37,18 @@ class ResponseHeadersViewer extends ScrollPane { this.setFitToHeight(true); this.setFitToWidth(true); - map = new MultivaluedHashMap<>(); + map = new HashMap<>(); } void populate(HashMap headers) { map.clear(); - headers.forEach((key, value) -> map.putSingle(key, value)); + headers.forEach((key, value) -> map.put(key, value)); populate(); } void populate(EverestResponse response) { map.clear(); - response.getHeaders().forEach((key, value) -> map.putSingle(key, value.get(0))); + response.getHeaders().forEach((key, value) -> map.put(key, value.get(0))); populate(); } @@ -60,11 +59,15 @@ class ResponseHeadersViewer extends ScrollPane { Label keyLabel = new Label(key + ": "); keyLabel.getStyleClass().addAll("visualizerKeyLabel", "visualizerLabel"); - Label valueLabel = new Label(value.get(0)); + Label valueLabel = new Label(value); valueLabel.getStyleClass().addAll("visualizerValueLabel", "visualizerLabel"); container.getChildren().add(new HBox(keyLabel, valueLabel)); }); } + + public HashMap getHeaders() { + return new HashMap<>(map); + } }