Fix issue where responseHeaders were lost in tab-switching

This commit is contained in:
Rohit Awate 2018-07-17 20:30:50 +05:30
parent 7f9c14d6f6
commit ac0fb816f2
2 changed files with 11 additions and 7 deletions

View file

@ -437,6 +437,7 @@ public class DashboardController implements Initializable {
statusCodeDescription.setText(Response.Status.fromStatusCode(state.statusCode).getReasonPhrase()); statusCodeDescription.setText(Response.Status.fromStatusCode(state.statusCode).getReasonPhrase());
responseTime.setText(Long.toString(state.responseTime) + " ms"); responseTime.setText(Long.toString(state.responseTime) + " ms");
responseSize.setText(Integer.toString(state.responseSize) + " B"); responseSize.setText(Integer.toString(state.responseSize) + " B");
System.out.println(state.responseHeaders.size());
responseHeadersViewer.populate(state.responseHeaders); responseHeadersViewer.populate(state.responseHeaders);
} }
@ -627,7 +628,7 @@ public class DashboardController implements Initializable {
dashboardState.showResponse = responseLayer.isVisible(); dashboardState.showResponse = responseLayer.isVisible();
if (dashboardState.showResponse) { if (dashboardState.showResponse) {
dashboardState.responseHeaders = headerTabController.getHeaders(); dashboardState.responseHeaders = responseHeadersViewer.getHeaders();
dashboardState.statusCode = Integer.parseInt(statusCode.getText()); dashboardState.statusCode = Integer.parseInt(statusCode.getText());
String temp = responseSize.getText(); String temp = responseSize.getText();

View file

@ -23,12 +23,11 @@ import javafx.scene.control.ScrollPane;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javax.ws.rs.core.MultivaluedHashMap;
import java.util.HashMap; import java.util.HashMap;
class ResponseHeadersViewer extends ScrollPane { class ResponseHeadersViewer extends ScrollPane {
private VBox container; private VBox container;
private MultivaluedHashMap<String, String> map; private HashMap<String, String> map;
ResponseHeadersViewer() { ResponseHeadersViewer() {
this.container = new VBox(); this.container = new VBox();
@ -38,18 +37,18 @@ class ResponseHeadersViewer extends ScrollPane {
this.setFitToHeight(true); this.setFitToHeight(true);
this.setFitToWidth(true); this.setFitToWidth(true);
map = new MultivaluedHashMap<>(); map = new HashMap<>();
} }
void populate(HashMap<String, String> headers) { void populate(HashMap<String, String> headers) {
map.clear(); map.clear();
headers.forEach((key, value) -> map.putSingle(key, value)); headers.forEach((key, value) -> map.put(key, value));
populate(); populate();
} }
void populate(EverestResponse response) { void populate(EverestResponse response) {
map.clear(); 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(); populate();
} }
@ -60,11 +59,15 @@ class ResponseHeadersViewer extends ScrollPane {
Label keyLabel = new Label(key + ": "); Label keyLabel = new Label(key + ": ");
keyLabel.getStyleClass().addAll("visualizerKeyLabel", "visualizerLabel"); keyLabel.getStyleClass().addAll("visualizerKeyLabel", "visualizerLabel");
Label valueLabel = new Label(value.get(0)); Label valueLabel = new Label(value);
valueLabel.getStyleClass().addAll("visualizerValueLabel", "visualizerLabel"); valueLabel.getStyleClass().addAll("visualizerValueLabel", "visualizerLabel");
container.getChildren().add(new HBox(keyLabel, valueLabel)); container.getChildren().add(new HBox(keyLabel, valueLabel));
}); });
} }
public HashMap<String, String> getHeaders() {
return new HashMap<>(map);
}
} }