Merge pull request #1 from alexlegarnd/swing
Convert project from JavaFX to Swing
This commit was merged in pull request #1.
This commit is contained in:
15
README.md
15
README.md
@@ -5,17 +5,6 @@ Just send a GET, POST, PUT or DELETE HTTP request on a server and get it's respo
|
|||||||
|
|
||||||
# Build
|
# Build
|
||||||
|
|
||||||
You need JavaFX 14, you can download it [here](https://gluonhq.com/products/javafx/)
|
⚠ Nothing is working for now
|
||||||
|
|
||||||
I use the language level 14 of Java, if you want to use Java 11, you need to refactor some Switches/Cases
|
I use the language level 15 of Java, if you want to use Java 11, you need to refactor some Switches/Cases
|
||||||
|
|
||||||
Tested (and compiled) on Windows 10 and IntelliJ
|
|
||||||
|
|
||||||
# Known issues
|
|
||||||
|
|
||||||
* Issue with HTTPS on IIS (SSL Handshake failed)
|
|
||||||
|
|
||||||
# Binaries
|
|
||||||
|
|
||||||
Compiled binaries with installer downloadable [here](https://alexisdelhaie.ovh/dlcenter/endpoint-installer.exe). (There is no fancy web page now)
|
|
||||||
This installer are based on [chronos-installer-bootstrap](https://github.com/alexlegarnd/chronos-installer-bootstrap) and [chronos-installer](https://github.com/alexlegarnd/chronos-installer)
|
|
||||||
|
|||||||
BIN
javafx.bootstrap/javafx.bootstrap/icon.ico
Normal file
BIN
javafx.bootstrap/javafx.bootstrap/icon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 113 KiB |
@@ -52,7 +52,7 @@ END
|
|||||||
|
|
||||||
// Icon with lowest ID value placed first to ensure application icon
|
// Icon with lowest ID value placed first to ensure application icon
|
||||||
// remains consistent on all systems.
|
// remains consistent on all systems.
|
||||||
IDI_ICON2 ICON "C:\\Users\\robof\\Downloads\\icon.ico"
|
IDI_ICON2 ICON ".\\icon.ico"
|
||||||
|
|
||||||
#endif // English (United States) resources
|
#endif // English (United States) resources
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdParam
|
|||||||
si.cb = sizeof(si);
|
si.cb = sizeof(si);
|
||||||
ZeroMemory(&pi, sizeof(pi));
|
ZeroMemory(&pi, sizeof(pi));
|
||||||
|
|
||||||
LPTSTR command = _tcsdup(TEXT(".\\runtime\\bin\\javaw.exe --module-path \".\\lib\" --add-modules javafx.controls,javafx.fxml -jar .\\app\\EndPoint.jar"));
|
LPTSTR command = _tcsdup(TEXT(".\\runtime\\bin\\javaw.exe -cp .\\app\\EndPoint.jar ovh.alexisdelhaie.endpoint.Application"));
|
||||||
if (!CreateProcess(NULL, command, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
|
if (!CreateProcess(NULL, command, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
|
||||||
{
|
{
|
||||||
CloseHandle(&pi.hProcess);
|
CloseHandle(&pi.hProcess);
|
||||||
|
|||||||
36
pom.xml
Normal file
36
pom.xml
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>ovh.alexisdelhaie</groupId>
|
||||||
|
<artifactId>EndPoint</artifactId>
|
||||||
|
<version>0.1.3</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.release>15</maven.compiler.release>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-core</artifactId>
|
||||||
|
<version>2.11.3</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>2.11.3</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.formdev/flatlaf -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.formdev</groupId>
|
||||||
|
<artifactId>flatlaf</artifactId>
|
||||||
|
<version>0.43</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
Manifest-Version: 1.0
|
|
||||||
Main-Class: ovh.alexisdelhaie.endpoint.Main
|
|
||||||
|
|
||||||
3
src/main/java/META-INF/MANIFEST.MF
Normal file
3
src/main/java/META-INF/MANIFEST.MF
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
Manifest-Version: 1.0
|
||||||
|
Main-Class: ovh.alexisdelhaie.endpoint.Application
|
||||||
|
|
||||||
21
src/main/java/ovh/alexisdelhaie/endpoint/Application.java
Normal file
21
src/main/java/ovh/alexisdelhaie/endpoint/Application.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package ovh.alexisdelhaie.endpoint;
|
||||||
|
|
||||||
|
import com.formdev.flatlaf.FlatIntelliJLaf;
|
||||||
|
import ovh.alexisdelhaie.endpoint.utils.Tools;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class Application {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws UnsupportedLookAndFeelException, IOException {
|
||||||
|
UIManager.setLookAndFeel(new FlatIntelliJLaf());
|
||||||
|
MainWindow dialog = new MainWindow();
|
||||||
|
dialog.pack();
|
||||||
|
dialog.setTitle("EndPoint");
|
||||||
|
dialog.setVisible(true);
|
||||||
|
Tools.centerFrame(dialog);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
127
src/main/java/ovh/alexisdelhaie/endpoint/MainWindow.form
Normal file
127
src/main/java/ovh/alexisdelhaie/endpoint/MainWindow.form
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ovh.alexisdelhaie.endpoint.MainWindow">
|
||||||
|
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="4" column-count="16" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="10" left="10" bottom="10" right="10"/>
|
||||||
|
<constraints>
|
||||||
|
<xy x="48" y="54" width="1098" height="665"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="d63fe" class="javax.swing.JComboBox" binding="methodBox">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="69" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<model>
|
||||||
|
<item value="GET"/>
|
||||||
|
<item value="POST"/>
|
||||||
|
<item value="PUT"/>
|
||||||
|
<item value="DELETE"/>
|
||||||
|
<item value="HEAD"/>
|
||||||
|
</model>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="4f0bf" class="javax.swing.JTextField" binding="urlField">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="14" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="150" height="-1"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
|
<component id="842fb" class="javax.swing.JButton" binding="sendButton">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="15" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Send"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<tabbedpane id="59105" binding="tabbedPane1" default-binding="true">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="0" row-span="1" col-span="16" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="200" height="200"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</tabbedpane>
|
||||||
|
<component id="269e7" class="javax.swing.JButton" binding="newTabButton">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="15" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="+"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<hspacer id="99ebb">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="10" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<hspacer id="61410">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="11" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<hspacer id="a631b">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="12" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<hspacer id="a9cf4">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="13" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<hspacer id="98507">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="14" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<component id="8a044" class="javax.swing.JProgressBar" binding="progressBar1" default-binding="true">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="0" row-span="1" col-span="5" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
|
<component id="d8db9" class="javax.swing.JLabel" binding="statusLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="5" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<font style="1"/>
|
||||||
|
<text value="Execute request to get status"/>
|
||||||
|
<visible value="false"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<hspacer id="ddb06">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="7" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<hspacer id="205f4">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="8" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<hspacer id="8678b">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="9" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<component id="45ca1" class="javax.swing.JButton" binding="settingsButton" default-binding="true">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="14" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Settings"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
||||||
243
src/main/java/ovh/alexisdelhaie/endpoint/MainWindow.java
Normal file
243
src/main/java/ovh/alexisdelhaie/endpoint/MainWindow.java
Normal file
@@ -0,0 +1,243 @@
|
|||||||
|
package ovh.alexisdelhaie.endpoint;
|
||||||
|
|
||||||
|
import ovh.alexisdelhaie.endpoint.builder.TabBuilder;
|
||||||
|
import ovh.alexisdelhaie.endpoint.configuration.ConfigurationDialog;
|
||||||
|
import ovh.alexisdelhaie.endpoint.configuration.ConfigurationProperties;
|
||||||
|
import ovh.alexisdelhaie.endpoint.http.HttpClient;
|
||||||
|
import ovh.alexisdelhaie.endpoint.http.Request;
|
||||||
|
import ovh.alexisdelhaie.endpoint.http.RequestBuilder;
|
||||||
|
import ovh.alexisdelhaie.endpoint.http.Response;
|
||||||
|
import ovh.alexisdelhaie.endpoint.utils.MessageDialog;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.event.DocumentEvent;
|
||||||
|
import javax.swing.event.DocumentListener;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.security.KeyManagementException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class MainWindow extends JFrame {
|
||||||
|
|
||||||
|
private enum StatusColor {
|
||||||
|
INFORMATION("#53baf5"),
|
||||||
|
SUCCESS("#7ccf16"),
|
||||||
|
REDIRECTION("#b153f5"),
|
||||||
|
ERROR_CLIENT("#f5ca53"),
|
||||||
|
ERROR_SERVER("#f55353");
|
||||||
|
|
||||||
|
private final String hex;
|
||||||
|
|
||||||
|
StatusColor(String s) {
|
||||||
|
hex = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHex() {
|
||||||
|
return hex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
public final static int WIDTH = 1280;
|
||||||
|
public final static int HEIGHT = 720;
|
||||||
|
|
||||||
|
private JPanel contentPane;
|
||||||
|
private JComboBox<String> methodBox;
|
||||||
|
private JTextField urlField;
|
||||||
|
private JButton sendButton;
|
||||||
|
private JTabbedPane tabbedPane1;
|
||||||
|
private JButton newTabButton;
|
||||||
|
private JProgressBar progressBar1;
|
||||||
|
private JLabel statusLabel;
|
||||||
|
private JButton settingsButton;
|
||||||
|
|
||||||
|
private final ConfigurationProperties props;
|
||||||
|
private final HashMap<Integer, String> urls;
|
||||||
|
|
||||||
|
private final ConcurrentHashMap<Integer, Boolean> controlState;
|
||||||
|
private final ConcurrentHashMap<Integer, Response> responses;
|
||||||
|
|
||||||
|
public MainWindow() throws IOException {
|
||||||
|
props = new ConfigurationProperties();
|
||||||
|
controlState = new ConcurrentHashMap<>();
|
||||||
|
responses = new ConcurrentHashMap<>();
|
||||||
|
urls = new HashMap<>();
|
||||||
|
setIconImage(ImageIO.read(MainWindow.class.getResource("/icon.png")));
|
||||||
|
setContentPane(contentPane);
|
||||||
|
setMinimumSize(new Dimension(WIDTH, HEIGHT));
|
||||||
|
setSize(WIDTH, HEIGHT);
|
||||||
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
TabBuilder.create(tabbedPane1, "New request", urls, urlField);
|
||||||
|
Component tab = tabbedPane1.getSelectedComponent();
|
||||||
|
urls.put(tab.hashCode(), "");
|
||||||
|
enableControl(true, tab.hashCode());
|
||||||
|
settingsButton.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
super.mouseClicked(e);
|
||||||
|
ConfigurationDialog.showDialog(props);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
newTabButton.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
super.mouseClicked(e);
|
||||||
|
TabBuilder.create(tabbedPane1, "New request", urls, urlField);
|
||||||
|
Component tab = tabbedPane1.getSelectedComponent();
|
||||||
|
urls.put(tab.hashCode(), "");
|
||||||
|
enableControl(true, tab.hashCode());
|
||||||
|
showStatus(tab.hashCode());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
sendButton.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
super.mouseClicked(e);
|
||||||
|
if (!urlField.getText().isBlank()) {
|
||||||
|
sendRequest();
|
||||||
|
} else {
|
||||||
|
MessageDialog.info("Url field empty", "Please enter an url");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
tabbedPane1.addChangeListener(e -> {
|
||||||
|
if (tabbedPane1.getSelectedIndex() != -1) {
|
||||||
|
int hashCode = tabbedPane1.getSelectedComponent().hashCode();
|
||||||
|
urlField.setText(urls.get(hashCode));
|
||||||
|
enableControl(controlState.get(hashCode), hashCode);
|
||||||
|
showStatus(tab.hashCode());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
urlField.getDocument().addDocumentListener(new DocumentListener() {
|
||||||
|
public void changedUpdate(DocumentEvent e) {
|
||||||
|
warn();
|
||||||
|
}
|
||||||
|
public void removeUpdate(DocumentEvent e) {
|
||||||
|
warn();
|
||||||
|
}
|
||||||
|
public void insertUpdate(DocumentEvent e) {
|
||||||
|
warn();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void warn() {
|
||||||
|
if (tabbedPane1.getSelectedIndex() != -1) {
|
||||||
|
urls.put(tabbedPane1.getSelectedComponent().hashCode(), urlField.getText());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendRequest() {
|
||||||
|
Optional<JSplitPane> possibleTab = getSelectedTab();
|
||||||
|
if (possibleTab.isPresent()) {
|
||||||
|
JSplitPane tab = possibleTab.get();
|
||||||
|
int tabHashCode = tab.hashCode();
|
||||||
|
statusLabel.setVisible(false);
|
||||||
|
enableControl(false, tabHashCode);
|
||||||
|
int i = tabbedPane1.indexOfComponent(tab);
|
||||||
|
JTextArea responseBody = TabBuilder.getResponseArea(i);
|
||||||
|
responseBody.setForeground(Color.black);
|
||||||
|
responseBody.setText("");
|
||||||
|
JTextArea bodyField = TabBuilder.getBody(i);
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
String url = urlField.getText();
|
||||||
|
HttpClient h = new HttpClient(props);
|
||||||
|
Request r = new RequestBuilder(url)
|
||||||
|
.setCustomHeaders(TabBuilder.getHeaders(i))
|
||||||
|
.build();
|
||||||
|
Optional<Response> possibleRes = Optional.empty();
|
||||||
|
switch ((String) Objects.requireNonNull(methodBox.getSelectedItem())) {
|
||||||
|
case "GET" -> possibleRes = h.get(r);
|
||||||
|
case "POST" -> possibleRes = h.post(r, bodyField.getText());
|
||||||
|
case "PUT" -> possibleRes = h.put(r, bodyField.getText());
|
||||||
|
case "DELETE" -> possibleRes = h.delete(r);
|
||||||
|
case "HEAD" -> possibleRes = h.head(r);
|
||||||
|
}
|
||||||
|
if (possibleRes.isPresent()) {
|
||||||
|
Response res = possibleRes.get();
|
||||||
|
responses.put(tabHashCode, res);
|
||||||
|
responseBody.setText(res.getBody());
|
||||||
|
}
|
||||||
|
} catch (KeyManagementException | IOException | NoSuchAlgorithmException e) {
|
||||||
|
responseBody.setForeground(Color.red);
|
||||||
|
responseBody.setText(e.getMessage());
|
||||||
|
if (responses.containsKey(tabHashCode)) {
|
||||||
|
responses.remove(tabHashCode);
|
||||||
|
showStatus(tabHashCode);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
enableControl(true, tabHashCode);
|
||||||
|
showStatus(tabHashCode);
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
} else {
|
||||||
|
MessageDialog.error("Error", "Cannot get current tab");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enableControl(Boolean state, int hashCode) {
|
||||||
|
if (Objects.nonNull(state)) {
|
||||||
|
controlState.put(hashCode, state);
|
||||||
|
if (tabbedPane1.getSelectedComponent().hashCode() == hashCode) {
|
||||||
|
sendButton.setEnabled(state);
|
||||||
|
urlField.setEnabled(state);
|
||||||
|
methodBox.setEnabled(state);
|
||||||
|
progressBar1.setIndeterminate(!state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showStatus(int hashCode) {
|
||||||
|
if (controlState.get(hashCode) && responses.containsKey(hashCode) &&
|
||||||
|
tabbedPane1.getSelectedComponent().hashCode() == hashCode) {
|
||||||
|
statusLabel.setForeground(Color.BLACK);
|
||||||
|
Response res = responses.get(hashCode);
|
||||||
|
final StringBuilder sb = new StringBuilder();
|
||||||
|
if (res.getStatusCode() != -1) {
|
||||||
|
sb.append(res.getStatusCode())
|
||||||
|
.append(" ")
|
||||||
|
.append(res.getStatus())
|
||||||
|
.append(" (in ")
|
||||||
|
.append(res.getTime())
|
||||||
|
.append(" ms)");
|
||||||
|
if (res.getStatusCode() >= 100 && res.getStatusCode() < 200) {
|
||||||
|
statusLabel.setForeground(Color.decode(StatusColor.INFORMATION.getHex()));
|
||||||
|
} else if (res.getStatusCode() >= 200 && res.getStatusCode() < 300) {
|
||||||
|
statusLabel.setForeground(Color.decode(StatusColor.SUCCESS.getHex()));
|
||||||
|
} else if (res.getStatusCode() >= 300 && res.getStatusCode() < 400) {
|
||||||
|
statusLabel.setForeground(Color.decode(StatusColor.REDIRECTION.getHex()));
|
||||||
|
} else if (res.getStatusCode() >= 400 && res.getStatusCode() < 500) {
|
||||||
|
statusLabel.setForeground(Color.decode(StatusColor.ERROR_CLIENT.getHex()));
|
||||||
|
} else if (res.getStatusCode() >= 500) {
|
||||||
|
statusLabel.setForeground(Color.decode(StatusColor.ERROR_SERVER.getHex()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sb.append("in ")
|
||||||
|
.append(res.getTime())
|
||||||
|
.append(" ms");
|
||||||
|
}
|
||||||
|
|
||||||
|
statusLabel.setText(sb.toString());
|
||||||
|
statusLabel.setVisible(true);
|
||||||
|
} else {
|
||||||
|
statusLabel.setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Optional<JSplitPane> getSelectedTab() {
|
||||||
|
Component c = tabbedPane1.getSelectedComponent();
|
||||||
|
if (c instanceof JSplitPane) {
|
||||||
|
return Optional.of((JSplitPane) c);
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
142
src/main/java/ovh/alexisdelhaie/endpoint/builder/TabBuilder.java
Normal file
142
src/main/java/ovh/alexisdelhaie/endpoint/builder/TabBuilder.java
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
package ovh.alexisdelhaie.endpoint.builder;
|
||||||
|
|
||||||
|
import ovh.alexisdelhaie.endpoint.utils.Tools;
|
||||||
|
import ovh.alexisdelhaie.endpoint.utils.adapter.CustomDeleteMouseAdapter;
|
||||||
|
import ovh.alexisdelhaie.endpoint.utils.adapter.CustomNewMouseAdapter;
|
||||||
|
import ovh.alexisdelhaie.endpoint.utils.adapter.DeleteParamMouseAdapter;
|
||||||
|
import ovh.alexisdelhaie.endpoint.utils.adapter.NewParamMouseAdapter;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.table.DefaultTableModel;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class TabBuilder {
|
||||||
|
|
||||||
|
private static final HashMap<String, Component> indexes = new HashMap<>();
|
||||||
|
|
||||||
|
public static void create(JTabbedPane tab, String label, HashMap<Integer, String> urls, JTextField urlField) {
|
||||||
|
Component c = tab.add("", buildMainPanel(urlField));
|
||||||
|
int index = tab.indexOfComponent(c);
|
||||||
|
updateIndexes(index);
|
||||||
|
tab.setTabComponentAt(index, buildTabPanel(tab, c, label, urls));
|
||||||
|
tab.setSelectedComponent(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void updateIndexes(int index) {
|
||||||
|
indexes.put("main[" + index + "].responseTextArea", indexes.get("main[waiting].responseTextArea"));
|
||||||
|
indexes.put("main[" + index + "].body", indexes.get("main[waiting].body"));
|
||||||
|
indexes.put("main[" + index + "].params", indexes.get("main[waiting].params"));
|
||||||
|
indexes.put("main[" + index + "].headers", indexes.get("main[waiting].headers"));
|
||||||
|
indexes.remove("main[waiting].responseTextArea");
|
||||||
|
indexes.remove("main[waiting].body");
|
||||||
|
indexes.remove("main[waiting].params");
|
||||||
|
indexes.remove("main[waiting].headers");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JPanel buildTabPanel(JTabbedPane tab, Component c, String label, HashMap<Integer, String> urls) {
|
||||||
|
JPanel p = new JPanel(new GridBagLayout());
|
||||||
|
p.setOpaque(false);
|
||||||
|
JLabel l = new JLabel(label);
|
||||||
|
GridBagConstraints g = new GridBagConstraints();
|
||||||
|
g.gridx = 0;
|
||||||
|
g.gridy = 0;
|
||||||
|
g.weightx = 1;
|
||||||
|
p.add(l, g);
|
||||||
|
g.gridx++;
|
||||||
|
g.weightx = 0;
|
||||||
|
p.add(buildCloseButton(tab, c, urls), g);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JButton buildCloseButton(JTabbedPane tab, Component c, HashMap<Integer, String> urls) {
|
||||||
|
JButton b = new JButton("×");
|
||||||
|
b.setBorderPainted(false);
|
||||||
|
b.setFocusPainted(false);
|
||||||
|
b.setOpaque(false);
|
||||||
|
b.setContentAreaFilled(false);
|
||||||
|
b.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
super.mouseClicked(e);
|
||||||
|
urls.remove(c.hashCode());
|
||||||
|
tab.remove(c);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JSplitPane buildMainPanel(JTextField urlField) {
|
||||||
|
JTextArea t = new JTextArea();
|
||||||
|
t.setBackground(Color.WHITE);
|
||||||
|
t.setEditable(false);
|
||||||
|
JScrollPane sp = new JScrollPane(t);
|
||||||
|
indexes.put("main[waiting].responseTextArea", t);
|
||||||
|
return new JSplitPane(
|
||||||
|
JSplitPane.VERTICAL_SPLIT,
|
||||||
|
buildParametersTabbedPane(urlField),
|
||||||
|
sp
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JTabbedPane buildParametersTabbedPane(JTextField urlField) {
|
||||||
|
JTabbedPane p = new JTabbedPane();
|
||||||
|
p.add("Params", buildParamsTab(true, urlField));
|
||||||
|
p.add("Authorization", new JPanel());
|
||||||
|
p.add("Headers", buildParamsTab(false, null));
|
||||||
|
JTextArea body = new JTextArea();
|
||||||
|
indexes.put("main[waiting].body", body);
|
||||||
|
p.add("Body", body);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JTextArea getResponseArea(int index) {
|
||||||
|
return (JTextArea) indexes.get("main[" + index + "].responseTextArea");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JTextArea getBody(int index) {
|
||||||
|
return (JTextArea) indexes.get("main[" + index + "].body");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HashMap<String, String> getParams(int index) {
|
||||||
|
JTable t = (JTable) indexes.get("main[" + index + "].params");
|
||||||
|
return Tools.tableToHashMap(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HashMap<String, String> getHeaders(int index) {
|
||||||
|
JTable t = (JTable) indexes.get("main[" + index + "].headers");
|
||||||
|
return Tools.tableToHashMap(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JPanel buildParamsTab(boolean isParam, JTextField urlField) {
|
||||||
|
String[] headers = {"Keys", "Values"};
|
||||||
|
DefaultTableModel model = new DefaultTableModel(new Object[][]{}, headers);
|
||||||
|
JPanel p = new JPanel();
|
||||||
|
JTable t = new JTable(model);
|
||||||
|
indexes.put((isParam) ? "main[waiting].params" : "main[waiting].headers", t);
|
||||||
|
JButton addButton = new JButton("New");
|
||||||
|
JButton delButton = new JButton("Remove");
|
||||||
|
delButton.setEnabled(false);
|
||||||
|
t.getSelectionModel().addListSelectionListener(event -> delButton.setEnabled(t.getSelectedRows().length > 0));
|
||||||
|
if (isParam) {
|
||||||
|
addButton.addMouseListener(new NewParamMouseAdapter(t, urlField));
|
||||||
|
delButton.addMouseListener(new DeleteParamMouseAdapter(t, urlField));
|
||||||
|
} else {
|
||||||
|
addButton.addMouseListener(new CustomNewMouseAdapter(t));
|
||||||
|
delButton.addMouseListener(new CustomDeleteMouseAdapter(t));
|
||||||
|
}
|
||||||
|
p.add(addButton);
|
||||||
|
p.add(delButton);
|
||||||
|
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
|
||||||
|
|
||||||
|
JPanel pp = new JPanel();
|
||||||
|
pp.add(p);
|
||||||
|
JScrollPane sp = new JScrollPane(t);
|
||||||
|
pp.add(sp);
|
||||||
|
pp.setLayout(new BoxLayout(pp, BoxLayout.Y_AXIS));
|
||||||
|
return pp;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ovh.alexisdelhaie.endpoint.configuration.AboutDialog">
|
||||||
|
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="10" left="10" bottom="10" right="10"/>
|
||||||
|
<constraints>
|
||||||
|
<xy x="48" y="54" width="451" height="414"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="e3588" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="9d713" class="javax.swing.JLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Author: Alexis Delhaie (@alexlegarnd)"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="b3568" class="javax.swing.JLabel" binding="version">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Version: 0.0.0 (Unrecognized)"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="444e9" class="javax.swing.JLabel" binding="javaVersion">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Software: Java version not recognized"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="40714" class="javax.swing.JLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Installer: Delphi 10.3.3 Community"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="93468" class="javax.swing.JLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Installer Bootstrap: Python 3.8.5 [MSC v.1924 (AMD64)]"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package ovh.alexisdelhaie.endpoint.configuration;
|
||||||
|
|
||||||
|
import ovh.alexisdelhaie.endpoint.utils.Tools;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class AboutDialog extends JDialog {
|
||||||
|
|
||||||
|
public static final int WIDTH = 450;
|
||||||
|
public static final int HEIGHT = 500;
|
||||||
|
|
||||||
|
public static final String VERSION = "0.1.3";
|
||||||
|
|
||||||
|
private JPanel contentPane;
|
||||||
|
private JLabel version;
|
||||||
|
private JLabel javaVersion;
|
||||||
|
|
||||||
|
private AboutDialog() {
|
||||||
|
setContentPane(contentPane);
|
||||||
|
setModal(true);
|
||||||
|
setTitle("About EndPoint");
|
||||||
|
version.setText("Version: " + VERSION + " (NOT FINISHED)");
|
||||||
|
javaVersion.setText("Software: Java " + System.getProperty("java.version") + " (GUI: Java Swing)");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showDialog() {
|
||||||
|
AboutDialog dialog = new AboutDialog();
|
||||||
|
dialog.setModal(true);
|
||||||
|
dialog.setMinimumSize(new Dimension(WIDTH, HEIGHT));
|
||||||
|
dialog.setMaximumSize(new Dimension(WIDTH, HEIGHT));
|
||||||
|
dialog.setResizable(false);
|
||||||
|
Tools.centerFrame(dialog);
|
||||||
|
dialog.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,175 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ovh.alexisdelhaie.endpoint.configuration.ConfigurationDialog">
|
||||||
|
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="10" left="10" bottom="10" right="10"/>
|
||||||
|
<constraints>
|
||||||
|
<xy x="48" y="54" width="436" height="548"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<hspacer id="98af6">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="e7465" class="javax.swing.JButton" binding="buttonOK">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="OK"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<component id="6ce6a" class="javax.swing.JButton" binding="aboutButton" default-binding="true">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="About"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="e3588" layout-manager="GridLayoutManager" row-count="7" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="bd5a4" class="javax.swing.JLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<font style="1"/>
|
||||||
|
<text value="SSL"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<hspacer id="cead8">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<vspacer id="d1324">
|
||||||
|
<constraints>
|
||||||
|
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
|
<component id="c7f68" class="javax.swing.JLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Allow invalid SSL certificate"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="29186" class="javax.swing.JLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Downgrade when SSL failed"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="6b9a8" class="javax.swing.JLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<font style="1"/>
|
||||||
|
<text value="Requests"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="a81f8" class="javax.swing.JLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="HTTP Version"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<hspacer id="b74d9">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="1" row-span="1" col-span="3" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<hspacer id="a9ad8">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<component id="747d1" class="javax.swing.JComboBox" binding="httpVersion">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="2" row-span="1" col-span="3" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<model>
|
||||||
|
<item value="HTTP/1.0"/>
|
||||||
|
<item value="HTTP/1.1"/>
|
||||||
|
</model>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<hspacer id="c9d2e">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="1" row-span="1" col-span="3" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<component id="51da5" class="javax.swing.JLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Timeout (TTL)"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="fb7c" class="javax.swing.JCheckBox" binding="allowInvalidSsl">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="3d1d" class="javax.swing.JCheckBox" binding="allowDowngrade">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<hideActionText value="true"/>
|
||||||
|
<horizontalAlignment value="10"/>
|
||||||
|
<selected value="true"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="e63f7" class="javax.swing.JSpinner" binding="timeout">
|
||||||
|
<constraints>
|
||||||
|
<grid row="5" column="2" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package ovh.alexisdelhaie.endpoint.configuration;
|
||||||
|
|
||||||
|
import ovh.alexisdelhaie.endpoint.utils.Tools;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class ConfigurationDialog extends JDialog {
|
||||||
|
|
||||||
|
public static final int WIDTH = 450;
|
||||||
|
public static final int HEIGHT = 700;
|
||||||
|
|
||||||
|
private JPanel contentPane;
|
||||||
|
private JButton buttonOK;
|
||||||
|
private JCheckBox allowInvalidSsl;
|
||||||
|
private JCheckBox allowDowngrade;
|
||||||
|
private JComboBox<String> httpVersion;
|
||||||
|
private JSpinner timeout;
|
||||||
|
private JButton aboutButton;
|
||||||
|
|
||||||
|
private final ConfigurationProperties props;
|
||||||
|
|
||||||
|
private ConfigurationDialog(ConfigurationProperties props) {
|
||||||
|
setContentPane(contentPane);
|
||||||
|
setModal(true);
|
||||||
|
getRootPane().setDefaultButton(buttonOK);
|
||||||
|
setTitle("Settings");
|
||||||
|
this.props = props;
|
||||||
|
buttonOK.addActionListener(e -> onOK());
|
||||||
|
aboutButton.addActionListener(e -> AboutDialog.showDialog());
|
||||||
|
allowInvalidSsl.setSelected(this.props.getBooleanProperty("allowInvalidSsl", false));
|
||||||
|
allowDowngrade.setSelected(this.props.getBooleanProperty("allowDowngrade", true));
|
||||||
|
httpVersion.setSelectedItem(this.props.getStringProperty("httpVersion", "HTTP/1.0"));
|
||||||
|
timeout.setValue(this.props.getIntegerProperty("timeout", 10000));
|
||||||
|
|
||||||
|
allowInvalidSsl.addActionListener((e) -> {
|
||||||
|
this.props.setProperty("allowInvalidSsl", String.valueOf(allowInvalidSsl.isSelected()));
|
||||||
|
});
|
||||||
|
allowDowngrade.addActionListener((e) -> {
|
||||||
|
this.props.setProperty("allowDowngrade", String.valueOf(allowDowngrade.isSelected()));
|
||||||
|
});
|
||||||
|
httpVersion.addActionListener((e) -> {
|
||||||
|
this.props.setProperty("httpVersion", (String) httpVersion.getSelectedItem());
|
||||||
|
});
|
||||||
|
timeout.addChangeListener((e) -> {
|
||||||
|
this.props.setProperty("timeout", String.valueOf(timeout.getValue()));
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onOK() {
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showDialog(ConfigurationProperties props) {
|
||||||
|
ConfigurationDialog dialog = new ConfigurationDialog(props);
|
||||||
|
dialog.setModal(true);
|
||||||
|
dialog.setMinimumSize(new Dimension(WIDTH, HEIGHT));
|
||||||
|
dialog.setMaximumSize(new Dimension(WIDTH, HEIGHT));
|
||||||
|
dialog.setResizable(false);
|
||||||
|
Tools.centerFrame(dialog);
|
||||||
|
dialog.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ package ovh.alexisdelhaie.endpoint.configuration;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import javafx.scene.control.Alert;
|
import ovh.alexisdelhaie.endpoint.utils.MessageDialog;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -52,15 +52,18 @@ public class ConfigurationProperties {
|
|||||||
return defaultB;
|
return defaultB;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getIntegerProperty(String key, int defaultI) {
|
||||||
|
if (properties.containsKey(key)) {
|
||||||
|
return Integer.parseInt(properties.get(key));
|
||||||
|
}
|
||||||
|
return defaultI;
|
||||||
|
}
|
||||||
|
|
||||||
private void save() {
|
private void save() {
|
||||||
try {
|
try {
|
||||||
mapper.writeValue(new File(filepath), properties);
|
mapper.writeValue(new File(filepath), properties);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
MessageDialog.error("Cannot save settings", "There was an error while saving settings file");
|
||||||
alert.setTitle("Cannot save settings");
|
|
||||||
alert.setHeaderText("There was an error while saving settings file");
|
|
||||||
alert.setContentText(e.getMessage());
|
|
||||||
alert.showAndWait();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,11 +74,7 @@ public class ConfigurationProperties {
|
|||||||
properties = mapper.readValue(f, new TypeReference<Map<String, String>>() { });
|
properties = mapper.readValue(f, new TypeReference<Map<String, String>>() { });
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
MessageDialog.error("Cannot initialize settings", "There was an error while initializing settings file");
|
||||||
alert.setTitle("Cannot initialize settings");
|
|
||||||
alert.setHeaderText("There was an error while initializing settings file");
|
|
||||||
alert.setContentText(e.getMessage());
|
|
||||||
alert.showAndWait();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,11 +87,7 @@ public class ConfigurationProperties {
|
|||||||
Files.createDirectories(path);
|
Files.createDirectories(path);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
MessageDialog.error("Cannot create app folder", "There was an error while creating appdata folder");
|
||||||
alert.setTitle("Cannot create app folder");
|
|
||||||
alert.setHeaderText("There was an error while creating appdata folder");
|
|
||||||
alert.setContentText(e.getMessage());
|
|
||||||
alert.showAndWait();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,17 +22,21 @@ public class HttpClient {
|
|||||||
public final static int DEFAULT_TIMEOUT = 10000;
|
public final static int DEFAULT_TIMEOUT = 10000;
|
||||||
public final static boolean DEFAULT_ALLOW_INVALID_SSL = false;
|
public final static boolean DEFAULT_ALLOW_INVALID_SSL = false;
|
||||||
public final static boolean DEFAULT_ALLOW_DOWNGRADE = true;
|
public final static boolean DEFAULT_ALLOW_DOWNGRADE = true;
|
||||||
public final static String DEFAULT_HTTP_VERSION = "HTTP/1.1";
|
public final static String DEFAULT_HTTP_VERSION = "HTTP/1.0";
|
||||||
|
|
||||||
private final boolean allowInvalidSsl;
|
private final boolean allowInvalidSsl;
|
||||||
private final boolean allowDowngrade;
|
private final boolean allowDowngrade;
|
||||||
private final String httpVersion;
|
private final String httpVersion;
|
||||||
|
private final int timeout;
|
||||||
|
|
||||||
private boolean downgraded;
|
private boolean downgraded;
|
||||||
|
|
||||||
public HttpClient(ConfigurationProperties props) {
|
public HttpClient(ConfigurationProperties props) {
|
||||||
this.allowInvalidSsl = props.getBooleanProperty("allowInvalidSsl", DEFAULT_ALLOW_INVALID_SSL);
|
this.allowInvalidSsl = props.getBooleanProperty("allowInvalidSsl", DEFAULT_ALLOW_INVALID_SSL);
|
||||||
this.allowDowngrade = props.getBooleanProperty("allowDowngrade", DEFAULT_ALLOW_DOWNGRADE);
|
this.allowDowngrade = props.getBooleanProperty("allowDowngrade", DEFAULT_ALLOW_DOWNGRADE);
|
||||||
this.httpVersion = props.getStringProperty("httpVersion", DEFAULT_HTTP_VERSION);
|
this.httpVersion = props.getStringProperty("httpVersion", DEFAULT_HTTP_VERSION);
|
||||||
|
this.timeout = props.getIntegerProperty("timeout", DEFAULT_TIMEOUT);
|
||||||
|
|
||||||
this.downgraded = false;
|
this.downgraded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +103,7 @@ public class HttpClient {
|
|||||||
private Socket buildSocket(String host, int port) throws IOException {
|
private Socket buildSocket(String host, int port) throws IOException {
|
||||||
Socket s = new Socket(host, port);
|
Socket s = new Socket(host, port);
|
||||||
s.setKeepAlive(false);
|
s.setKeepAlive(false);
|
||||||
s.setSoTimeout(DEFAULT_TIMEOUT);
|
s.setSoTimeout(timeout);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +128,7 @@ public class HttpClient {
|
|||||||
SSLSocket s = (SSLSocket) factory.createSocket(host, port);
|
SSLSocket s = (SSLSocket) factory.createSocket(host, port);
|
||||||
s.setEnabledProtocols(new String[] { "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2" });
|
s.setEnabledProtocols(new String[] { "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2" });
|
||||||
s.setKeepAlive(false);
|
s.setKeepAlive(false);
|
||||||
s.setSoTimeout(DEFAULT_TIMEOUT);
|
s.setSoTimeout(timeout);
|
||||||
if (allowDowngrade) {
|
if (allowDowngrade) {
|
||||||
try {
|
try {
|
||||||
s.startHandshake();
|
s.startHandshake();
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ovh.alexisdelhaie.endpoint.utils.InsertToTableDialog">
|
||||||
|
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="10" left="10" bottom="10" right="10"/>
|
||||||
|
<constraints>
|
||||||
|
<xy x="48" y="54" width="436" height="214"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<hspacer id="98af6">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="e7465" class="javax.swing.JButton" binding="buttonOK">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="OK"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="5723f" class="javax.swing.JButton" binding="buttonCancel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Cancel"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="e3588" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="c8c26" class="javax.swing.JLabel" binding="message">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<font size="24"/>
|
||||||
|
<text value="Label"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="b2442" class="javax.swing.JTextField" binding="keyField">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="150" height="-1"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
|
<component id="2a539" class="javax.swing.JTextField" binding="valueField">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="150" height="-1"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
|
<component id="ae42e" class="javax.swing.JLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Key"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="481b3" class="javax.swing.JLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Value"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package ovh.alexisdelhaie.endpoint.utils;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.*;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class InsertToTableDialog extends JDialog {
|
||||||
|
|
||||||
|
public static final int WIDTH = 325;
|
||||||
|
public static final int HEIGHT = 195;
|
||||||
|
|
||||||
|
private JPanel contentPane;
|
||||||
|
private JButton buttonOK;
|
||||||
|
private JButton buttonCancel;
|
||||||
|
private JTextField keyField;
|
||||||
|
private JTextField valueField;
|
||||||
|
private JLabel message;
|
||||||
|
|
||||||
|
private boolean accepted = false;
|
||||||
|
|
||||||
|
private InsertToTableDialog(String message) {
|
||||||
|
setTitle("Insert");
|
||||||
|
setContentPane(contentPane);
|
||||||
|
setModal(true);
|
||||||
|
getRootPane().setDefaultButton(buttonOK);
|
||||||
|
this.message.setText(message);
|
||||||
|
|
||||||
|
buttonOK.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
onOK();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonCancel.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
onCancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// call onCancel() when cross is clicked
|
||||||
|
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||||
|
addWindowListener(new WindowAdapter() {
|
||||||
|
public void windowClosing(WindowEvent e) {
|
||||||
|
onCancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// call onCancel() on ESCAPE
|
||||||
|
contentPane.registerKeyboardAction(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
onCancel();
|
||||||
|
}
|
||||||
|
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onOK() {
|
||||||
|
accepted = true;
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onCancel() {
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Optional<KeyValuePair> showDialog(String message) {
|
||||||
|
InsertToTableDialog dialog = new InsertToTableDialog(message);
|
||||||
|
dialog.setModal(true);
|
||||||
|
dialog.setMinimumSize(new Dimension(WIDTH, HEIGHT));
|
||||||
|
dialog.setMaximumSize(new Dimension(WIDTH, HEIGHT));
|
||||||
|
dialog.setResizable(false);
|
||||||
|
Tools.centerFrame(dialog);
|
||||||
|
dialog.setVisible(true);
|
||||||
|
if (dialog.accepted && !dialog.keyField.getText().isBlank()) {
|
||||||
|
return Optional.of(new KeyValuePair(dialog.keyField.getText(), dialog.valueField.getText()));
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package ovh.alexisdelhaie.endpoint.utils;
|
||||||
|
|
||||||
|
public class KeyValuePair {
|
||||||
|
|
||||||
|
private String key;
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
public KeyValuePair(String key, String value) {
|
||||||
|
this.key = key;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package ovh.alexisdelhaie.endpoint.utils;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class MessageDialog {
|
||||||
|
|
||||||
|
public static void error(String title, String message) {
|
||||||
|
JOptionPane.showMessageDialog(new JFrame(), message, title,
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void warning(String title, String message) {
|
||||||
|
JOptionPane.showMessageDialog(new JFrame(), message, title,
|
||||||
|
JOptionPane.WARNING_MESSAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void info(String title, String message) {
|
||||||
|
JOptionPane.showMessageDialog(new JFrame(), message, title,
|
||||||
|
JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
35
src/main/java/ovh/alexisdelhaie/endpoint/utils/Tools.java
Normal file
35
src/main/java/ovh/alexisdelhaie/endpoint/utils/Tools.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package ovh.alexisdelhaie.endpoint.utils;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.table.DefaultTableModel;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class Tools {
|
||||||
|
|
||||||
|
public static Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
|
||||||
|
|
||||||
|
public static void centerFrame(Dialog dialog) {
|
||||||
|
int y = (int)( screen.getHeight() / 2 ) - dialog.getHeight() / 2;
|
||||||
|
int x = (int)( screen.getWidth() / 2 ) - dialog.getWidth() / 2;
|
||||||
|
dialog.setLocation(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void centerFrame(Frame frame) {
|
||||||
|
int y = (int)( screen.getHeight() / 2 ) - frame.getHeight() / 2;
|
||||||
|
int x = (int)( screen.getWidth() / 2 ) - frame.getWidth() / 2;
|
||||||
|
frame.setLocation(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HashMap<String, String> tableToHashMap(JTable table) {
|
||||||
|
HashMap<String, String> result = new HashMap<>();
|
||||||
|
DefaultTableModel m = (DefaultTableModel) table.getModel();
|
||||||
|
for (int i = 0; i < m.getRowCount(); i++) {
|
||||||
|
String key = (String) m.getValueAt(i, 0);
|
||||||
|
String value = (String) m.getValueAt(i, 1);
|
||||||
|
result.put(key, value);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package ovh.alexisdelhaie.endpoint.utils.adapter;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.table.DefaultTableModel;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
|
||||||
|
public class CustomDeleteMouseAdapter extends MouseAdapter {
|
||||||
|
|
||||||
|
protected final JTable table;
|
||||||
|
protected boolean valid = false;
|
||||||
|
|
||||||
|
public CustomDeleteMouseAdapter(JTable table) {
|
||||||
|
this.table = table;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
super.mouseClicked(e);
|
||||||
|
updateTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateTable() {
|
||||||
|
int n = table.getSelectedRows().length;
|
||||||
|
if (n > 0) {
|
||||||
|
DefaultTableModel m = (DefaultTableModel) table.getModel();
|
||||||
|
for(int i = 0; i < n; i++) {
|
||||||
|
m.removeRow(table.getSelectedRow());
|
||||||
|
}
|
||||||
|
valid = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package ovh.alexisdelhaie.endpoint.utils.adapter;
|
||||||
|
|
||||||
|
import ovh.alexisdelhaie.endpoint.utils.InsertToTableDialog;
|
||||||
|
import ovh.alexisdelhaie.endpoint.utils.KeyValuePair;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.table.DefaultTableModel;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class CustomNewMouseAdapter extends MouseAdapter {
|
||||||
|
|
||||||
|
protected final JTable table;
|
||||||
|
protected boolean valid = false;
|
||||||
|
|
||||||
|
public CustomNewMouseAdapter(JTable table) {
|
||||||
|
this.table = table;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
super.mouseClicked(e);
|
||||||
|
updateTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateTable() {
|
||||||
|
Optional<KeyValuePair> result = InsertToTableDialog.showDialog("Enter value");
|
||||||
|
if (result.isPresent()) {
|
||||||
|
DefaultTableModel m = (DefaultTableModel) table.getModel();
|
||||||
|
m.addRow(new Object[]{result.get().getKey(), result.get().getValue()});
|
||||||
|
valid = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package ovh.alexisdelhaie.endpoint.utils.adapter;
|
||||||
|
|
||||||
|
import ovh.alexisdelhaie.endpoint.url.URLGenerator;
|
||||||
|
import ovh.alexisdelhaie.endpoint.utils.Tools;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
|
||||||
|
public class DeleteParamMouseAdapter extends CustomDeleteMouseAdapter {
|
||||||
|
|
||||||
|
private final JTextField urlField;
|
||||||
|
|
||||||
|
public DeleteParamMouseAdapter(JTable table, JTextField urlField) {
|
||||||
|
super(table);
|
||||||
|
this.urlField = urlField;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
super.mouseClicked(e);
|
||||||
|
if (super.valid) {
|
||||||
|
urlField.setText(URLGenerator.processNewUrl(Tools.tableToHashMap(super.table), urlField.getText()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package ovh.alexisdelhaie.endpoint.utils.adapter;
|
||||||
|
|
||||||
|
import ovh.alexisdelhaie.endpoint.url.URLGenerator;
|
||||||
|
import ovh.alexisdelhaie.endpoint.utils.Tools;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
|
||||||
|
public class NewParamMouseAdapter extends CustomNewMouseAdapter {
|
||||||
|
|
||||||
|
private final JTextField urlField;
|
||||||
|
|
||||||
|
public NewParamMouseAdapter(JTable table, JTextField urlField) {
|
||||||
|
super(table);
|
||||||
|
this.urlField = urlField;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
super.mouseClicked(e);
|
||||||
|
if (super.valid) {
|
||||||
|
urlField.setText(URLGenerator.processNewUrl(Tools.tableToHashMap(super.table), urlField.getText()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
@@ -1,33 +0,0 @@
|
|||||||
package ovh.alexisdelhaie.endpoint;
|
|
||||||
|
|
||||||
import javafx.application.Application;
|
|
||||||
import javafx.fxml.FXMLLoader;
|
|
||||||
import javafx.scene.Parent;
|
|
||||||
import javafx.scene.Scene;
|
|
||||||
import javafx.scene.image.Image;
|
|
||||||
import javafx.stage.Stage;
|
|
||||||
import ovh.alexisdelhaie.endpoint.controllers.Controller;
|
|
||||||
|
|
||||||
public class Main extends Application {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void start(Stage primaryStage) throws Exception{
|
|
||||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("mainwindow.fxml"));
|
|
||||||
Parent root = loader.load();
|
|
||||||
Controller controller = loader.getController();
|
|
||||||
controller.setStageAndSetupListeners(primaryStage);
|
|
||||||
primaryStage.setTitle("EndPoint");
|
|
||||||
primaryStage.setScene(new Scene(root, 1067, 644));
|
|
||||||
primaryStage.setMinWidth(1067);
|
|
||||||
primaryStage.setMinHeight(644);
|
|
||||||
primaryStage.setMaximized(true);
|
|
||||||
primaryStage.getIcons().add( new Image(
|
|
||||||
Main.class.getResourceAsStream( "icon.png" )));
|
|
||||||
primaryStage.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
launch(args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
package ovh.alexisdelhaie.endpoint.controllers;
|
|
||||||
|
|
||||||
import javafx.collections.FXCollections;
|
|
||||||
import javafx.event.ActionEvent;
|
|
||||||
import javafx.fxml.FXML;
|
|
||||||
import javafx.fxml.FXMLLoader;
|
|
||||||
import javafx.scene.Parent;
|
|
||||||
import javafx.scene.Scene;
|
|
||||||
import javafx.scene.control.Alert;
|
|
||||||
import javafx.scene.control.CheckBox;
|
|
||||||
import javafx.scene.control.ChoiceBox;
|
|
||||||
import javafx.scene.image.Image;
|
|
||||||
import javafx.scene.input.MouseEvent;
|
|
||||||
import javafx.stage.Modality;
|
|
||||||
import javafx.stage.Stage;
|
|
||||||
import ovh.alexisdelhaie.endpoint.configuration.ConfigurationProperties;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class ConfigurationController
|
|
||||||
{
|
|
||||||
|
|
||||||
private ConfigurationProperties configurationProperties;
|
|
||||||
private Stage primaryStage;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private CheckBox allowInvalidSsl;
|
|
||||||
@FXML
|
|
||||||
private CheckBox allowDowngrade;
|
|
||||||
@FXML
|
|
||||||
private ChoiceBox<String> httpVersion;
|
|
||||||
|
|
||||||
public void setStageAndSetupListeners(Stage s) {
|
|
||||||
primaryStage = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConfigurationProperties(ConfigurationProperties properties) {
|
|
||||||
String[] versions = { "HTTP/1.1", "HTTP/1.0" };
|
|
||||||
httpVersion.setItems(FXCollections.observableArrayList(versions));
|
|
||||||
configurationProperties = properties;
|
|
||||||
allowInvalidSsl.setSelected(properties.getBooleanProperty("allowInvalidSsl", false));
|
|
||||||
allowDowngrade.setSelected(properties.getBooleanProperty("allowDowngrade", true));
|
|
||||||
httpVersion.setValue(properties.getStringProperty("httpVersion", versions[0]));
|
|
||||||
httpVersion.setOnAction(this::onChoiceBoxValueChanged);
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private void onBooleanValueChanged(MouseEvent event) {
|
|
||||||
CheckBox c = (CheckBox) event.getSource();
|
|
||||||
configurationProperties.setProperty(c.getId(), String.valueOf(c.isSelected()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private void onChoiceBoxValueChanged(ActionEvent event) {
|
|
||||||
ChoiceBox<String> c = (ChoiceBox<String>) event.getSource();
|
|
||||||
configurationProperties.setProperty(c.getId(), c.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private void showAboutDialog() {
|
|
||||||
try {
|
|
||||||
Stage dialog = new Stage();
|
|
||||||
Parent xml = FXMLLoader.load(getClass().getResource("about.fxml"));
|
|
||||||
dialog.initOwner(primaryStage);
|
|
||||||
dialog.setScene(new Scene(xml, 707, 365));
|
|
||||||
dialog.setMaxHeight(365);
|
|
||||||
dialog.setMinHeight(365);
|
|
||||||
dialog.setMaxWidth(707);
|
|
||||||
dialog.setMinWidth(707);
|
|
||||||
dialog.setResizable(false);
|
|
||||||
dialog.setTitle("About EndPoint");
|
|
||||||
dialog.getIcons().add( new Image(
|
|
||||||
Controller.class.getResourceAsStream( "icon.png" )));
|
|
||||||
dialog.initModality(Modality.APPLICATION_MODAL);
|
|
||||||
dialog.showAndWait();
|
|
||||||
} catch (IOException e) {
|
|
||||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
|
||||||
alert.setTitle("Cannot initialize About");
|
|
||||||
alert.setHeaderText("There was an error while initializing this dialog");
|
|
||||||
alert.setContentText(e.getMessage());
|
|
||||||
alert.showAndWait();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,471 +0,0 @@
|
|||||||
package ovh.alexisdelhaie.endpoint.controllers;
|
|
||||||
|
|
||||||
import javafx.application.Platform;
|
|
||||||
import javafx.beans.property.StringProperty;
|
|
||||||
import javafx.collections.FXCollections;
|
|
||||||
import javafx.fxml.FXML;
|
|
||||||
import javafx.fxml.FXMLLoader;
|
|
||||||
import javafx.fxml.Initializable;
|
|
||||||
import javafx.geometry.Orientation;
|
|
||||||
import javafx.scene.Node;
|
|
||||||
import javafx.scene.Parent;
|
|
||||||
import javafx.scene.Scene;
|
|
||||||
import javafx.scene.control.*;
|
|
||||||
import javafx.scene.control.cell.PropertyValueFactory;
|
|
||||||
import javafx.scene.image.Image;
|
|
||||||
import javafx.scene.layout.GridPane;
|
|
||||||
import javafx.scene.layout.Pane;
|
|
||||||
import javafx.scene.paint.Color;
|
|
||||||
import javafx.stage.Modality;
|
|
||||||
import javafx.stage.Stage;
|
|
||||||
import org.apache.commons.validator.routines.UrlValidator;
|
|
||||||
import ovh.alexisdelhaie.endpoint.configuration.ConfigurationProperties;
|
|
||||||
import ovh.alexisdelhaie.endpoint.http.HttpClient;
|
|
||||||
import ovh.alexisdelhaie.endpoint.http.Request;
|
|
||||||
import ovh.alexisdelhaie.endpoint.http.RequestBuilder;
|
|
||||||
import ovh.alexisdelhaie.endpoint.http.Response;
|
|
||||||
import ovh.alexisdelhaie.endpoint.impl.EditCell;
|
|
||||||
import ovh.alexisdelhaie.endpoint.model.Param;
|
|
||||||
import ovh.alexisdelhaie.endpoint.url.URLGenerator;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.security.KeyManagementException;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.ResourceBundle;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public class Controller implements Initializable {
|
|
||||||
|
|
||||||
private enum StatusColor {
|
|
||||||
INFORMATION("#53baf5"),
|
|
||||||
SUCCESS("#7ccf16"),
|
|
||||||
REDIRECTION("#b153f5"),
|
|
||||||
ERROR_CLIENT("#f5ca53"),
|
|
||||||
ERROR_SERVER("#f55353"),
|
|
||||||
DEFAULT("BLACK");
|
|
||||||
|
|
||||||
private final String hex;
|
|
||||||
|
|
||||||
StatusColor(String s) {
|
|
||||||
hex = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getHex() {
|
|
||||||
return hex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private enum RequestTab {
|
|
||||||
PARAMS(0),
|
|
||||||
AUTHORIZATION(1),
|
|
||||||
HEADERS(2),
|
|
||||||
BODY(3),
|
|
||||||
RESPONSE(4);
|
|
||||||
|
|
||||||
private final int index;
|
|
||||||
|
|
||||||
RequestTab (int i) { index = i; }
|
|
||||||
public int getIndex() { return index; }
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private ChoiceBox<String> httpMethod;
|
|
||||||
@FXML
|
|
||||||
private TabPane tabs;
|
|
||||||
@FXML
|
|
||||||
private TextField requestInput;
|
|
||||||
@FXML
|
|
||||||
private Pane runningIndicatorPane;
|
|
||||||
|
|
||||||
private Stage primaryStage;
|
|
||||||
private HashMap<Integer, String> requests;
|
|
||||||
private HashMap<Integer, String> methods;
|
|
||||||
|
|
||||||
private ConfigurationProperties properties;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
|
||||||
properties = new ConfigurationProperties();
|
|
||||||
requests = new HashMap<>();
|
|
||||||
methods = new HashMap<>();
|
|
||||||
String[] method = { "GET", "POST", "HEAD", "PUT", "DELETE" };
|
|
||||||
httpMethod.setItems(FXCollections.observableArrayList(method));
|
|
||||||
httpMethod.setValue(method[0]);
|
|
||||||
httpMethod.setOnAction(actionEvent -> httpMethodChanged());
|
|
||||||
tabs.getSelectionModel().selectedItemProperty().addListener(
|
|
||||||
(ov, t, t1) -> {
|
|
||||||
requestInput.setText((t1 != null) ? requests.get(t1.hashCode()) : "");
|
|
||||||
httpMethod.setValue((t1 != null) ? methods.get(t1.hashCode()) : httpMethod.getValue());
|
|
||||||
}
|
|
||||||
);
|
|
||||||
createNewTab();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Tab newTab() {
|
|
||||||
SplitPane sp = new SplitPane();
|
|
||||||
|
|
||||||
Tab params = new Tab("Params", createParamTable());
|
|
||||||
Tab auth = new Tab("Authorization");
|
|
||||||
Tab headers = new Tab("Headers", createParamTable());
|
|
||||||
Tab body = new Tab("Body", new TextArea());
|
|
||||||
Tab response = new Tab("Response", createResponseTab());
|
|
||||||
|
|
||||||
TabPane options = new TabPane();
|
|
||||||
TextArea ta = new TextArea();
|
|
||||||
ta.setEditable(false);
|
|
||||||
|
|
||||||
options.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
|
|
||||||
options.getTabs().addAll(params, auth, headers, body, response);
|
|
||||||
sp.getItems().add(options);
|
|
||||||
sp.getItems().add(ta);
|
|
||||||
sp.setOrientation(Orientation.VERTICAL);
|
|
||||||
|
|
||||||
Tab tab = new Tab("untitled", sp);
|
|
||||||
tab.setOnCloseRequest(arg0 -> {
|
|
||||||
requests.remove(tab.hashCode());
|
|
||||||
methods.remove(tab.hashCode());
|
|
||||||
});
|
|
||||||
|
|
||||||
return tab;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private ScrollPane createResponseTab() {
|
|
||||||
ScrollPane sp = new ScrollPane();
|
|
||||||
Pane p = new Pane();
|
|
||||||
sp.setContent(p);
|
|
||||||
try {
|
|
||||||
Parent xml = FXMLLoader.load(getClass().getResource("responsetab.fxml"));
|
|
||||||
p.getChildren().add(xml);
|
|
||||||
TableView<Param> headers = (TableView<Param>) p.lookup("#headers");
|
|
||||||
headers.getColumns().get(0).setCellValueFactory(new PropertyValueFactory<>("name"));
|
|
||||||
headers.getColumns().get(1).setCellValueFactory(new PropertyValueFactory<>("value"));
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.err.println(e.getMessage());
|
|
||||||
}
|
|
||||||
return sp;
|
|
||||||
}
|
|
||||||
|
|
||||||
private TableView<Param> createParamTable() {
|
|
||||||
TableView<Param> paramsTable = new TableView<>();
|
|
||||||
|
|
||||||
TableColumn<Param, String> name = createColumn("Name", Param::name);
|
|
||||||
TableColumn<Param, String> value = createColumn("Value", Param::value);
|
|
||||||
|
|
||||||
name.prefWidthProperty().bind(paramsTable.widthProperty().multiply(0.5));
|
|
||||||
value.prefWidthProperty().bind(paramsTable.widthProperty().multiply(0.5));
|
|
||||||
|
|
||||||
name.setOnEditCommit(t -> {
|
|
||||||
TableView<Param> tv = t.getTableView();
|
|
||||||
t.getRowValue().name().set(t.getNewValue());
|
|
||||||
manageEmptyCells(t, tv);
|
|
||||||
});
|
|
||||||
value.setOnEditCommit(t -> {
|
|
||||||
TableView<Param> tv = t.getTableView();
|
|
||||||
t.getRowValue().value().set(t.getNewValue());
|
|
||||||
manageEmptyCells(t, tv);
|
|
||||||
});
|
|
||||||
|
|
||||||
paramsTable.getColumns().add(name);
|
|
||||||
paramsTable.getColumns().add(value);
|
|
||||||
|
|
||||||
paramsTable.setEditable(true);
|
|
||||||
paramsTable.getItems().add(new Param());
|
|
||||||
|
|
||||||
return paramsTable;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void manageEmptyCells(TableColumn.CellEditEvent<Param, String> t, TableView<Param> tv) {
|
|
||||||
if (t.getRowValue().isEmpty() && tv.getItems().size() > 1) {
|
|
||||||
tv.getItems().remove(t.getRowValue());
|
|
||||||
}
|
|
||||||
if (!tv.getItems().get(tv.getItems().size() - 1).isEmpty()) {
|
|
||||||
tv.getItems().add(new Param());
|
|
||||||
}
|
|
||||||
requestInput.setText(URLGenerator.processNewUrl(getParamsMap(), requestInput.getText()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private TableColumn<Param, String> createColumn(String title, Function<Param, StringProperty> property) {
|
|
||||||
TableColumn<Param, String> col = new TableColumn<>(title);
|
|
||||||
col.setCellValueFactory(cellData -> property.apply(cellData.getValue()));
|
|
||||||
|
|
||||||
col.setCellFactory(column -> EditCell.createStringEditCell());
|
|
||||||
return col ;
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private void start() {
|
|
||||||
if (requestInput.getText().isBlank()) {
|
|
||||||
Alert alert = new Alert(Alert.AlertType.WARNING);
|
|
||||||
alert.setTitle("URL field empty");
|
|
||||||
alert.setContentText("Enter your URL in the field at the top of the window.");
|
|
||||||
alert.showAndWait();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
runningIndicatorPane.setVisible(true);
|
|
||||||
new Thread(() -> {
|
|
||||||
final String method = httpMethod.getValue();
|
|
||||||
Optional<TextArea> textArea = getCurrentTextArea();
|
|
||||||
Optional<Response> response = Optional.empty();
|
|
||||||
if (textArea.isPresent()) {
|
|
||||||
try {
|
|
||||||
Request r = new RequestBuilder(requestInput.getText())
|
|
||||||
.setCustomHeaders(getCustomHeaders())
|
|
||||||
.build();
|
|
||||||
HttpClient hc = new HttpClient(properties);
|
|
||||||
switch (method) {
|
|
||||||
case "GET" -> response = hc.get(r);
|
|
||||||
case "POST" -> response = hc.post(r, getBody());
|
|
||||||
case "PUT" -> response = hc.put(r, getBody());
|
|
||||||
case "DELETE" -> response = hc.delete(r);
|
|
||||||
case "HEAD" -> response = hc.head(r);
|
|
||||||
}
|
|
||||||
if (response.isPresent()) {
|
|
||||||
final Response res = response.get();
|
|
||||||
Platform.runLater(() -> {
|
|
||||||
textArea.get().setStyle(null);
|
|
||||||
textArea.get().setText(res.getBody());
|
|
||||||
updateResponseTab(res);
|
|
||||||
setSelectedTab(RequestTab.RESPONSE);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (IOException | NoSuchAlgorithmException | KeyManagementException e) {
|
|
||||||
System.err.println(e.getMessage());
|
|
||||||
textArea.ifPresent(area -> Platform.runLater(() -> {
|
|
||||||
resetResponseTab();
|
|
||||||
area.setStyle("-fx-text-fill: red");
|
|
||||||
area.setText("Somethings went wrong: " + e.getMessage());
|
|
||||||
}));
|
|
||||||
} finally {
|
|
||||||
Platform.runLater(() -> {
|
|
||||||
runningIndicatorPane.setVisible(false);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Platform.runLater(() -> {
|
|
||||||
runningIndicatorPane.setVisible(false);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private void updateResponseTab(Response res) {
|
|
||||||
Optional<Tab> responseTab = getCurrentResponseTab();
|
|
||||||
if (responseTab.isPresent()) {
|
|
||||||
Label status = (Label) responseTab.get().getContent().lookup("#status");
|
|
||||||
status.setText(String.format("%s %s", res.getStatusCode(), res.getStatus()));
|
|
||||||
if (res.getStatusCode() >= 100 && res.getStatusCode() < 200) {
|
|
||||||
status.setTextFill(Color.web(StatusColor.INFORMATION.getHex()));
|
|
||||||
} else if (res.getStatusCode() >= 200 && res.getStatusCode() < 300) {
|
|
||||||
status.setTextFill(Color.web(StatusColor.SUCCESS.getHex()));
|
|
||||||
} else if (res.getStatusCode() >= 300 && res.getStatusCode() < 400) {
|
|
||||||
status.setTextFill(Color.web(StatusColor.REDIRECTION.getHex()));
|
|
||||||
} else if (res.getStatusCode() >= 400 && res.getStatusCode() < 500) {
|
|
||||||
status.setTextFill(Color.web(StatusColor.ERROR_CLIENT.getHex()));
|
|
||||||
} else if (res.getStatusCode() >= 500) {
|
|
||||||
status.setTextFill(Color.web(StatusColor.ERROR_SERVER.getHex()));
|
|
||||||
}
|
|
||||||
Label time = (Label) responseTab.get().getContent().lookup("#time");
|
|
||||||
time.setText(String.format("%s ms", res.getTime()));
|
|
||||||
TextArea raw = (TextArea) responseTab.get().getContent().lookup("#raw");
|
|
||||||
raw.setText(res.getRawResponse());
|
|
||||||
TextArea request = (TextArea) responseTab.get().getContent().lookup("#request");
|
|
||||||
request.setText(res.getRequest().getRawRequest());
|
|
||||||
GridPane downgradedIndicator = (GridPane) responseTab.get().getContent().lookup("#downgraded_indicator");
|
|
||||||
downgradedIndicator.setVisible(res.isDowngraded());
|
|
||||||
TableView<Param> headers = (TableView<Param>) responseTab.get().getContent().lookup("#headers");
|
|
||||||
headers.getItems().clear();
|
|
||||||
for (Map.Entry<String, String> entry : res.getHeaders().entrySet()) {
|
|
||||||
headers.getItems().add(new Param(entry.getKey(), entry.getValue()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setSelectedTab(RequestTab rt) {
|
|
||||||
Optional<TabPane> options = getRequestOptionsTab();
|
|
||||||
options.ifPresent(tabPane -> tabPane.getSelectionModel().select(rt.getIndex()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private void resetResponseTab() {
|
|
||||||
Optional<Tab> responseTab = getCurrentResponseTab();
|
|
||||||
if (responseTab.isPresent()) {
|
|
||||||
Label status = (Label) responseTab.get().getContent().lookup("#status");
|
|
||||||
status.setTextFill(Color.web(StatusColor.DEFAULT.getHex()));
|
|
||||||
status.setText("...");
|
|
||||||
Label time = (Label) responseTab.get().getContent().lookup("#time");
|
|
||||||
time.setText("... ms");
|
|
||||||
TextArea raw = (TextArea) responseTab.get().getContent().lookup("#raw");
|
|
||||||
raw.setText("");
|
|
||||||
TextArea request = (TextArea) responseTab.get().getContent().lookup("#request");
|
|
||||||
request.setText("");
|
|
||||||
GridPane downgradedIndicator = (GridPane) responseTab.get().getContent().lookup("#downgraded_indicator");
|
|
||||||
downgradedIndicator.setVisible(false);
|
|
||||||
TableView<Param> headers = (TableView<Param>) responseTab.get().getContent().lookup("#headers");
|
|
||||||
headers.getItems().clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private HashMap<String, String> getCustomHeaders() {
|
|
||||||
HashMap<String, String> result = new HashMap<>();
|
|
||||||
Optional<TabPane> tabs = getRequestOptionsTab();
|
|
||||||
if (tabs.isPresent()) {
|
|
||||||
Node n = tabs.get().getTabs().get(RequestTab.HEADERS.getIndex()).getContent();
|
|
||||||
toHashMap(result, n, true);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getBody() {
|
|
||||||
Optional<TabPane> tabs = getRequestOptionsTab();
|
|
||||||
if (tabs.isPresent()) {
|
|
||||||
Node n = tabs.get().getTabs().get(RequestTab.BODY.getIndex()).getContent();
|
|
||||||
if (n instanceof TextArea) {
|
|
||||||
return ((TextArea) n).getText();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
private HashMap<String, String> getParamsMap() {
|
|
||||||
HashMap<String, String> result = new HashMap<>();
|
|
||||||
Optional<TabPane> tabs = getRequestOptionsTab();
|
|
||||||
if (tabs.isPresent()) {
|
|
||||||
Node n = tabs.get().getTabs().get(RequestTab.PARAMS.getIndex()).getContent();
|
|
||||||
toHashMap(result, n, false);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private void toHashMap(HashMap<String, String> result, Node n, boolean lowering) {
|
|
||||||
if (n instanceof TableView) {
|
|
||||||
TableView<Param> tv = (TableView<Param>) n;
|
|
||||||
for (Param p : tv.getItems()) {
|
|
||||||
if (!p.isEmpty()) {
|
|
||||||
String key = (lowering) ? p.getName().toLowerCase() : p.getName();
|
|
||||||
result.put(key, p.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Optional<TabPane> getRequestOptionsTab() {
|
|
||||||
Optional<SplitPane> requestTab = getCurrentRequestTab();
|
|
||||||
if (requestTab.isPresent()) {
|
|
||||||
Node n = requestTab.get().getItems().get(0);
|
|
||||||
if (n instanceof TabPane) {
|
|
||||||
return Optional.of((TabPane) n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Optional<SplitPane> getCurrentRequestTab() {
|
|
||||||
Node n = tabs.getSelectionModel().getSelectedItem().getContent();
|
|
||||||
if (n instanceof SplitPane) {
|
|
||||||
return Optional.of((SplitPane) n);
|
|
||||||
}
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Optional<TextArea> getCurrentTextArea() {
|
|
||||||
Optional<SplitPane> requestTab = getCurrentRequestTab();
|
|
||||||
if (requestTab.isPresent()) {
|
|
||||||
Node n = requestTab.get().getItems().get(1);//
|
|
||||||
if (n instanceof TextArea) {
|
|
||||||
return Optional.of((TextArea) n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Optional<Tab> getCurrentResponseTab() {
|
|
||||||
Optional<TabPane> requestTab = getRequestOptionsTab();
|
|
||||||
if (requestTab.isPresent()) {
|
|
||||||
Tab n = requestTab.get().getTabs().get(RequestTab.RESPONSE.getIndex());
|
|
||||||
return Optional.of(n);
|
|
||||||
}
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private void createNewTab() {
|
|
||||||
new Thread(() -> {
|
|
||||||
Tab t = newTab();
|
|
||||||
requests.put(t.hashCode(), "");
|
|
||||||
methods.put(t.hashCode(), httpMethod.getValue());
|
|
||||||
Platform.runLater(() -> {
|
|
||||||
tabs.getTabs().add(t);
|
|
||||||
tabs.getSelectionModel().select(t);
|
|
||||||
});
|
|
||||||
}).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStageAndSetupListeners(Stage s) {
|
|
||||||
primaryStage = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private void showConfigurationDialog() {
|
|
||||||
try {
|
|
||||||
Stage dialog = new Stage();
|
|
||||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("configuration.fxml"));
|
|
||||||
Parent xml = loader.load();
|
|
||||||
ConfigurationController controller = loader.getController();
|
|
||||||
controller.setStageAndSetupListeners(primaryStage);
|
|
||||||
controller.setConfigurationProperties(properties);
|
|
||||||
dialog.initOwner(primaryStage);
|
|
||||||
dialog.setScene(new Scene(xml, 412, 556));
|
|
||||||
dialog.setMaxHeight(556);
|
|
||||||
dialog.setMinHeight(556);
|
|
||||||
dialog.setMaxWidth(412);
|
|
||||||
dialog.setMinWidth(412);
|
|
||||||
dialog.setResizable(false);
|
|
||||||
dialog.setTitle("Settings");
|
|
||||||
dialog.getIcons().add( new Image(
|
|
||||||
Controller.class.getResourceAsStream( "icon.png" )));
|
|
||||||
dialog.initModality(Modality.APPLICATION_MODAL);
|
|
||||||
dialog.showAndWait();
|
|
||||||
} catch (IOException e) {
|
|
||||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
|
||||||
alert.setTitle("Cannot initialize Settings");
|
|
||||||
alert.setHeaderText("There was an error while initializing this dialog");
|
|
||||||
alert.setContentText(e.getMessage());
|
|
||||||
alert.showAndWait();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void httpMethodChanged() {
|
|
||||||
Tab tab = tabs.getSelectionModel().getSelectedItem();
|
|
||||||
methods.put(tab.hashCode(), httpMethod.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private void requestInputOnKeyPressed() {
|
|
||||||
Tab tab = tabs.getSelectionModel().getSelectedItem();
|
|
||||||
String url = requestInput.getText();
|
|
||||||
requests.put(tab.hashCode(), url);
|
|
||||||
if (url.isBlank()) {
|
|
||||||
tab.setText("Untitled");
|
|
||||||
} else {
|
|
||||||
url = URLGenerator.addSchemaToUrl(url);
|
|
||||||
UrlValidator urlValidator = new UrlValidator();
|
|
||||||
if (urlValidator.isValid(url)) {
|
|
||||||
try {
|
|
||||||
URL u = new URL(url);
|
|
||||||
tab.setText(u.getHost());
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
System.err.println(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
|
|
||||||
<?import javafx.scene.control.*?>
|
|
||||||
<?import javafx.scene.image.*?>
|
|
||||||
<?import javafx.scene.layout.*?>
|
|
||||||
<?import javafx.scene.text.*?>
|
|
||||||
|
|
||||||
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="365.0" prefWidth="707.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
|
|
||||||
<children>
|
|
||||||
<ImageView fitHeight="111.0" fitWidth="707.0" pickOnBounds="true" preserveRatio="true" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
|
||||||
<image>
|
|
||||||
<Image url="@banner.png" />
|
|
||||||
</image></ImageView>
|
|
||||||
<GridPane layoutX="32.0" layoutY="123.0" prefHeight="224.0" prefWidth="348.0">
|
|
||||||
<columnConstraints>
|
|
||||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
|
||||||
</columnConstraints>
|
|
||||||
<rowConstraints>
|
|
||||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
|
||||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
|
||||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
|
||||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
|
||||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
|
||||||
</rowConstraints>
|
|
||||||
<children>
|
|
||||||
<Label text="Author: Alexis Delhaie (@alexlegarnd)">
|
|
||||||
<font>
|
|
||||||
<Font size="13.0" />
|
|
||||||
</font>
|
|
||||||
</Label>
|
|
||||||
<Label text="Software: Java 14.0.2 (GUI: JavaFX 15)" GridPane.rowIndex="2">
|
|
||||||
<font>
|
|
||||||
<Font size="13.0" />
|
|
||||||
</font>
|
|
||||||
</Label>
|
|
||||||
<Label text="Installer: Delphi 10.3.3 Community" GridPane.rowIndex="3">
|
|
||||||
<font>
|
|
||||||
<Font size="13.0" />
|
|
||||||
</font>
|
|
||||||
</Label>
|
|
||||||
<Label text="Installer Bootstrap: Python 3.8.5 [MSC v.1924 (AMD64)]" GridPane.rowIndex="4">
|
|
||||||
<font>
|
|
||||||
<Font size="13.0" />
|
|
||||||
</font>
|
|
||||||
</Label>
|
|
||||||
<Label text="Version: 0.1.2 (Not finished)" GridPane.rowIndex="1">
|
|
||||||
<font>
|
|
||||||
<Font size="13.0" />
|
|
||||||
</font>
|
|
||||||
</Label>
|
|
||||||
</children>
|
|
||||||
</GridPane>
|
|
||||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="428.0" layoutY="111.0" prefHeight="224.0" prefWidth="216.0" text=" (((///////////////////////( *(((///////////////////////// , /(///////////////////////// /((/////////////////////// /(((////////////////////// / ((((((/////////////////// (((((((((((( ((((((((///////////////// (((((((((((((((((( .((((((((((/////////////// ((((((((((((((((((((((. ((((((((((((((/////////// (((((((((((((((((((((((((( (((((((((((((((((//////// ((((((((((((((((((((((((((((. ((((((((((((((((((((///// ((((((((((((((((((((((((((((((( ((((((((((((((((((((((((/ &(((((((((((((((((((((((((((((((( ((((((((((((((((((((((((( ((((((((((((((((((((((((((((((((( (( .(((((((((((((((( #####((((((((((((((((((((((((((((( (((((((((((((((((( #########(((((((((((((((((((((((( *((((*. (((((((((((((((((((( #############((((((((((((( ((((((((((((((((( ((((((((((((((((((((( ##################(((((((((((* (((((((((((((((((((. ((((((((((((((((((( &#####################(((((((((((, (((((((((((((((((((( (((((((((((((((( #########################(((((((( (((((((((((((((( ((((((((((((((( #############################((. ((((((((((/ /((((((((((((( ############################## ((((( (((((((((((( ############################# *((((((((((( ############################# ((((((((((( ############################ (((((((((( ############################ (((((((((( ############################, ((((((((((( ############################### #########(((( ############################################# ##################################### ######################### " textAlignment="CENTER" AnchorPane.bottomAnchor="30.0" AnchorPane.rightAnchor="63.0" AnchorPane.topAnchor="111.0">
|
|
||||||
<font>
|
|
||||||
<Font name="Consolas" size="4.0" />
|
|
||||||
</font>
|
|
||||||
</Label>
|
|
||||||
</children>
|
|
||||||
</AnchorPane>
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 43 KiB |
@@ -1,28 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
|
|
||||||
<?import javafx.scene.control.Button?>
|
|
||||||
<?import javafx.scene.control.CheckBox?>
|
|
||||||
<?import javafx.scene.control.ChoiceBox?>
|
|
||||||
<?import javafx.scene.control.Label?>
|
|
||||||
<?import javafx.scene.layout.AnchorPane?>
|
|
||||||
<?import javafx.scene.text.Font?>
|
|
||||||
|
|
||||||
<AnchorPane maxHeight="556.0" maxWidth="412.0" minHeight="556.0" minWidth="412.0" prefHeight="556.0" prefWidth="412.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ovh.alexisdelhaie.endpoint.controllers.ConfigurationController">
|
|
||||||
<Label layoutX="20.0" layoutY="14.0" text="SSL">
|
|
||||||
<font>
|
|
||||||
<Font name="System Bold" size="12.0" />
|
|
||||||
</font>
|
|
||||||
</Label>
|
|
||||||
<Label layoutX="20.0" layoutY="40.0" prefHeight="18.0" prefWidth="148.0" text="Allow invalid SSL certificate" />
|
|
||||||
<CheckBox fx:id="allowInvalidSsl" layoutX="381.0" layoutY="41.0" mnemonicParsing="false" onMouseClicked="#onBooleanValueChanged" AnchorPane.rightAnchor="14.199999999999989" AnchorPane.topAnchor="41.0" />
|
|
||||||
<Label layoutX="20.0" layoutY="59.0" prefHeight="18.0" prefWidth="148.0" text="Downgrade when SSL failed" />
|
|
||||||
<CheckBox fx:id="allowDowngrade" layoutX="381.0" layoutY="60.0" mnemonicParsing="false" onMouseClicked="#onBooleanValueChanged" selected="true" AnchorPane.rightAnchor="14.333333333333332" AnchorPane.topAnchor="60.0" />
|
|
||||||
<Button layoutX="14.0" layoutY="515.0" mnemonicParsing="false" onMouseClicked="#showAboutDialog" prefHeight="26.0" prefWidth="58.0" text="About" AnchorPane.bottomAnchor="15.0" AnchorPane.leftAnchor="14.0" />
|
|
||||||
<Label layoutX="20.0" layoutY="97.0" prefHeight="18.0" prefWidth="72.0" text="Requests">
|
|
||||||
<font>
|
|
||||||
<Font name="System Bold" size="12.0" />
|
|
||||||
</font>
|
|
||||||
</Label>
|
|
||||||
<Label layoutX="20.0" layoutY="126.0" prefHeight="18.0" prefWidth="72.0" text="HTTP version" />
|
|
||||||
<ChoiceBox fx:id="httpVersion" layoutX="308.0" layoutY="123.0" prefHeight="26.0" prefWidth="90.0" />
|
|
||||||
</AnchorPane>
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
|
|
||||||
<?import javafx.scene.control.*?>
|
|
||||||
<?import javafx.scene.layout.*?>
|
|
||||||
<?import javafx.scene.text.*?>
|
|
||||||
|
|
||||||
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="890.0" prefWidth="1149.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
|
|
||||||
<columnConstraints>
|
|
||||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="295.0" minWidth="0.0" prefWidth="19.33333381017049" />
|
|
||||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="344.3333333333333" minWidth="10.0" prefWidth="55.0" />
|
|
||||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="648.6666781107585" minWidth="10.0" prefWidth="359.0" />
|
|
||||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="668.0" minWidth="5.333333333333314" prefWidth="17.0" />
|
|
||||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="678.0" minWidth="10.0" prefWidth="674.0" />
|
|
||||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="632.6666361490886" minWidth="10.0" prefWidth="23.0" />
|
|
||||||
</columnConstraints>
|
|
||||||
<rowConstraints>
|
|
||||||
<RowConstraints maxHeight="128.00000762939453" minHeight="0.0" prefHeight="1.0" vgrow="SOMETIMES" />
|
|
||||||
<RowConstraints maxHeight="128.00000762939453" minHeight="0.0" prefHeight="16.0" vgrow="SOMETIMES" />
|
|
||||||
<RowConstraints maxHeight="201.0" minHeight="0.0" prefHeight="17.0" vgrow="SOMETIMES" />
|
|
||||||
<RowConstraints maxHeight="636.0" minHeight="10.0" prefHeight="461.0" vgrow="SOMETIMES" />
|
|
||||||
<RowConstraints maxHeight="188.0" minHeight="8.0" prefHeight="23.0" vgrow="SOMETIMES" />
|
|
||||||
<RowConstraints maxHeight="333.0" minHeight="10.0" prefHeight="326.0" vgrow="SOMETIMES" />
|
|
||||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
|
||||||
</rowConstraints>
|
|
||||||
<children>
|
|
||||||
<Label text="Time" GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
|
||||||
<Label text="Status" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
|
||||||
<Label fx:id="status" text="..." GridPane.columnIndex="2" GridPane.rowIndex="1">
|
|
||||||
<font>
|
|
||||||
<Font name="System Bold" size="12.0" />
|
|
||||||
</font></Label>
|
|
||||||
<Label fx:id="time" text="... ms" GridPane.columnIndex="2" GridPane.rowIndex="2">
|
|
||||||
<font>
|
|
||||||
<Font name="System Bold" size="12.0" />
|
|
||||||
</font></Label>
|
|
||||||
<TableView fx:id="headers" prefHeight="321.0" prefWidth="599.0" GridPane.columnIndex="1" GridPane.columnSpan="2" GridPane.rowIndex="3">
|
|
||||||
<columns>
|
|
||||||
<TableColumn prefWidth="75.0" text="Key" />
|
|
||||||
<TableColumn prefWidth="75.0" text="Value" />
|
|
||||||
</columns>
|
|
||||||
<columnResizePolicy>
|
|
||||||
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
|
|
||||||
</columnResizePolicy>
|
|
||||||
</TableView>
|
|
||||||
<TextArea fx:id="raw" editable="false" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="4" GridPane.rowIndex="3">
|
|
||||||
<font>
|
|
||||||
<Font name="Consolas" size="12.0" />
|
|
||||||
</font>
|
|
||||||
</TextArea>
|
|
||||||
<Label text="Raw" GridPane.columnIndex="4" GridPane.rowIndex="2" />
|
|
||||||
<TextArea fx:id="request" editable="false" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="4" GridPane.rowIndex="5">
|
|
||||||
<font>
|
|
||||||
<Font name="Consolas" size="12.0" />
|
|
||||||
</font>
|
|
||||||
</TextArea>
|
|
||||||
<Label text="Sent request" GridPane.columnIndex="4" GridPane.rowIndex="4" />
|
|
||||||
<GridPane fx:id="downgraded_indicator" visible="false" GridPane.columnIndex="4" GridPane.rowIndex="1">
|
|
||||||
<columnConstraints>
|
|
||||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="382.0" minWidth="10.0" prefWidth="30.0" />
|
|
||||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="644.0" minWidth="10.0" prefWidth="644.0" />
|
|
||||||
</columnConstraints>
|
|
||||||
<rowConstraints>
|
|
||||||
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
|
|
||||||
</rowConstraints>
|
|
||||||
<children>
|
|
||||||
<Label prefHeight="17.0" prefWidth="354.0" text="This request was downgraded from SSL to plain text" textFill="#cfa600" GridPane.columnIndex="1" />
|
|
||||||
<Label alignment="CENTER" contentDisplay="CENTER" prefHeight="22.0" prefWidth="37.0" text="" textAlignment="CENTER" textFill="#cfa600">
|
|
||||||
<font>
|
|
||||||
<Font name="Segoe MDL2 Assets" size="20.0" />
|
|
||||||
</font>
|
|
||||||
</Label>
|
|
||||||
</children>
|
|
||||||
</GridPane>
|
|
||||||
</children>
|
|
||||||
</GridPane>
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 22 KiB |
@@ -1,135 +0,0 @@
|
|||||||
/*
|
|
||||||
Stolen code from Github : https://gist.github.com/james-d/be5bbd6255a4640a5357#file-editcell-java-L109
|
|
||||||
*/
|
|
||||||
package ovh.alexisdelhaie.endpoint.impl;
|
|
||||||
|
|
||||||
import javafx.event.Event;
|
|
||||||
import javafx.scene.control.ContentDisplay;
|
|
||||||
import javafx.scene.control.TableCell;
|
|
||||||
import javafx.scene.control.TableColumn;
|
|
||||||
import javafx.scene.control.TableColumn.CellEditEvent;
|
|
||||||
import javafx.scene.control.TablePosition;
|
|
||||||
import javafx.scene.control.TableView;
|
|
||||||
import javafx.scene.control.TextField;
|
|
||||||
import javafx.scene.input.KeyCode;
|
|
||||||
import javafx.scene.input.KeyEvent;
|
|
||||||
import javafx.util.StringConverter;
|
|
||||||
|
|
||||||
|
|
||||||
public class EditCell<S, T> extends TableCell<S, T> {
|
|
||||||
|
|
||||||
// Text field for editing
|
|
||||||
// TODO: allow this to be a plugable control.
|
|
||||||
private final TextField textField = new TextField();
|
|
||||||
|
|
||||||
// Converter for converting the text in the text field to the user type, and vice-versa:
|
|
||||||
private final StringConverter<T> converter ;
|
|
||||||
|
|
||||||
public EditCell(StringConverter<T> converter) {
|
|
||||||
this.converter = converter ;
|
|
||||||
|
|
||||||
itemProperty().addListener((obx, oldItem, newItem) -> {
|
|
||||||
if (newItem == null) {
|
|
||||||
setText(null);
|
|
||||||
} else {
|
|
||||||
setText(converter.toString(newItem));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
setGraphic(textField);
|
|
||||||
setContentDisplay(ContentDisplay.TEXT_ONLY);
|
|
||||||
|
|
||||||
textField.setOnAction(evt -> {
|
|
||||||
commitEdit(this.converter.fromString(textField.getText()));
|
|
||||||
});
|
|
||||||
textField.focusedProperty().addListener((obs, wasFocused, isNowFocused) -> {
|
|
||||||
if (! isNowFocused) {
|
|
||||||
commitEdit(this.converter.fromString(textField.getText()));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
textField.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
|
|
||||||
if (event.getCode() == KeyCode.ESCAPE) {
|
|
||||||
textField.setText(converter.toString(getItem()));
|
|
||||||
cancelEdit();
|
|
||||||
event.consume();
|
|
||||||
} else if (event.getCode() == KeyCode.RIGHT) {
|
|
||||||
getTableView().getSelectionModel().selectRightCell();
|
|
||||||
event.consume();
|
|
||||||
} else if (event.getCode() == KeyCode.LEFT) {
|
|
||||||
getTableView().getSelectionModel().selectLeftCell();
|
|
||||||
event.consume();
|
|
||||||
} else if (event.getCode() == KeyCode.UP) {
|
|
||||||
getTableView().getSelectionModel().selectAboveCell();
|
|
||||||
event.consume();
|
|
||||||
} else if (event.getCode() == KeyCode.DOWN) {
|
|
||||||
getTableView().getSelectionModel().selectBelowCell();
|
|
||||||
event.consume();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenience converter that does nothing (converts Strings to themselves and vice-versa...).
|
|
||||||
*/
|
|
||||||
public static final StringConverter<String> IDENTITY_CONVERTER = new StringConverter<String>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString(String object) {
|
|
||||||
return object;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String fromString(String string) {
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenience method for creating an EditCell for a String value.
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static <S> EditCell<S, String> createStringEditCell() {
|
|
||||||
return new EditCell<S, String>(IDENTITY_CONVERTER);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// set the text of the text field and display the graphic
|
|
||||||
@Override
|
|
||||||
public void startEdit() {
|
|
||||||
super.startEdit();
|
|
||||||
textField.setText(converter.toString(getItem()));
|
|
||||||
setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
|
|
||||||
textField.requestFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
// revert to text display
|
|
||||||
@Override
|
|
||||||
public void cancelEdit() {
|
|
||||||
super.cancelEdit();
|
|
||||||
setContentDisplay(ContentDisplay.TEXT_ONLY);
|
|
||||||
}
|
|
||||||
|
|
||||||
// commits the edit. Update property if possible and revert to text display
|
|
||||||
@Override
|
|
||||||
public void commitEdit(T item) {
|
|
||||||
|
|
||||||
// This block is necessary to support commit on losing focus, because the baked-in mechanism
|
|
||||||
// sets our editing state to false before we can intercept the loss of focus.
|
|
||||||
// The default commitEdit(...) method simply bails if we are not editing...
|
|
||||||
if (! isEditing() && ! item.equals(getItem())) {
|
|
||||||
TableView<S> table = getTableView();
|
|
||||||
if (table != null) {
|
|
||||||
TableColumn<S, T> column = getTableColumn();
|
|
||||||
CellEditEvent<S, T> event = new CellEditEvent<>(table,
|
|
||||||
new TablePosition<S,T>(table, getIndex(), column),
|
|
||||||
TableColumn.editCommitEvent(), item);
|
|
||||||
Event.fireEvent(column, event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
super.commitEdit(item);
|
|
||||||
|
|
||||||
setContentDisplay(ContentDisplay.TEXT_ONLY);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
|
|
||||||
<?import javafx.scene.control.*?>
|
|
||||||
<?import javafx.scene.layout.*?>
|
|
||||||
|
|
||||||
<AnchorPane xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ovh.alexisdelhaie.endpoint.controllers.Controller">
|
|
||||||
<TextField fx:id="requestInput" layoutX="109.0" layoutY="39.0" onKeyTyped="#requestInputOnKeyPressed" prefHeight="25.0" prefWidth="861.0" AnchorPane.leftAnchor="109.0" AnchorPane.rightAnchor="96.99999999999989" AnchorPane.topAnchor="39.0" />
|
|
||||||
<Button layoutX="979.0" layoutY="39.0" mnemonicParsing="false" onMouseClicked="#start" prefHeight="25.0" prefWidth="73.0" text="Send" AnchorPane.rightAnchor="16.0" AnchorPane.topAnchor="39.0" />
|
|
||||||
<ChoiceBox id="httpMethod" fx:id="httpMethod" layoutX="14.0" layoutY="39.0" prefHeight="25.0" prefWidth="85.0" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="39.0" />
|
|
||||||
<Label layoutX="109.0" layoutY="21.0" text="Request URL" />
|
|
||||||
<TabPane fx:id="tabs" layoutX="-1.0" layoutY="104.0" prefHeight="540.0" prefWidth="1067.0" tabClosingPolicy="ALL_TABS" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="104.0">
|
|
||||||
</TabPane>
|
|
||||||
<Button layoutX="1022.0" layoutY="71.0" mnemonicParsing="false" onMouseClicked="#createNewTab" prefHeight="25.0" prefWidth="31.0" text="+" AnchorPane.rightAnchor="16.0" AnchorPane.topAnchor="71.0" />
|
|
||||||
<Button layoutX="1020.0" layoutY="8.0" mnemonicParsing="false" onMouseClicked="#showConfigurationDialog" prefHeight="25.0" prefWidth="73.0" text="Settings" AnchorPane.rightAnchor="16.0" AnchorPane.topAnchor="8.0" />
|
|
||||||
<Pane fx:id="runningIndicatorPane" layoutX="109.0" layoutY="74.0" prefHeight="17.0" prefWidth="200.0" visible="false">
|
|
||||||
<children>
|
|
||||||
<ProgressIndicator layoutX="2.0" layoutY="1.0" prefHeight="17.0" prefWidth="18.0" />
|
|
||||||
<Label layoutX="23.0" layoutY="1.0" prefHeight="17.0" prefWidth="133.0" text="Running..." />
|
|
||||||
</children>
|
|
||||||
</Pane>
|
|
||||||
</AnchorPane>
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
package ovh.alexisdelhaie.endpoint.model;
|
|
||||||
|
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
|
||||||
import javafx.beans.property.StringProperty;
|
|
||||||
|
|
||||||
public class Param {
|
|
||||||
|
|
||||||
private final StringProperty _name = new SimpleStringProperty();
|
|
||||||
private final StringProperty _value = new SimpleStringProperty();
|
|
||||||
|
|
||||||
public Param() {
|
|
||||||
_name.set("");
|
|
||||||
_value.set("");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Param(String n, String v) {
|
|
||||||
_name.set(n);
|
|
||||||
_value.set(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return _name.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public StringProperty name() {
|
|
||||||
return _name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getValue() {
|
|
||||||
return _value.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public StringProperty value() {
|
|
||||||
return _value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return (_name.get().isBlank() && _value.get().isBlank());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
final StringBuffer sb = new StringBuffer("Param{");
|
|
||||||
sb.append("_name=").append(_name.get());
|
|
||||||
sb.append(", _value=").append(_value.get());
|
|
||||||
sb.append('}');
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user