Add option to open link in browser for HTML responses and minor improvements
This commit is contained in:
parent
e1e282c08b
commit
c86f18038e
5 changed files with 57 additions and 24 deletions
|
@ -43,6 +43,8 @@ import javafx.fxml.FXMLLoader;
|
|||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.StackPane;
|
||||
|
@ -52,9 +54,11 @@ import org.fxmisc.flowless.VirtualizedScrollPane;
|
|||
import javax.ws.rs.ProcessingException;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.awt.*;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
|
@ -154,31 +158,33 @@ public class DashboardController implements Initializable {
|
|||
responseArea.selectAll();
|
||||
responseArea.copy();
|
||||
responseArea.deselect();
|
||||
snackbar.show("Response rawBody copied to clipboard.", 5000);
|
||||
snackbar.show("Response body copied to clipboard.", 5000);
|
||||
});
|
||||
|
||||
responseTypeBox.getItems().addAll("JSON", "XML", "HTML", "PLAIN TEXT");
|
||||
|
||||
responseTypeBox.valueProperty().addListener(change -> {
|
||||
String type = responseTypeBox.getValue();
|
||||
try {
|
||||
switch (type) {
|
||||
case "JSON":
|
||||
HighlightMode mode;
|
||||
switch (type) {
|
||||
case "JSON":
|
||||
try {
|
||||
JsonNode node = EverestUtilities.jsonMapper.readTree(responseArea.getText());
|
||||
responseArea.setText(EverestUtilities.jsonMapper.writeValueAsString(node), HighlightMode.JSON);
|
||||
break;
|
||||
case "XML":
|
||||
responseArea.setText(responseArea.getText(), HighlightMode.XML);
|
||||
break;
|
||||
case "HTML":
|
||||
responseArea.setText(responseArea.getText(), HighlightMode.HTML);
|
||||
break;
|
||||
default:
|
||||
responseArea.setText(responseArea.getText(), HighlightMode.PLAIN);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Services.loggingService.logWarning("Response could not be parsed.", e, LocalDateTime.now());
|
||||
} catch (IOException e) {
|
||||
Services.loggingService.logWarning("Response could not be parsed.", e, LocalDateTime.now());
|
||||
}
|
||||
return;
|
||||
case "XML":
|
||||
mode = HighlightMode.XML;
|
||||
break;
|
||||
case "HTML":
|
||||
mode = HighlightMode.XML;
|
||||
break;
|
||||
default:
|
||||
mode = HighlightMode.PLAIN;
|
||||
}
|
||||
responseArea.setMode(mode);
|
||||
});
|
||||
|
||||
errorTitle.setText("Oops... That's embarrassing!");
|
||||
|
@ -427,6 +433,18 @@ public class DashboardController implements Initializable {
|
|||
case "text/html":
|
||||
responseTypeBox.setValue("HTML");
|
||||
responseArea.setText(responseBody, HighlightMode.HTML);
|
||||
if (Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
|
||||
snackbar.show("Open link in browser?", "YES", 5000, e -> {
|
||||
snackbar.close();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Desktop.getDesktop().browse(new URI(addressField.getText()));
|
||||
} catch (Exception ex) {
|
||||
Services.loggingService.logWarning("Invalid URL encountered while opening in browser.", ex, LocalDateTime.now());
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
}
|
||||
break;
|
||||
default:
|
||||
responseTypeBox.setValue("PLAIN TEXT");
|
||||
|
@ -566,6 +584,16 @@ public class DashboardController implements Initializable {
|
|||
* @param state - State of the dashboard
|
||||
*/
|
||||
public void setState(DashboardState state) {
|
||||
/*
|
||||
The only value from a set of constants in the state.json file is the httpMethod
|
||||
which, if manipulated to a non-standard value by the user, would still
|
||||
be loaded into the httpMethodBox, causing severe errors while making requests.
|
||||
|
||||
To prevent this, we check if it is a standard value (GET, POST, PUT, PATCH or DELETE) and
|
||||
only then proceed to applying the rest of the state values to the Dashboard.
|
||||
|
||||
This is an extreme case, but still something to be taken care of.
|
||||
*/
|
||||
boolean validMethod = false;
|
||||
for (String method : httpMethods) {
|
||||
if (state.httpMethod.equals(method))
|
||||
|
|
|
@ -333,7 +333,7 @@ public class HomeWindowController implements Initializable {
|
|||
|
||||
int relativityIndex = controller.getRelativityIndex(searchString);
|
||||
|
||||
// Split the string into words and get total relativity index as sum of individual indices.
|
||||
// Split the string into words and get total relativity index as the sum of individual indices.
|
||||
String words[] = searchString.split("\\s");
|
||||
for (String word : words)
|
||||
relativityIndex += controller.getRelativityIndex(word);
|
||||
|
|
|
@ -57,7 +57,7 @@ public class EverestUtilities {
|
|||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Services.loggingService.logInfo("BugReporter was copied to installation folder.", LocalDateTime.now());
|
||||
Services.loggingService.logInfo("BugReporter was copied to installation directory.", LocalDateTime.now());
|
||||
|
||||
}).start();
|
||||
}
|
||||
|
|
|
@ -306,7 +306,7 @@
|
|||
}
|
||||
|
||||
.visualizerLabel {
|
||||
-fx-font-family: "Liberation Mono", monospace;
|
||||
-fx-font-family: "Liberation Mono", "Consolas", "Courier New", "Monaco", "DejaVu Sans Mono", monospace;
|
||||
}
|
||||
|
||||
.visualizerRootLabel {
|
||||
|
@ -374,3 +374,8 @@
|
|||
-fx-text-fill: white;
|
||||
-fx-alignment: center;
|
||||
}
|
||||
|
||||
.jfx-snackbar-action .text {
|
||||
-fx-fill: azure;
|
||||
-fx-font-weight: bold;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*General rules for EverestCodeArea*/
|
||||
/* General rules for EverestCodeArea */
|
||||
|
||||
.everest-code-area {
|
||||
-fx-background-color: #282828;
|
||||
|
@ -22,7 +22,7 @@
|
|||
|
||||
.everest-code-area .text {
|
||||
-fx-fill: #ababab;
|
||||
-fx-font-family: "Liberation Mono", monospace;
|
||||
-fx-font-family: "Liberation Mono", "Consolas", "Courier New", "Monaco", "DejaVu Sans Mono", monospace;
|
||||
-fx-font-size: 17px;
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@
|
|||
-fx-fill: azure !important;
|
||||
}
|
||||
|
||||
/*Common to JSON and XML*/
|
||||
/* Common to JSON and XML */
|
||||
|
||||
.xml_bracket,
|
||||
.json_curly {
|
||||
|
@ -52,7 +52,7 @@
|
|||
-fx-fill: cornflowerblue !important;
|
||||
}
|
||||
|
||||
/*JSON-specific*/
|
||||
/* JSON-specific */
|
||||
|
||||
.json_array {
|
||||
-fx-fill: limegreen !important;
|
||||
|
@ -68,7 +68,7 @@
|
|||
-fx-font-weight: bold;
|
||||
}
|
||||
|
||||
/*XML-specific*/
|
||||
/* XML-specific */
|
||||
|
||||
.xml_attribute {
|
||||
-fx-fill: darkviolet !important;
|
||||
|
|
Loading…
Reference in a new issue