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.fxml.Initializable;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
import javafx.scene.input.KeyCode;
|
import javafx.scene.input.KeyCode;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.layout.StackPane;
|
import javafx.scene.layout.StackPane;
|
||||||
|
@ -52,9 +54,11 @@ import org.fxmisc.flowless.VirtualizedScrollPane;
|
||||||
import javax.ws.rs.ProcessingException;
|
import javax.ws.rs.ProcessingException;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.awt.*;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -154,31 +158,33 @@ public class DashboardController implements Initializable {
|
||||||
responseArea.selectAll();
|
responseArea.selectAll();
|
||||||
responseArea.copy();
|
responseArea.copy();
|
||||||
responseArea.deselect();
|
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.getItems().addAll("JSON", "XML", "HTML", "PLAIN TEXT");
|
||||||
|
|
||||||
responseTypeBox.valueProperty().addListener(change -> {
|
responseTypeBox.valueProperty().addListener(change -> {
|
||||||
String type = responseTypeBox.getValue();
|
String type = responseTypeBox.getValue();
|
||||||
try {
|
HighlightMode mode;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "JSON":
|
case "JSON":
|
||||||
|
try {
|
||||||
JsonNode node = EverestUtilities.jsonMapper.readTree(responseArea.getText());
|
JsonNode node = EverestUtilities.jsonMapper.readTree(responseArea.getText());
|
||||||
responseArea.setText(EverestUtilities.jsonMapper.writeValueAsString(node), HighlightMode.JSON);
|
responseArea.setText(EverestUtilities.jsonMapper.writeValueAsString(node), HighlightMode.JSON);
|
||||||
break;
|
} catch (IOException e) {
|
||||||
case "XML":
|
Services.loggingService.logWarning("Response could not be parsed.", e, LocalDateTime.now());
|
||||||
responseArea.setText(responseArea.getText(), HighlightMode.XML);
|
}
|
||||||
break;
|
return;
|
||||||
case "HTML":
|
case "XML":
|
||||||
responseArea.setText(responseArea.getText(), HighlightMode.HTML);
|
mode = HighlightMode.XML;
|
||||||
break;
|
break;
|
||||||
default:
|
case "HTML":
|
||||||
responseArea.setText(responseArea.getText(), HighlightMode.PLAIN);
|
mode = HighlightMode.XML;
|
||||||
}
|
break;
|
||||||
} catch (IOException e) {
|
default:
|
||||||
Services.loggingService.logWarning("Response could not be parsed.", e, LocalDateTime.now());
|
mode = HighlightMode.PLAIN;
|
||||||
}
|
}
|
||||||
|
responseArea.setMode(mode);
|
||||||
});
|
});
|
||||||
|
|
||||||
errorTitle.setText("Oops... That's embarrassing!");
|
errorTitle.setText("Oops... That's embarrassing!");
|
||||||
|
@ -427,6 +433,18 @@ public class DashboardController implements Initializable {
|
||||||
case "text/html":
|
case "text/html":
|
||||||
responseTypeBox.setValue("HTML");
|
responseTypeBox.setValue("HTML");
|
||||||
responseArea.setText(responseBody, HighlightMode.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;
|
break;
|
||||||
default:
|
default:
|
||||||
responseTypeBox.setValue("PLAIN TEXT");
|
responseTypeBox.setValue("PLAIN TEXT");
|
||||||
|
@ -566,6 +584,16 @@ public class DashboardController implements Initializable {
|
||||||
* @param state - State of the dashboard
|
* @param state - State of the dashboard
|
||||||
*/
|
*/
|
||||||
public void setState(DashboardState state) {
|
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;
|
boolean validMethod = false;
|
||||||
for (String method : httpMethods) {
|
for (String method : httpMethods) {
|
||||||
if (state.httpMethod.equals(method))
|
if (state.httpMethod.equals(method))
|
||||||
|
|
|
@ -333,7 +333,7 @@ public class HomeWindowController implements Initializable {
|
||||||
|
|
||||||
int relativityIndex = controller.getRelativityIndex(searchString);
|
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");
|
String words[] = searchString.split("\\s");
|
||||||
for (String word : words)
|
for (String word : words)
|
||||||
relativityIndex += controller.getRelativityIndex(word);
|
relativityIndex += controller.getRelativityIndex(word);
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class EverestUtilities {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
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();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
|
@ -306,7 +306,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.visualizerLabel {
|
.visualizerLabel {
|
||||||
-fx-font-family: "Liberation Mono", monospace;
|
-fx-font-family: "Liberation Mono", "Consolas", "Courier New", "Monaco", "DejaVu Sans Mono", monospace;
|
||||||
}
|
}
|
||||||
|
|
||||||
.visualizerRootLabel {
|
.visualizerRootLabel {
|
||||||
|
@ -374,3 +374,8 @@
|
||||||
-fx-text-fill: white;
|
-fx-text-fill: white;
|
||||||
-fx-alignment: center;
|
-fx-alignment: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.jfx-snackbar-action .text {
|
||||||
|
-fx-fill: azure;
|
||||||
|
-fx-font-weight: bold;
|
||||||
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*General rules for EverestCodeArea*/
|
/* General rules for EverestCodeArea */
|
||||||
|
|
||||||
.everest-code-area {
|
.everest-code-area {
|
||||||
-fx-background-color: #282828;
|
-fx-background-color: #282828;
|
||||||
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
.everest-code-area .text {
|
.everest-code-area .text {
|
||||||
-fx-fill: #ababab;
|
-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;
|
-fx-font-size: 17px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@
|
||||||
-fx-fill: azure !important;
|
-fx-fill: azure !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Common to JSON and XML*/
|
/* Common to JSON and XML */
|
||||||
|
|
||||||
.xml_bracket,
|
.xml_bracket,
|
||||||
.json_curly {
|
.json_curly {
|
||||||
|
@ -52,7 +52,7 @@
|
||||||
-fx-fill: cornflowerblue !important;
|
-fx-fill: cornflowerblue !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*JSON-specific*/
|
/* JSON-specific */
|
||||||
|
|
||||||
.json_array {
|
.json_array {
|
||||||
-fx-fill: limegreen !important;
|
-fx-fill: limegreen !important;
|
||||||
|
@ -68,7 +68,7 @@
|
||||||
-fx-font-weight: bold;
|
-fx-font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*XML-specific*/
|
/* XML-specific */
|
||||||
|
|
||||||
.xml_attribute {
|
.xml_attribute {
|
||||||
-fx-fill: darkviolet !important;
|
-fx-fill: darkviolet !important;
|
||||||
|
|
Loading…
Reference in a new issue